int x, y; float speed; int direction; void setup() { size(600,300); x = 0; y = 300; speed = 0; direction = 1; } void draw() { background(255,255,255); drawCar(x); x = int(x + speed); if (x < 0) { x = 0; speed = 0; } else if (x+100 > width) { x = width - 100; speed = 0; } speed = speed + (0.10*direction); println(speed); } void mousePressed() { direction = direction * -1; } void drawCar(int x) { // Draw the body fill(150,150,150); // gray rect(x, y-30, 100, 20); quad(x+20,y-30,x+30,y-45,x+55,y-45,x+70,y-30); // Draw the wheels fill(0,0,0); // black ellipse(x+20, y-10, 20, 20); ellipse(x+75, y-10, 20, 20); fill(255,255,255); // white ellipse(x+20, y-10, 10, 10); ellipse(x+75, y-10, 10, 10); }