-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflowfield.js
59 lines (43 loc) · 1.07 KB
/
flowfield.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
var gui;
var inc = 0.1;
var scl = 10;
var cols, rows;
var zoff = 0;
var fr;
var particles = [];
var flowfield;
function setup() {
createCanvas(500, 500);
cols = floor(width / scl);
rows = floor(height / scl);
fr = createP('');
bg = color('rgba(0, 0, 0, 1)');
flowfield = new Array(cols * rows);
for (var i = 0; i < 100; i++) {
particles[i] = new Particle();
}
background(bg);
};
function draw() {
var yoff = 0;
for (var y = 0; y < rows; y++) {
var xoff = 0;
for (var x = 0; x < cols; x++) {
var index = x + y * cols;
var angle = noise(xoff, yoff, zoff) * TWO_PI * 4;
var v = p5.Vector.fromAngle(angle);
v.setMag(1);
flowfield[index] = v;
xoff += inc;
}
yoff += inc;
zoff += 0.0001;
}
for (var i = 0; i < particles.length; i++) {
particles[i].follow(flowfield);
particles[i].update();
particles[i].edges();
particles[i].show();
}
fr.html('FPS:' + floor(frameRate()));
};