-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchakra.js
61 lines (59 loc) · 2.08 KB
/
chakra.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
function chakra(xposi, yposi, thickness){
this.radius = thickness;
this.x = random(0, width);
this.y = random(0, height);
this.xnew = xposi;
this.ynew = yposi;
this.speedx = (this.xnew- this.x)/160;
this.speedy = (this.ynew- this.y)/160;
this.show = function(){
//Color
fill(0,0,255);
noStroke();
//Create the dots for every frame & check whether they have reached their destination or not
if(this.speedx > 0 && this.speedy > 0){
if(this.x < this.xnew && this.y < this.ynew){
ellipse(this.x , this.y, this.radius);
}else{
ellipse(this.xnew,this.ynew,this.radius);
this.speedx = 0;
this.speedy = 0;
}
}
if(this.speedx < 0 && this.speedy > 0){
if(this.x > this.xnew && this.y < this.ynew){
ellipse(this.x , this.y, this.radius);
}else{
ellipse(this.xnew,this.ynew,this.radius);
this.speedx = 0;
this.speedy = 0;
}
}
if(this.speedx > 0 && this.speedy < 0){
if(this.x < this.xnew && this.y > this.ynew){
ellipse(this.x , this.y, this.radius);
}else{
ellipse(this.xnew,this.ynew,this.radius);
this.speedx = 0;
this.speedy = 0;
}
}
if(this.speedx < 0 && this.speedy < 0){
if(this.x > this.xnew && this.y > this.ynew){
ellipse(this.x , this.y, this.radius);
}else{
ellipse(this.xnew,this.ynew,this.radius);
this.speedx = 0;
this.speedy = 0;
}
}
if(this.speedx == 0 && this.speedy == 0){
ellipse(this.xnew,this.ynew,this.radius);
}
}
//Change position of dot at every frame
this.move = function(){
this.x += this.speedx;
this.y += this.speedy;
}
}