Skip to content

Commit 68d47fd

Browse files
committed
Made all the changes as per the readme guidelines
1 parent 1f3a518 commit 68d47fd

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Initialize Three.js scene
2+
const scene = new THREE.Scene();
3+
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
4+
const renderer = new THREE.WebGLRenderer();
5+
renderer.setSize(window.innerWidth, window.innerHeight);
6+
document.getElementById('container').appendChild(renderer.domElement);
7+
8+
// Create floating islands
9+
const islandGeometry = new THREE.BoxGeometry(5, 0.5, 5);
10+
const islandMaterial = new THREE.MeshPhongMaterial({ color: 0x00ff00 });
11+
const islands = [];
12+
13+
for (let i = 0; i < 10; i++) {
14+
const island = new THREE.Mesh(islandGeometry, islandMaterial);
15+
island.position.x = (Math.random() - 0.5) * 50;
16+
island.position.y = Math.random() * 10;
17+
island.position.z = (Math.random() - 0.5) * 50;
18+
islands.push(island);
19+
scene.add(island);
20+
}
21+
22+
// Add clouds (particles)
23+
const cloudGeometry = new THREE.BufferGeometry();
24+
const cloudMaterial = new THREE.PointsMaterial({ color: 0xffffff, size: 0.1 });
25+
const cloudVertices = [];
26+
27+
for (let i = 0; i < 1000; i++) {
28+
const x = (Math.random() - 0.5) * 100;
29+
const y = Math.random() * 20;
30+
const z = (Math.random() - 0.5) * 100;
31+
cloudVertices.push(x, y, z);
32+
}
33+
34+
cloudGeometry.setAttribute('position', new THREE.Float32BufferAttribute(cloudVertices, 3));
35+
const clouds = new THREE.Points(cloudGeometry, cloudMaterial);
36+
scene.add(clouds);
37+
38+
// Add directional light for better shading
39+
const light = new THREE.DirectionalLight(0xffffff, 1);
40+
light.position.set(1, 1, 1);
41+
scene.add(light);
42+
43+
// Set initial camera position
44+
camera.position.set(0, 10, 20);
45+
46+
// Render loop
47+
const animate = () => {
48+
requestAnimationFrame(animate);
49+
50+
// Rotate islands
51+
islands.forEach(island => {
52+
island.rotation.x += 0.005;
53+
island.rotation.y += 0.005;
54+
});
55+
56+
// Move clouds
57+
cloudGeometry.attributes.position.array.forEach((_, i) => {
58+
cloudGeometry.attributes.position.array[i] += i % 3 === 0 ? 0.005 : 0;
59+
if (cloudGeometry.attributes.position.array[i] > 20) {
60+
cloudGeometry.attributes.position.array[i] = -20;
61+
}
62+
});
63+
cloudGeometry.attributes.position.needsUpdate = true;
64+
65+
// Day-night cycle
66+
light.intensity = Math.abs(Math.sin(Date.now() * 0.0001));
67+
68+
renderer.render(scene, camera);
69+
};
70+
71+
// Handle window resize
72+
window.addEventListener('resize', () => {
73+
const newWidth = window.innerWidth;
74+
const newHeight = window.innerHeight;
75+
76+
camera.aspect = newWidth / newHeight;
77+
camera.updateProjectionMatrix();
78+
79+
renderer.setSize(newWidth, newHeight);
80+
});
81+
82+
animate();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link rel="stylesheet" href="style.css">
7+
<title>Floating Islands</title>
8+
</head>
9+
<body>
10+
<div id="container"></div>
11+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
12+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/OrbitControls.min.js"></script>
13+
<script src="app.js"></script>
14+
</body>
15+
</html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
body {
2+
margin: 0;
3+
overflow: hidden;
4+
}
5+
6+
#container {
7+
position: absolute;
8+
}

0 commit comments

Comments
 (0)