summaryrefslogtreecommitdiff
path: root/internal/generator/templates/themes/cosmos/theme.js
blob: be51bd7aae4d5992a3250c43fde2208721b5db67 (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

    (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();
        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(48,1,0.1,90);ca.position.set(0,0.5,10);
        var planet=new THREE.Mesh(new THREE.SphereGeometry(1.35,24,24),new THREE.MeshBasicMaterial({color:0xc8853a,transparent:true,opacity:0.92}));
        var ring=new THREE.Mesh(new THREE.TorusGeometry(2.1,0.05,8,64),new THREE.MeshBasicMaterial({color:0xffd166,transparent:true,opacity:0.85}));
        ring.rotation.x=Math.PI/2.25;var moon=new THREE.Mesh(new THREE.SphereGeometry(0.35,12,12),new THREE.MeshBasicMaterial({color:0x9b5de5,transparent:true,opacity:0.8}));
        moon.position.set(2.8,0.6,0.5);g.add(planet);g.add(ring);g.add(moon);sc.add(g);sz();window.addEventListener('resize',sz);
        function loop(now){raf=requestAnimationFrame(loop);var t=(now-t0)*0.001;g.rotation.y=t*0.22;planet.rotation.y=t*0.35;
            moon.position.x=2.6*Math.cos(t*0.7);moon.position.z=2.6*Math.sin(t*0.7);ren.render(sc,ca);}
        raf=requestAnimationFrame(loop);
    })();


    // Cosmos WebGL: ringed planet, swirling nebula blobs, asteroid belt, and stars.
    // The planet sits at lower-right and slowly rotates; asteroids orbit it;
    // nebula clouds drift with additive blending for a deep-space glow.
    (function() {
        var _wild = false;
        var scene, camera, renderer, clock;
        var planet, planetRings = [];
        var asteroids = [];
        var ASTEROID_COUNT = 300;
        var asteroidAngles, asteroidRadii, asteroidSpeeds, asteroidY;

        function buildPlanet() {
            // Planet body — warm golden tone
            planet = new THREE.Mesh(
                new THREE.SphereGeometry(14, 48, 48),
                new THREE.MeshPhongMaterial({
                    color: 0xc8853a, emissive: 0x3a1800, emissiveIntensity: 0.4, shininess: 60
                })
            );
            planet.position.set(28, -18, -55);
            scene.add(planet);

            // Ring system — 5 tilted torus rings in gold/purple
            var ringCols = [0xffd166, 0xc07c30, 0xffd166, 0x9b5de5, 0xffd166];
            for (var i = 0; i < 5; i++) {
                var ring = new THREE.Mesh(
                    new THREE.TorusGeometry(18 + i * 2.5, 0.5 - i * 0.06, 8, 128),
                    new THREE.MeshBasicMaterial({ color: ringCols[i], transparent: true, opacity: 0.55 - i * 0.08, side: THREE.DoubleSide })
                );
                ring.position.copy(planet.position);
                ring.rotation.x = Math.PI / 2.4;
                ring.rotation.z = 0.2;
                scene.add(ring);
                planetRings.push(ring);
            }
        }

        function buildNebula() {
            // Large translucent additive blobs for the nebula cloud
            var nCols = [0x9b5de5, 0x4cc9f0, 0x7b2fff, 0x4cc9f0, 0x9b5de5];
            var nPos  = [[-30,20,-80],[-10,-10,-90],[20,30,-70],[-20,-25,-95],[10,15,-85]];
            nCols.forEach(function(c, i) {
                var mesh = new THREE.Mesh(
                    new THREE.SphereGeometry(22 + i * 4, 16, 16),
                    new THREE.MeshBasicMaterial({
                        color: c, transparent: true, opacity: 0.09,
                        blending: THREE.AdditiveBlending, depthWrite: false
                    })
                );
                mesh.position.set(nPos[i][0], nPos[i][1], nPos[i][2]);
                scene.add(mesh);
            });
        }

        function buildAsteroids() {
            asteroidAngles = new Float32Array(ASTEROID_COUNT);
            asteroidRadii  = new Float32Array(ASTEROID_COUNT);
            asteroidSpeeds = new Float32Array(ASTEROID_COUNT);
            asteroidY      = new Float32Array(ASTEROID_COUNT);

            var geo = new THREE.BufferGeometry();
            var pos = new Float32Array(ASTEROID_COUNT * 3);
            for (var i = 0; i < ASTEROID_COUNT; i++) {
                asteroidAngles[i] = Math.random() * Math.PI * 2;
                asteroidRadii[i]  = 20 + Math.random() * 12;
                asteroidSpeeds[i] = 0.003 + Math.random() * 0.004;
                asteroidY[i]      = (Math.random() - 0.5) * 3;
                pos[i*3] = pos[i*3+1] = pos[i*3+2] = 0;
            }
            geo.setAttribute('position', new THREE.BufferAttribute(pos, 3));
            asteroids = new THREE.Points(geo, new THREE.PointsMaterial({
                color: 0xaaaaaa, size: 0.3, transparent: true, opacity: 0.7
            }));
            // Asteroids orbit the planet — they live in planet-relative coords
            planet.add(asteroids);
        }

        function buildStars() {
            var pos = new Float32Array(2500 * 3);
            for (var i = 0; i < 2500 * 3; i += 3) {
                var r = 100 + Math.random() * 80, t = Math.random() * Math.PI * 2, p = Math.acos(2 * Math.random() - 1);
                pos[i]   = r * Math.sin(p) * Math.cos(t);
                pos[i+1] = r * Math.sin(p) * Math.sin(t);
                pos[i+2] = r * Math.cos(p);
            }
            var geo = new THREE.BufferGeometry();
            geo.setAttribute('position', new THREE.BufferAttribute(pos, 3));
            scene.add(new THREE.Points(geo, new THREE.PointsMaterial({ color: 0xffffff, size: 0.18, transparent: true, opacity: 0.85 })));
        }

        function initThree() {
            scene = new THREE.Scene();
            scene.background = new THREE.Color(0x020214);
            scene.fog = new THREE.Fog(0x020214, 80, 200);

            camera = new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 0.1, 300);
            camera.position.set(0, 6, 38);
            camera.lookAt(0, 0, 0);

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

            scene.add(new THREE.AmbientLight(0x4cc9f0, 0.4));
            var sun = new THREE.PointLight(0xffd166, 3, 300);
            sun.position.set(-60, 40, 30);
            scene.add(sun);

            buildPlanet();
            buildNebula();
            buildAsteroids();
            buildStars();

            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 t = clock.getElapsedTime();

            var sm = _wild ? 22 : 1;
            planet.rotation.y += 0.0015 * sm;

            // Planet rings tilt and counter-spin wildly
            for (var ri = 0; ri < planetRings.length; ri++) {
                planetRings[ri].rotation.y += 0.002 * sm;
                planetRings[ri].rotation.z += 0.001 * sm * (ri % 2 === 0 ? 1 : -1);
            }

            // Asteroid belt: warp-speed orbit + radial breathing + vertical scatter in wild
            var pos = asteroids.geometry.attributes.position;
            for (var i = 0; i < ASTEROID_COUNT; i++) {
                asteroidAngles[i] += asteroidSpeeds[i] * sm;
                var a = asteroidAngles[i];
                var r = asteroidRadii[i] + (_wild ? Math.sin(t * 2.1 + i * 0.3) * 9 : 0);
                var y = asteroidY[i]      + (_wild ? Math.sin(t * 3.0 + i * 0.7) * 2.5 : 0);
                pos.setXYZ(i, Math.cos(a) * r, y, Math.sin(a) * r);
            }
            pos.needsUpdate = true;

            // Camera: chaotic deep-space flight in wild, gentle orbit otherwise
            if (_wild) {
                camera.position.x = Math.sin(t * 0.38) * 20;
                camera.position.y = 6 + Math.sin(t * 0.29) * 10;
                camera.position.z = 38 + Math.sin(t * 0.21) * 14;
                camera.fov = 60 + Math.sin(t * 0.47) * 18;
            } else {
                camera.position.x = Math.sin(t * 0.06) * 6;
                camera.position.y = 6 + Math.sin(t * 0.04) * 2;
                camera.position.z = 38;
                camera.fov = 60;
            }
            camera.updateProjectionMatrix();

            renderer.render(scene, camera);
        }

        initThree();

        // Cosmos nav/wild effects — shooting star on navigate, warp speed on wild
        window.snonuxOpenEffect = function(post) {
            // Materialise from deep space — zoom + gold shimmer + orbiting ring
            var modal = document.getElementById('post-modal');
            if (modal) { modal.classList.add('sno-modal-zoom'); setTimeout(function() { modal.classList.remove('sno-modal-zoom'); }, 400); }
            var r = post ? post.getBoundingClientRect() : {left: window.innerWidth/2, top: window.innerHeight/2, width: 0, height: 0};
            var ring = document.createElement('div');
            ring.style.cssText = 'position:fixed;top:' + (r.top+r.height/2-5) + 'px;left:' + (r.left+r.width/2-5) + 'px;z-index:997;pointer-events:none;width:10px;height:10px;border-radius:50%;border:2px solid rgba(255,209,102,0.85);box-shadow:0 0 12px rgba(155,93,229,0.5);transition:all 0.4s ease,opacity 0.4s';
            document.body.appendChild(ring);
            setTimeout(function() { ring.style.transform='scale(32)'; ring.style.opacity='0'; setTimeout(function() { ring.remove(); }, 440); }, 15);
        };
        window.snonuxCloseEffect = function() {
            var d = document.createElement('div');
            d.style.cssText = 'position:fixed;inset:0;z-index:998;pointer-events:none;background:radial-gradient(ellipse at center,rgba(155,93,229,0.12) 0%,transparent 65%);transition:opacity 0.25s';
            document.body.appendChild(d);
            setTimeout(function() { d.style.opacity='0'; setTimeout(function() { d.remove(); }, 280); }, 15);
        };
        window.snonuxScrollEffect = function(dir) {
            var isDown = dir === 'down';
            var thick = _wild ? '14px' : '5px';
            var d = document.createElement('div');
            // Cosmos: purple-to-gold stardust streak
            d.style.cssText = 'position:fixed;left:0;right:0;height:' + thick + ';z-index:9000;pointer-events:none;' +
                'background:linear-gradient(90deg,transparent,rgba(155,93,229,0.9),rgba(255,200,0,0.9),rgba(155,93,229,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);
        };
        window.snonuxNavEffect = function() {
            // Shooting star CSS line flashes across screen
            var d = document.createElement('div');
            var angle = 30 + Math.random() * 30;
            d.style.cssText = 'position:fixed;top:' + (10+Math.random()*40) + '%;left:-10%;z-index:998;pointer-events:none;width:35%;height:2px;background:linear-gradient(90deg,transparent,rgba(255,209,102,0.9),transparent);transform:rotate(-' + angle + 'deg);transition:left 0.28s ease,opacity 0.28s';
            document.body.appendChild(d);
            setTimeout(function() { d.style.left='110%'; d.style.opacity='0'; setTimeout(function() { d.remove(); }, 320); }, 20);
        };
        window.snonuxPageEffect = function() {
            // Warp flash — stars streak white
            var d = document.createElement('div');
            d.style.cssText = 'position:fixed;inset:0;z-index:998;pointer-events:none;background:radial-gradient(ellipse at center,rgba(255,255,255,0.25) 0%,transparent 70%);transition:opacity 0.2s';
            document.body.appendChild(d);
            setTimeout(function() { d.style.opacity='0'; setTimeout(function() { d.remove(); }, 230); }, 20);
        };
    })();