P4P2010-05-13

From Noisebridge
Revision as of 22:43, 13 May 2010 by Jtfoote (talk | contribs) (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; …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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);
}