Spaces:
Running
Running
Update index.html
Browse files- index.html +118 -52
index.html
CHANGED
|
@@ -1,58 +1,124 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
-
<head>
|
| 4 |
-
<
|
| 5 |
-
<
|
| 6 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
<script src="https://cdn.babylonjs.com/babylon.js"></script>
|
| 8 |
-
<
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
<canvas id="renderCanvas"></canvas>
|
|
|
|
| 12 |
<script>
|
| 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 |
</html>
|
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8" />
|
| 5 |
+
<title>DNA Fractal Demo</title>
|
|
|
|
| 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 |
+
}
|
| 21 |
+
</style>
|
| 22 |
+
</head>
|
| 23 |
+
<body>
|
| 24 |
<canvas id="renderCanvas"></canvas>
|
| 25 |
+
|
| 26 |
<script>
|
| 27 |
+
// Create the BabylonJS engine
|
| 28 |
+
const canvas = document.getElementById("renderCanvas");
|
| 29 |
+
const engine = new BABYLON.Engine(canvas, true);
|
| 30 |
+
|
| 31 |
+
// Create a new scene
|
| 32 |
+
const scene = new BABYLON.Scene(engine);
|
| 33 |
+
|
| 34 |
+
// Create a camera
|
| 35 |
+
const camera = new BABYLON.ArcRotateCamera(
|
| 36 |
+
"Camera",
|
| 37 |
+
0,
|
| 38 |
+
0,
|
| 39 |
+
10,
|
| 40 |
+
new BABYLON.Vector3(0, 0, 0),
|
| 41 |
+
scene
|
| 42 |
+
);
|
| 43 |
+
|
| 44 |
+
// Attach the camera to the canvas
|
| 45 |
+
camera.attachControl(canvas, true);
|
| 46 |
+
|
| 47 |
+
// Create a DNA fractal
|
| 48 |
+
const DNAFractal = BABYLON.MeshBuilder.CreateTube(
|
| 49 |
+
"DNAFractal",
|
| 50 |
+
{
|
| 51 |
+
path: [
|
| 52 |
+
new BABYLON.Vector3(0, 0, 0),
|
| 53 |
+
new BABYLON.Vector3(0, 1, 0),
|
| 54 |
+
new BABYLON.Vector3(0.5, 1.5, 0),
|
| 55 |
+
new BABYLON.Vector3(0.5, 2.5, 0),
|
| 56 |
+
new BABYLON.Vector3(0, 3, 0),
|
| 57 |
+
],
|
| 58 |
+
radius: 0.5,
|
| 59 |
+
tessellation: 64,
|
| 60 |
+
sideOrientation: BABYLON.Mesh.DOUBLESIDE,
|
| 61 |
+
},
|
| 62 |
+
scene
|
| 63 |
+
);
|
| 64 |
+
|
| 65 |
+
// Add a material to the DNA fractal
|
| 66 |
+
const DNAFractalMaterial = new BABYLON.StandardMaterial(
|
| 67 |
+
"DNAFractalMaterial",
|
| 68 |
+
scene
|
| 69 |
+
);
|
| 70 |
+
DNAFractalMaterial.diffuseColor = new BABYLON.Color3(1, 0.5, 0);
|
| 71 |
+
DNAFractalMaterial.specularColor = new BABYLON.Color3(0.1, 0.1, 0.1);
|
| 72 |
+
DNAFractal.material = DNAFractalMaterial;
|
| 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 |
+
|