Skip to content

Commit 4c146c7

Browse files
authored
Merge pull request #43 from moolordking/master [skip ci]
New Lava Lamp Effect
2 parents 9939397 + 0a25f5d commit 4c146c7

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

web/priv/js_effects/LavaLamp.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
let t = 0;
2+
3+
return class LavaLamp {
4+
constructor(display) {
5+
this.display = display;
6+
7+
this.#clear();
8+
}
9+
10+
#clear() {
11+
this.display.flush();
12+
}
13+
14+
rounder(n, d) {
15+
n *= 2;
16+
if (n > 1) {
17+
n = 1;
18+
} else if (n < 0.8) {
19+
n = 0;
20+
}
21+
d /= this.display.width/4;
22+
if (d > 255) {
23+
d = 255;
24+
}
25+
return n * 255 - d;
26+
}
27+
28+
dist(x1,y1,x2,y2) {
29+
return (x1-x2)**2 + (y1-y2)**2;
30+
}
31+
32+
update() {
33+
t += 0.05;
34+
for (let x = 0; x < this.display.width; x++) {
35+
for (let y = 0; y < this.display.height; y++) {
36+
let dist = this.dist(this.display.width/2,this.display.height/2, x, y);
37+
let r = Math.abs((Math.sin((x/10)**1.5 + (t/3))+Math.cos((y/10)**1.5 + t)));
38+
let g = Math.abs((Math.sin((x/1)/10 - t)+Math.cos((y/1)/10 - (t/2))));
39+
let b = 1-Math.abs((Math.cos((x/0.8)/10 + t*2)+Math.tan((y/1.2)/10 - (t/2))));
40+
this.display.setPixel(x, y, [this.rounder(r - 0.5,dist), this.rounder(g - 0.5, dist), this.rounder(b,dist)]);
41+
}
42+
}
43+
this.display.flush();
44+
}
45+
}

0 commit comments

Comments
 (0)