void setup() { size(500, 200); fill(0, 200, 0); caterpillar(50, 50, 20, 10); caterpillar(50, 100, 10, 5); fill(255, 255, 0); caterpillar(100, 150, 10, 10); } /* Render a caterpillar with n overlapping body segments, each with radius r, and with the head at the left end, centered at (x,y). */ void caterpillar(int x, int y, int r, int n) { float space = r; for (int k=r-1; k >= 0; k--) { ellipse(x+k*space, y, 2*r, 2*r); } pushStyle(); fill(0); ellipse(x-r/4, y-r/4, r/5, r/5); ellipse(x+r/4, y-r/4, r/5, r/5); popStyle(); }