Skip to content

Instantly share code, notes, and snippets.

@companje
Created January 16, 2012 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save companje/1621018 to your computer and use it in GitHub Desktop.
Save companje/1621018 to your computer and use it in GitHub Desktop.
voor marijn
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