Best JavaScript code snippet using wpt
webgl.js
Source:webgl.js
...222 void main() { \223 gl_FragColor = v_color; \224 } ';225 var figuresCache = null;226 function initFiguresGL() {227 var canvas, gl;228 generateGL();229 canvas = currentCanvas;230 currentCanvas = null;231 gl = currentGL;232 currentGL = null;233 // setup a GLSL program234 var vertexShader = createVertexShader(gl, figuresVertexShaderCode);235 var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);236 var program = createProgram(gl, [vertexShader, fragmentShader]);237 gl.useProgram(program);238 var cache = {};239 cache.gl = gl;240 cache.canvas = canvas;241 cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');242 cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');243 cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');244 cache.positionLocation = gl.getAttribLocation(program, 'a_position');245 cache.colorLocation = gl.getAttribLocation(program, 'a_color');246 figuresCache = cache;247 }248 function drawFigures(width, height, backgroundColor, figures, context) {249 if (!figuresCache) {250 initFiguresGL();251 }252 var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;253 canvas.width = width;254 canvas.height = height;255 gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);256 gl.uniform2f(cache.resolutionLocation, width, height);257 // count triangle points258 var count = 0;259 var i, ii, rows;260 for (i = 0, ii = figures.length; i < ii; i++) {261 switch (figures[i].type) {262 case 'lattice':263 rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;264 count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;...
Using AI Code Generation
1var scene = new THREE.Scene();2var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );3var renderer = new THREE.WebGLRenderer();4renderer.setSize( window.innerWidth, window.innerHeight );5document.body.appendChild( renderer.domElement );6var geometry = new THREE.BoxGeometry( 1, 1, 1 );7var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );8var cube = new THREE.Mesh( geometry, material );9scene.add( cube );10camera.position.z = 5;11renderer.render( scene, camera );12var wptoolkit = require('wptoolkit');13wptoolkit.initFiguresGL();14var animate = function () {15 requestAnimationFrame( animate );16 cube.rotation.x += 0.01;17 cube.rotation.y += 0.01;18 renderer.render( scene, camera );19};20animate();21{22 "scripts": {23 },24 "dependencies": {25 }26}
Using AI Code Generation
1var gl;2var canvas = document.getElementById('canvas');3try {4 gl = initFiguresGL(canvas);5} catch (e) {6 alert('Could not initialise WebGL, sorry :-(');7}8var gl;9var canvas = document.getElementById('canvas');10try {11 gl = initFiguresGL(canvas);12} catch (e) {13 alert('Could not initialise WebGL, sorry :-(');14}15var gl;16var canvas = document.getElementById('canvas');17try {18 gl = initFiguresGL(canvas);19} catch (e) {20 alert('Could not initialise WebGL, sorry :-(');21}22var gl;23var canvas = document.getElementById('canvas');24try {25 gl = initFiguresGL(canvas);26} catch (e) {27 alert('Could not initialise WebGL, sorry :-(');28}29var gl;30var canvas = document.getElementById('canvas');31try {32 gl = initFiguresGL(canvas);33} catch (e) {34 alert('Could not initialise WebGL, sorry :-(');35}36var gl;37var canvas = document.getElementById('canvas');38try {39 gl = initFiguresGL(canvas);40} catch (e) {41 alert('Could not initialise WebGL, sorry :-(');42}43var gl;44var canvas = document.getElementById('canvas');45try {46 gl = initFiguresGL(canvas);47} catch (e) {48 alert('Could not initialise WebGL, sorry :-(');49}50var gl;51var canvas = document.getElementById('canvas');52try {53 gl = initFiguresGL(canvas);
Using AI Code Generation
1var figures = initFiguresGL();2function initFiguresGL() {3 var figures = [];4 var figure = new Figure();5 ];6 figure.indices = [0, 1, 2];7 figures.push(figure);8 return figures;9}10function Figure() {11 this.vertices = [];12 this.indices = [];13 this.colors = [];14 this.normals = [];15 this.textureCoords = [];16 this.glBuffers = [];17 this.glBufferIndices = [];18 this.glBufferColors = [];19 this.glBufferNormals = [];20 this.glBufferTextureCoords = [];21 this.glBufferTexture = [];22 this.glBufferTextureIndex = [];23}24function initBuffers() {25 for (var i = 0; i < figures.length; i++) {26 var figure = figures[i];27 figure.glBufferIndices = gl.createBuffer();28 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, figure.glBufferIndices);29 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(figure.indices), gl.STATIC_DRAW);30 figure.glBuffers = gl.createBuffer();31 gl.bindBuffer(gl.ARRAY_BUFFER, figure.glBuffers);32 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(figure.vertices), gl.STATIC_DRAW);33 figure.glBufferColors = gl.createBuffer();34 gl.bindBuffer(gl.ARRAY_BUFFER, figure.glBufferColors);35 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(figure.colors), gl.STATIC_DRAW);36 figure.glBufferNormals = gl.createBuffer();37 gl.bindBuffer(gl.ARRAY_BUFFER, figure.glBufferNormals);38 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(figure.normals), gl.STATIC_DRAW);39 figure.glBufferTextureCoords = gl.createBuffer();40 gl.bindBuffer(gl.ARRAY_BUFFER, figure.glBufferTextureCoords);41 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(figure.textureCoords), gl.STATIC_DRAW);
Using AI Code Generation
1var canvas = document.getElementById("canvas");2var gl = wptoolkit.initFiguresGL(canvas);3var triangle = new wptoolkit.Figure(gl);4var rectangle = new wptoolkit.Figure(gl);5var circle = new wptoolkit.Figure(gl);6triangle.addTriangle({7});8rectangle.addRectangle({9});10circle.addCircle({11});12triangle.draw();13rectangle.draw();14circle.draw();15circle.draw();16rectangle.draw();17triangle.draw();18circle.draw();19rectangle.draw();20triangle.draw();21rectangle.draw();22circle.draw();23circle.draw();24rectangle.draw();25triangle.draw();26circle.draw();27rectangle.draw();28triangle.draw();29rectangle.draw();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!