-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
592 lines (516 loc) · 27.6 KB
/
index.html
File metadata and controls
592 lines (516 loc) · 27.6 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>retrogrids</title>
<link href="https://fonts.googleapis.com/css2?family=Michroma&display=auto" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css">
<script>
var favIcon = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAABg2lDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw1AUhU9TpSIRB4uIOGSoTnZREcdSxSJYKG2FVh1MXvoHTRqSFBdHwbXg4M9i1cHFWVcHV0EQ/AFxF5wUXaTE+5JCixgfXN7Hee8c7rsPEJpVplk9MUDTbTOdiEu5/KoUeoWIYQSpIjKzjGRmMQvf9XWPAN/vojzL/96fa0AtWAwISMQxZpg28Qbx7KZtcN4nDrOyrBKfE0+a1CDxI9cVj984l1wWeGbYzKbnicPEUqmLlS5mZVMjniGOqJpO+ULOY5XzFmetWmftPvkLxYK+kuE61RgSWEISKUhQUEcFVdiI0q6TYiFN53Ef/6jrT5FLIVcFjBwLqEGD7PrB/+D3bK3i9JSXJMaB3hfH+RgHQrtAq+E438eO0zoBgs/Ald7x15rA3CfpjY4WOQIGt4GL646m7AGXO8DIkyGbsisFqYRiEXg/o2/KA0O3QP+aN7f2OU4fgCzNavkGODgEJkqUve7z7r7uuf17pz2/H63Ccr63qadlAAAACXBIWXMAAAsTA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4CAgL9/f3////+/v4AAAAAAAAAAAAAAAAAAAAEAAAAAAAA/v7+AQEB/v7+/f39/v7+AAAA9vb2+vr6+/v7AgICAAAAAgIC/f39////CQkJAAAA/v7+/Pz8/f39AgIC/v7+/v7+9PT0/v7+/v7+////AAAAAAAAAAAAAAAABAAAAAAAAAAAAP////////z8/P///+7u7vX19fr6+vr6+gMDAwAAAP39/f7+/v7+/gICAgAAAP////39/f39/QICAv39/f////7+/v39/f39/f7+/v///wAAAAAAAP7+/gL+/v7+/v7+/v7+/v7+/v79/f0AAAD////4+Pj4+Pj7+/v7+/v7+/v9/f39/f3+/v79/f0AAADz8/P7+/v7+/v+/v77+/sODg7////9/f39/f3+/v7+/v7+/v4AAAAAAAAEAAAAAAAA/////v7+AwMDDQ0NAwMD/v7++/v7+fn5+vr6BQUFAAAAAAAACgoK/Pz8/v7+AAAA9fX1/Pz8+vr6BQUF////AwMDBgYGCAgIAAAA////////AAAA/v7+AAAABAAAAP///wMDAxISEgkJCfLy8vj4+AoKCvr6+vv7+/v7+wAAAAAAAAAAAPv7+/z8/P39/QAAAPz8/Pv7+/v7+/39/f7+/gAAAO7u7v7+/hISEv39/fHx8f7+/gAAAAAAAAQCAgITExMFBQXx8fHz8/MODg79/f38/Pzz8/P39/f7+/sAAAAAAAABAQH8/Pz///8CAgIAAAD9/f37+/v9/f3+/v7+/v7////9/f339/fr6+sAAAAXFxfx8fHw8PD+/v4EGBgY8fHx9/f3AAAABgYG+Pj419fXERER+Pj49vb2+/v7AgICAAAAAgIC/f39/Pz8BAQEAAAA/////f39+/v7+/v7////BgYG/v7++/v7+/v78/PzAAAACwsLGBgY9fX1BPn5+fj4+P7+/gAAAPv7+/f399LS0gEBASIiIgYGBuDg4Pn5+QUFBQICAv39/f///////wAAAP7+/vz8/Pv7+/f39/v7+wUFBff39/n5+fv7+/7+/v////X19QcHBwgICATz8/MUFBT7+/vx8fH9/f34+PgBAQEAAAAAAAAXFxcUFBTm5ubm5ub7+/v7+/v9/f3+/v4AAAD+/v79/f36+voAAAD9/f2xsbHl5eX39/f7+/sCAgIODg4FBQXr6+v39/cE9fX1+Pj4DAwMFBQU9/f38vLy/v7+AAAAAgIC////AQEBHh4eGxsb4uLi+Pj4+/v7/f39AAAA/Pz8+/v7DAwMHR0dDAwM0NDQ/f39/f39CwsLCQkJ8fHx6urq/v7+/v7+BAAAAP39/fPz8/T09A0NDRcXF/T09PPz8/39/QAAAAICAv39/QICAiEhIQQEBAMDA/39/QAAAPz8/BcXFw8PD/39/fb29v7+/ggICA4ODvX19eTk5P39/f7+/v///wAAAAQAAAAAAAD+/v4AAADw8PDy8vIQEBAXFxf19fX09PQAAAACAgL+/v4AAAAEBAQODg4DAwP7+/sHBwcDAwP7+/v9/f0FBQUQEBD6+vrm5ub8/Pz+/v7+/v7////+/v7///8BampqAAAAAAAAAAAAAAAAAAAAAAAAAwMDEBAQCAgI8/Pz+Pj4AAAAAgICAwMDCwsLCAgIAgIC+/v7+Pj4+/v7Dw8PAAAA7u7u9vb2/f39/v7+AAAA////AAAA/v7+////BAAAAAAAAAAAAAAAAAAAAP7+/gAAAP7+/uvr6wUFBRMTEw0NDfHx8fj4+P7+/vX19fb29gAAAAQEBAsLCw0NDezs7Pf39/7+/v39/f7+/v///wAAAP7+/v///wAAAP7+/gQAAAAAAAAAAAD+/v4AAAAAAAAAAAAAAAAAAAD7+/vq6uoGBgYQEBAEBATx8fH7+/sCAgIDAwMKCgr19fXx8fH///8AAAD+/v7+/v4AAAAAAAAAAAAAAAABAQEAAAADAwP26theipUX4gAAAABJRU5ErkJggg==";
var docHead = document.getElementsByTagName('head')[0];
var newLink = document.createElement('link');
newLink.rel = 'shortcut icon';
newLink.type = 'image/x-icon';
newLink.href = 'data:image/png;base64,'+favIcon;
docHead.appendChild(newLink);
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-FZT9SY6GH4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-FZT9SY6GH4');
</script>
<style>
body {
margin:0;
font-family:'Michroma',sans-serif; font-weight:bold;
color:#EEEEEE;
text-shadow:0 0 10px #FFFFFF, 0 0 20px #FFFFFF;
}
canvas { display:block; }
#footer {
position:fixed; bottom:0px; width:100%; display:flex;
font-size:40px;
}
#footer a { color:#FFFFFF; text-decoration:none; }
#footer a:hover { color:#000000; text-decoration:none; }
#footer > div { flex:1; padding:20px 32px 20px 32px; }
#footer > div:nth-child(2) { text-align:right; }
.noselect {
-webkit-touch-callout:none; /* iOS Safari */
-webkit-user-select:none; /* Safari */
-khtml-user-select:none; /* Konqueror HTML */
-moz-user-select:none; /* Old versions of Firefox */
-ms-user-select:none; /* Internet Explorer/Edge */
user-select:none; /* Non-prefixed version, currently
supported by Chrome, Edge, Opera and Firefox */
}
@media all and (max-width:500px) {
#footer { font-size:20px; }
#footer > div { padding:12px 16px 12px 16px; }
}
</style>
</head>
<body>
<canvas style="border:1px solid #000000; display:none;" id="texture" width="100" height="100"></canvas>
<div id="footer" class="noselect">
<div>retrogrids</div>
<div>
<span><a href="mailto:contact@retrogrids.io"><i class="far fa-envelope"></i></a></span>
<span><a href="https://github.com/retrogrids"><i class="fab fa-github"></i></a></span>
</div>
</div>
<script type="x-shader/x-vertex" id="vertexshader">
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
</script>
<script type="x-shader/x-fragment" id="fragmentshader">
uniform sampler2D baseTexture;
uniform sampler2D bloomTexture;
varying vec2 vUv;
void main() {
gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );
}
</script>
<script type="importmap">
{
"imports": {
"three": "../threejs/three.module.js"
}
}
</script>
<script type="module">
import * as THREE from "./threejs/three.module.js";
import { EffectComposer } from "./threejs/examples/jsm/postprocessing/EffectComposer.js";
import { RenderPass } from "./threejs/examples/jsm/postprocessing/RenderPass.js";
import { ShaderPass } from "./threejs/examples/jsm/postprocessing/ShaderPass.js";
import { UnrealBloomPass } from "./threejs/examples/jsm/postprocessing/UnrealBloomPass.js";
import { OutputPass } from "./threejs/examples/jsm/postprocessing/OutputPass.js";
class Fountain {
tap(modulus, x, y) {
x = (x === 0) ? 17 : x;
y = (y === 0) ? 11 : y;
return (Math.pow(x + 17, 2) + (x + 17) * (y * 13) + Math.pow(y * 13, 3)) % modulus;
}
}
class Three {
constructor() {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x333333);
this.scene = scene;
// Camera creation and configuration.
const camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.x = -15;
camera.position.y = -15;
camera.position.z = 15;
camera.lookAt(new THREE.Vector3(0, 0, 0));
camera.rotation.z = -(Math.PI / 2)/3;
camera.updateMatrixWorld();
this.camera = camera;
// Rendering pipeline components.
this.materials = {};
this.darkMaterial = new THREE.MeshBasicMaterial({ color: 'black' });
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(3 /* window.devicePixelRatio */);
renderer.toneMapping = THREE.ReinhardToneMapping;
renderer.toneMappingExposure = Math.pow(1.3, 4.0);
document.body.appendChild(renderer.domElement);
this.renderer = renderer;
const renderScene = new RenderPass(scene, camera);
// Pipeline definition (bloom).
const bloomPass = new UnrealBloomPass(new THREE.Vector2(window.innerWidth, window.innerHeight), 1.5, 0.4, 0.85);
bloomPass.threshold = Number( 0.9 );
bloomPass.strength = Number( 0.5);
bloomPass.radius = Number( 0.3 );
const bloomComposer = new EffectComposer(renderer);
bloomComposer.renderToScreen = false;
bloomComposer.addPass(renderScene);
bloomComposer.addPass(bloomPass);
this.bloomComposer = bloomComposer;
// Pipeline definition (final).
const mixPass = new ShaderPass(
new THREE.ShaderMaterial({
uniforms: {
baseTexture: { value: null },
bloomTexture: { value: bloomComposer.renderTarget2.texture }
},
vertexShader: document.getElementById("vertexshader").textContent,
fragmentShader: document.getElementById("fragmentshader").textContent,
defines: {}
}),
"baseTexture"
);
mixPass.needsSwap = true;
const outputPass = new OutputPass();
const finalComposer = new EffectComposer(renderer);
finalComposer.addPass(renderScene);
finalComposer.addPass(mixPass);
finalComposer.addPass(outputPass);
this.finalComposer = finalComposer;
// Layers.
this.layers = {BLOOM_SCENE: 1};
const bloomLayer = new THREE.Layers();
bloomLayer.set(this.layers.BLOOM_SCENE);
this.bloomLayer = bloomLayer;
}
fillWindow() {
this.renderer.setSize(window.innerWidth, window.innerHeight);
this.renderer.setPixelRatio(3 /* window.devicePixelRatio */);
}
render() {
const self = this;
self.scene.traverse(function (obj) {
if ( obj.isMesh && self.bloomLayer.test( obj.layers ) === false ) {
self.materials[ obj.uuid ] = obj.material;
obj.material = self.darkMaterial;
}
});
self.bloomComposer.render();
self.scene.traverse(function (obj) {
if ( self.materials[ obj.uuid ] ) {
obj.material = self.materials[ obj.uuid ];
delete self.materials[ obj.uuid ];
}
});
self.finalComposer.render();
}
}
class Entity extends THREE.Group {
constructor() {
super();
}
addEdges(mesh, layer) {
const entity = this;
const edgesGeometry = new THREE.EdgesGeometry(mesh.geometry);
const edgeVertices = edgesGeometry.attributes.position.array;
let howMany = 0;
for (let i = 0; i < edgeVertices.length; i += 6) {
howMany++;
const s = new THREE.Vector3(edgeVertices[i], edgeVertices[i + 1], edgeVertices[i + 2]);
const t = new THREE.Vector3(edgeVertices[i + 3], edgeVertices[i + 4], edgeVertices[i + 5]);
// Create the edge as a box connecting the two vertices.
const center = new THREE.Vector3().add(s).add(t).divideScalar(2);
const edgeVector = new THREE.Vector3().add(t).sub(s);
const size = edgeVector.length();
const edgeGeometry = new THREE.BoxGeometry(0.03, size, 0.03);
const edgeMaterial = new THREE.MeshBasicMaterial({ color: 0xFFFFFF });
const edge = new THREE.Mesh(edgeGeometry, edgeMaterial);
// Position the edge to match the calculated center.
edge.position.copy(center);
const alignmentVector = edgeVector.normalize();
const defaultAxis = new THREE.Vector3(0, 1, 0);
const quaternion = new THREE.Quaternion().setFromUnitVectors(defaultAxis, alignmentVector);
edge.applyQuaternion(quaternion);
if (!(s.z < 0 && t.z < 0)) {
entity.add(edge);
if (layer !== undefined) {
edge.layers.enable( layer );
}
}
}
}
static disposeMaterial(material) {
if (material.map) material.map.dispose();
if (material.lightMap) material.lightMap.dispose();
if (material.bumpMap) material.bumpMap.dispose();
if (material.normalMap) material.normalMap.dispose();
if (material.specularMap) material.specularMap.dispose();
if (material.envMap) material.envMap.dispose();
material.dispose();
}
dispose() {
const group = this;
group.traverse(function(child) {
if (child instanceof THREE.Mesh) {
if (child.geometry) {
child.geometry.dispose();
}
if (child.material) {
if (Array.isArray(child.material)) {
for (const material of child.material) {
Entity.disposeMaterial(material);
}
} else {
Entity.disposeMaterial(child.material);
}
}
}
});
// Iterating backwards is safer.
for (let i = group.children.length - 1; i >= 0; i--) {
group.remove(group.children[i]);
}
}
}
class State {
constructor() {
this.position = { x: 0, y: 0 };
}
}
class Vicinity {
constructor() {
this.blocks = {};
}
}
class Interaction {
constructor() {
this.drag = false;
this.dragEvent = null;
this.mouseLast = {x: null, y: null, down: false};
}
}
class App {
constructor() {
this.fountain = new Fountain();
this.three = new Three();
this.state = new State();
this.vicinity = new Vicinity();
this.interaction = new Interaction();
this.config = {};
this.roster = {};
}
updateVicinity() {
const self = this;
const radius = 50;
const state = self.state;
const alignedX = -Math.floor(state.position.x);
const alignedY = -Math.floor(state.position.y);
for (let c = alignedX - radius; c < alignedX + radius; c++) {
for (let r = alignedY - radius; r < alignedY + radius; r++) {
const x = Math.floor(c);
const y = Math.floor(r);
const coordinate = x + ',' + y;
if (Math.abs(x - alignedX - 2) + Math.abs(y - alignedY - 2) <= radius) {
if (!(coordinate in self.vicinity.blocks) || self.vicinity.blocks[coordinate] === undefined) {
const edificeMaterial = new THREE.MeshBasicMaterial({ color: 0x000000 });
const condition_one = Math.abs(self.fountain.tap(217, c + 50, r + 50)) > 150;
const condition_two = Math.abs(self.fountain.tap(217, Math.round(c/10) + 50, Math.round(r/10) + 50)) > 90;
const condition_three = Math.abs(self.fountain.tap(117, Math.round(c/7) + 50, Math.round(r/7) + 50)) > 70;
if (condition_one && condition_two /* && condition_three */) {
let hgt = 0;
hgt = (1 * Math.abs(self.fountain.tap(479, c + 50, r + 50)) * 0.01) * 0.5;
hgt = 0.5 + 0.1 * ((hgt * 17) % 19);
let bw = 0.3 * ((self.fountain.tap(217, c + 50, r + 50) % 100) / 100);
let bl = 0.3 * ((self.fountain.tap(213, c + 89, r + 17) % 100) / 100);
if (condition_one) {
const tmp = bw;
bw = bl;
bl = tmp;
}
const edificeGeometry = new THREE.BoxGeometry(0.4 + bw, 0.4 + bl, hgt);
const edificeMesh = new THREE.Mesh(edificeGeometry, edificeMaterial);
const edifice = new Entity();
edifice.add(edificeMesh);
edifice.addEdges(edificeMesh, self.three.layers.BLOOM_SCENE);
self.three.scene.add(edifice);
edifice.position.set(c, r, hgt / 2);
edifice.reference = {x: c, y: r};
self.vicinity.blocks[coordinate] = edifice;
}
}
}
}
}
for (const coordinates in self.vicinity.blocks) {
const xy = coordinates.split(",");
const x = parseFloat(xy[0]);
const y = parseFloat(xy[1]);
const bldg = self.vicinity.blocks[coordinates];
bldg.position.x = bldg.reference.x + self.state.position.x + 0.5;
bldg.position.y = bldg.reference.y + self.state.position.y + 0.5;
if (Math.abs(x - alignedX - 2) + Math.abs(y - alignedY - 2) > radius) {
self.three.scene.remove(bldg);
bldg.dispose();
delete self.vicinity.blocks[coordinates];
}
}
}
createScene() {
const self = this;
const config = self.config;
const roster = self.roster;
// Grid.
config.gridSpan = 120;
const gridColor = 0x444444;
const gridMaterial = new THREE.MeshStandardMaterial({
color: gridColor,
roughness: 0.2, // Smooth to rough (0 to 1).
metalness: 0.8,
emissive: gridColor, // Light emitted from the surface.
envMapIntensity: 1,
});
const gridTrailGeometry = new THREE.BoxGeometry(1, 0.03, 0.03);
const gridTrailMaterial = new THREE.MeshStandardMaterial({
color: 0xAAAAAA,
roughness: 0.2,
metalness: 0.8,
emissive: 0xAAAAAA,
envMapIntensity: 1,
});
const gridSpan = self.config.gridSpan;
roster.gridRowLines = [];
roster.gridTrails = [];
const geometryLineRow = new THREE.BoxGeometry(gridSpan * 2, 0.025, 0.025);
for (let r = -gridSpan; r <= gridSpan; r++) {
const gridRowLine = new THREE.Mesh(geometryLineRow, gridMaterial);
gridRowLine.layers.enable( self.three.layers.BLOOM_SCENE );
gridRowLine.position.y = r;
gridRowLine.reference = {x: gridRowLine.position.x, y: gridRowLine.position.y};
roster.gridRowLines.push(gridRowLine);
self.three.scene.add(gridRowLine);
const gridTrail = new THREE.Mesh(gridTrailGeometry, gridTrailMaterial);
gridTrail.layers.enable( self.three.layers.BLOOM_SCENE );
gridTrail.position.y = r;
gridTrail.reference = {x: Math.random() * gridSpan * 2, y: gridRowLine.position.y};
gridTrail.initial = {x: gridTrail.reference.x, y: gridTrail.position.y};
roster.gridTrails.push(gridTrail);
self.three.scene.add(gridTrail);
}
roster.gridColumnLines = [];
const geometryLineCol = new THREE.BoxGeometry(0.025, gridSpan * 2, 0.025);
for (let c = -gridSpan; c <= gridSpan; c++) {
const gridColumnLine = new THREE.Mesh(geometryLineCol, gridMaterial);
gridColumnLine.layers.enable( self.three.layers.BLOOM_SCENE );
gridColumnLine.position.x = c;
gridColumnLine.reference = {x: gridColumnLine.position.x, y: gridColumnLine.position.y};
roster.gridColumnLines.push(gridColumnLine);
self.three.scene.add(gridColumnLine);
}
// Other embellishments and accessories.
config.bubblesDiameter = 200;
roster.bubbles = [];
const bubblesRadius = Math.floor(config.bubblesDiameter / 2);
for (let x = -bubblesRadius; x < bubblesRadius; x++) {
for (let y = -bubblesRadius; y < bubblesRadius; y++) {
if (Math.abs(self.fountain.tap(217, x + 50, y + 50)) > 30) {
continue;
}
if (Math.abs(self.fountain.tap(479, x + 50, y + 50)) < 30) {
const bubbleSize = Math.pow(Math.random(), 2) * 0.12;
const bubbleInteriorMaterial = new THREE.MeshBasicMaterial({ color: 0x333333 });
const bubbleInteriorGeometry = new THREE.SphereGeometry(bubbleSize, 8, 8);
const bubbleInterior = new THREE.Mesh(bubbleInteriorGeometry, bubbleInteriorMaterial);
bubbleInterior.lookAt(self.three.camera.position);
const bubbleExteriorMaterial = new THREE.MeshBasicMaterial({ color: 0xFFFFFF });
const bubbleExteriorGeometry = new THREE.TorusGeometry( bubbleSize + 0.002, bubbleSize / 5, 16, 100 );
const bubbleExterior = new THREE.Mesh(bubbleExteriorGeometry, bubbleExteriorMaterial);
bubbleExterior.layers.enable( self.three.layers.BLOOM_SCENE );
bubbleExterior.lookAt(self.three.camera.position);
const bubble = new Entity();
bubble.add(bubbleInterior);
bubble.add(bubbleExterior);
bubble.position.set(x * 0.3, y * 0.3, Math.random() * 4);
bubble.reference = {x: bubble.position.x, y: bubble.position.y};
bubble.vx = -0.01 + Math.random() * 0.02;
bubble.vy = -0.01 + Math.random() * 0.02;
bubble.exterior = bubbleExterior;
roster.bubbles.push(bubble);
self.three.scene.add(bubble);
}
}
}
}
createInteraction() {
const self = this;
window.addEventListener("resize", () => {
self.three.fillWindow();
self.three.camera.aspect = window.innerWidth / window.innerHeight;
self.three.camera.updateProjectionMatrix();
});
document.addEventListener('mousewheel', (event) => {
//self.three.camera.position.z += event.deltaY / 1000;
});
document.addEventListener('mousedown', (event) => {
self.interaction.drag = true;
self.interaction.dragEvent = {
mouseX: event.clientX,
mouseY: event.clientY,
cameraX: self.three.camera.position.x,
cameraY: self.three.camera.position.y,
statePositionX: self.state.position.x,
statePositionY: self.state.position.y,
};
self.interaction.mouseLast.down = true;
});
document.addEventListener('mousemove', (event) => {
const dragEvent = self.interaction.dragEvent;
if (self.interaction.drag) {
const dragX = -0.015 * (event.clientX - dragEvent.mouseX);
const dragY = -0.015 * (event.clientY - dragEvent.mouseY);
self.state.position.x = dragEvent.statePositionX + dragY - dragX;
self.state.position.y = dragEvent.statePositionY + dragY + dragX;
}
self.interaction.mouseLast.x = event.clientX;
self.interaction.mouseLast.y = event.clientY;
});
document.addEventListener('mouseup', () => {
self.interaction.drag = false;
self.interaction.dragEvent = null;
self.interaction.mouseLast.down = false;
});
}
animate() {
const self = this;
requestAnimationFrame(function () { self.animate(); });
self.updateVicinity();
const gridSpan = self.config.gridSpan;
const gridRowLines = self.roster.gridRowLines;
const gridColumnLines = self.roster.gridColumnLines;
const gridTrails = self.roster.gridTrails;
for (let i = 0; i < gridRowLines.length; i++) {
gridRowLines[i].position.y = gridRowLines[i].reference.y + (app.state.position.y % 1);
gridTrails[i].position.y = gridTrails[i].reference.y + (app.state.position.y % 1);
gridColumnLines[i].position.x = gridColumnLines[i].reference.x + (app.state.position.x % 1);
gridTrails[i].position.x = gridTrails[i].reference.x + (app.state.position.x % 1);
gridTrails[i].reference.x = gridTrails[i].reference.x + 1;
if (gridTrails[i].reference.x > gridTrails[i].initial.x + gridSpan) {
gridTrails[i].reference.x = gridTrails[i].initial.x - gridSpan;
}
}
const bubblesDiameter = self.config.bubblesDiameter / 4;
const bubblesRadius = bubblesDiameter / 2;
const bubbles = self.roster.bubbles;
for (let i = 0; i < bubbles.length; i++) {
const bubble = bubbles[i];
bubble.reference.x += bubble.vx;
bubble.reference.y += bubble.vy;
bubble.position.x = (bubble.reference.x + self.state.position.x);
bubble.position.y = (bubble.reference.y + self.state.position.y);
bubble.position.z -= 0.001;
if (bubble.position.z < 0) {
bubble.position.z = 6;
}
if (bubble.position.x < -bubblesRadius) {
bubble.reference.x += bubblesDiameter;
} else if (bubble.position.x > bubblesRadius) {
bubble.reference.x -= bubblesDiameter;
}
if (bubble.position.y < -bubblesRadius) {
bubble.reference.y += bubblesDiameter;
} else if (bubble.position.y > bubblesRadius) {
bubble.reference.y -= bubblesDiameter;
}
bubble.exterior.lookAt(self.three.camera.position);
}
app.state.position.x -= 0.01;
app.state.position.y -= 0.001;
self.three.render();
}
initialize() {
const self = this;
self.createScene();
self.createInteraction();
this.animate(); // Set up the per-frame animation callback.
}
}
const app = new App();
app.initialize();
</script>
</body>
</html>