// Animates a car with spinning wheels and // a headlight traveling across screen. int xval =-35; int dx = 1; int angle = 0; void setup() { size(600,150); rectMode(CENTER); ellipseMode(CENTER); } void draw() { background(100); carMotion(); } void carMotion() { pushMatrix(); translate(xval, height/2); light(); carBody(); pushMatrix(); translate(20, 15); rotate(radians(angle)); wheel(); popMatrix(); pushMatrix(); translate(-20, 15); rotate(radians(angle)); wheel(); popMatrix(); xval += dx; angle+= 5; if (xval > width+35) xval = 0; popMatrix(); } void carBody() { fill(180,180,255); rect(0,-25,30,20); fill(80,80,255); rect(0,0,70,30); } void light() { noStroke(); fill(255,255,0); if ( (xval% 10) < 5) { triangle(35,0,width+35,10,width+35,-10); } rect(35,0,10,10); stroke(0); } void wheel() { fill(0); ellipse(0,0,20,20); fill(155,100,0); rect(0,0,20,6); }