Created
December 3, 2016 19:09
-
-
Save prabod/51f35979d7dbc7f8da7809db050e3baa to your computer and use it in GitHub Desktop.
Random Population
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's going on at line 17 ?