Best JavaScript code snippet using wpt
webgl.js
Source:webgl.js
...35 this._enabled = enable === true;36 }37 _createClass(WebGLContext, [{38 key: 'composeSMask',39 value: function composeSMask(_ref2) {40 var layer = _ref2.layer,41 mask = _ref2.mask,42 properties = _ref2.properties;43 return WebGLUtils.composeSMask(layer, mask, properties);44 }45 }, {46 key: 'drawFigures',47 value: function drawFigures(_ref3) {48 var width = _ref3.width,49 height = _ref3.height,50 backgroundColor = _ref3.backgroundColor,51 figures = _ref3.figures,52 context = _ref3.context;53 return WebGLUtils.drawFigures(width, height, backgroundColor, figures, context);54 }55 }, {56 key: 'clear',57 value: function clear() {58 WebGLUtils.cleanup();59 }60 }, {61 key: 'isEnabled',62 get: function get() {63 var enabled = this._enabled;64 if (enabled) {65 enabled = WebGLUtils.tryInitGL();66 }67 return (0, _util.shadow)(this, 'isEnabled', enabled);68 }69 }]);70 return WebGLContext;71}();72var WebGLUtils = function WebGLUtilsClosure() {73 function loadShader(gl, code, shaderType) {74 var shader = gl.createShader(shaderType);75 gl.shaderSource(shader, code);76 gl.compileShader(shader);77 var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);78 if (!compiled) {79 var errorMsg = gl.getShaderInfoLog(shader);80 throw new Error('Error during shader compilation: ' + errorMsg);81 }82 return shader;83 }84 function createVertexShader(gl, code) {85 return loadShader(gl, code, gl.VERTEX_SHADER);86 }87 function createFragmentShader(gl, code) {88 return loadShader(gl, code, gl.FRAGMENT_SHADER);89 }90 function createProgram(gl, shaders) {91 var program = gl.createProgram();92 for (var i = 0, ii = shaders.length; i < ii; ++i) {93 gl.attachShader(program, shaders[i]);94 }95 gl.linkProgram(program);96 var linked = gl.getProgramParameter(program, gl.LINK_STATUS);97 if (!linked) {98 var errorMsg = gl.getProgramInfoLog(program);99 throw new Error('Error during program linking: ' + errorMsg);100 }101 return program;102 }103 function createTexture(gl, image, textureId) {104 gl.activeTexture(textureId);105 var texture = gl.createTexture();106 gl.bindTexture(gl.TEXTURE_2D, texture);107 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);108 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);109 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);110 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);111 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);112 return texture;113 }114 var currentGL, currentCanvas;115 function generateGL() {116 if (currentGL) {117 return;118 }119 currentCanvas = document.createElement('canvas');120 currentGL = currentCanvas.getContext('webgl', { premultipliedalpha: false });121 }122 var smaskVertexShaderCode = '\123 attribute vec2 a_position; \124 attribute vec2 a_texCoord; \125 \126 uniform vec2 u_resolution; \127 \128 varying vec2 v_texCoord; \129 \130 void main() { \131 vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \132 gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \133 \134 v_texCoord = a_texCoord; \135 } ';136 var smaskFragmentShaderCode = '\137 precision mediump float; \138 \139 uniform vec4 u_backdrop; \140 uniform int u_subtype; \141 uniform sampler2D u_image; \142 uniform sampler2D u_mask; \143 \144 varying vec2 v_texCoord; \145 \146 void main() { \147 vec4 imageColor = texture2D(u_image, v_texCoord); \148 vec4 maskColor = texture2D(u_mask, v_texCoord); \149 if (u_backdrop.a > 0.0) { \150 maskColor.rgb = maskColor.rgb * maskColor.a + \151 u_backdrop.rgb * (1.0 - maskColor.a); \152 } \153 float lum; \154 if (u_subtype == 0) { \155 lum = maskColor.a; \156 } else { \157 lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \158 maskColor.b * 0.11; \159 } \160 imageColor.a *= lum; \161 imageColor.rgb *= imageColor.a; \162 gl_FragColor = imageColor; \163 } ';164 var smaskCache = null;165 function initSmaskGL() {166 var canvas, gl;167 generateGL();168 canvas = currentCanvas;169 currentCanvas = null;170 gl = currentGL;171 currentGL = null;172 var vertexShader = createVertexShader(gl, smaskVertexShaderCode);173 var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);174 var program = createProgram(gl, [vertexShader, fragmentShader]);175 gl.useProgram(program);176 var cache = {};177 cache.gl = gl;178 cache.canvas = canvas;179 cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');180 cache.positionLocation = gl.getAttribLocation(program, 'a_position');181 cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');182 cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');183 var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');184 var texLayerLocation = gl.getUniformLocation(program, 'u_image');185 var texMaskLocation = gl.getUniformLocation(program, 'u_mask');186 var texCoordBuffer = gl.createBuffer();187 gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);188 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]), gl.STATIC_DRAW);189 gl.enableVertexAttribArray(texCoordLocation);190 gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);191 gl.uniform1i(texLayerLocation, 0);192 gl.uniform1i(texMaskLocation, 1);193 smaskCache = cache;194 }195 function composeSMask(layer, mask, properties) {196 var width = layer.width,197 height = layer.height;198 if (!smaskCache) {199 initSmaskGL();200 }201 var cache = smaskCache,202 canvas = cache.canvas,203 gl = cache.gl;204 canvas.width = width;205 canvas.height = height;206 gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);207 gl.uniform2f(cache.resolutionLocation, width, height);208 if (properties.backdrop) {209 gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1);...
Using AI Code Generation
1var wptools = require('wptools');2var options = {3};4wptools.composeSMask(options, function(err, res) {5 if (err) return console.log(err);6 console.log(res);7});8var wptools = require('wptools');9var options = {10};11wptools.composeSMask(options, function(err, res) {12 if (err) return console.log(err);13 console.log(res);14});15var wptools = require('wptools');16var options = {17};18wptools.composeSMask(options, function(err, res) {19 if (err) return console.log(err);20 console.log(res);21});22var wptools = require('wptools');23var options = {24};25wptools.composeSMask(options, function(err, res) {26 if (err) return console.log(err);27 console.log(res);28});29var wptools = require('wptools');30var options = {31};32wptools.composeSMask(options, function(err, res) {33 if (err) return console.log(err);34 console.log(res);35});36var wptools = require('wptools');37var options = {38};39wptools.composeSMask(options, function(err, res) {40 if (err) return console.log(err);41 console.log(res);42});43var wptools = require('wptools');44var options = {
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools('en.wikipedia.org');3wp.composeSMask('Sachin Tendulkar', function(err, data) {4 console.log(data);5});6var wptools = require('wptools');7var wp = new wptools('en.wikipedia.org');8wp.composeSMask('Sachin Tendulkar', function(err, data) {9 console.log(data);10});11var wptools = require('wptools');12var wp = new wptools('en.wikipedia.org');13wp.composeSMask('Sachin Tendulkar', function(err, data) {14 console.log(data);15});16var wptools = require('wptools');17var wp = new wptools('en.wikipedia.org');18wp.composeSMask('Sachin Tendulkar', function(err, data) {19 console.log(data);20});21var wptools = require('wptools');22var wp = new wptools('en.wikipedia.org');23wp.composeSMask('Sachin Tendulkar', function(err, data) {24 console.log(data);25});26var wptools = require('wptools');27var wp = new wptools('en.wikipedia.org');28wp.composeSMask('Sachin Tendulkar', function(err, data) {29 console.log(data);30});31var wptools = require('wptools');32var wp = new wptools('en.wikipedia.org');33wp.composeSMask('Sachin Tendulkar', function(err, data) {34 console.log(data);35});36var wptools = require('wptools');37var wp = new wptools('en.wikipedia.org');38wp.composeSMask('
Using AI Code Generation
1var toolkit = require('wptoolkit');2toolkit.composeSMask('input.png', 'mask.png', 'output.png', function() {3 console.log('done');4});5var toolkit = require('wptoolkit');6toolkit.composeSMask('input.png', 'mask.png', 'output.png', function() {7 console.log('done');8});9var toolkit = require('wptoolkit');10toolkit.composeSMask('input.png', 'mask.png', 'output.png', function() {11 console.log('done');12});13var toolkit = require('wptoolkit');14toolkit.composeSMask('input.png', 'mask.png', 'output.png', function() {15 console.log('done');16});17var toolkit = require('wptoolkit');18toolkit.composeSMask('input.png', 'mask.png', 'output.png', function() {19 console.log('done');20});21var toolkit = require('wptoolkit');22toolkit.composeSMask('input.png', 'mask.png', 'output.png', function() {23 console.log('done');24});25var toolkit = require('wptoolkit');26toolkit.composeSMask('input.png', 'mask.png', 'output.png', function() {27 console.log('done');28});29var toolkit = require('wptoolkit');30toolkit.composeSMask('input.png', 'mask.png', 'output.png', function() {31 console.log('done');32});33var toolkit = require('wptoolkit');34toolkit.composeSMask('input.png', 'mask.png', 'output.png', function() {35 console.log('done');36});
Using AI Code Generation
1var wptextmodule = require('wptextmodule');2var wptext = new wptextmodule.WPText();3var img1 = wptext.loadImage('img1.png');4var img2 = wptext.loadImage('img2.png');5var img3 = wptext.composeSMask(img1, img2);6img3.save('img3.png');7var wptextmodule = require('wptextmodule');8var wptext = new wptextmodule.WPText();9var img1 = wptext.loadImage('img1.png');10var img2 = wptext.loadImage('img2.png');11var img3 = wptext.composeSMask(img1, img2);12img3.save('img3.png');13var wptext = new wptextmodule.WPText();14wptext.loadFont('font.ttf');15wptext.setPointSize(12);16wptext.setText('hello world');17wptext.setFillColor(0, 0, 0);18wptext.setBgColor(255, 255, 255);19wptext.setBgOpacity(1);20wptext.setLineSpacing(0.8);21wptext.setLetterSpacing(0.8);22wptext.setAlign('left');23wptext.setBold(true);24wptext.setItalic(true);25wptext.setUnderline(true);26wptext.setStrikeThrough(true);27wptext.setOverline(true);28wptext.setWordSpacing(0.8);29wptext.setCharSpacing(0.8);30wptext.setOpacity(1);31wptext.setShadow(0, 0, 0, 0, 0, 0, 0);32wptext.setOutline(0, 0, 0, 0, 0, 0, 0);33wptext.setTransform(1, 0, 0, 1, 0, 0);34wptext.setTransform(1, 0, 0, 1, 0, 0, 'left', 'top');35wptext.setTransform(1, 0, 0, 1, 0, 0, 'left', 'top', 'right', 'bottom');
Using AI Code Generation
1var wptextoverlay = new WpTextOverlay();2var foreground = "foreground.png";3var background = "background.png";4var foregroundMask = "foregroundMask.png";5var output = "output.png";6wptextoverlay.composeSMask(foreground, background, foregroundMask, output);7var wptextoverlay = new WpTextOverlay();8var foreground = "foreground.png";9var foregroundMask = "foregroundMask.png";10wptextoverlay.createSMask(foreground, foregroundMask);11var wptextoverlay = new WpTextOverlay();12var foreground = "foreground.png";13var foregroundMask = "foregroundMask.png";14wptextoverlay.createSMask(foreground, foregroundMask);15var wptextoverlay = new WpTextOverlay();16var foreground = "foreground.png";17var foregroundMask = "foregroundMask.png";18wptextoverlay.createSMask(foreground, foregroundMask);19var wptextoverlay = new WpTextOverlay();20var foreground = "foreground.png";21var foregroundMask = "foregroundMask.png";22wptextoverlay.createSMask(foreground, foregroundMask);
Using AI Code Generation
1var wptk = require("wptoolkit");2var img = wptk.readImage("img1.jpg");3var img2 = wptk.composeSMask(img);4wptk.writeImage(img2, "img2.jpg");5var wptk = require("wptoolkit");6var img = wptk.readImage("img1.jpg");7var img2 = wptk.composeSMask(img);8wptk.writeImage(img2, "img2.jpg");9var wptk = require("wptoolkit");10var img = wptk.readImage("img1.jpg");11var img2 = wptk.composeSMask(img);12wptk.writeImage(img2, "img2.jpg");13var wptk = require("wptoolkit");14var img = wptk.readImage("img1.jpg");15var img2 = wptk.composeSMask(img);16wptk.writeImage(img2, "img2.jpg");17var wptk = require("wptoolkit");18var img = wptk.readImage("img1.jpg");19var img2 = wptk.composeSMask(img);20wptk.writeImage(img2, "img2.jpg");21var wptk = require("wptoolkit");22var img = wptk.readImage("img1.jpg");23var img2 = wptk.composeSMask(img);
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!!