forked from jacobsorme/kexjobb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spiral.js
47 lines (46 loc) · 1.37 KB
/
spiral.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
class Spiral extends Cleaner {
constructor(x,y,radius,color,ang, speed){
super(x,y,radius,color,ang,speed);
this.inSpiral = false;
this.turn = 0.2;
this.margin = 70;
}
resetSpiralParams(){
this.turn = 0.2;
this.inSpiral = false;
}
move(){
this.x += (this.speed*Math.cos(this.ang));
this.y += (this.speed*Math.sin(this.ang));
if( this.inSpiral || (this.x>this.margin && this.y>this.margin && this.x<canvas.width-this.margin && this.y<canvas.height-this.margin)){
this.rotate(this.ang+this.turn);
this.turn=this.turn/(1.01-(0.01-Math.abs(this.turn)/22));
this.inSpiral=true;
}
if(this.x+this.radius>canvas.width) {
this.bounceRight();
this.x=canvas.width-this.radius;
//this.trace.push([this.x,this.y]);
this.resetSpiralParams();
}
else if(this.x-this.radius<0) {
this.bounceLeft();
this.x=this.radius+0;
//this.trace.push([this.x,this.y]);
this.resetSpiralParams();
}
else if(this.y-this.radius<0) {
this.bounceTop();
this.y=this.radius;
//this.trace.push([this.x,this.y]);
this.resetSpiralParams();
}
else if(this.y+this.radius>canvas.height) {
this.bounceBottom();
this.y=canvas.height-this.radius;
//this.trace.push([this.x,this.y]);
this.resetSpiralParams();
}
this.trace.push([this.x,this.y]);
}
}