Processing Forum
Robot R1, R2, R3; color c1, c2, c3; void setup() { size(400, 400); c1 = color(#FA08EA); c2 = color(#12FA08); c3 = color(#0A08FA); R1 = new Robot(width/2, height/2, c1, c2, c3); R2 = new Robot(width/2-80, height/2+80, c3, c1, c2); R3 = new Robot(width/2+80, height/2-80, c2, c3, c1); } void draw() { background(#FAB608); R1.display(); R2.display(); R3.display(); rectMode(CENTER); noFill(); rect(width/2, height/2, 80, 140); rect(width/2-80, height/2+80, 80, 140); rect(width/2+80, height/2-80, 80, 140); } // definition of the Robot class class Robot { // variables (what a Robot is) float xPos; float yPos; color bodyColor; color headColor; color eyeColor; // constructor (build a Robot) Robot(float x, float y, color bc, color hc, color ec) { xPos = x; yPos = y; bodyColor = bc; headColor = hc; eyeColor = ec; } // function (what a Robot does) void display() { rectMode(CENTER); ellipseMode(CENTER); // draw body fill(bodyColor); rect(xPos, yPos, 20, 100); // draw head fill(headColor); ellipse(xPos, yPos-30, 60, 60); // draw eyes fill(eyeColor); ellipse(xPos-19, yPos-30, 16, 32); ellipse(xPos+19, yPos-30, 16, 32); // draw legs stroke(0); line(xPos-10, yPos+50, xPos-20, yPos+60); line(xPos+10, yPos+50, xPos+20, yPos+60); } }