File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change 1
- import { main } from "./lava/app"
1
+ import { startLavaAnimation } from "./lava/app"
2
2
import { createEffect } from 'solid-js' ;
3
3
4
4
function App ( ) {
5
- createEffect ( ( ) => {
6
- main ( )
7
- } )
5
+ createEffect ( ( ) => startLavaAnimation ( ) )
8
6
9
7
return (
10
8
< >
11
- { /* Background */ }
9
+ { /* Background. Mounting point for lava animation */ }
12
10
< canvas id = "background" class = "fixed inset-0 w-screen h-screen" />
13
11
14
12
{ /* Content */ }
Original file line number Diff line number Diff line change @@ -3,7 +3,15 @@ import * as TWGL from 'twgl.js';
3
3
import vertexShader from './glsl/vertex.glsl' ;
4
4
import fragmentShader from './glsl/fragment.glsl' ;
5
5
6
- export function main ( ) {
6
+ /**
7
+ * Initializes and starts a WebGL-based lava animation in the background canvas.
8
+ * The animation uses spherical coordinates to position the camera and renders
9
+ * a full-screen quad with custom shaders.
10
+ *
11
+ * @returns {Function } A cleanup function that cancels the animation frame when called
12
+ * @throws {Error } If WebGL context cannot be obtained or shader compilation fails
13
+ */
14
+ export function startLavaAnimation ( ) {
7
15
// Calculate camera position
8
16
// based on THREE.Vector3.setFromSphericalCoords(radius, phi, theta)
9
17
const DEG_TO_RAD = Math . PI / 180 ;
@@ -57,4 +65,7 @@ export function main() {
57
65
58
66
frameId = requestAnimationFrame ( render ) ;
59
67
}
68
+
69
+ // Return cleanup function
70
+ return ( ) => cancelAnimationFrame ( frameId ) ;
60
71
}
You can’t perform that action at this time.
0 commit comments