Spaces:
Running
Running
Update index.html
Browse files- 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 |
-
|
| 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 |
-
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 |
-
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
}
|
| 74 |
-
animate();
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>
|