-
Notifications
You must be signed in to change notification settings - Fork 20
/
gradients.js
49 lines (38 loc) · 1.11 KB
/
gradients.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
return class GradientsEffect {
constructor(display) {
this.display = display;
this.frameRate = 1; // Integer controlling screen update rate.
this.gradientSpeed = 1; // Number of how fast gradients move across.
this.#clear();
this.tick = 0;
}
#clear() {
for (let x = 0; x < this.display.width; x++) {
for (let y = 0; y < this.display.height; y++) {
this.display.setPixel(x, y, [0,0,0]);
}
}
this.display.flush();
}
update() {
this.tick = this.tick + 1
// Higher frameRate values -> less updates/sec
if (this.tick % this.frameRate == 1) {
this.display.flush();
return;
};
// New Date Object
let D = new Date();
let t = D.getTime();
// Sets gradient speeds
t = (t/100 * this.gradientSpeed);
// Sets pixels
for (let x = 0; x < this.display.width; x++) {
for (let y = 0; y < this.display.height; y++) {
this.display.setPixel(x, y, [Math.sin(((x + t)*0.017)) * 255, Math.cos(((y + t)*0.017)) * 255, 255*Math.tan(x+y)/2]);
}
}
// Sends to display
this.display.flush();
}
};