Graphics & Interactive Programming Lab 1 M. Meyer */ /** ******************** Use setup() to specify things that need to be done once, at the beggining of the sketch */ void setup() { background( #eeeeee ); size (500, 500); } /** ******************** Use draw() to specify things that you want to have done repeatedly. NOTE: draw() must be present in your program, even if it is left empty. */ void draw() { } /** ******************** Event Listners: Use event-listners like keyPressed() to allow users of your program to cause things to happen. */ void keyPressed() { if ( key == 'A' || key == 'a' ) { // || means 'or' background( #eeeeee ); } else if ( key =='S' || key == 's' ) { /* Make a snowman */ strokeWeight(1); stroke(#000000); fill(#ffffff); ellipse(250, 300, 90, 90); ellipse(250, 250, 50, 50); ellipse(250, 220, 30, 30); } else if ( key == 'D' || key == 'd' ) { /* Dress the snowman */ strokeWeight(2); // 4 pixels wide point(245, 215); // Left Eye point(255, 215); // Right Eye arc(250, 220, 20, 20, 0, PI); } else if ( key == 'F' || key == 'f' ) { // Give the snowman arms strokeWeight(3); line(225, 250, 200, 270); line(200, 270, 225, 290); line(275, 250, 300, 230); line(300, 230, 285, 220); } else if ( key == 'G' || key == 'g' ) { // Arm the snowman with a bazooka strokeWeight(1); fill(#8B8A8A); quad(190, 310, 200, 320, 320, 190, 310, 180); quad(190, 300, 180, 310, 200, 330, 210, 320); quad(310, 170, 300, 180, 320, 200, 330, 190); // Redraw arms strokeWeight(3); line(300, 230, 285, 220); line(200, 270, 225, 290); } else if ( key == 'H' || key == 'h' ) { killersnowman(); } } /** ******************** Functions: Functions are sections of code that you create and name. Below we have created a single function called killersnowman(). I can run the commands that are included in killersnowman() from anywhere in the program by "calling" the function. See the last 'else if' statement in the eventlistner section for an example.

Source code: Lab1_Example

Built with Processing