-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgaussian-waves.html
More file actions
296 lines (251 loc) · 12.1 KB
/
gaussian-waves.html
File metadata and controls
296 lines (251 loc) · 12.1 KB
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gaussian Wave Dynamics</title>
<style>
body { margin: 0; overflow: hidden; background-color: #010103; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
canvas { display: block; }
/* Settings Button (Glassmorphism Style) */
#settings-button {
position: absolute;
top: 20px;
right: 20px;
width: 50px;
height: 50px;
background: rgba(255, 255, 255, 0.08);
backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
z-index: 100;
transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
color: white;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
#settings-button:hover {
background: rgba(255, 255, 255, 0.15);
transform: rotate(90deg) scale(1.1);
}
#settings-button svg {
width: 28px;
height: 28px;
fill: currentColor;
}
/* Control Panel Container */
#gui-container {
position: absolute;
top: 85px;
right: 20px;
z-index: 99;
transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
opacity: 0;
pointer-events: none;
transform: translateY(-20px);
}
#gui-container.visible {
opacity: 1;
pointer-events: auto;
transform: translateY(0);
}
/* Custom lil-gui Styling for Glassmorphism Effect */
.lil-gui {
--background-color: rgba(15, 15, 25, 0.85) !important;
--header-color: rgba(40, 40, 60, 0.9) !important;
--widget-color: rgba(255, 255, 255, 0.05) !important;
--number-color: #a39155 !important;
backdrop-filter: blur(20px) !important;
border: 1px solid rgba(255, 255, 255, 0.1) !important;
border-radius: 14px !important;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8) !important;
padding: 10px !important;
}
#ui-info {
position: absolute;
bottom: 25px;
left: 25px;
color: rgba(255, 255, 255, 0.2);
pointer-events: none;
font-size: 10px;
text-transform: uppercase;
letter-spacing: 4px;
}
</style>
</head>
<body>
<div id="ui-info">Wave Dynamics • Interference Engine</div>
<div id="settings-button" title="Adjust Parameters">
<svg viewBox="0 0 24 24">
<path d="M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.13,5.91,7.62,6.29L5.23,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.72,8.87 c-0.11,0.21-0.06,0.47,0.12,0.61l2.03,1.58C4.84,11.36,4.81,11.68,4.81,12c0,0.32,0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z"/>
</svg>
</div>
<div id="gui-container"></div>
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/",
"lil-gui": "https://cdn.jsdelivr.net/npm/lil-gui@0.19/+esm"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import GUI from 'lil-gui';
// --- Scene Setup ---
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.set(0, 0, 3.2);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
document.body.appendChild(renderer.domElement);
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.autoRotate = true;
controls.autoRotateSpeed = 0.5;
// --- Initial Parameters (Requested) ---
const params = {
amplitude: 0.1144, // Wave Force
decay: 1.122, // Echo Duration
interval: 1.9305, // Wave Interval
waveFreq: 24.43, // Wave Density
speed: 0.342, // Exp. Speed
colorInner: '#050510', // Base Color (Deep Dark)
colorOuter: '#a39155', // Crest Color (Golden)
wireframe: false
};
const uniforms = {
uTime: { value: 0 },
uAmplitude: { value: params.amplitude },
uDecay: { value: params.decay },
uInterval: { value: params.interval },
uWaveFreq: { value: params.waveFreq },
uSpeed: { value: params.speed },
uColorInner: { value: new THREE.Color(params.colorInner) },
uColorOuter: { value: new THREE.Color(params.colorOuter) }
};
// --- Vertex Shader: Wave Dynamics ---
const vertexShader = `
varying vec3 vNormal;
varying vec3 vPosition;
varying float vEnergy;
uniform float uTime;
uniform float uAmplitude;
uniform float uDecay;
uniform float uInterval;
uniform float uWaveFreq;
uniform float uSpeed;
// Hash function for pseudo-random wave origins
vec3 hash31(float p) {
vec3 p3 = fract(vec3(p) * vec3(.1031, .1030, .0973));
p3 += dot(p3, p3.yzx + 33.33);
return normalize(fract((p3.xxy + p3.yzz) * p3.zyx) - 0.5);
}
float getWaveRipples(vec3 p, float id) {
float offset = id * 1.618;
float tLocal = mod(uTime + offset, uInterval);
float cycleId = floor((uTime + offset) / uInterval);
vec3 originPos = hash31(id + cycleId * 10.0);
float dist = acos(clamp(dot(normalize(p), normalize(originPos)), -1.0, 1.0));
float radius = tLocal * uSpeed * 2.5;
float timeDecay = exp(-tLocal * uDecay);
// Concentric ripples calculation
float ripple = sin(uWaveFreq * (dist - radius)) * exp(-abs(dist - radius) * 5.0);
float echo = sin(uWaveFreq * 0.8 * (dist - radius * 0.8)) * exp(-abs(dist - radius * 0.8) * 8.0) * 0.4;
float mask = smoothstep(0.2, -0.1, dist - radius);
return (ripple + echo) * timeDecay * mask;
}
void main() {
vNormal = normal;
vec3 pos = position;
float totalW = 0.0;
// Process 10 simultaneous wave fronts
for(float i = 0.0; i < 10.0; i++) {
totalW += getWaveRipples(pos, i);
}
vEnergy = totalW;
// Radial displacement based on wave energy
vec3 newPos = pos + normalize(pos) * (totalW * uAmplitude);
vPosition = newPos;
gl_Position = projectionMatrix * modelViewMatrix * vec4(newPos, 1.0);
}
`;
// --- Fragment Shader: Golden Aesthetics & Glow ---
const fragmentShader = `
varying vec3 vNormal;
varying vec3 vPosition;
varying float vEnergy;
uniform vec3 uColorInner;
uniform vec3 uColorOuter;
void main() {
vec3 n = normalize(vNormal);
vec3 viewDir = normalize(cameraPosition - vPosition);
// Fresnel effect for atmospheric edge highlight
float fresnel = pow(1.0 - dot(n, viewDir), 2.5);
float intensity = abs(vEnergy);
// Mix colors based on ripple intensity
vec3 baseColor = mix(uColorInner, uColorOuter, smoothstep(0.0, 1.2, intensity));
// Neon/Metallic glow effect on crests
vec3 glow = uColorOuter * pow(intensity, 1.5) * 4.0;
vec3 finalColor = baseColor + (glow * 0.4) + (fresnel * uColorOuter * 0.5);
// Add depth and contrast
finalColor *= (0.35 + intensity * 0.65);
gl_FragColor = vec4(finalColor, 1.0);
}
`;
// --- Geometry Setup ---
const geometry = new THREE.IcosahedronGeometry(1, 110);
const material = new THREE.ShaderMaterial({
vertexShader,
fragmentShader,
uniforms
});
const sphere = new THREE.Mesh(geometry, material);
scene.add(sphere);
// Background Stars
const starCoords = [];
for(let i=0; i<1000; i++) starCoords.push((Math.random()-0.5)*20, (Math.random()-0.5)*20, (Math.random()-0.5)*20);
const starGeo = new THREE.BufferGeometry();
starGeo.setAttribute('position', new THREE.Float32BufferAttribute(starCoords, 3));
const starMat = new THREE.PointsMaterial({ color: 0x444466, size: 0.01 });
scene.add(new THREE.Points(starGeo, starMat));
// --- User Interface (English) ---
const guiContainer = document.getElementById('gui-container');
const gui = new GUI({ container: guiContainer, title: 'Wave Parameters' });
gui.add(params, 'decay', 0.1, 5.0).name('Echo Duration').onChange(v => uniforms.uDecay.value = v);
gui.add(params, 'interval', 0.5, 6.0).name('Wave Interval').onChange(v => uniforms.uInterval.value = v);
gui.add(params, 'amplitude', 0, 0.4).name('Wave Amplitude').onChange(v => uniforms.uAmplitude.value = v);
gui.add(params, 'waveFreq', 5, 80).name('Wave Density').onChange(v => uniforms.uWaveFreq.value = v);
gui.add(params, 'speed', 0.1, 2.0).name('Expansion Speed').onChange(v => uniforms.uSpeed.value = v);
gui.addColor(params, 'colorInner').name('Base Color').onChange(v => uniforms.uColorInner.value.set(v));
gui.addColor(params, 'colorOuter').name('Crest Color').onChange(v => uniforms.uColorOuter.value.set(v));
gui.add(params, 'wireframe').name('View Wireframe').onChange(v => material.wireframe = v);
// Settings toggle logic
const settingsBtn = document.getElementById('settings-button');
settingsBtn.addEventListener('click', () => {
guiContainer.classList.toggle('visible');
});
// --- Animation Loop ---
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
uniforms.uTime.value = clock.getElapsedTime();
controls.update();
renderer.render(scene, camera);
}
animate();
// Handle Resize
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>