awacke1 commited on
Commit
f8acd7a
·
1 Parent(s): f8b2ba3

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +118 -52
index.html CHANGED
@@ -1,58 +1,124 @@
1
  <!DOCTYPE html>
2
  <html>
3
- <head>
4
- <title>DNA Sequence</title>
5
- <meta charset="UTF-8">
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
  <script src="https://cdn.babylonjs.com/babylon.js"></script>
8
- <script src="https://cdn.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>
9
- </head>
10
- <body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  <canvas id="renderCanvas"></canvas>
 
12
  <script>
13
- var canvas = document.getElementById("renderCanvas");
14
- var engine = new BABYLON.Engine(canvas, true);
15
-
16
- var createScene = function () {
17
- var scene = new BABYLON.Scene(engine);
18
- var camera = new BABYLON.ArcRotateCamera("Camera", -Math.PI / 2, Math.PI / 2, 10, BABYLON.Vector3.Zero(), scene);
19
- camera.attachControl(canvas, true);
20
-
21
- // Create a DNA strand
22
- var dnaStrand = BABYLON.MeshBuilder.CreateTorusKnot("dnaStrand", {
23
- radius: 1.5,
24
- tube: 0.3,
25
- radialSegments: 32,
26
- tubularSegments: 64,
27
- p: 2,
28
- q: 3
29
- }, scene);
30
-
31
- // Create the material for the DNA strand
32
- var dnaMaterial = new BABYLON.StandardMaterial("dnaMaterial", scene);
33
- dnaMaterial.diffuseTexture = new BABYLON.Texture("https://i.imgur.com/06QxEyj.jpg", scene);
34
- dnaMaterial.emissiveColor = new BABYLON.Color3(0.1, 0.1, 0.1);
35
- dnaMaterial.specularColor = new BABYLON.Color3(0.2, 0.2, 0.2);
36
-
37
- // Apply the material to the DNA strand
38
- dnaStrand.material = dnaMaterial;
39
-
40
- // Add some lights to the scene
41
- var light1 = new BABYLON.PointLight("light1", new BABYLON.Vector3(5, 10, 5), scene);
42
- var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(-5, -10, -5), scene);
43
-
44
- return scene;
45
- }
46
-
47
- var scene = createScene();
48
-
49
- engine.runRenderLoop(function () {
50
- scene.render();
51
- });
52
-
53
- window.addEventListener("resize", function () {
54
- engine.resize();
55
- });
56
- </script>
57
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+