Created
January 16, 2012 14:05
-
-
Save companje/1621018 to your computer and use it in GitHub Desktop.
voor marijn
This file contains 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
PImage img; | |
color rood = color(255,0,0); | |
color blauw = color(0,0,255); | |
void setup() { | |
size(500, 500); | |
img = new PImage(100,100); | |
background(255); | |
} | |
void draw() { | |
image(img,0,0,width,height); | |
if (keyPressed && key=='a') { | |
img.set(mouseX/5, mouseY/5, rood); | |
} | |
if (keyPressed && key=='b') { | |
img.set(mouseX/5, mouseY/5, blauw); | |
} | |
float fitness = 0; | |
//fitness checkt hoeveel blauwe en rode elkaar aanraken. | |
for (int y=1; y<img.height-1; y++) { | |
for (int x=1; x<img.width-1; x++) { | |
if (img.get(x,y)==rood) { | |
//nu al z'n buren checken | |
if (img.get(x-1,y)==blauw) fitness++; | |
if (img.get(x+1,y)==blauw) fitness++; | |
if (img.get(x,y-1)==blauw) fitness++; | |
if (img.get(x,y+1)==blauw) fitness++; | |
} | |
} | |
} | |
text("fitness: " + fitness,10,15); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment