Spaces:
Running
Running
Update index.html
Browse files- index.html +53 -105
index.html
CHANGED
@@ -1,20 +1,17 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
<head>
|
4 |
-
<meta charset="
|
5 |
-
<title>DNA Fractal
|
6 |
-
<script src="https://cdn.babylonjs.com/babylon.js"></script>
|
7 |
<style>
|
8 |
-
html,
|
9 |
-
body {
|
10 |
-
overflow: hidden;
|
11 |
width: 100%;
|
12 |
height: 100%;
|
13 |
margin: 0;
|
14 |
padding: 0;
|
|
|
15 |
}
|
16 |
-
|
17 |
-
#renderCanvas {
|
18 |
width: 100%;
|
19 |
height: 100%;
|
20 |
}
|
@@ -22,103 +19,54 @@
|
|
22 |
</head>
|
23 |
<body>
|
24 |
<canvas id="renderCanvas"></canvas>
|
25 |
-
|
|
|
26 |
<script>
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
new BABYLON.Vector3(
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
scene
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
// Animate the DNA fractal
|
75 |
-
let time = 0;
|
76 |
-
scene.registerAfterRender(function () {
|
77 |
-
time += 0.01;
|
78 |
-
|
79 |
-
const positions = DNAFractal.getVerticesData(
|
80 |
-
BABYLON.VertexBuffer.PositionKind
|
81 |
-
);
|
82 |
-
const colors = DNAFractal.getVerticesData(
|
83 |
-
BABYLON.VertexBuffer.ColorKind
|
84 |
-
);
|
85 |
-
|
86 |
-
for (let i = 0; i < positions.length; i += 3) {
|
87 |
-
const x = positions[i];
|
88 |
-
const y = positions[i + 1];
|
89 |
-
const z = positions[i + 2];
|
90 |
-
|
91 |
-
const color = colors[i / 3];
|
92 |
-
|
93 |
-
const scale = 0.5 + 0.5 * Math.sin(time + y * 10);
|
94 |
-
const rotation = Math.PI * 2 * Math.sin(time + x * 10);
|
95 |
-
|
96 |
-
positions[i] = x * scale;
|
97 |
-
positions[i + 1] = y * scale * Math.cos(rotation);
|
98 |
-
positions[i + 2] = y * scale * Math.sin(rotation);
|
99 |
-
|
100 |
-
colors[i / 3] = new BABYLON.Color4(
|
101 |
-
color.r,
|
102 |
-
color.g,
|
103 |
-
color.b,1);
|
104 |
-
}
|
105 |
-
DNAFractal.updateVerticesData(
|
106 |
-
BABYLON.VertexBuffer.PositionKind,
|
107 |
-
positions
|
108 |
-
);
|
109 |
-
DNAFractal.updateVerticesData(BABYLON.VertexBuffer.ColorKind, colors);
|
110 |
-
});
|
111 |
-
|
112 |
-
// Render the scene
|
113 |
-
engine.runRenderLoop(function () {
|
114 |
-
scene.render();
|
115 |
-
});
|
116 |
-
|
117 |
-
// Resize the canvas when the window is resized
|
118 |
-
window.addEventListener("resize", function () {
|
119 |
-
engine.resize();
|
120 |
-
});
|
121 |
-
</script>
|
122 |
</body>
|
123 |
</html>
|
124 |
-
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<title>DNA Fractal</title>
|
|
|
6 |
<style>
|
7 |
+
html, body {
|
|
|
|
|
8 |
width: 100%;
|
9 |
height: 100%;
|
10 |
margin: 0;
|
11 |
padding: 0;
|
12 |
+
overflow: hidden;
|
13 |
}
|
14 |
+
canvas {
|
|
|
15 |
width: 100%;
|
16 |
height: 100%;
|
17 |
}
|
|
|
19 |
</head>
|
20 |
<body>
|
21 |
<canvas id="renderCanvas"></canvas>
|
22 |
+
<script src="https://cdn.babylonjs.com/babylon.js"></script>
|
23 |
+
<script src="https://cdn.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>
|
24 |
<script>
|
25 |
+
window.addEventListener('DOMContentLoaded', () => {
|
26 |
+
// Get the canvas element and create the Babylon scene
|
27 |
+
const canvas = document.getElementById('renderCanvas');
|
28 |
+
const engine = new BABYLON.Engine(canvas, true);
|
29 |
+
const scene = new BABYLON.Scene(engine);
|
30 |
+
|
31 |
+
// Set up the camera
|
32 |
+
const camera = new BABYLON.ArcRotateCamera('Camera', 0, 0, 10, BABYLON.Vector3.Zero(), scene);
|
33 |
+
camera.attachControl(canvas, true);
|
34 |
+
|
35 |
+
// Create the DNA fractal shape
|
36 |
+
const shape = BABYLON.MeshBuilder.CreateBox('Shape', {size: 1}, scene);
|
37 |
+
shape.scaling = new BABYLON.Vector3(0.5, 1, 0.5);
|
38 |
+
shape.rotation = new BABYLON.Vector3(Math.PI / 4, 0, 0);
|
39 |
+
|
40 |
+
// Create the fractal by cloning and rotating the shape
|
41 |
+
const numLevels = 5;
|
42 |
+
const angle = Math.PI / 4;
|
43 |
+
const scale = 0.5;
|
44 |
+
const fractal = new BABYLON.Mesh('Fractal', scene);
|
45 |
+
fractal.addChild(shape);
|
46 |
+
for (let i = 0; i < numLevels; i++) {
|
47 |
+
const child = shape.clone(`Level ${i}`);
|
48 |
+
child.scaling = child.scaling.scale(scale);
|
49 |
+
child.rotation = child.rotation.add(new BABYLON.Vector3(0, angle, 0));
|
50 |
+
fractal.addChild(child);
|
51 |
+
shape = child;
|
52 |
+
}
|
53 |
+
|
54 |
+
// Apply the DNA texture to the fractal
|
55 |
+
const dnaTexture = new BABYLON.Texture('https://i.imgur.com/f5GcE7Y.jpg', scene);
|
56 |
+
const material = new BABYLON.StandardMaterial('Material', scene);
|
57 |
+
material.diffuseTexture = dnaTexture;
|
58 |
+
fractal.material = material;
|
59 |
+
|
60 |
+
// Start the Babylon engine and render the scene
|
61 |
+
engine.runRenderLoop(() => {
|
62 |
+
scene.render();
|
63 |
+
});
|
64 |
+
|
65 |
+
// Handle window resizing
|
66 |
+
window.addEventListener('resize', () => {
|
67 |
+
engine.resize();
|
68 |
+
});
|
69 |
+
});
|
70 |
+
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
</body>
|
72 |
</html>
|
|