Question: * Computer Graphics ellipse.js class Ellipse 2 D { static vertexPositions = [ ] ; static vertexColors = [ ] ; static shaderProgram = -
Computer Graphics
ellipse.js
class EllipseD
static vertexPositions ;
static vertexColors ;
static shaderProgram ;
static positionBuffer ;
static colorBuffer ;
static aPositionShader ;
static aColorShader ;
static initialize
EllipseDshaderProgram initShadersglvshaderglslfshaderglsl;
const radiusX ;
const radiusY ; Scale the ycoordinate down to
const center vec radiusY;
const numSegments ;
for let i ; i numSegments; i
const angle i numSegments Math.PI;
const x radiusX Math.cosangle center;
const y radiusY Math.sinangle center;
const red ;
EllipseDvertexPositions.pushvecx y;
EllipseDvertexColors.pushvecred;
Load the data into the GPU
EllipseDpositionBuffer glcreateBuffer;
glbindBufferglARRAYBUFFER, EllipseDpositionBuffer;
glbufferDataglARRAYBUFFER, flattenEllipseDvertexPositions glSTATICDRAW;
EllipseDcolorBuffer glcreateBuffer;
glbindBufferglARRAYBUFFER, EllipseDcolorBuffer;
glbufferDataglARRAYBUFFER, flattenEllipseDvertexColors glSTATICDRAW;
Associate our shader variables with our data buffer
EllipseDaPositionShader glgetAttribLocationEllipseDshaderProgram, "aPosition";
EllipseDaColorShader glgetAttribLocationEllipseDshaderProgram, "aColor";
constructor
if EllipseDshaderProgram EllipseDinitialize;
draw
gluseProgramEllipseDshaderProgram;
glbindBufferglARRAYBUFFER, EllipseDpositionBuffer;
glvertexAttribPointerEllipseDaPositionShader, glFLOAT, false, ;
glbindBufferglARRAYBUFFER, EllipseDcolorBuffer;
glvertexAttribPointerEllipseDaColorShader, glFLOAT, false, ;
glenableVertexAttribArrayEllipseDaPositionShader;
glenableVertexAttribArrayEllipseDaColorShader;
gldrawArraysglTRIANGLEFAN, EllipseDvertexPositions.length;
gldisableVertexAttribArrayEllipseDaPositionShader;
gldisableVertexAttribArrayEllipseDaColorShader;
app.js
var canvas;
var gl;
var sq;
var sq;
var sq;
var sq;
var sq;
var sq;
var triangle;
var circle;
var ellipse;
window.onload function init
canvas document.getElementByIdglcanvas" ;
gl canvas.getContextwebgl;
if gl alert "WebGL isn't available" ;
glviewport canvas.width, canvas.height ;
glclearColor;
sq new Square;
sq new Square;
sq new Square;
sq new Square;
sq new Square;
sq new Square;
triangle new TriangleD;
circle new CircleD;
ellipse new EllipseD;
render;
;
function render
glclear glCOLORBUFFERBIT ;
sqdraw;
sqdraw;
sqdraw;
sqdraw;
sqdraw;
sqdraw;
triangle.draw;
circle.draw;
ellipse.draw;
index.html
Not supported
Define a button that changes the orientation of the red ellipse by degrees.
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
