Skip to content

Commit

Permalink
-tweaked default starting vars
Browse files Browse the repository at this point in the history
-added rate of rotation gene #6
-other minor tweaks
  • Loading branch information
CorpusCallosum committed Apr 15, 2012
1 parent 1137af0 commit df45975
Show file tree
Hide file tree
Showing 5 changed files with 1,556 additions and 43 deletions.
15 changes: 8 additions & 7 deletions NaturalSelection/DNA.pde
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ class DNA {
else {
//DEFINE default values here
for (int i = 0; i < dna.length; i++) {
dna[i] = .2;
dna[i] = .4;
}

/* dna[0] = 0; //degree of rotation of branches
dna[1] = 0; //the scale factor of sub-branches
dna[2] = 0; //number of branches per level
dna[3] = 1; //number of levels of recursion
dna[4] = 0; //size of the first branch
dna[5] = 1; //change in number of branches per level range -2,+2*/

// dna[0] = 0; //degree of rotation of branches
dna[1] = 0.1; //the scale factor of sub-branches
/* dna[2] = 0; //number of branches per level
dna[3] = 1; //number of levels of recursion*/
dna[4] = .1; //size of the first branch
/*dna[5] = 1; //change in number of branches per level range -2,+2*/

/*
//GENES ARE******
Expand Down
48 changes: 16 additions & 32 deletions NaturalSelection/DrawingClass.pde
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Drawing {
int levelCnt = 0;

//GENES
float theta, l, branchStep, thickness, gRotY, gRotZ;
float theta, l, branchStep, thickness, gRotY, gRotZ, rotRate;
int numSub, numLevels;

//Create a new face
Expand All @@ -44,57 +44,40 @@ class Drawing {
l = genes.getGene(1)*2+.1; //the scale factor of sub-branches
numSub = round(genes.getGene(2)*5)+1; //number of branches per level
numLevels = round(genes.getGene(3)*4)+1; //number of levels of recursion
float startSize = (genes.getGene(4)*(height/2))+height/5; //size of the first branch
float startSize = (genes.getGene(4)*(height/2))+height/5; //size of the first branch
branchStep = (genes.getGene(5)*4)-2; //range -2,+2
rotRate = genes.getGene(6); //rotation rate


// gRotY = radians(genes.getGene(6)*360); //degree of rotation of branches
// gRotZ = radians(genes.getGene(7)*360); //degree of rotation of branches

// branchGrowth = genes.getGene(5)*2;
// thickness = round(genes.getGene(5)*5)+1;

//
stroke(1);
strokeWeight(1);
// pushMatrix();
// translate(width/2, height/2);
/* rotateX(rotX);
rotateY(rotY);
rotateZ(rotZ);*/
branch(startSize, 0);
// popMatrix();

/* rotX+=.02;
rotY+=.01;
rotZ+=.03;
if (rotX >= 2*PI) {
rotX = 0;
}
if (rotY >= 2*PI) {
rotY = 0;
}
if (rotZ >= 2*PI) {
rotZ = 0;
}*/

branch(startSize, 0, theta);

}

void branch(float h, int level) {
void branch(float h, int level, float rot) {
// println("branch");


// numSub = ceil(numSub*(branchGrowth*(level+1)));
//increment number of sub branches based on step num, per level
//increment number of sub branches based on step num, per level
int numSubBranches = round(numSub + (level*branchStep));
// println(h);

//modify rate genes
h *= l;
rot *= rotRate;

// All recursive functions must have an exit condition!!!!
// Here, ours is when it reaches the number of levels gene
if (level < numLevels) {
// if (h > 3) {
for (float i = 0; i<=numSubBranches; i++) {
pushMatrix(); // Save the current state of transformation (i.e. where are we now)
rotateX(theta); // Rotate by theta
rotateX(rot); // Rotate by theta
rotateY((i/numSubBranches)*(PI*2)); // Rotate Y
// rotateY(gRotY); // Rotate by theta

Expand All @@ -111,7 +94,8 @@ class Drawing {
println(e);
}
}
branch(h, level+1); // Ok, now call myself to draw sub-branches

branch(h, level+1, rot); // Ok, now call myself to draw sub-branches
popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
}
}
Expand Down
6 changes: 4 additions & 2 deletions NaturalSelection/NaturalSelection.pde
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void setup() {
// int popmax = 10;
float mutationRate = .05; // A pretty high mutation rate here, our population is rather small we need to enforce variety
// Create a population with a target phrase, mutation rate, and population max
popul = new Population(mutationRate, popMax);
popul = new Population(mutationRate, popMax, false);
makeNewGeneration();

//face tracking!
Expand Down Expand Up @@ -89,8 +89,10 @@ void draw() {

//WEBCAM DISPLAY
// display the image
if (debug)
if (debug){
image( opencv.image(), 0, 0 );
text("fps:"+frameRate, 500, y);
}

//FACE DETECTON************************************
// face detection
Expand Down
4 changes: 2 additions & 2 deletions NaturalSelection/Population.pde
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class Population {
float rotX, rotY, rotZ = 0;

//*INITIALIZE THE POPULATION*//
Population(float m, int num) {
Population(float m, int num, boolean randomize) {
mutationRate = m;
MAX = num;
population = new Drawing[MAX];
darwin = new ArrayList();
generations = 0;
for (int i = 0; i < population.length; i++) {
population[i] = new Drawing(new DNA(false), width/2, height/2);
population[i] = new Drawing(new DNA(randomize), width/2, height/2);
}
}

Expand Down
Loading

0 comments on commit df45975

Please sign in to comment.