-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
178 lines (148 loc) · 5.93 KB
/
Copy pathindex.html
File metadata and controls
178 lines (148 loc) · 5.93 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Binary Waveforms</title>
<style>
body {
margin: 0;
background-color: #05050a;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
overflow: hidden;
font-family: sans-serif;
}
#canvas3d {
width: 100vw;
height: 100vh;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
</head>
<body>
<div id="canvas3d"></div>
<script>
// --- 1. Setup Three.js Scene, Camera, and Renderer ---
const container = document.getElementById('canvas3d');
const scene = new THREE.Scene();
// Lighter fog so the brighter particles aren't dimmed in the distance
scene.fog = new THREE.FogExp2(0x05050a, 0.008);
const camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 50, 100);
camera.lookAt(0, 0, 0);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(window.devicePixelRatio);
// Boost overall output brightness/contrast
if (renderer.toneMapping !== undefined) {
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.6;
}
container.appendChild(renderer.domElement);
// --- 2. Create Particle Shell ---
const particleCount = 16000; // a bit denser for more presence
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(particleCount * 3);
const colors = new Float32Array(particleCount * 3);
const particleRadii = new Float32Array(particleCount);
const maxRadius = 40;
for (let i = 0; i < particleCount; i++) {
const u = Math.random();
const v = Math.random();
const theta = u * 2.0 * Math.PI;
const phi = Math.acos(2.0 * v - 1.0);
const r = Math.random() * maxRadius;
particleRadii[i] = r;
const x = r * Math.sin(phi) * Math.cos(theta);
const y = r * Math.sin(phi) * Math.sin(theta);
const z = r * Math.cos(phi);
positions[i * 3] = x;
positions[i * 3 + 1] = y;
positions[i * 3 + 2] = z;
colors[i * 3] = 0;
colors[i * 3 + 1] = 0;
colors[i * 3 + 2] = 0;
}
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
const material = new THREE.PointsMaterial({
size: 1.3, // smaller points, still bright via additive blending
vertexColors: true,
transparent: true,
opacity: 1.0, // full opacity, let additive blending do the glow work
blending: THREE.AdditiveBlending,
depthWrite: false
});
const particleSystem = new THREE.Points(geometry, material);
scene.add(particleSystem);
const boundaryGeo = new THREE.SphereGeometry(maxRadius, 16, 16);
const boundaryMat = new THREE.MeshBasicMaterial({
color: 0xffffff,
wireframe: true,
transparent: true,
opacity: 0.06 // slightly more visible shell
});
const boundaryMesh = new THREE.Mesh(boundaryGeo, boundaryMat);
scene.add(boundaryMesh);
// --- 3. Animation and Wave Physics ---
let currentRadius = 0;
const waveSpeed = 0.3; // a touch faster — more energetic pulse
const waveWidth = 4.5; // slightly wider wavefront
const intensityBoost = 1.6; // overdrive multiplier for brightness/power
function animate() {
requestAnimationFrame(animate);
currentRadius += waveSpeed;
if (currentRadius > maxRadius + waveWidth) {
currentRadius = 0;
}
const colorAttribute = geometry.attributes.color;
for (let i = 0; i < particleCount; i++) {
const r = particleRadii[i];
// 1. Outward Wave (Cyan)
let distOut = Math.abs(r - currentRadius);
let ampOut = 0;
if (distOut < waveWidth) {
ampOut = Math.cos((distOut / waveWidth) * Math.PI) * 0.5 + 0.5;
}
// 2. Inward Wave (Red)
let inwardWaveFront = maxRadius - currentRadius;
let distIn = Math.abs(r - inwardWaveFront);
let ampIn = 0;
if (distIn < waveWidth) {
ampIn = -(Math.cos((distIn / waveWidth) * Math.PI) * 0.5 + 0.5);
}
// 3. Destructive Combination
let netAmplitude = ampOut + ampIn;
// Overdrive: push intensity above 1.0 — additive blending lets
// overlapping/bright particles bloom hotter without changing hue
let boosted = netAmplitude * intensityBoost;
if (boosted > 0.01) {
colorAttribute.setXYZ(i, 0, boosted, boosted);
} else if (boosted < -0.01) {
colorAttribute.setXYZ(i, Math.abs(boosted), 0, 0);
} else {
// faint ambient glow instead of pure black, so the sphere
// never goes fully dark between pulses
colorAttribute.setXYZ(i, 0.02, 0.02, 0.03);
}
}
colorAttribute.needsUpdate = true;
particleSystem.rotation.y += 0.0028;
particleSystem.rotation.x += 0.0014;
boundaryMesh.rotation.y += 0.0028;
boundaryMesh.rotation.x += 0.0014;
renderer.render(scene, camera);
}
window.addEventListener('resize', onWindowResize, false);
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
animate();
</script>
</body>
</html>