P4P2010-05-13: Difference between revisions
Jump to navigation
Jump to search
(Created page with 'Programming for Poets, class 5/13 We went through varibles and functions, and created a program pongball that is the first start towards a bouncing Pong ball int ballx = 0; …') |
No edit summary |
||
| Line 9: | Line 9: | ||
int pballx = 0; | int pballx = 0; | ||
int pbally = 200; | int pbally = 200; | ||
void setup() { | void setup() { | ||
// size of our drawing window | // size of our drawing window | ||
| Line 17: | Line 17: | ||
background(128); | background(128); | ||
} | } | ||
void draw() { | void draw() { | ||
| Line 24: | Line 24: | ||
fill(128); | fill(128); | ||
drawball(pballx,pbally); | drawball(pballx,pbally); | ||
// update the ball location | // update the ball location | ||
ballx = ballx + 2; | ballx = ballx + 2; | ||
bally = bally + 1; | bally = bally + 1; | ||
// and draw it | // and draw it | ||
stroke(255); | stroke(255); | ||
Latest revision as of 22:44, 13 May 2010
Programming for Poets, class 5/13
We went through varibles and functions, and created a program pongball that is the first start towards a bouncing Pong ball
int ballx = 0;
int bally = 200;
int pballx = 0;
int pbally = 200;
void setup() {
// size of our drawing window
size(400, 400);
// set the background color to gray
background(128);
}
void draw() {
// draw over the previous ball location
stroke(128); // gray
fill(128);
drawball(pballx,pbally);
// update the ball location
ballx = ballx + 2;
bally = bally + 1;
// and draw it
stroke(255);
fill(255); //white
drawball(ballx,bally);
// save the new location for next time
pballx = ballx;
pbally = bally;
}
// draw a paddle-shaped box at the given coordinates
void drawbox(int x, int y) {
rect(30,y,10,40);
}
// draw a ball at the given coordinates
void drawball(int foo, int bar) {
ellipse(foo,bar,10,10);
}