This is a joint project between me and John Holder. You play a variation on Tetris by moving left and right in front of a video camera. The game tracks movement using a very simple tracking algorithm that runs a lot faster than using an overkill tracking library.
Code:
//white tracking function, scans source image for the greatest value of brightness in vertical columns
//the return value is the brightest column scanned
static int trackWhite(PImage source, int columns, int columnWidth, int speed){
int [] brightnessTotal = new int[columns];
for(int i = 0; i < columns; i++){
for(int j = 0; j < source.height; j++){
for(int k = 0; k < columnWidth; k += speed){
int pixel = (i * columnWidth) + k + j * source.width;
brightnessTotal[i] += grey(source.pixels[pixel]);
}
}
}
int brightest = -1;
int bright = -1;
for(int i = 0; i < columns; i++){
if(brightnessTotal[i] > brightest){
bright = i;
brightest = brightnessTotal[i];
}
}
return bright;
}
//integer brightness function for extra speed
static int grey(color p){
return max((p >> 16) & 0xFF, (p >> 8) & 0xFF, p & 0xFF);
}
The game also features a 3D font called
quadText which has functions to render it and an object which generates wobbly quadText.
The unfinished project page is
here and has a link to a source code archive.
Honourable mentions to Fry for the speedy brightness value function and JohnG whose work inspired the quadText function and classes.
If anyone has comments on how better to present the project page, if the code is hard to read or any general feedback, I invite you to respond to this post.