-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrop.js
38 lines (34 loc) · 968 Bytes
/
drop.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
// This file contains the drop class that is used to make the rain.
class drop{
constructor(){
this.position = createVector(random(windowWidth),random(-100,windowHeight))
this.velocity = createVector(0,random(3,7))
this.force = createVector(0,0)
}
applyForce(f){
this.force.add(f)
}
checkEdges(){
if(this.position.x>windowWidth){
this.position.x = 0
}
if(this.position.y>windowHeight){
this.position.y = 0
this.velocity = createVector(0,random(3,7))
}
if(this.position.x<0){
this.position.x = windowWidth
}
}
update(){
this.velocity.add(this.force)
this.position.add(this.velocity)
this.checkEdges()
this.force.mult(0)
}
show(){
fill(255,227,216)
noStroke()
rect(this.position.x,this.position.y,3,7)
}
}