-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutorial.pde
More file actions
37 lines (27 loc) · 844 Bytes
/
Tutorial.pde
File metadata and controls
37 lines (27 loc) · 844 Bytes
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
Population test;
PVector goal = new PVector(400, 10); // parameters is location of goal
void setup() {
size(800, 800); //size of the window
frameRate(100);//increase this to make the dots go faster
test = new Population(1000);//create a new population with 1000 members
}
void draw() {
background(255);
//draw goal
fill(0, 255, 0);
ellipse(goal.x, goal.y, 10, 10);
//draw obstacle(s)
fill(0, 0, 255); //paintbrush becomes blue
// rect(0, 300, 600, 10); // x=0,y=300,width=600,height=10
// rect(200, 500, 600, 10); // x=200,y=500,width=600,height=10
if (test.allDotsDead()) {
//genetic algorithm
test.calculateFitness();
test.naturalSelection();
test.mutateDemBabies();
} else {
//if any of the dots are still alive then update and then show them
test.update();
test.show();
}
}