-
Notifications
You must be signed in to change notification settings - Fork 22
/
colour_changing_spiral.js
118 lines (118 loc) · 2.24 KB
/
colour_changing_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
return class MyEffect
{
add(input, change, dir)
{
input+= dir*change;
return input;
}
constructor(display)
{
this.display = display;
this.r = 255;
this.g = 255;
this.b = 255;
this.tick = 0;
this.x=0;
this.y=0;
this.rdir=1;
this.gdir=1;
this.bdir=1;
this.layer=0;
this.ldir=1;
}
update()
{
this.tick++;
this.display.flush();
//Speed of Change: V
for (let a = 0;a< 20 ;a++)
{
this.r=this.add(this.r,this.tick%10,this.rdir)
if (this.r>255||this.r<0)
{
this.rdir*=-1;
}
this.g=this.add(this.g,(this.tick%100)/10,this.gdir)
if (this.g>255||this.g<0)
{
this.gdir*=-1;
}
this.b=this.add(this.b,(this.tick%1000)/100,this.bdir)
if (this.b>255||this.b<0)
{
this.bdir*=-1;
}
this.display.setPixel(this.x, this.y, [this.r, this.g,this.b ]);
//this.display.setPixel(this.x, this.y, [255,255,255]);
this.paintspiral();
}
}
paintspiral()
{
if(this.x==40&&this.y==this.display.height/2)
{
this.x=0;
this.y=0;
this.layer=0;
}
if (this.y == this.layer)
{
if (this.x == this.display.width - this.layer - this.ldir)
{
this.y += this.ldir;
}
else
{
this.x += this.ldir;
}
}
else if (this.x == this.display.width - this.layer - this.ldir)
{
if (this.y == this.display.height - this.layer - this.ldir)
{
this.x -= this.ldir;
}
else
{
this.y += this.ldir;
}
}
else if (this.y == this.display.height - this.layer - this.ldir)
{
if (this.x == this.layer)
{
this.y -= this.ldir;
}
else
{
this.x -= this.ldir;
}
}
else if (this.x == this.layer)
{
if (this.y == this.layer + this.ldir)
{
this.layer += this.ldir;
}
else
{
this.y -= this.ldir;
}
}
}
paintdown()
{
this.x++;
if (this.x>=this.display.width)
{
this.x=0;
this.y++;
{
if (this.y>=this.display.height)
{
this.y=0;
}
}
}
}
}