blob: c62dd47ce929c0e8ea8b521d32412cb894f1e3f4 (
plain)
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
|
function Particle(x, y, m, c) {
this.pos = createVector(x, y);
this.vel = createVector(0, 0);
this.acc = createVector(0, 0);
this.colour = c;
this.mass = m;
this.applyForce = function(force) {
this.acc.add(p5.Vector.div(force, this.mass));
}
this.applyDrag = function(drag_coeff) {
var rev_vel = createVector().sub(this.vel);
var drag = rev_vel.mult(drag_coeff);
this.applyForce(drag);
}
this.update = function() {
this.vel.add(this.acc);
this.pos.add(this.vel);
this.acc.mult(0);
if (this.pos.x <= 0 || this.pos.x >= wid)
this.vel.x = -this.vel.x;
if (this.pos.y <= 0)
this.vel.y = -this.vel.y;
}
this.show = function() {
point(this.pos.x, this.pos.y);
}
this.gone = function() {
return this.pos.y >= hei;
}
}
|