Assignment 3.2

Post date: Jun 24, 2010 3:33:15 AM

Piano code:

void setup() {

size(600, 400); // sets size

background(225); // sets background color to white

}

void draw() {

fill(0); // sets fill color to black

rect(50, 50, 500, 300); // draws rectangle for backboard of piano

fill(225); // sets fill color to white

rect(60, 100, 50, 240); // draws rectangles for keys

rect(121, 100, 50, 240);

rect(182, 100, 50, 240);

rect(243, 100, 50, 240);

rect(307, 100, 50, 240);

rect(368, 100, 50, 240);

rect(429, 100, 50, 240);

rect(490, 100, 50, 240);

}

void keyPressed(){

int keyIndexq = -1; // sets key, in this case q, as variable to

if(key >= 'P' && key <= 'Q') { // carry out the specific function

keyIndexq = key - 'Q';

}else if (key >= 'p' && key <= 'q'){

keyIndexq = key-'q';

fill(0);

rect(60, 100, 50, 240); // fills over white key, makes it black

fill(50);

rect(60, 100, 50, 210); // draws new rectangle indicating key being pressed

delay(20); // gives a slight delay so when the key is held down,

} // the key will also have the appearance of being held down

int keyIndexw = -1;

if(key >= 'W' && key <= 'X') {

keyIndexw = key - 'W';

}else if (key >= 'w' && key <= 'x'){

keyIndexw = key-'w';

fill(0);

rect(121, 100, 50, 240);

fill(50);

rect(121, 100, 50, 210);

delay(20);

}

int keyIndexe = -1; // I borrowed this snippet of code from the keyboard basic example

if(key >= 'D' && key <= 'E') { // it can be found at http://processing.org/learning/basics/keyboard.html

keyIndexe = key - 'E';

}else if (key >= 'd' && key <= 'e'){

keyIndexe = key-'e';

fill(0);

rect(182, 100, 50, 240);

fill(50);

rect(182, 100, 50, 210);

delay(20);

}

int keyIndexr = -1;

if(key >= 'R' && key <= 'S') {

keyIndexr = key - 'R';

}else if (key >= 'r' && key <= 's'){

keyIndexr = key-'r';

fill(0);

rect(243, 100, 50, 240);

fill(50);

rect(243, 100, 50, 210);

delay(20);

}

int keyIndexy = -1;

if(key >= 'Y' && key <= 'Z') {

keyIndexy = key - 'Y';

}else if (key >= 'y' && key <= 'z'){

keyIndexy = key-'y';

fill(0);

rect(307, 100, 50, 240);

fill(50);

rect(307, 100, 50, 210);

delay(20);

}

int keyIndexu = -1;

if(key >= 'U' && key <= 'V') {

keyIndexu = key - 'U';

}else if (key >= 'u' && key <= 'v'){

keyIndexu = key-'u';

fill(0);

rect(368, 100, 50, 240);

fill(50);

rect(368, 100, 50, 210);

delay(20);

}

int keyIndexi = -1;

if(key >= 'I' && key <= 'J') {

keyIndexi = key - 'I';

}else if (key >= 'i' && key <= 'j'){

keyIndexi = key-'i';

fill(0);

rect(429, 100, 50, 240);

fill(50);

rect(429, 100, 50, 210);

delay(20);

}

int keyIndexo = -1;

if(key >= 'N' && key <= 'O') {

keyIndexo = key - 'O';

}else if (key >= 'n' && key <= 'o'){

keyIndexo = key-'o';

fill(0);

rect(490, 100, 50, 240);

fill(50);

rect(490, 100, 50, 210);

delay(20);

}

}

This draws a keyboard with 8 notes. It uses keys Q, W, E, R, Y, U, I, and O, corresponding to each key, from left to right. When each key on the keyboard is pressed, the corresponding key on the program will appear as if it has been pressed. When the key on the keyboard is held down, the key on the program will appear as if it is held down as well.

I could not upload the video to youtube so I could post it on here. How do I convert a .swf file to a .MPEG-2 file? I added the video as an attachment instead.