-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
88 lines (77 loc) · 1.92 KB
/
Copy pathsketch.js
File metadata and controls
88 lines (77 loc) · 1.92 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var population;
var lifespan = 150;
var lifeP;
var count = 0;
var target;
var maxforce = 1.5;
var numberofhits = 0;
var numberofhitsP;
var locked = undefined;
var obstacles = [];
var mutationRate = 0.025;
var flag = false;
function reset() {
population.reset();
this.obstacles = [];
}
function Target1() {
this.pos = createVector(width / 2, 50);
this.r = 30;
this.color = [color(0, 0, 255), color(255, 255, 255), color(255, 0, 0)];
this.show = function () {
noStroke();
for (var i = 0; i < this.color.length; i++) {
fill(this.color[i]);
ellipse(this.pos.x, this.pos.y, this.r - 10 * i, this.r - 10 * i);
}
};
}
function setup() {
createCanvas(windowWidth * 0.9, windowHeight * 0.7);
population = new Population();
lifeP = createP();
numberofhitsP = createP();
target1 = new Target1();
numberofhitsP.style("color:white");
lifeP.style("color:white");
}
function draw() {
background(0);
population.run();
lifeP.html("Iterations for this epoch: " + count);
numberofhitsP.html("Number of Hits in this epoch: " + numberofhits);
count++;
if (count == lifespan) {
population.evaluate();
population.selection();
count = 0;
numberofhits = 0;
}
if (drawrect) {
if (locked == true) {
var w = abs(mouseX - startPos.x);
var h = abs(mouseY - startPos.y);
var tempColor = color(120);
tempColor.setAlpha(100);
stroke(20);
fill(tempColor);
var corner = createVector(
mouseX < startPos.x ? mouseX : startPos.x,
mouseY < startPos.y ? mouseY : startPos.y
);
rect(corner.x, corner.y, w, h);
} else if (locked == false) {
console.log("Ahoy");
var temp = new Obstacle();
console.log(temp);
obstacles.push(temp);
drawrect = false;
locked = undefined;
}
}
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].show();
}
fill(color(255, 110, 0));
target1.show();
}