-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticle.js
42 lines (36 loc) · 1.13 KB
/
particle.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
function Particle() {
this.pos = createVector(random(50, width - 50), random(50, height - 50));
// this.pos = createVector(random(width), random(height));
this.vel = p5.Vector.random2D();
this.acc = createVector(0, 0);
this.mass = 5;
this.maxSpeed = 1;
this.update = function() {
this.vel.add(this.acc)
this.vel.limit(this.maxSpeed);
this.pos.add(this.vel)
this.acc.mult(0);
}
this.show = function() {
stroke(0, 5);
strokeWeight(1);
// fill(0 , 5);
// ellipse(this.pos.x, this.pos.y, 0.5);
point(this.pos.x, this.pos.y);
}
this.applyForce = function(force) {
this.acc.add(force);
}
this.follow = function(v) {
var x = floor(this.pos.x / scl);
var y = floor(this.pos.y / scl);
var i = x + y * cols;
this.applyForce(v[i]);
}
this.edges = function() {
if (this.pos.x < 50) this.pos.x = width - 50;
if (this.pos.x > width - 50) this.pos.x = 50;
if (this.pos.y < 50) this.pos.y = height - 50;
if (this.pos.y > height - 50) this.pos.y = 50;
}
}