-
Notifications
You must be signed in to change notification settings - Fork 1
/
sketch.js
49 lines (38 loc) · 1.13 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var pop;
var maxpop = 1;
var c, ctx, data, workingCtx, fittestCtx;
var fit;
var lastBestFitness = 0;
var lastBestFitPolygon = null;
function preload(){
c = document.getElementById("refCanvas");
ctx = c.getContext("2d");
data = ctx.getImageData(0, 0, 200, 200);
}
function setup(){
createCanvas(200, 200);
c = document.getElementById("defaultCanvas0");
workingCtx = c.getContext("2d");
c.style.display = "none"
c = document.getElementById("fittestCanvas");
fittestCtx = c.getContext("2d");
pop = new Population(maxpop);
pop.calculateFitness();
fit = createP();
}
function draw(){
// pop.calculateFitness();
// pop.sortFitness();
// if(pop.population[0].fitness < lastBestFitness){
// pop.population[0] = lastBestFitPolygon;
// }
// lastBestFitPolygon = pop.population[0];
// lastBestFitness = pop.population[0].fitness;
// pop.population[0].drawToASpecificContext(fittestCtx);
// fit.html(Math.round(pop.population[0].fitness*10000)/100);
// pop.selection();
pop.population[0].drawToASpecificContext(fittestCtx);
bestFitness = Math.round(pop.population[0].fitness*10000)/100;
fit.html(bestFitness);
pop.selection();
}