Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

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
You can’t perform that action at this time.