-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Spinning Cube - Three.js</title> | ||
<style> | ||
body { margin: 0; } | ||
canvas { display: block; } | ||
</style> | ||
</head> | ||
<body> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script> | ||
<script> | ||
// Set up the scene, camera, and renderer | ||
const scene = new THREE.Scene(); | ||
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); | ||
const renderer = new THREE.WebGLRenderer(); | ||
|
||
renderer.setSize(window.innerWidth, window.innerHeight); | ||
document.body.appendChild(renderer.domElement); | ||
|
||
// Create a cube | ||
const geometry = new THREE.BoxGeometry(); | ||
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00, wireframe: true }); | ||
const cube = new THREE.Mesh(geometry, material); | ||
scene.add(cube); | ||
|
||
camera.position.z = 5; | ||
|
||
// Create the animation loop | ||
function animate() { | ||
requestAnimationFrame(animate); | ||
|
||
// Rotate the cube | ||
cube.rotation.x += 0.01; | ||
cube.rotation.y += 0.01; | ||
|
||
renderer.render(scene, camera); | ||
} | ||
|
||
// Start the animation | ||
animate(); | ||
|
||
// Handle window resizing | ||
window.addEventListener('resize', () => { | ||
const width = window.innerWidth; | ||
const height = window.innerHeight; | ||
|
||
renderer.setSize(width, height); | ||
camera.aspect = width / height; | ||
camera.updateProjectionMatrix(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |