Due Date:
Work should be submitted via WISE Wednesday, Feb 10, 2010, 30 minutes before the beginning of class.
Become familiar with conditional expressions, animation, and functions.
In class we cover the basics of these topics. If you want more examples, more depth, or further explanations, please refer to the following pages of the text.
int a = 0;
void setup() {
size(200, 200);
background(0);
}
void draw() {
rect(a, 0, 10, height);
a = a+1;
if (a == width) {
a = 0;
}
}
There is a lot going in this program that isn't obvious:
Experiment with boolean expressions and boolean operators: Modify the draw() function so that the rectangle moves differently, e.g. up/down, back and forth, other...
Create a user defined function that combines several shapes into a more complex shape whose location, like the rectangle,
is determined by the "a" variable. Call it from setup(). (remove draw() temporarily). For example:
int a = 20;
void setup() {
size(200, 200);
background(0);
snowMan();
}
void snowMan() {
ellipseMode(CENTER);
ellipse(a, 30, 20,20);
ellipse(a, 50, 30,30);
ellipse(a, 85, 50,50);
}
int a = 20;
void setup() {
size(200, 200);
background(0);
}
void draw() {
background(0);
snowMan();
a = a+1;
if (a == width) {
a = 0;
}
}
void snowMan() {
ellipseMode(CENTER);
ellipse(a, 30, 20,20);
ellipse(a, 50, 30,30);
ellipse(a, 85, 50,50);
}
Partner up with at one or two other people. Copy your partners' shape functions (e.g. snowMan) into to your code so that you have now have your shape function as well as theirs. Call all of the shape functions from draw(). (If their code is long you might want to exchange the code using a thumbdrive.) Can you get the different shapes to appear to move independently? Feel free to modify their code and expand on your code in any way.
No matter what you do, make sure you:
Saving a snapshot of your animation: If you add the function to your code:
then, Processing will save your animation to an image whenever you press a key on the keyboard. Add this code and
save an image at an interesting point in your animation.
void keyPressed() {
save("snowman.png");
}
Saving the animation as an applet: When you have an animation that you like, go to the Processing Menu and choose "file->Export". This will create and open up a folder that contains a Java applet and an html web page (you can place this on your own web page if you want). Double click on the file called index.html to watch your animation run.
Wednesday, Feb 10, 30 minutes before class:
You are to turn in via Wise a single zipped file containing your Processing sketch folder for your final animation. The sketch folder should include the 1) Processing code, 2) an image snapshot, and 3) the folder with the applet. In the submission text area of Wise, please list the names of your partners.
Before turning in any of your code, make sure that you have cleaned it up as follows:
- Delete any unused code.
- Formatted the code so that it is easy to read (e.g use the auto format tool).
- Added comments so that someone else looking at the code can follow what the code does.