// Dartmouth CS 2, Winter 2009, Chris Bailey-Kellogg // Notes 7 | Sketch 2 // The current coordinates of the ball float x, y; // Step sizes float dx=1, dy=1; void setup() { size(400,400); smooth(); background(0); fill(255); noStroke(); println("x/X: de/increase x step size"); println("y/Y: de/increase y step size"); println("c: go to center of window"); x = width/2; y = height/2; } void draw() { background(0); ellipse(x,y,20,20); // take a step, but stay on screen x += dx; x = constrain(x,0,width); y += dy; y = constrain(y,0,height); } void keyPressed() { if (key=='x') dx--; else if (key=='X') dx++; else if (key=='y') dy--; else if (key=='Y') dy++; else if (key=='c') { x = width/2; y = height/2; } println("dx:"+dx+", dy:"+dy); }