-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
79 lines (66 loc) · 1.46 KB
/
Copy pathsketch.js
File metadata and controls
79 lines (66 loc) · 1.46 KB
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
77
78
let particles = [];
const NUM_PARTICLES = 5000;
const NOISE_SCALE = 0.002;
const NOISE_STRENGTH = 10;
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 255);
background(0);
// Different every run
noiseSeed(floor(random(100000)));
randomSeed(floor(random(100000)));
for (let i = 0; i < NUM_PARTICLES; i++) {
particles.push(new Particle());
}
}
function draw() {
// Feedback fade (IMPORTANT)
fill(0, 20);
noStroke();
rect(0, 0, width, height);
stroke(
noise(frameCount * 0.01) * 255,
200,
255,
100
);
;
for (let p of particles) {
p.update();
p.show();
}
}
class Particle {
constructor() {
this.pos = createVector(random(width), random(height));
this.vel = p5.Vector.random2D();
this.speed = random(0.5, 2);
}
update() {
let angle =
noise(
this.pos.x * NOISE_SCALE,
this.pos.y * NOISE_SCALE,
frameCount * 0.0005
) *
TWO_PI *
NOISE_STRENGTH;
let force = p5.Vector.fromAngle(angle);
this.vel.add(force);
this.vel.limit(this.speed);
this.pos.add(this.vel);
// Wrap edges
if (this.pos.x < 0) this.pos.x = width;
if (this.pos.x > width) this.pos.x = 0;
if (this.pos.y < 0) this.pos.y = height;
if (this.pos.y > height) this.pos.y = 0;
}
show() {
let hue = noise(
this.pos.x * 0.01,
this.pos.y * 0.01,
frameCount * 0.005
) * 255;
stroke(hue, 200, 255, 120);
point(this.pos.x, this.pos.y);
}