Skip to content

Commit 392957c

Browse files
authored
Merge pull request #45 from tommmb/master
add plasma effect
2 parents b82a052 + eda6315 commit 392957c

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
return class MyEffect {
2+
constructor(display) {
3+
this.display = display;
4+
this.#clear();
5+
6+
// Time and animation parameters
7+
this.time = 0;
8+
this.speed = 0.03;
9+
10+
// Display dimensions
11+
this.width = display.width;
12+
this.height = display.height;
13+
this.centerX = this.width / 2;
14+
this.centerY = this.height / 2;
15+
this.maxDistance = Math.sqrt(this.centerX * this.centerX + this.centerY * this.centerY);
16+
17+
// Color parameters
18+
this.colorCycle = 20;
19+
this.colorShift = 2.0;
20+
21+
// Pattern parameters
22+
this.waveScale = 15;
23+
this.waveSpeed = 2;
24+
25+
// No particles in this version
26+
}
27+
28+
#clear() {
29+
for (let x = 0; x < this.width; x++) {
30+
for (let y = 0; y < this.height; y++) {
31+
this.display.setPixel(x, y, [0, 0, 0]);
32+
}
33+
}
34+
this.display.flush();
35+
}
36+
37+
// Particle system removed
38+
39+
update() {
40+
// Update time
41+
this.time += this.speed;
42+
43+
// No particle updates needed
44+
45+
// Pre-calculate time-based values
46+
const timeVal1 = this.time;
47+
const timeVal2 = this.time * 0.8;
48+
const timeVal3 = this.time * this.waveSpeed;
49+
const timeVal4 = this.time * 0.5;
50+
const colorTimeBase = this.time / this.colorCycle;
51+
52+
// Render each pixel
53+
for (let x = 0; x < this.width; x++) {
54+
// Pre-calculate x-dependent values
55+
const xWave = Math.sin(x / this.waveScale + timeVal1) * 0.5;
56+
57+
for (let y = 0; y < this.height; y++) {
58+
// Calculate relative position from center
59+
const dx = x - this.centerX;
60+
const dy = y - this.centerY;
61+
const distance = Math.sqrt(dx * dx + dy * dy);
62+
const angle = Math.atan2(dy, dx);
63+
64+
// Calculate vignette effect (darker at edges)
65+
const vignette = 1 - (distance / this.maxDistance) * 0.3;
66+
67+
// Base pattern value - flowing plasma effect
68+
const yWave = Math.sin(y / this.waveScale + timeVal2) * 0.5;
69+
const distanceWave = Math.sin(distance / this.waveScale - timeVal3) * 0.5;
70+
const angleWave = Math.sin(angle * 5 + timeVal4) * 0.5;
71+
72+
let value = xWave + yWave + distanceWave + angleWave;
73+
74+
// Add fractal-like detail
75+
value += Math.sin((x * y) / (this.waveScale * 10) + timeVal1) * 0.2;
76+
77+
// Particle influence removed
78+
79+
// Add oscillating ring effect
80+
const ringEffect = Math.sin(distance / 10 - this.time * 1.5) * 0.2 *
81+
Math.exp(-Math.abs(distance - 50 * (1 + Math.sin(this.time * 0.2))) / 20);
82+
value += ringEffect;
83+
84+
// Normalize value to 0-1 range
85+
value = (value + 2.5) / 5;
86+
87+
// Calculate color with shifting phase
88+
const r = Math.sin(value * Math.PI * 2 + colorTimeBase) * 0.5 + 0.5;
89+
const g = Math.sin(value * Math.PI * 2 + colorTimeBase + this.colorShift) * 0.5 + 0.5;
90+
const b = Math.sin(value * Math.PI * 2 + colorTimeBase + this.colorShift * 2) * 0.5 + 0.5;
91+
92+
// Apply color power for more vibrant colors and vignette effect
93+
const color = [
94+
Math.floor(r * r * 255 * vignette),
95+
Math.floor(g * g * 255 * vignette),
96+
Math.floor(b * b * 255 * vignette)
97+
];
98+
99+
// Set pixel
100+
this.display.setPixel(x, y, color);
101+
}
102+
}
103+
104+
// Particle cores removed
105+
106+
// Flush the display
107+
this.display.flush();
108+
}
109+
}

0 commit comments

Comments
 (0)