awacke1 commited on
Commit
46bf520
·
1 Parent(s): 9f757ed

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +61 -52
index.html CHANGED
@@ -16,68 +16,77 @@
16
  <script src="https://threejs.org/examples/js/libs/dat.gui.min.js"></script>
17
  <script src="https://threejs.org/examples/js/curves/NURBSCurve.js"></script>
18
  <script>
19
- // Set up the scene
20
- const scene = new THREE.Scene();
 
21
 
22
- // Set up the camera
23
- const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
24
- camera.position.z = 5;
25
 
26
- // Set up the renderer
27
- const renderer = new THREE.WebGLRenderer();
28
- renderer.setSize(window.innerWidth, window.innerHeight);
29
- document.body.appendChild(renderer.domElement);
30
 
31
- // Set up the skybox
32
- const loader = new THREE.CubeTextureLoader();
33
- const texture = loader.load([
34
- 'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/pz.jpg',
35
- 'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/nz.jpg',
36
- 'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/py.jpg',
37
- 'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/ny.jpg',
38
- 'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/px.jpg',
39
- 'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/nx.jpg'
40
- ]);
41
- scene.background = texture;
42
 
43
- // Set up the lighting
44
- const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
45
- scene.add(ambientLight);
46
- const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
47
- directionalLight.position.set(0, 1, 0);
48
- scene.add(directionalLight);
49
 
50
- // Set up the geometry
51
- const lsystem = new LSystem();
52
- lsystem.addRule('F', 'F+F-F-F+F');
53
- lsystem.setAxiom('F+F+F+F');
54
- lsystem.iterate(3);
55
- const lines = lsystem.getLines();
56
- const material = new THREE.LineBasicMaterial({ color: 0xffffff });
57
- const geometry = new THREE.BufferGeometry().setFromPoints(lines);
58
- const fractal = new THREE.LineSegments(geometry, material);
59
- scene.add(fractal);
60
 
61
- // Set up the controls
62
- const controls = new THREE.OrbitControls(camera, renderer.domElement);
63
 
64
- // Set up the animation
65
- function animate() {
66
- requestAnimationFrame(animate);
67
 
68
- fractal.rotation.x += 0.01;
69
- fractal.rotation.y += 0.01;
70
 
71
- controls.update();
72
- renderer.render(scene, camera);
 
 
 
 
 
 
 
 
73
  }
74
- animate();
75
 
76
- // Set up the GUI
77
- const gui = new dat.GUI();
78
- gui.add(fractal.material, 'linewidth', 0.1, 10);
79
- gui.add(fractal.material, 'opacity', 0.1, 1);
80
- gui.add(fractal.material, 'transparent');
 
 
 
 
 
 
 
 
81
  </script>
82
  </body>
83
- </html>
 
16
  <script src="https://threejs.org/examples/js/libs/dat.gui.min.js"></script>
17
  <script src="https://threejs.org/examples/js/curves/NURBSCurve.js"></script>
18
  <script>
19
+ function init() {
20
+ // Set up the scene
21
+ const scene = new THREE.Scene();
22
 
23
+ // Set up the camera
24
+ const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
25
+ camera.position.z = 5;
26
 
27
+ // Set up the renderer
28
+ const renderer = new THREE.WebGLRenderer();
29
+ renderer.setSize(window.innerWidth, window.innerHeight);
30
+ document.body.appendChild(renderer.domElement);
31
 
32
+ // Set up the skybox
33
+ const loader = new THREE.CubeTextureLoader();
34
+ const texture = loader.load([
35
+ 'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/pz.jpg',
36
+ 'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/nz.jpg',
37
+ 'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/py.jpg',
38
+ 'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/ny.jpg',
39
+ 'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/px.jpg',
40
+ 'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/nx.jpg'
41
+ ]);
42
+ scene.background = texture;
43
 
44
+ // Set up the lighting
45
+ const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
46
+ scene.add(ambientLight);
47
+ const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
48
+ directionalLight.position.set(0, 1, 0);
49
+ scene.add(directionalLight);
50
 
51
+ // Set up the geometry
52
+ const fractal = generateFractal();
53
+ scene.add(fractal);
 
 
 
 
 
 
 
54
 
55
+ // Set up the controls
56
+ const controls = new THREE.OrbitControls(camera, renderer.domElement);
57
 
58
+ // Set up the animation
59
+ function animate() {
60
+ requestAnimationFrame(animate);
61
 
62
+ fractal.rotation.x += 0.01;
63
+ fractal.rotation.y += 0.01;
64
 
65
+ controls.update();
66
+ renderer.render(scene, camera);
67
+ }
68
+ animate();
69
+
70
+ // Set up the GUI
71
+ const gui = new dat.GUI();
72
+ gui.add(fractal.material, 'linewidth', 0.1, 10);
73
+ gui.add(fractal.material, 'opacity', 0.1, 1);
74
+ gui.add(fractal.material, 'transparent');
75
  }
 
76
 
77
+ function generateFractal() {
78
+ const lsystem = new LSystem();
79
+ lsystem.addRule('F', 'F+F-F-F+F');
80
+ lsystem.setAxiom('F+F+F+F');
81
+ lsystem.iterate(3);
82
+ const lines = lsystem.getLines();
83
+ const material = new THREE.LineBasicMaterial({ color: 0xffffff });
84
+ const geometry = new THREE.BufferGeometry().setFromPoints(lines);
85
+ const fractal = new THREE.LineSegments(geometry, material);
86
+ return fractal;
87
+ }
88
+
89
+ window.onload = init;
90
  </script>
91
  </body>
92
+ </html>