/**
*
Eye for an Eye by Aaron Steed 2006
* A closed automata ecology of necrophages
*
* Original sketch by Aaron Steed:
* - http://robotacid.com/PBeta/eye4anEye
*
* 2010-02-12 subpixel:
* - Updated code to work with Processing 1.0,
* Traer Physics 3.0 and the current
* Genetic Algorithm Library
* - PROBLEM: Don't know what to do for gene.kill() in Plankton.draw(); seems nothing to do
*/
/*
* 2010-02-12 subpixel v01:
* - PApplet.framerate() replaced by frameRate()
* - GeneticAlgorithm.makeChromosome() replaced by soup.createChromosome()
*
* 2010-02-12 subpixel v02:
* - Keep track of forces (Spring and Attraction objects) and remove them
* when removing associated particles
*/
import ai_ga.*;
import traer.physics.*;
//import processing.pdf.*;
ParticleSystem ether;
Vector plankton, amoeba;
Soup soup;
float backgroundRed, backgroundGreen, backgroundBlue, backgroundRedTemp, backgroundGreenTemp, backgroundBlueTemp;
int [] backgroundTable = {#B788F8, #F888E4, #F88890, #F8C788, #E7F888, #A2F888, #88F8C5, #88DFF8, #88A5F8};
int backgroundChoice;
int wide, high;
void setup(){
size(400, 350);
frameRate(24);
wide = width;
high = height;
ether = new ParticleSystem(0.0, 0.01);
amoeba = new Vector();
soup = new Soup();
plankton = new Vector();
backgroundChoice = (int)random(backgroundTable.length);
backgroundRed = backgroundRedTemp = red(backgroundTable[backgroundChoice]);
backgroundGreen = backgroundGreenTemp = green(backgroundTable[backgroundChoice]);
backgroundBlue = backgroundBlueTemp = blue(backgroundTable[backgroundChoice]);
for(int i = 0; i < 5; i++){
// amoeba.add(new Amoeba(random(-wide * 0.5, wide * 0.5), random(-high * 0.5, high * 0.5), soup.makeChromosome()));
amoeba.add(new Amoeba(random(-wide * 0.4, wide * 0.4), random(-high * 0.4, high * 0.4), soup.createChromosome()));
}
for(int i = 0; i < 20; i++){
plankton.add(new Plankton());
}
ellipseMode(CENTER);
smooth();
}
void draw(){
scale(1.0);
drawRoutines();
ether.tick();
}
void mousePressed(){
//beginRecord(PDF, "amoeba.pdf");
drawRoutines();
//endRecord();
}
void drawRoutines(){
fadeBackground();
pushMatrix();
translate(wide * 0.5, high * 0.5);
for(int i = 0; i < amoeba.size(); i++){
Amoeba temp = (Amoeba)amoeba.get(i);
temp.draw();
}
for(int i = 0; i < plankton.size(); i++){
Plankton temp = (Plankton)plankton.get(i);
temp.draw();
}
popMatrix();
}
void setBackground(){
backgroundChoice = (int)random(backgroundTable.length);
backgroundRed = red(backgroundTable[backgroundChoice]);
backgroundGreen = green(backgroundTable[backgroundChoice]);
backgroundBlue = blue(backgroundTable[backgroundChoice]);
}
void fadeBackground(){
float redDelta = abs(backgroundRed - backgroundRedTemp);
float greenDelta = abs(backgroundGreen - backgroundGreenTemp);
float blueDelta = abs(backgroundBlue - backgroundBlueTemp);
if(redDelta + greenDelta + blueDelta < 0.05){
setBackground();
}
if(redDelta > 0.01){
backgroundRedTemp += (backgroundRed - backgroundRedTemp) * 0.005;
}
if(greenDelta > 0.01){
backgroundGreenTemp += (backgroundGreen - backgroundGreenTemp) * 0.005;
}
if(blueDelta > 0.01){
backgroundBlueTemp += (backgroundBlue - backgroundBlueTemp) * 0.005;
}
background(backgroundRedTemp, backgroundGreenTemp, backgroundBlueTemp);
}