Created
May 9, 2015 14:27
-
-
Save darkwave/f4f6fe81afce00dc3889 to your computer and use it in GitHub Desktop.
Robottini
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Robot { | |
float x; | |
float y; | |
float torsoW = random(50, 100); | |
float torsoH = torsoW + 10; | |
color torsoColor = color(random(360), 100, 100); | |
float eyesRadius = 10; | |
color eyesColor = color(random(360), 100, 100); | |
Robot(float posX, float posY) { | |
x = posX; | |
y = posY; | |
} | |
void display() { | |
pushMatrix(); | |
translate(x, y); | |
fill(hue(torsoColor), 80, 80); | |
ellipse(0, -torsoH, torsoW * 0.8, torsoW * 0.7); | |
fill(eyesColor); | |
ellipse(-(eyesRadius + 2), -torsoH -5, eyesRadius, eyesRadius); | |
ellipse((eyesRadius + 2), -torsoH -5, eyesRadius, eyesRadius); | |
fill(torsoColor); | |
rect(0, -torsoH / 2, torsoW, torsoH); | |
popMatrix(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Robot[] r; | |
Robot[] rTemp; | |
int numberOfRobots = 3; | |
boolean reloadArray = false; | |
void setup() { | |
//size(800, 600); | |
rectMode(CENTER); | |
noStroke(); | |
colorMode(HSB, 360, 100, 100); | |
r = new Robot[numberOfRobots]; | |
for (int i = 0; i < r.length; i++) { | |
r[i] = new Robot(random(width), random(height)); | |
} | |
} | |
void draw() { | |
background(#ffffff); | |
if (reloadArray == true) { | |
r = rTemp; | |
reloadArray = false; | |
} | |
for (int i = 0; i < r.length; i++) { | |
r[i].display(); | |
} | |
} | |
void mouseReleased() { | |
rTemp = new Robot[r.length + 1]; | |
for (int i = 0; i < r.length; i++) { | |
rTemp[i] = r[i]; | |
} | |
rTemp[rTemp.length - 1] = new Robot(mouseX, mouseY); | |
reloadArray = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment