/* donatello_v3.pde Edited by Justin Hsia (orig. Larry Synder) Draws multiple abstracted Teenage Mutant Ninja Turtles. We use separate variables to control their horizontal movements. Using the modulus operator, make one Donatello wrap from right-to-left. */ int x1 = 0; // x-position of Donatello 1 int x2 = 460; // x-position of Donatello 2 void setup() { size(500,500); // set drawing canvas size noStroke(); // no outlines } // draw Donatellos moving void draw() { background(255,245,220); // paint over drawing canvas donatello(x1); donatello(x2); // update body positions (change increment/decrement to change speed) x1 = (x1 + 3) % 460; // move right, but wrap around once right edge encountered x2 = max(x2 - 1, 0); // move left, but stop at edge } // draw Donatello void donatello(int x_pos) { fill(0,100,0); // dark green rect(x_pos,182,40,15); // top of head fill(88,44,141); // purple rect(x_pos,197,40,6); // bandana mask fill(0,100,0); // dark green rect(x_pos,203,40,20); // bottom of head fill(219,136,0); // dark yellow rect(x_pos,223,40,50); // shell fill(0,100,0); // dark green rect(x_pos,273,40,45); // lower body }