Related questions
Using comments within the code itself, can you provide an line by line explanation of the below JavaScript file? The file itself deals with WebGl and if that helps you.
Please and thank you
JavaScript file:
function MVbuffer(size) {
var b = {};
b.buf = new Float32Array(size);
b.index = 0;
b.push = function(x) {
for(var i=0; i<x.length; i++) {
b.buf[b.index+i] = x[i];
}
b.index += x.length;
b.type = '';
}
return b;
}
function isVector(v) {
if(v.type == "vec2" || v.type == "vec3" || v.type == "vec4") return true;
return false;
}
function isMatrix(v) {
if(v.type == "mat2" || v.type == "mat3" || v.type == "mat4") return true;
return false;
}
function radians( degrees ) {
return degrees * Math.PI / 180.0;
}
//----------------------------------------------------------------------------
function patch() {
var out = new Array(4);
for(var i = 0; i< 4; i++) out[i] = new Array(4);
out.type = "patch";
return out;
}
function curve() {
var out = new Array(4);
out.type = "curve";
return out;
}
//
//
//
function vec2()
{
var out = new Array(2);
out.type = 'vec2';
switch ( arguments.length ) {
case 0:
out[0] = 0.0;
out[1] = 0.0;
break;
case 1:
if(isVector(arguments[0] && (arguments[0].type != 'vec2'))) {
out[0] = arguments[0][0];
out[1] = arguments[0][1];
}
break;
case 2:
out[0] = arguments[0];
out[1] = arguments[1];
break;
}
return out;
}
function vec3()
{
//var result = _argumentsToArray( arguments );
var out = new Array(3);
out.type = 'vec3';
switch ( arguments.length ) {
case 0:
out[0] = 0.0;
out[1] = 0.0;
out[2] = 0.0;
return out;
case 1:
if(isVector(arguments[0]) && (arguments[0].type == "vec3")) {
out[0] = arguments[0][0];
out[1] = arguments[0][1];
out[2] = arguments[0][2];
return out;
}
case 3:
out[0] = arguments[0];
out[1] = arguments[1];
out[2] = arguments[2];
return out;
default:
throw "vec3: wrong arguments";
}
return out;
}
function vec4()
{
var out = new Array(4);
out.type = 'vec4';
switch ( arguments.length ) {
case 0:
out[0] = 0.0;
out[1] = 0.0;
out[2] = 0.0;
out[3] = 0.0;
return out;
case 1:
if(isVector(arguments[0])) {
if(arguments[0].type == "vec4") {
out[0] = arguments[0][0];
out[1] = arguments[0][1];
out[2] = arguments[0][2];
out[3] = arguments[0][3];
return out;
}
}
else if(arguments[0].type == "vec3") {
out[0] = arguments[0][0];
out[1] = arguments[0][1];
out[2] = arguments[0][2];
out[3] = 1.0;
return out;
}
else {
out[0] = arguments[0][0];
out[1] = arguments[0][1];
out[2] = arguments[0][2];
out[3] = arguments[0][3];
return out;
}
case 2:
if(typeof(arguments[0])=='number'&&arguments[1].type == 'vec3') {
out[0] = arguments[0];
out[1] = arguments[1][0];
out[2] = arguments[1][1];
out[3] = arguments[1][2];
return out;
}
return out;
case 4:
if(isVector(arguments[0])) {
out[0] = arguments[0][0];
out[1] = arguments[0][1];
out[2] = arguments[0][2];
out[3] = arguments[0][3];
return out;
}
out[0] = arguments[0];
out[1] = arguments[1];
out[2] = arguments[2];
out[3] = arguments[3];
return out;
case 3:
out[0] = arguments[0][0];
out[1] = arguments[0][1];
out[2] = arguments[0][2];
out[3] = 1.0;
return out;
default:
throw "vec4: wrong arguments";
}
}
Step by stepSolved in 3 steps
- Write a program that reads movie data from a CSV (comma separated values) file and output the data in a formatted table. The program first reads the name of the CSV file from the user. The program then reads the CSV file and outputs the contents according to the following requirements: Each row contains the title, rating, and all showtimes of a unique movie. A space is placed before and after each vertical separator ('|') in each row. Column 1 displays the movie titles and is left justified with a minimum of 44 characters. If the movie title has more than 44 characters, output the first 44 characters only. Column 2 displays the movie ratings and is right justified with a minimum of 5 characters. Column 3 displays all the showtimes of the same movie, separated by a space. Each row of the CSV file contains the showtime, title, and rating of a movie. Assume data of the same movie are grouped in consecutive rows. Hints: Use the find() function to find the index of a comma in each row of...arrow_forwardThe following program rotates a cube with mouse clicks. In the display callback, the Lookat function is used to point the viewer, whose location can be altered by the x, X, y, Y, z and Z keys. The perspective view is set in the reshape callback. Create the code /* cubeview.cpp */ #include <stdlib.h> #include <GL/glut.h> GLfloat vertices[][3] = {{-1.0,-1.0,-1.0},{1.0,-1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}}; GLfloat normals[][3] = {{-1.0,-1.0,-1.0},{1.0,-1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}}; GLfloat colors[][3] = {{0.0,0.0,0.0}, {0.0,0.0,1.0}, {0.0,1.0,0.0}, {0.0,1.0,1.0}, {1.0,0.0,0.0}, {1.0,0.0,1.0}, {1.0,1.0,0.0}, {1.0,1.0,1.0}}; void polygon(int a, int b, int c , int d) {...arrow_forwardPlease answer the question in the screenshot. The language used here is Java.arrow_forward
- Written in Python with docstring please if applicable Thank youarrow_forwardWhat are the Javadoc comments for each class? I am strugglingarrow_forwardComplete the rotate_text() function that takes 2 parameters, a string data and an integer n. If n is positive, then the function will shift all the characters in data forward by n positions, with characters at the end of the string being moved to the start of the string. If n is 0 then the text remains the same. For example: rotate_text('abcde', rotate_text('abcde', rotate_text('abcde', 1) would return the string 'eabcd' 3) would return the string 'cdeab' 5) would return the string 'abcde' rotate_text('abcde', 6) would return the string 'eabcd' ... and so on. If n is negative, then the function will shift the characters in data backward by n positions, with characters at the start of the string being moved to the end of the string. For example: rotate text('abcde', -1) would return the string 'bcdea'arrow_forward
- Javascript Use a for/of loop to iterate over the array of students. For each student, use a template literal to print out their name, age, and major in a formatted string. (e.g. John is 18 years old and is studying Computer Science.) Within the template literal, use object dot notation to access the name, age, and major properties of the student object. Use a console.log() to print out the formatted string for each student. Test the code by running it and verifying that it prints out the details of each student in a formatted string.============================================================================== const students = [ { name: "John", age: 18, major: "Computer Science" }, { name: "Newton", age: 19, major: "Mathematics" }, { name: "Barry", age: 20, major: "Physics" }, ]; // Iterate through the array of objects students using for/of // Print a message to the console that includes the student's name, age, and major // Example: John is 18 years old and...arrow_forwardThis is needed in Java Given an existing ArrayList named friendList, find the first index of a friend named Sasha and store it in a new variable named index.arrow_forwardWrite a function named addGPA in JavaScript that takes an array of students as input and returns the list of students with a gpa property added to each student. You may assume that each student in the input has a valid qualityPoints property and a valid creditHours property. Calculate gpa by dividing quality points by credit hours. For example, • addGPA ( []) should return [] • addGPA ( [{name: 'Sam Jones', quality Points: 60, creditHours: 20}) should return [{name: 'Sam Jones', qualityPoints: 60, creditHours: 20, gpa: 3.0}] You may use any built-in Array method.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education