Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
The below code is suppose to make a rotating colored 3d cube using html (canvas) and JavaScript but I cannot get it to work properly. What am I doing wrong? What is the problem? This is a WebGL project if that helps. All that is rendered is what is seen in the attatched image. Thank you for your help.
Source code HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rotating Colored Cube</title>
<script type="text/javascript" src="glMatrix-1.0.1.min.js">
</script>
<script type="text/javascript" src="WebGL.js">
</script>
</head>
<body>
<canvas id="myCanvas" width="600" height="250"
style="border:1px solid black;">
</canvas>
</body>
</html>
JavaScript source code:
function initBuffers(gl){
var cubeBuffers = {}
cubeBuffers.positionBuffer = gl.createArrayBuffer([
// Front face
-1, -1, 1,
1, -1, 1,
1, 1, 1,
-1, 1, 1,
// Back face
-1, -1, -1,
-1, 1, -1,
1, 1, -1,
1, -1, -1,
// Top face
-1, 1, -1,
-1, 1, 1,
1, 1, 1,
1, 1, -1,
// Bottom face
-1, -1, -1,
1, -1, -1,
1, -1, 1,
-1, -1, 1,
// Right face
1, -1, -1,
1, 1, -1,
1, 1, 1,
1, -1, 1,
// Left face
-1, -1, -1,
-1, -1, 1,
-1, 1, 1,
-1, 1, -1
]);
// build color Vertices
var colors = [
[1, 0, 1, 1], // Front face - Pink
[0, 1, 0, 1], // Back face - Green
[0, 0, 1, 1], // Top face - Blue
[0, 1, 1, 1], // Bottom face - Turquoise
[1, 1, 0, 1], // Right face - Yellow
[1, 0, 0, 1] // Left face - Red
];
var colorVertices = [];
for (var n in colors) {
var color = colors[n];
for (var i=0; i < 4; i++) {
colorVertices = colorVertices.concat(color);
}
}
cubeBuffers.colorBuffer = gl.createArrayBuffer(colorVertices);
cubeBuffers.indexBuffer = gl.createElementArrayBuffer([
0, 1, 2, 0, 2, 3, // Front face
4, 5, 6, 4, 6, 7, // Back face
8, 9, 10, 8, 10, 11, // Top face
12, 13, 14, 12, 14, 15, // Bottom face
16, 17, 18, 16, 18, 19, // Right face
20, 21, 22, 20, 22, 23 // Left face
]);
return cubeBuffers;
}
function stage(gl, cubeBuffers, angle){
// set field of view at 45 degrees
// set viewing range between 0.1 and 100.0 units away.
gl.perspective(45, 0.1, 100);
gl.identity();
// translate model-view matrix
gl.translate(0, 0, -5);
// rotate model-view matrix about x-axis (tilt box downwards)
gl.rotate(Math.PI * 0.15, 1, 0, 0);
// rotate model-view matrix about y-axis
gl.rotate(angle, 0, 1, 0);
gl.pushPositionBuffer(cubeBuffers);
gl.pushColorBuffer(cubeBuffers);
gl.pushIndexBuffer(cubeBuffers);
gl.drawElements(cubeBuffers);
}
window.onload = function(){
var gl = new WebGL("myCanvas", "experimental-webgl");
gl.setShaderProgram("VARYING_COLOR");
var cubeBuffers = initBuffers(gl);
var angle = 0;
gl.setStage(function(){
// update angle
var angularVelocity = Math.PI / 4; // radians / second
var angleEachFrame = angularVelocity * this.getTimeInterval() / 1000;
angle += angleEachFrame;
this.clear();
stage(this, cubeBuffers, angle);
});
gl.start();
};
SAVE
AI-Generated Solution
info
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
Unlock instant AI solutions
Tap the button
to generate a solution
to generate a solution
Click the button to generate
a solution
a solution
Knowledge Booster
Similar questions
- Write an android project that consist of the following: One activity (java file). Two different layouts (XML files). Each layout will have the following: Textview: contains the type of the layout you choose for this layout, for example, ConstraintLayout, table-layout, or LinearLayout (vertically or horizontally)…etc Textview: contains show your full name. Textview: to show your student ID. A button: upon clicking, the button should switch the layout of the activity. For example, the button in layout 1 should change the layout to layout 2, and the button in layout 2 should change the layout to layout 1. Use your own name and ID. The nams is " Alanood " and the ID " 190139479 " .arrow_forwardwe are going to create a new subclass of the SimpleGeometricObject class, namedTriangle. Copy the source code of the SimpleGeometricObject class from the following link: https://liveexample.pearsoncmg.com/html/SimpleGeometricObject.html TASK 1: Create a Triangle class that extends the SimpleGeometricObject class in Eclipse, followingthe below UML diagram. Use the following formula to calculate the area of a triangle: A = 1/2 × base × height TASK 2: Create a TestTriangle class in an individual .java file. In the main method,(1) Create a Triangle object with default base and height values.(2) Create a Triangle object with specified base = 3 and height =4. TASK 3: Add a toString() method to the Triangle class. In this toString() method,(1) Print the base, height, and area of a Triangle object.(2) Call the toString() method of the superclass using the super key word.Then, in the main method of the TestTriangle class, make the two Triangle objects that youcreated in Task 2…arrow_forwardPlease help me with this question. I am having trouble understanding what to do. The HTML code is provided in one of the images below as well as the instructions. The client_side.js and the CSS code are provide below Thank you CLIENT; var url = "http://localhost:3000/post"; var myID; var guessWord; function resetGame(){ var myName = prompt("What is your name?") document.getElementById("mistakes").innerHTML = "Wrong Letters: " // request server to start a new game! $.post(url+'?data='+JSON.stringify({ 'name':myName, //client's identity on the server 'action':'generateWord'}), response); } function printGuess(){ //you write code here! //1. Locate the HTML element with ID 'guessarea' //2. Cycle through the 'guessWord' array and write // each character to the 'guessarea' in turn } function makeGuess(){ //ask the server to validate the guess $.post(…arrow_forward
- Use HTML/CSS/JavaScript to build a textbox that accepts a maximum of ten lower-case alphabetic characters. The entering of upper-case alphabetic characters, numeric characters, or special characters are prevented by your code. That is, the prohibited characters are unable to appear in the textbox. Events are to be addressed by JavaScript event listeners. Usage of HTML onEventName attributes are strictly prohibited. Note: you do not have to code a complete working webpage, only necessary code that satisfy the requirements are needed.arrow_forwardJavascript .1. create a new global object variable “signUp” to store the sign-up information. Add the following properties to the object: name, email, phone, address, city, state, zip, foodAllergies, frequency, size and initialize all to a blank stringarrow_forwardI've created this project with using C++ before but this time I am trying to create a Tic tac toe using JavaScript (going to use CSS and make it look nice once I figure out to how even it get it working.) but the requirements for the project are..1. Create an html page that display's a Tic Tac Toe grid2. Ask for player one's name (use prompts or HTML Form)3. Ask for player two's name (use prompts or HTML Form)4. Display a message on the page that says "Joe's Turn" (or whatever player one's name is)5. Let "Joe" take his turn by clicking on a square in the grid6. Mark it with an X (or O)7. Display a message on the page that says "Sue's Turn" (or whatever player two's name is)8. Let "Sue" take her turn by clicking on a square in the grid9. Mark it with an O (or X)10. Continue alternating until there is a winner or a tie11. Display a message declaring the winner (or tie)12. Add a Play Again button that functions as follows:- It only appears after the game is over- It disappears once they…arrow_forward
- Using comments in the code, can you provide a line by line explination as to what the below HTML file is doing? The file relates to a WebGL program if that helps you. Please & thank you HTML File: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > <title>3D Sierpinski Gasket</title> <script id="vertex-shader" type="x-shader/x-vertex"> #version 300 es in vec3 aPosition; in vec3 aColor; out vec4 vColor; void main() { gl_Position = vec4(aPosition, 1.0); vColor = vec4(aColor, 1.0); } </script> <script id="fragment-shader" type="x-shader/x-fragment"> #version 300 es precision mediump float; in vec4 vColor; out vec4 fColor; void main() { fColor = vColor; } </script> <script type="text/javascript" src="../Common/initShaders.js"></script> <script type="text/javascript" src="../Common/MVnew.js"></script> <script type="text/javascript"…arrow_forwardWhen I printout the javaScript class array, containing several instances from my javascript file, it only shows up on my console, but not on the webpage. How do I get it to show up on the webpage. It has to be done from a separte js file not listed on the same page as the html. This is the code I am using to write out the values in the array. class Item { constructor(name, description, date) { this.name = name; this.description = description; this.date = date; } } const items = []; // Create 7 instances of the Item class items.push(new Item("item1", "description1", "2022-01-01")); items.push(new Item("item2", "description2", "2022-01-02")); items.push(new Item("item3", "description3", "2022-01-03")); items.push(new Item("item4", "description4", "2022-01-04")); items.push(new Item("item5", "description5", "2022-01-05")); items.push(new Item("item6", "description6", "2022-01-06")); items.push(new Item("item7", "description7",…arrow_forwardUsing DrawingPanel.java (from chapter 3G), draw a grid for filling in a 4 x 4 square of cell containing integers. For this part of the assignment the values are not important, but you are welcome to use the values shown in the magic square from below. Note that the values in any horizontal row, vertical column or main diagonals add up to 34, in addition to various sub-squares in the larger square also add up to the same value. Requirements: The magic square should be centered in the panel The values in each of the cells should be centered in that cell (both horizontally and vertically). You can assume the values will be <= 99 (i.e., at most 2 digits). For this part of the assignment, you can hard-code the values; you will store them in a 2-dimensional array (from chapter 7) when implementing Part B of the assignment. The title "CSC 142 Magic Square" is centered horizontally in the panel and at y = 50 You are free to choose the colors, fonts, font sizes and effects. This is what I used…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education