Created
December 13, 2014 04:21
-
-
Save edsonsoares/a8d559c6e44446e2c181 to your computer and use it in GitHub Desktop.
Code for dance game inspired on Voguing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CLass Lettering (variable X&Y positions, size and alpha) | |
class Lettering { | |
String text; | |
float x; | |
float y; | |
color col; | |
PFont font; | |
int fontSize; | |
Lettering (PFont tempFont, int tempFontSize, String tempText, float tempX, float tempY) { | |
font = tempFont; | |
fontSize = tempFontSize; | |
text = tempText; | |
x = tempX; | |
y = tempY; | |
} | |
void setColor (color tempColor) { | |
col = tempColor; | |
} | |
void setText(String newText) { | |
text = newText; | |
} | |
void setPosition (float xTemp, float yTemp) { | |
x = xTemp; | |
y = yTemp; | |
} | |
void display () { | |
textFont (font, fontSize); | |
fill (col); | |
text(text, x, y); | |
} | |
void disappear () { | |
col = color(0,0,0,0); | |
} | |
} // End of Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Title { | |
String title = "VOGUING"; | |
PFont font = createFont("Didot", 64); | |
float x; | |
float y; | |
float speed; | |
Title (float tempx, float tempspeed) { | |
x = tempx; | |
speed = tempspeed; | |
} | |
void write () { | |
textFont(font); | |
textSize(900); | |
//fill(255, 95, 165, 100); | |
fill(232, 169, 12, 100); | |
//fill(255, 0, 0, 100); | |
text(title, x, y); | |
y = 270; | |
} | |
void move () { | |
x = x - speed; | |
if (x < width - 10000) { | |
x = width - 10000; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.video.*; | |
// Elements Background video | |
Movie video; | |
// Elements Capture Cam | |
// cam | |
Capture cam; | |
// previous camera frame | |
PImage prevCamFrame; | |
PImage camImage; | |
float threshold = 100; | |
// Elements timer | |
int savedTime; // When Timer started | |
int passedTime; //Time passed | |
int totalTime = 150000; // Total Time | |
//Text Elements | |
// Intro "Voguing" | |
Title title1; | |
//Arraylist of words (incentive words for the user) | |
Lettering[] words; | |
PFont font; | |
void setup() { | |
//GENERAL | |
//frameRate(30); | |
size(1280, 720, P2D); | |
textMode(SHAPE); | |
savedTime = millis(); | |
//CAMERA | |
//println(Capture.list()); | |
//Filming with built in camera | |
cam = new Capture(this, 1280, 720); | |
//Filming from the webcam: | |
//cam = new Capture(this, "name=Logitech Camera,size=800x600,fps=30"); | |
cam.start(); | |
// Create an empty image the same size as the cam | |
prevCamFrame = createImage(1280, 720, RGB); | |
camImage = createImage(cam.width, cam.height, ARGB); | |
//VIDEO FILE | |
video = new Movie(this, "backvideo2.mov"); | |
video.play(); | |
//LETTERINGS | |
//title | |
title1 = new Title (2800, 8); | |
//Initialize the Arraylist of words | |
words = new Lettering[10]; | |
font = createFont("Story Book.otf", 32); | |
textAlign(CENTER, CENTER); | |
words[0] = new Lettering( font, 250, "Start", width/2, height/2); | |
words[0].setColor( color(255, 95, 165, 255) ); | |
words[1] = new Lettering(font, 100, "Werk, God Damnit!", width/2, height/2); | |
words[1].setColor( color(255, 95, 165, 255) ); | |
words[2] = new Lettering(font, 50, "EXTRAVAGANZA", 10, 80); | |
words[2].setColor( color(255, 255, 255, 255) ); | |
words[3] = new Lettering(font, 150, "BAM!", 10, 40); | |
words[3].setColor( color(255, 255, 255, 255) ); | |
words[4] = new Lettering(font, 130, "Fierce", 10, 40); | |
words[4].setColor( color(217, 217, 217, 127) ); | |
words[5] = new Lettering(font, 110, "House Down", width/2, 200); | |
words[5].setColor( color(0, 0, 0, 255) ); | |
words[6] = new Lettering(font, 60, "Score", width/2, 270); | |
words[6].setColor( color(0, 0, 0, 255) ); | |
words[7] = new Lettering(font, 170, "80.9", width/2, 350); | |
words[7].setColor( color(0, 0, 0, 255) ); | |
} | |
void draw() { | |
//Calculate How much time has passed | |
int passedTime = millis() - savedTime; | |
// raise the tint back up to 100% opacity | |
tint(255, 255); | |
//drawTheBackgroundDancer(); | |
image(video, 0, 0, width, height); | |
// Name of the game | |
title1.write(); | |
title1.move(); | |
// if the title1 x is lower than a certain variable, draw the camera. | |
if (title1.x < width - 4000) { | |
drawTheCamera(); | |
} | |
if ((title1.x < width - 4000) && (title1.x > width - 4300)) { | |
words[0].display(); | |
} | |
if (passedTime > 30000 & passedTime < 34000) { | |
words[1].display(); | |
} | |
if (passedTime > 55000 & passedTime < 58000) { | |
words[2].setColor(color(random(100, 255), 0, random(100, 255))); | |
words[2].setPosition(190, 144); | |
words[2].display(); | |
words[2].setPosition(190, 288); | |
words[2].display(); | |
words[2].setPosition(190, 432); | |
words[2].display(); | |
words[2].setPosition(190, 576); | |
words[2].display(); | |
words[2].setPosition(width - 190, 144); | |
words[2].display(); | |
words[2].setPosition(width - 190, 288); | |
words[2].display(); | |
words[2].setPosition(width - 190, 432); | |
words[2].display(); | |
words[2].setPosition(width - 10, 576); | |
words[2].display(); | |
} | |
if (passedTime > 82500 & passedTime < 84500) { | |
words[3].setColor(color(255)); | |
words[3].setPosition(320, height/2); | |
words[3].display(); | |
words[3].setPosition(960, height/2); | |
words[3].display(); | |
} | |
if (passedTime > 105000 & passedTime < 115000) { | |
words[4].setPosition(20, height/2); | |
words[4].display(); | |
words[4].setPosition(320, height/2); | |
words[4].display(); | |
words[4].setPosition(860, height/2); | |
words[4].display(); | |
words[4].setPosition(1160, height/2); | |
words[4].display(); | |
} | |
if (passedTime > 140000 & passedTime < 160000) { | |
words[5].display(); | |
words[6].display(); | |
words[7].display(); | |
} | |
} | |
void movieEvent(Movie video) { | |
video.read(); | |
} | |
void drawTheCamera() { | |
// Save previous frame for motion detection | |
prevCamFrame.copy(cam, 0, 0, cam.width, cam.height, 0, 0, cam.width, cam.height); | |
prevCamFrame.updatePixels(); //Read image from the camera | |
cam.read(); | |
pushMatrix(); | |
translate(0, 0); | |
//we need to do the motion detection here | |
cam.loadPixels(); | |
camImage.loadPixels(); | |
prevCamFrame.loadPixels(); | |
// Begin loop to walk through every pixel | |
for (int x = 0; x < cam.width; x ++ ) { | |
for (int y = 0; y < cam.height; y ++ ) { | |
int loc = x + y*cam.width; // Step 1, what is the 1D pixel location | |
color current = cam.pixels[loc]; // Step 2, what is the current color | |
color previous = prevCamFrame.pixels[loc]; // Step 3, what is the previous color | |
// Step 4, compare colors (previous vs. current) | |
float r1 = red(current); | |
float g1 = green(current); | |
float b1 = blue(current); | |
float r2 = red(previous); | |
float g2 = green(previous); | |
float b2 = blue(previous); | |
float diff = dist(r1, g1, b1, r2, g2, b2); | |
// Step 5, How different are the colors? | |
// If the color at that pixel has changed, then there is motion at that pixel. | |
if (diff > threshold) { | |
// If motion, display black | |
camImage.pixels[loc] = color(255, 95, 165, 255); | |
} else { | |
// If not, display white | |
camImage.pixels[loc] = color(0, 0, 0, 0); | |
} | |
} | |
} | |
camImage.updatePixels(); | |
//} | |
// flipping the video | |
pushMatrix(); | |
scale(-1.0, 1.0); | |
image(camImage, -camImage.width, 0); | |
popMatrix(); | |
popMatrix(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment