-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathburam.js
71 lines (60 loc) · 1.78 KB
/
buram.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
let particles = [];
function setup() {
createCanvas(800, 600);
background(0); // Set background to black
// Create initial particles
for (let i = 0; i < 50; i++) {
particles.push(new Particle(random(width), random(height)));
}
}
function draw() {
// Move and display particles
for (let particle of particles) {
particle.update();
particle.display();
}
}
class Particle {
constructor(x, y) {
this.pos = createVector(x, y);
this.vel = p5.Vector.random2D().mult(random(1, 3));
this.acc = createVector(0, 0);
this.history = [];
this.maxHistory = 100;
this.angle = random(TWO_PI);
this.noiseOffset = createVector(random(1000), random(1000));
this.color = color(random(255), random(255), random(255));
}
update() {
this.vel.add(this.acc);
this.pos.add(this.vel);
this.acc.mult(0);
// Add position to history
let v = createVector(this.pos.x, this.pos.y);
this.history.push(v);
// Limit history length
if (this.history.length > this.maxHistory) {
this.history.splice(0, 1);
}
// Apply Perlin noise to the angle
let angleChange = map(noise(this.noiseOffset.x, this.noiseOffset.y), 0, 1, -0.1, 0.1);
this.angle += angleChange;
this.noiseOffset.add(0.01, 0.01);
// Update velocity based on angle
this.vel.rotate(this.angle);
}
display() {
noStroke();
fill(this.color); // Random color
ellipse(this.pos.x, this.pos.y, 4);
// Draw history
beginShape();
for (let i = 0; i < this.history.length; i++) {
let pos = this.history[i];
let transparency = map(i, 0, this.history.length, 0, 100);
fill(red(this.color), green(this.color), blue(this.color), transparency);
ellipse(pos.x, pos.y, 4);
}
endShape();
}
}