-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
76 lines (54 loc) · 1.45 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Created by nomaterials on 03/06/2017.
*/
// Using this variable to decide whether to draw all the stuff
var debug = true;
//Use forcefield
var flow = true;
//Flow field of vectors
var flowfield;
//Array to store agents
var pop = 250; // vehicle population
var vehicles = [];
//GUI elements
var cohesionSlider;
var separationSlider;
var alignmentSlider;
function setup() {
var canvas = createCanvas(windowWidth, windowHeight);
cohesionSlider = createSlider(0, 5, 1, 0.1);
separationSlider = createSlider(0, 5, 1, 0.1);
alignmentSlider = createSlider(0, 5, 1, 0.1);
//make new flowfield obj with resolution 16
if(flow)
flowfield = new FlowField(20);
for (var i = 0; i < 400; i++) {
vehicles.push(new Vehicle(random(width), random(height), random(2.5, 5), random(0.1, 0.5)));
}
}
function draw() {
background(51);
// Display the flowfield in "debug" mode
if (debug && flow)
flowfield.display();
for(var i = 0; i < vehicles.length; i++) {
//Apply Seek & Seperate behaviours
//vehicles[i].applyBehaviours(vehicles);
//Follow force field
if(flow)
vehicles[i].follow(flowfield);
//Flock behaviour
vehicles[i].flock(vehicles);
vehicles[i].run();
}
}
function keyPressed() {
if (key == ' ') {
debug = !debug;
}
}
// Make a new flowfield
function mousePressed() {
if(flow)
flowfield.init();
}