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

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +83 -71
index.html CHANGED
@@ -1,92 +1,104 @@
1
  <!DOCTYPE html>
2
- <html lang="en">
3
  <head>
4
- <meta charset="UTF-8">
5
- <title>Three.js 3D Scene with Fractal Object</title>
6
  <style>
7
  body {
8
  margin: 0;
9
  overflow: hidden;
10
  }
 
 
 
 
11
  </style>
12
  </head>
13
  <body>
14
- <script src="https://threejs.org/build/three.min.js"></script>
15
- <script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
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>
 
1
  <!DOCTYPE html>
2
+ <html>
3
  <head>
4
+ <meta charset="utf-8">
5
+ <title>Tilemap Example</title>
6
  <style>
7
  body {
8
  margin: 0;
9
  overflow: hidden;
10
  }
11
+ canvas {
12
+ width: 100%;
13
+ height: 100%;
14
+ }
15
  </style>
16
  </head>
17
  <body>
18
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
 
 
 
19
  <script>
20
+ // create the scene
21
+ var scene = new THREE.Scene();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ // create the camera
24
+ var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
25
+ camera.position.z = 5;
26
 
27
+ // create the renderer
28
+ var renderer = new THREE.WebGLRenderer();
29
+ renderer.setSize(window.innerWidth, window.innerHeight);
30
+ document.body.appendChild(renderer.domElement);
31
 
32
+ // create the tilemap
33
+ var tilemap = [
34
+ [0, 0, 0, 0, 0],
35
+ [0, 1, 1, 1, 0],
36
+ [0, 1, 1, 1, 0],
37
+ [0, 1, 1, 1, 0],
38
+ [0, 0, 0, 0, 0],
39
+ ];
40
+ var tileSize = 1;
41
+ var tileGeometry = new THREE.PlaneGeometry(tileSize, tileSize);
42
+ var tileMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff });
43
+ var tiles = [];
44
+ for (var i = 0; i < tilemap.length; i++) {
45
+ for (var j = 0; j < tilemap[i].length; j++) {
46
+ if (tilemap[i][j] === 1) {
47
+ var tile = new THREE.Mesh(tileGeometry, tileMaterial);
48
+ tile.position.x = (j - tilemap[i].length / 2) * tileSize;
49
+ tile.position.y = (-i + tilemap.length / 2) * tileSize;
50
+ scene.add(tile);
51
+ tiles.push(tile);
52
+ }
53
+ }
54
+ }
55
 
56
+ // create the arrow buttons
57
+ var arrowUp = document.createElement('button');
58
+ arrowUp.innerText = '↑';
59
+ arrowUp.style.position = 'absolute';
60
+ arrowUp.style.left = '50%';
61
+ arrowUp.style.top = '10px';
62
+ arrowUp.addEventListener('click', function() {
63
+ camera.position.y += 1;
64
+ });
65
+ document.body.appendChild(arrowUp);
66
 
67
+ var arrowDown = document.createElement('button');
68
+ arrowDown.innerText = '↓';
69
+ arrowDown.style.position = 'absolute';
70
+ arrowDown.style.left = '50%';
71
+ arrowDown.style.bottom = '10px';
72
+ arrowDown.addEventListener('click', function() {
73
+ camera.position.y -= 1;
74
+ });
75
+ document.body.appendChild(arrowDown);
76
 
77
+ var arrowLeft = document.createElement('button');
78
+ arrowLeft.innerText = '←';
79
+ arrowLeft.style.position = 'absolute';
80
+ arrowLeft.style.left = '10px';
81
+ arrowLeft.style.top = '50%';
82
+ arrowLeft.addEventListener('click', function() {
83
+ camera.position.x -= 1;
84
+ });
85
+ document.body.appendChild(arrowLeft);
86
 
87
+ var arrowRight = document.createElement('button');
88
+ arrowRight.innerText = '→';
89
+ arrowRight.style.position = 'absolute';
90
+ arrowRight.style.right = '10px';
91
+ arrowRight.style.top = '50%';
92
+ arrowRight.addEventListener('click(function() {
93
+ camera.position.x += 1;
94
+ });
95
+ document.body.appendChild(arrowRight);
96
+ // animate the scene
97
+ function animate() {
98
+ requestAnimationFrame(animate);
99
+ renderer.render(scene, camera);
100
  }
101
+ animate();
 
102
  </script>
103
  </body>
104
+ </html>