Question: * Computer Graphics ellipse.js class Ellipse 2 D { static vertexPositions = [ ] ; static vertexColors = [ ] ; static shaderProgram = -

*Computer Graphics
ellipse.js
class Ellipse2D {
static vertexPositions =[];
static vertexColors =[];
static shaderProgram =-1;
static positionBuffer =-1;
static colorBuffer =-1;
static aPositionShader =-1;
static aColorShader =-1;
static initialize(){
Ellipse2D.shaderProgram = initShaders(gl,"/vshader.glsl","/fshader.glsl");
const radiusX =0.2;
const radiusY =0.2*0.6; // Scale the y-coordinate down to 60%
const center = vec2(-0.6,0.85- radiusY);
const numSegments =30;
for (let i =0; i = numSegments; i++){
const angle =(i / numSegments)*2* Math.PI;
const x = radiusX * Math.cos(angle)+ center[0];
const y = radiusY * Math.sin(angle)+ center[1];
const red =1.0;
Ellipse2D.vertexPositions.push(vec2(x, y));
Ellipse2D.vertexColors.push(vec3(red,0.0,0.0));
}
// Load the data into the GPU
Ellipse2D.positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, Ellipse2D.positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, flatten(Ellipse2D.vertexPositions), gl.STATIC_DRAW);
Ellipse2D.colorBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, Ellipse2D.colorBuffer);
gl.bufferData(gl.ARRAY_BUFFER, flatten(Ellipse2D.vertexColors), gl.STATIC_DRAW);
// Associate our shader variables with our data buffer
Ellipse2D.aPositionShader = gl.getAttribLocation(Ellipse2D.shaderProgram, "aPosition");
Ellipse2D.aColorShader = gl.getAttribLocation(Ellipse2D.shaderProgram, "aColor");
}
constructor(){
if (Ellipse2D.shaderProgram ===-1) Ellipse2D.initialize();
}
draw(){
gl.useProgram(Ellipse2D.shaderProgram);
gl.bindBuffer(gl.ARRAY_BUFFER, Ellipse2D.positionBuffer);
gl.vertexAttribPointer(Ellipse2D.aPositionShader, 2, gl.FLOAT, false, 0,0);
gl.bindBuffer(gl.ARRAY_BUFFER, Ellipse2D.colorBuffer);
gl.vertexAttribPointer(Ellipse2D.aColorShader, 3, gl.FLOAT, false, 0,0);
gl.enableVertexAttribArray(Ellipse2D.aPositionShader);
gl.enableVertexAttribArray(Ellipse2D.aColorShader);
gl.drawArrays(gl.TRIANGLE_FAN, 0, Ellipse2D.vertexPositions.length);
gl.disableVertexAttribArray(Ellipse2D.aPositionShader);
gl.disableVertexAttribArray(Ellipse2D.aColorShader);
}
}
app.js
var canvas;
var gl;
var sq;
var sq2;
var sq3;
var sq4;
var sq5;
var sq6;
var triangle;
var circle;
var ellipse;
window.onload = function init(){
canvas = document.getElementById("gl-canvas" );
gl = canvas.getContext('webgl2');
if (!gl ){ alert( "WebGL 2.0 isn't available" ); }
gl.viewport(0,0, canvas.width, canvas.height );
gl.clearColor(0.0,0.0,0.0,1.0);
sq = new Square();
sq2= new Square2();
sq3= new Square3();
sq4= new Square4();
sq5= new Square5();
sq6= new Square6();
triangle = new Triangle2D();
circle = new Circle2D();
ellipse = new Ellipse2D();
render();
};
function render(){
gl.clear( gl.COLOR_BUFFER_BIT );
sq.draw();
sq2.draw();
sq3.draw();
sq4.draw();
sq5.draw();
sq6.draw();
triangle.draw();
circle.draw();
ellipse.draw();
}
index.html
Not supported
Define a button that changes the orientation of the red ellipse by 90 degrees.
 *Computer Graphics ellipse.js class Ellipse2D { static vertexPositions =[]; static vertexColors

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!