Skip to content

Instantly share code, notes, and snippets.

@prabod
Created December 3, 2016 19:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prabod/51f35979d7dbc7f8da7809db050e3baa to your computer and use it in GitHub Desktop.
Save prabod/51f35979d7dbc7f8da7809db050e3baa to your computer and use it in GitHub Desktop.
Random Population
/**
* Generate random DNA for the Initial Generation
* Value Encoding is used for DNA encoding
* DNA = [RED, GREEN, BLUE, ALPHA, X1, Y1, X2, Y2, ...]
* */
randomGenes(){
var bString = [];
for (var i = 0; i < this.chromoSize; i+= this.geneSize){
/**
* Generate RGBA
* */
bString.push(
Math.random(), // R
Math.random(), // G
Math.random(), // B
Math.max(Math.random() * Math.random(), 0.2) //A
);
/**
* Generate random (x,y) for vertices
* */
var X = Math.random();
var Y = Math.random();
for (var j = 0; j < this.vertices ; j++){
bString.push(
X + Math.random() - 0.5,
Y + Math.random() - 0.5
);
}
}
this.valueString = bString;
}
@menuka94
Copy link

menuka94 commented Dec 5, 2016

What's going on at line 17 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment