Question: please review these codes Did the assignment output include a 3 D object selected from the list? ( Yes / No ) ( Sphere ,
please review these codes
Did the assignment output include a D object selected from the list? YesNoSphere Cube, or Torus Knot
Was the object animated making it move In both x and y directions within the viewing area and simulate bouncing off the walls when the edge of the viewing area was reached? YesNo
Was a basic color applied to the object and was the color changed every time the object encountered an edge of the viewing area? YesNo
Did the scene employ a lightyellow light source in a fixed position at the upper left corner to illuminate the object and did the illumination demonstrate both light and shadow on the object? YesNo
Was the JavaScript Three.js code well documented Scale of where is no comments and is comprehensive comments
Setup scene, camera, and renderer
const scene new THREE.Scene;
const camera new THREE.PerspectiveCamera window.innerWidth window.innerHeight, ;
const renderer new THREE.WebGLRenderer;
renderer.setSizewindowinnerWidth, window.innerHeight;
document.body.appendChildrendererdomElement;
Create a sphere with red color
const sphereGeometry new THREE.SphereGeometry;
const sphereMaterial new THREE.MeshPhongMaterial color: xff;
const sphere new THREE.MeshsphereGeometry sphereMaterial;
scene.addsphere;
Set initial position and velocity of the sphere
sphere.position.x ;
sphere.position.y ;
let velocity x: y: ;
Add a lightyellow light source at the upper left corner
const light new THREE.PointLightxffffe;
light.position.set;
scene.addlight;
Animation loop to move the sphere and handle bouncing
function animate
requestAnimationFrameanimate;
Update sphere position based on velocity
sphere.position.x velocity.x;
sphere.position.y velocity.y;
Check boundaries and reverse direction upon collision
if sphereposition.x sphere.position.x
velocity.x velocity.x; Reverse direction on Xaxis
sphere.material.color.setHexMathrandomxffffff; Change color randomly
if sphereposition.y sphere.position.y
velocity.y velocity.y; Reverse direction on Yaxis
sphere.material.color.setHexMathrandomxffffff; Change color randomly
Render the scene
renderer.renderscene camera;
Set the camera position and start the animation loop
camera.position.z ;
animate;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
