-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
39 lines (36 loc) · 1.16 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
let population;
let target;
const solids = [];
let mazeFinished = false;
let speedSlider;
let showAllSlider;
function setup() {
createCanvas(600, 800);
speedSlider = createSlider(1, 20, 1, 1);
showAllSlider = createButton('show best', true);
showAllSlider.mousePressed(showHandle);
population = new Population(1000, 100);
target = new Target();
solids.push(new Obstacle(0, height * 0.25, width * 0.75, 15));
solids.push(new Obstacle(width * 0.25, height * 0.50, width * 0.75, 15));
solids.push(new Obstacle(0, height * 0.75, width * 0.75, 15));
solids.push(new Obstacle((width * 0.25) - 15, height * 0.375, 15, height * 0.25));
solids.push(new Obstacle(width * 0.75, height * 0.625, 15, height * 0.25));
}
function draw() {
background(30);
target.show();
for (let i = 0; i < solids.length; i++) {
solids[i].show();
}
population.run();
}
function showHandle() {
let value = showAllSlider.value();
showAllSlider.value(value === 'false');
if (value === 'false') {
showAllSlider.html('show best');
} else {
showAllSlider.html('show all');
}
}