-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
50 lines (42 loc) · 1005 Bytes
/
script.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
var inc = 0.1;
let time = -1;
var scl = 10;
var cols, rows;
const SPRING_COLORS = [46.33, 12.86, 26.56, 188.92, 84.12];
var zoff = 0;
var particles = [];
var flowfield;
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB,255);
cols = floor(width / scl);
rows = floor(height / scl);
flowfield = new Array(cols * rows);
for (var i = 0; i < 300; i++) {
particles[i] = new Particle();
}
background(0);
}
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;
stroke(0, 50);
}
yoff += inc;
zoff += 0.0003;
}
for (var i = 0; i < particles.length; i++) {
particles[i].follow(flowfield);
particles[i].update();
particles[i].edges();
particles[i].show();
}
}