Question: Three.js and javascript programming - Stairs are made up of a series of steps , and each step is made up of a riser and

Three.js and javascript programming -

Stairs are made up of a series of steps, and each step is made up of a riser and a tread. The riser is the vertical part of the step and the tread is the horizontal part you step on (as labeled in the image below).

Write a function createStairs(riser, tread, width, nbrSteps) that returns a geometry for stairs made of nbrSteps many steps, where each step has specified width, and whose riser rises riser units and whose tread treads tread units (of course), and use your function is a program to render stairs. The geometry depicted below (sans labels) was created with the call createStairs(1, 2, 4, 5).

function createPyramid(n, rad, len) { var len2 = len / 2; var geom = new THREE.Geometry(); // push n + 1 vertices // first the apex... geom.vertices.push(new THREE.Vector3(0, len2, 0)); // and then the vertices of the base var inc = 2 * Math.PI / n; for (var i = 0, a = 0; i < n; i++, a += inc) { var cos = Math.cos(a); var sin = Math.sin(a); geom.vertices.push(new THREE.Vector3(rad * cos, -len2, rad * sin)); } // push the n triangular faces... for (var i = 1; i < n; i++) { var face = new THREE.Face3(i+1, i, 0); geom.faces.push(face); } var face = new THREE.Face3(1, n, 0); geom.faces.push(face); // and then push the n-2 faces of the base for (var i = 2; i < n; i++) { var face = new THREE.Face3(i, i+1, 1); geom.faces.push(face); } // set face normals and return the geometry geom.computeFaceNormals(); return geom; } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!