int x, y; float speed; void setup() { size(600,300); x = 0; y = 300; speed = 0; } void draw() { background(255,255,255); drawCar(x); x = int(x + speed); if (x+100 > width) noLoop(); if (x+50 < width/2) speed = speed + 0.10; else speed = speed - 0.10; speed = max(0, speed); } 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); }