Sunday 29 May 2011

Back to the gene garden




back to the gene garden:




float xoff = 0.0;
float xincrement = 0.01;
int THRESH = 100;//size of best int
int POP_MAX = 1200;
int maxSIZE = 122;//max cell size
int[] pop = new int[POP_MAX];
//int[] fit = new int[10];
ArrayList fittest;
ArrayList babies;
int b, c, bab, baby;
//int cycles = 9;
void setup() {
size(900, 200);
fittest = new ArrayList();
babies = new ArrayList();
for (int i=0; i < POP_MAX; i++) {
pop[i] = (int)random(0, maxSIZE);//fill first population
}
}



void draw() {
// noLoop();
frameRate(2);
babies.clear(); //kilfuture parents

int ran2 = (int)random(maxSIZE, maxSIZE+maxSIZE/2);
for (int yy = 0;yy<5;yy++) {
babies.add(ran2);//couple of mutants
}
float n = noise(xoff)*width;

// With each cycle, increment xoff
xoff += xincrement;

fill(255);
rect(0, 0, width, height);
//initial population
for (int i=0; i < POP_MAX; i++) {
// println(" " +pop[i] + " ");
// ellipse(i+30, 50, 25, 25);
getFit(pop[i]); //asess for fitness
}
for (int i=0; i < fittest.size(); i++) {
Integer a = (Integer)fittest.get(i);
//println(" " +a + " ");
}



//best babies bred from best of population:
for (int i=0; i < babies.size(); i++) {
Integer tempbab = (Integer)babies.get(i);
bab = tempbab;


noStroke();

fill((int)random(bab*2), (int)random(bab*3), (int)random(bab*2), bab);
// ellipse(i+bab+bab/2, 100, bab, bab);
ellipse(i+bab+bab/2, 100, bab, bab);
// ellipse((int)random(n),height/2,bab, bab);
}
/*for(int i=0;i=THRESH) {
// println(" " +check + " ");
fittest.add(check);
breed(check);
}
}

///add biggest together
void breed(int a) {

int ran = (int)random(fittest.size());
for (int i=0; i < ran; i++) {
Integer tempb = (Integer)fittest.get(i);
b = tempb;
}

for (int i=ran; i > ran; i++) {
Integer tempc = (Integer)fittest.get(i);
c = tempc;
}

// fill((int)random(20, 255), 20);
///println(b+c);
// translate(20, 20);
//ellipse(b, c, 20, 20);
// baby =b+c+(int)random(-200); //breed and mutate
baby =b+c; //slight mutation
babies.add(baby);
}
///ignore this (note to self)



World world;

void setup() {
size(1100, 200);

world = new World(15); //20
smooth();
}

void draw() {

background(255);
world.run();
}


void mousePressed() {
aahha
save(frameCount+".jpg");
}
////


class Food {

ArrayList food;
ArrayList ellie; //my random size variables
int eloc;
int a =80;

Food(int num) {
// Start with some food
food = new ArrayList();
ellie = new ArrayList();//random sizes
for (int i = 0; i < num; i++) {
food.add(new PVector(random(width), random(height)));
}

for (int i = 0; i < food.size(); i++) {

ellie.add(int(random(10, 78)));
}
}


void run() {

for (int i = 0; i < food.size(); i++) {
PVector loc = (PVector) food.get(i);
ellipseMode(CENTER);
eloc = (Integer) ellie.get(i);

fill(loc.x, eloc, loc.y);


ellipse(a+i*53, 80, eloc, eloc);
// rect(a+i*50, 80, eloc, eloc);
}
}

// Return the list of food
ArrayList getFood() {
return food;
}
}
/////


class World {


Food food;

// Constructor
World(int num) {

food = new Food(num);
}


void run() {
// Deal with food
food.run();
}
}
//thanks to D. Shiffman...

No comments:

Post a Comment