// Draw truck(s)
void setup() { // all sketch setup goes here size(400, 400); smooth(); background(255); } // setup()
void draw() { fill(255, 0, 0); ellipse(width/2, height/2, 100, 100); } // draw()
void mousePressed() { noStroke(); fill(random(80, 220)); truck(mouseX, mouseY, random(50, 120)); } // mousePressed()
void truck(float x, float y, float w) { //rect(x, y-h, w, h); float h; h = w/2; // draw body of truck beginShape(); vertex(x, y-0.1*h); vertex(x, y-h); vertex(x+0.6*w, y-h); vertex(x+0.75*w, y-0.5*h); vertex(x+w, y-0.5*h); vertex(x+w, y-0.1*h); endShape(CLOSE); // draw the driver's window fill(255); triangle(x+0.6*w, y-0.95*h, x+0.6*w, y-0.5*h, x+0.7*w, y-0.5*h); // Draw the wheels fill(0); ellipse(x+0.25*w, y-0.1*h, 0.2*h, 0.2*h); ellipse(x+0.75*w, y-0.1*h, 0.2*h, 0.2*h); } // truck()