summaryrefslogtreecommitdiff
path: root/internal/generator/templates/themes/volcano/theme.js
blob: 41de88a22554b8beb5454a15075c22216f6fe697 (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267

    (function(){
        if(document.documentElement.classList.contains('sno-splash-skip'))return;
        var cv=document.getElementById('splash-gl-canvas');
        if(!cv||typeof THREE==='undefined')return;
        var raf,ren,sc,ca,g=new THREE.Group(),t0=performance.now(),N=180,i,arr,geo,pts,pos;
        function cleanup(){window.removeEventListener('resize',sz);if(raf)cancelAnimationFrame(raf);raf=null;if(ren)ren.dispose();ren=null;window._snonuxSplashWebGLCleanup=null;}
        window._snonuxSplashWebGLCleanup=cleanup;
        function sz(){var w=cv.clientWidth||2,h=cv.clientHeight||2;if(ren)ren.setSize(w,h,false);if(ca){ca.aspect=w/h;ca.updateProjectionMatrix();}}
        ren=new THREE.WebGLRenderer({canvas:cv,antialias:true,alpha:true});ren.setClearColor(0,0);ren.setPixelRatio(Math.min(window.devicePixelRatio||1,2));
        sc=new THREE.Scene();ca=new THREE.PerspectiveCamera(52,1,0.1,70);ca.position.set(0,1.2,9);
        var cone=new THREE.Mesh(new THREE.ConeGeometry(1.5,4.2,10,1,true),new THREE.MeshBasicMaterial({color:0xff4400,wireframe:true,transparent:true,opacity:0.55}));
        cone.position.y=-0.8;g.add(cone);
        arr=new Float32Array(N*3);for(i=0;i<N;i++){arr[i*3]=(Math.random()-0.5)*5;arr[i*3+1]=Math.random()*5;arr[i*3+2]=(Math.random()-0.5)*5;}
        geo=new THREE.BufferGeometry();geo.setAttribute('position',new THREE.BufferAttribute(arr,3));
        pts=new THREE.Points(geo,new THREE.PointsMaterial({color:0xff8c00,size:0.1,transparent:true,opacity:0.75,blending:THREE.AdditiveBlending,depthWrite:false,sizeAttenuation:true}));
        g.add(pts);pos=geo.attributes.position;sc.add(g);sz();window.addEventListener('resize',sz);
        function loop(now){raf=requestAnimationFrame(loop);var t=(now-t0)*0.001,j,p,sp;
            for(j=0;j<pos.count;j++){p=j*3;sp=0.05+Math.sin(t*2.2+j*0.13)*0.018;pos.array[p+1]+=sp;if(pos.array[p+1]>6){pos.array[p+1]=-0.5;pos.array[p]=Math.sin(j*1.7+t)*2.2;}}
            pos.needsUpdate=true;cone.rotation.y=t*0.25;ren.render(sc,ca);}
        raf=requestAnimationFrame(loop);
    })();


    // Volcano WebGL: glowing lava floor, molten rock boulders, smoke plumes,
    // underground furnace glow sphere, and 3000 rising ember particles.
    (function() {
        var _wild = false;
        var N_EMBER = 3000;
        var N_SMOKE = 800;
        var scene, camera, renderer, clock;
        var emberPoints, smokePoints;
        var ePosArr, eColArr, sPosArr;
        var ePX, ePY, ePZ, eVX, eVY, eLife, eMaxLife;
        var sPX, sPY, sPZ, sSVY, sSLife, sSMaxLife;
        var lavaGeo, lavaFloor;

        function resetEmber(i) {
            ePX[i] = (Math.random() - 0.5) * 70;
            ePY[i] = -22 + (Math.random() - 0.5) * 4;
            ePZ[i] = (Math.random() - 0.5) * 30 - 5;
            eVX[i] = (Math.random() - 0.5) * 0.08;
            eVY[i] = 0.07 + Math.random() * 0.14;
            eMaxLife[i] = 0.4 + Math.random() * 0.6;
            eLife[i] = Math.random();
        }

        function resetSmoke(i) {
            sPX[i] = (Math.random() - 0.5) * 40;
            sPY[i] = -18 + Math.random() * 5;
            sPZ[i] = (Math.random() - 0.5) * 20 - 5;
            sSVY[i] = 0.015 + Math.random() * 0.025;
            sSMaxLife[i] = 1.5 + Math.random() * 2.0;
            sSLife[i] = Math.random();
        }

        function buildLavaFloor() {
            lavaGeo = new THREE.PlaneGeometry(200, 200, 60, 60);
            lavaFloor = new THREE.Mesh(lavaGeo, new THREE.MeshPhongMaterial({
                color: 0x8b1000, emissive: 0xff2200, emissiveIntensity: 0.6,
                shininess: 120
            }));
            lavaFloor.rotation.x = -Math.PI / 2;
            lavaFloor.position.y = -22;
            scene.add(lavaFloor);
        }

        function buildBoulders() {
            // Molten rock boulders with glowing emissive cores
            var boulderData = [
                [-18,-16,-15, 5], [20,-15,-20, 7], [-8,-14,-30, 4],
                [30,-16,-12, 6], [-28,-15,-25, 5]
            ];
            boulderData.forEach(function(b) {
                var mesh = new THREE.Mesh(
                    new THREE.IcosahedronGeometry(b[3], 1),
                    new THREE.MeshPhongMaterial({ color: 0x1a0500, emissive: 0xff4400, emissiveIntensity: 0.7, shininess: 20 })
                );
                mesh.position.set(b[0], b[1], b[2]);
                mesh.rotation.set(Math.random(), Math.random(), Math.random());
                scene.add(mesh);
            });
        }

        function buildFurnaceGlow() {
            // Underground furnace: massive low-opacity emissive sphere below the lava
            var glow = new THREE.Mesh(
                new THREE.SphereGeometry(45, 16, 16),
                new THREE.MeshBasicMaterial({ color: 0xff3300, transparent: true, opacity: 0.22, blending: THREE.AdditiveBlending, depthWrite: false })
            );
            glow.position.set(0, -60, -30);
            scene.add(glow);
        }

        function buildParticles() {
            ePX = new Float32Array(N_EMBER); ePY = new Float32Array(N_EMBER);
            ePZ = new Float32Array(N_EMBER); eVX = new Float32Array(N_EMBER);
            eVY = new Float32Array(N_EMBER); eLife = new Float32Array(N_EMBER);
            eMaxLife = new Float32Array(N_EMBER);
            ePosArr = new Float32Array(N_EMBER * 3);
            eColArr = new Float32Array(N_EMBER * 3);
            for (var i = 0; i < N_EMBER; i++) resetEmber(i);
            var eGeo = new THREE.BufferGeometry();
            eGeo.setAttribute('position', new THREE.BufferAttribute(ePosArr, 3));
            eGeo.setAttribute('color',    new THREE.BufferAttribute(eColArr, 3));
            emberPoints = new THREE.Points(eGeo, new THREE.PointsMaterial({
                size: 0.3, vertexColors: true,
                transparent: true, opacity: 0.95, blending: THREE.AdditiveBlending, depthWrite: false
            }));
            scene.add(emberPoints);

            sPX = new Float32Array(N_SMOKE); sPY = new Float32Array(N_SMOKE);
            sPZ = new Float32Array(N_SMOKE); sSVY = new Float32Array(N_SMOKE);
            sSLife = new Float32Array(N_SMOKE); sSMaxLife = new Float32Array(N_SMOKE);
            sPosArr = new Float32Array(N_SMOKE * 3);
            for (var j = 0; j < N_SMOKE; j++) resetSmoke(j);
            var sGeo = new THREE.BufferGeometry();
            sGeo.setAttribute('position', new THREE.BufferAttribute(sPosArr, 3));
            smokePoints = new THREE.Points(sGeo, new THREE.PointsMaterial({
                color: 0x444444, size: 1.8, transparent: true, opacity: 0.15, depthWrite: false
            }));
            scene.add(smokePoints);
        }

        function initThree() {
            scene = new THREE.Scene();
            scene.background = new THREE.Color(0x0d0802);
            scene.fog = new THREE.Fog(0x0d0802, 35, 100);

            camera = new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 0.1, 150);
            camera.position.set(0, 8, 50);
            camera.lookAt(0, -5, 0);

            renderer = new THREE.WebGLRenderer({ canvas: document.getElementById('three-canvas'), antialias: false });
            renderer.setSize(window.innerWidth, window.innerHeight);
            renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
            clock = new THREE.Clock();

            scene.add(new THREE.AmbientLight(0x220800, 1.0));
            var lavaLight = new THREE.PointLight(0xff4400, 4, 80);
            lavaLight.position.set(0, -15, 0);
            scene.add(lavaLight);

            buildLavaFloor();
            buildBoulders();
            buildFurnaceGlow();
            buildParticles();

            window.addEventListener('resize', onResize);
            animate();
        }

        function onResize() {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
        }

        function animate() {
            requestAnimationFrame(animate);
            var dt = clock.getDelta();
            var t  = clock.getElapsedTime();

            // Pulse the lava floor emissive intensity
            lavaFloor.material.emissiveIntensity = 0.4 + 0.25 * Math.sin(t * 1.8);

            // Animate lava floor vertices
            var lp = lavaGeo.attributes.position;
            for (var i = 0; i < lp.count; i++) {
                var lx = lp.getX(i), lz = lp.getZ(i);
                lp.setY(i, Math.sin(lx * 0.08 + t * 0.7) * 0.8 + Math.cos(lz * 0.1 + t * 0.5) * 0.6);
            }
            lp.needsUpdate = true;

            // Embers — wild mode eruption multiplies velocity 8x and shrinks lifespan
            var emberMult = _wild ? 8 : 1;
            for (var ei = 0; ei < N_EMBER; ei++) {
                eLife[ei] += dt / eMaxLife[ei] * emberMult;
                if (eLife[ei] > 1.0) resetEmber(ei);
                ePY[ei] += eVY[ei] * emberMult;
                ePX[ei] += eVX[ei] * emberMult;
                var idx = ei * 3, te = eLife[ei];
                ePosArr[idx] = ePX[ei]; ePosArr[idx+1] = ePY[ei]; ePosArr[idx+2] = ePZ[ei];
                var fade = Math.max(0, 1 - te * 1.3);
                eColArr[idx] = fade; eColArr[idx+1] = fade * Math.max(0, 1 - te * 2.2); eColArr[idx+2] = 0;
            }
            emberPoints.geometry.attributes.position.needsUpdate = true;
            emberPoints.geometry.attributes.color.needsUpdate    = true;

            // Smoke — wild mode makes smoke billow chaotically
            var smokeMult = _wild ? 5 : 1;
            for (var si = 0; si < N_SMOKE; si++) {
                sSLife[si] += dt / sSMaxLife[si] * smokeMult;
                if (sSLife[si] > 1.0) resetSmoke(si);
                sPY[si] += sSVY[si] * smokeMult;
                sPX[si] += (Math.random() - 0.5) * 0.04;
                var si3 = si * 3;
                sPosArr[si3] = sPX[si]; sPosArr[si3+1] = sPY[si]; sPosArr[si3+2] = sPZ[si];
            }
            smokePoints.geometry.attributes.position.needsUpdate = true;

            renderer.render(scene, camera);
        }

        initThree();

        // Volcano nav/wild effects — seismic tremor on navigate, full eruption on wild
        window.snonuxOpenEffect = function(post) {
            // Fly up from below like molten rock erupting
            var modal = document.getElementById('post-modal');
            if (modal) { modal.classList.add('sno-modal-fly'); setTimeout(function() { modal.classList.remove('sno-modal-fly'); }, 400); }
            // Ember burst from post position
            var r = post ? post.getBoundingClientRect() : {left: window.innerWidth/2, top: window.innerHeight/2};
            for (var i = 0; i < 6; i++) {
                (function(i) {
                    var e = document.createElement('div');
                    var ang = (i / 6) * Math.PI * 2; var dist = 60 + Math.random() * 60;
                    e.style.cssText = 'position:fixed;top:' + (r.top+r.height/2) + 'px;left:' + (r.left+r.width/2) + 'px;z-index:997;pointer-events:none;width:5px;height:5px;border-radius:50%;background:rgba(255,' + Math.floor(80+Math.random()*100) + ',0,0.9);transition:all 0.45s ease,opacity 0.45s';
                    document.body.appendChild(e);
                    setTimeout(function() { e.style.transform='translate(' + (Math.cos(ang)*dist) + 'px,' + (Math.sin(ang)*dist-50) + 'px) scale(0.2)'; e.style.opacity='0'; setTimeout(function() { e.remove(); }, 480); }, 20);
                })(i);
            }
        };
        window.snonuxCloseEffect = function() {
            var d = document.createElement('div');
            d.style.cssText = 'position:fixed;inset:0;z-index:998;pointer-events:none;background:rgba(255,68,0,0.12);transition:opacity 0.18s';
            document.body.appendChild(d);
            setTimeout(function() { d.style.opacity='0'; setTimeout(function() { d.remove(); }, 200); }, 15);
        };
        window.snonuxScrollEffect = function(dir) {
            var isDown = dir === 'down';
            var thick = _wild ? '14px' : '5px';
            var d = document.createElement('div');
            d.style.cssText = 'position:fixed;left:0;right:0;height:' + thick + ';z-index:9000;pointer-events:none;' +
                'background:linear-gradient(90deg,transparent,rgba(255,68,0,0.9),rgba(255,165,0,0.9),transparent);' +
                (isDown ? 'top:0;' : 'bottom:0;') +
                'transition:transform 0.3s ease,opacity 0.3s ease;';
            document.body.appendChild(d);
            setTimeout(function() { d.style.transform = isDown ? 'translateY(100vh)' : 'translateY(-100vh)'; d.style.opacity='0'; }, 16);
            setTimeout(function() { d.remove(); }, 380);
        };
        window.snonuxWildToggle = function() {
            _wild = !_wild;
            var b = document.getElementById('sno-wild-badge');
            if (b) b.classList.toggle('sno-wild-on', _wild);
            // Boost lava emissive intensity in wild eruption mode
            if (lavaFloor) lavaFloor.material.emissiveIntensity = _wild ? 2.5 : 0.6;
        };
        window.snonuxNavEffect = function() {
            // Seismic tremor — strong shake
            var ov = document.querySelector('.overlay');
            if (ov) { ov.classList.add('sno-fx-shake'); setTimeout(function() { ov.classList.remove('sno-fx-shake'); }, 420); }
            // Orange ember flash
            var d = document.createElement('div');
            d.style.cssText = 'position:fixed;inset:0;z-index:998;pointer-events:none;background:rgba(255,68,0,0.2);transition:opacity 0.25s';
            document.body.appendChild(d);
            setTimeout(function() { d.style.opacity='0'; setTimeout(function() { d.remove(); }, 280); }, 30);
        };
        window.snonuxPageEffect = function() {
            var d = document.createElement('div');
            d.style.cssText = 'position:fixed;inset:0;z-index:998;pointer-events:none;background:rgba(255,140,0,0.25);transition:opacity 0.2s';
            document.body.appendChild(d);
            setTimeout(function() { d.style.opacity='0'; setTimeout(function() { d.remove(); }, 220); }, 20);
            var ov = document.querySelector('.overlay');
            if (ov) { ov.classList.add('sno-fx-zoom'); setTimeout(function() { ov.classList.remove('sno-fx-zoom'); }, 330); }
        };
    })();