Skip to content

Commit 2f96ab7

Browse files
committedMar 23, 2024
fixed code
1 parent 44194d7 commit 2f96ab7

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed
 

‎main.js

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
import './style.css' //import the css file
22
import * as THREE from 'three'; //import the three.js library
33

4-
const scene = new THREE.Scene();
5-
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
4+
const scene = new THREE.Scene(); //create a scene
5+
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ); //create a camera with perspective projection
66

7+
//create a renderer, with a canvas element
78
const renderer = new THREE.WebGLRenderer({
89
canvas: document.querySelector('#bg'),
910
});
1011

1112
renderer.setSize(window.innerWidth, window.innerHeight); // set the size of the renderer to the window size
12-
document.body.appendChild(renderer.domElement); // append the renderer's DOM element to the body
13-
1413
renderer.setClearColor(0x000000, 0); // set the renderer's background color to clear color
15-
16-
17-
renderer.render(scene, camera); // render the scene with the camera
18-
renderer.setSize( window.innerWidth, window.innerHeight );
19-
document.body.appendChild( renderer.domElement )
20-
21-
14+
renderer.setSize( window.innerWidth, window.innerHeight ); //set the size of the renderer to the window size
2215
renderer.setPixelRatio(window.devicePixelRatio); //set pixel ratio to device pixel ratio
23-
renderer.setSize(window.innerWidth, window.innerHeight); //set size of renderer to window size, full screen canvas
24-
25-
camera.position.setZ(30); //set camera position to 30 units back
16+
document.body.appendChild( renderer.domElement ) //append the renderer's DOM element to the body
2617

18+
camera.position.z = 5; //set the camera's z position to 5
2719

28-
renderer.render(scene, camera); //render the scene with the camera
2920

3021
const geometry = new THREE.BoxGeometry( 1, 1, 1 );
3122
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
3223
const cube = new THREE.Mesh( geometry, material );
3324
scene.add( cube );
3425

35-
camera.position.z = 5;
26+
3627
//we want to set up a recursive function to set up infinite loop to animate automatically
3728
function animate() {
3829
requestAnimationFrame(animate); //request animation frame to animate

0 commit comments

Comments
 (0)
Please sign in to comment.