-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
59 lines (50 loc) · 1.53 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
50
51
52
53
54
55
56
57
58
59
const boids = [];
let alignSlider, cohesionSlider, separationSlider, perceptionRadius;
function setup() {
var canvas = createCanvas(1280, 720);
canvas.parent("sketch-div");
alignmentLabel = createSpan("Alignment:");
alignmentLabel.parent("alignment");
cohesionLabel = createSpan("Cohesion:");
cohesionLabel.parent("cohesion");
separationLabel = createSpan("Separation:");
separationLabel.parent("separation");
perceptionRadiusLabel = createSpan("Perception Radius:");
perceptionRadiusLabel.parent("perception_radius");
alignmentSlider = createSlider(0, 2, 1, 0.1);
alignmentSlider.parent("alignment");
cohesionSlider = createSlider(0, 2, 1, 0.1);
cohesionSlider.parent("cohesion");
separationSlider = createSlider(0, 2, 1, 0.1);
separationSlider.parent("separation");
perceptionRadiusSlider = createSlider(0, 200, 100, 10);
perceptionRadiusSlider.parent("perception_radius");
//trailBox = createCheckbox('Trails')
//trailBox.parent('checkBoxes')
//cursorBox = createCheckbox('Center to cursor')
//cursorBox.parent('checkBoxes')
resetButton = createButton("Reset");
resetButton.parent("buttons");
resetButton.mouseClicked(reset);
resetButton.size(100, AUTO);
makeBoids();
}
function makeBoids() {
for (let i = 0; i < 100; i++) {
boids.push(new Boid());
}
}
function reset() {
boids.splice(0, boids.length);
makeBoids();
}
function draw() {
background(51);
for (let boid of boids) {
boid.edges();
boid.flock(boids);
boid.update();
boid.show();
//boid.showTrail()
}
}