Best JavaScript code snippet using wpt
pattern_helper.js
Source:pattern_helper.js
...139 error('illigal figure');140 break;141 }142 }143 function createMeshCanvas(bounds, combinesScale, coords, colors, figures,144 backgroundColor) {145 // we will increase scale on some weird factor to let antialiasing take146 // care of "rough" edges147 var EXPECTED_SCALE = 1.1;148 // MAX_PATTERN_SIZE is used to avoid OOM situation.149 var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough150 var offsetX = Math.floor(bounds[0]);151 var offsetY = Math.floor(bounds[1]);152 var boundsWidth = Math.ceil(bounds[2]) - offsetX;153 var boundsHeight = Math.ceil(bounds[3]) - offsetY;154 var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *155 EXPECTED_SCALE)), MAX_PATTERN_SIZE);156 var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *157 EXPECTED_SCALE)), MAX_PATTERN_SIZE);158 var scaleX = boundsWidth / width;159 var scaleY = boundsHeight / height;160 var context = {161 coords: coords,162 colors: colors,163 offsetX: -offsetX,164 offsetY: -offsetY,165 scaleX: 1 / scaleX,166 scaleY: 1 / scaleY167 };168 var canvas, tmpCanvas, i, ii;169 if (WebGLUtils.isEnabled) {170 canvas = WebGLUtils.drawFigures(width, height, backgroundColor,171 figures, context);172 // https://bugzilla.mozilla.org/show_bug.cgi?id=972126173 tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);174 tmpCanvas.context.drawImage(canvas, 0, 0);175 canvas = tmpCanvas.canvas;176 } else {177 tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);178 var tmpCtx = tmpCanvas.context;179 var data = tmpCtx.createImageData(width, height);180 if (backgroundColor) {181 var bytes = data.data;182 for (i = 0, ii = bytes.length; i < ii; i += 4) {183 bytes[i] = backgroundColor[0];184 bytes[i + 1] = backgroundColor[1];185 bytes[i + 2] = backgroundColor[2];186 bytes[i + 3] = 255;187 }188 }189 for (i = 0; i < figures.length; i++) {190 drawFigure(data, figures[i], context);191 }192 tmpCtx.putImageData(data, 0, 0);193 canvas = tmpCanvas.canvas;194 }195 return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,196 scaleX: scaleX, scaleY: scaleY};197 }198 return createMeshCanvas;199})();200ShadingIRs.Mesh = {201 fromIR: function Mesh_fromIR(raw) {202 //var type = raw[1];203 var coords = raw[2];204 var colors = raw[3];205 var figures = raw[4];206 var bounds = raw[5];207 var matrix = raw[6];208 //var bbox = raw[7];209 var background = raw[8];210 return {211 type: 'Pattern',212 getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {213 var scale;214 if (shadingFill) {215 scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);216 } else {217 // Obtain scale from matrix and current transformation matrix.218 scale = Util.singularValueDecompose2dScale(owner.baseTransform);219 if (matrix) {220 var matrixScale = Util.singularValueDecompose2dScale(matrix);221 scale = [scale[0] * matrixScale[0],222 scale[1] * matrixScale[1]];223 }224 }225 // Rasterizing on the main thread since sending/queue large canvases226 // might cause OOM.227 var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,228 colors, figures, shadingFill ? null : background);229 if (!shadingFill) {230 ctx.setTransform.apply(ctx, owner.baseTransform);231 if (matrix) {232 ctx.transform.apply(ctx, matrix);233 }234 }235 ctx.translate(temporaryPatternCanvas.offsetX,236 temporaryPatternCanvas.offsetY);237 ctx.scale(temporaryPatternCanvas.scaleX,238 temporaryPatternCanvas.scaleY);239 return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');240 }241 };...
Using AI Code Generation
1function createMeshCanvas() {2 var canvas = document.createElement("canvas");3 var ctx = canvas.getContext("webgl");4 ctx.canvas.width = 512;5 ctx.canvas.height = 512;6 ctx.clearColor(0.0, 0.0, 0.0, 1.0);7 ctx.clear(ctx.COLOR_BUFFER_BIT);8 ctx.finish();9 return canvas;10}11function createMeshCanvas() {12 var canvas = document.createElement("canvas");13 var ctx = canvas.getContext("webgl");14 ctx.canvas.width = 512;15 ctx.canvas.height = 512;16 ctx.clearColor(0.0, 0.0, 0.0, 1.0);17 ctx.clear(ctx.COLOR_BUFFER_BIT);18 ctx.finish();19 return canvas;20}21function createMeshCanvas() {22 var canvas = document.createElement("canvas");23 var ctx = canvas.getContext("webgl");24 ctx.canvas.width = 512;25 ctx.canvas.height = 512;26 ctx.clearColor(0.0, 0.0, 0.0, 1.0);27 ctx.clear(ctx.COLOR_BUFFER_BIT);28 ctx.finish();29 return canvas;30}31function createMeshCanvas() {32 var canvas = document.createElement("canvas");33 var ctx = canvas.getContext("webgl");34 ctx.canvas.width = 512;35 ctx.canvas.height = 512;36 ctx.clearColor(0.0, 0.0, 0.0, 1.0);37 ctx.clear(ctx.COLOR_BUFFER_BIT);38 ctx.finish();39 return canvas;40}41function createMeshCanvas() {42 var canvas = document.createElement("canvas");43 var ctx = canvas.getContext("webgl");44 ctx.canvas.width = 512;45 ctx.canvas.height = 512;46 ctx.clearColor(0.0, 0.0, 0.0, 1.0);47 ctx.clear(ctx.COLOR_BUFFER_BIT);48 ctx.finish();49 return canvas;50}51function createMeshCanvas() {52 var canvas = document.createElement("canvas");53 var ctx = canvas.getContext("webgl");
Using AI Code Generation
1var meshCanvas = wpt.createMeshCanvas(100, 100);2meshCanvas.setMeshColor(0, 0, 0, 255);3meshCanvas.setMeshColor(1, 0, 0, 255);4meshCanvas.setMeshColor(2, 0, 0, 255);5meshCanvas.setMeshColor(3, 0, 0, 255);6meshCanvas.setMeshColor(4, 0, 0, 255);7meshCanvas.setMeshColor(5, 0, 0, 255);8meshCanvas.setMeshColor(6, 0, 0, 255);9meshCanvas.setMeshColor(7, 0, 0, 255);10meshCanvas.setMeshColor(8, 0, 0, 255);11meshCanvas.setMeshColor(9, 0, 0, 255);12meshCanvas.setMeshColor(10, 0, 0, 255);13meshCanvas.setMeshColor(11, 0, 0, 255);14meshCanvas.setMeshColor(12, 0, 0, 255);15meshCanvas.setMeshColor(13, 0, 0, 255);16meshCanvas.setMeshColor(14, 0, 0, 255);17meshCanvas.setMeshColor(15, 0, 0, 255);18meshCanvas.setMeshColor(16, 0, 0, 255);19meshCanvas.setMeshColor(17, 0, 0, 255);20meshCanvas.setMeshColor(18, 0, 0, 255);21meshCanvas.setMeshColor(19, 0, 0, 255);22meshCanvas.setMeshColor(20, 0, 0, 255);23meshCanvas.setMeshColor(21, 0, 0, 255);24meshCanvas.setMeshColor(22, 0, 0, 255);25meshCanvas.setMeshColor(23, 0, 0, 255);26meshCanvas.setMeshColor(24, 0, 0, 255);27meshCanvas.setMeshColor(25, 0, 0, 255);28meshCanvas.setMeshColor(26, 0, 0, 255);29meshCanvas.setMeshColor(27, 0, 0, 255);30meshCanvas.setMeshColor(28
Using AI Code Generation
1var mesh = createMeshCanvas("meshCanvas", 100, 100, 100, 100, 10, 10, 10, 10, 10, 10, 10, 10);2mesh.style.border = "1px solid #000";3mesh.style.backgroundColor = "#ccc";4mesh.addEventListener("click", function(e) {5 var x = e.offsetX;6 var y = e.offsetY;7 var index = mesh.getMeshIndexAtPoint(x, y);8 var rect = mesh.getMeshRect(index);9 var rect2 = mesh.getMeshRect(index - 1);10 var rect3 = mesh.getMeshRect(index + 1);11 var ctx = mesh.getContext("2d");12 ctx.fillStyle = "rgba(255, 0, 0, 0.5)";13 ctx.fillRect(rect.x, rect.y, rect.width, rect.height);14 ctx.fillRect(rect2.x, rect2.y, rect2.width, rect2.height);15 ctx.fillRect(rect3.x, rect3.y, rect3.width, rect3.height);16});17mesh.addEventListener("mousemove", function(e) {18 var x = e.offsetX;19 var y = e.offsetY;20 var index = mesh.getMeshIndexAtPoint(x, y);21 var rect = mesh.getMeshRect(index);22 var rect2 = mesh.getMeshRect(index - 1);23 var rect3 = mesh.getMeshRect(index + 1);24 var ctx = mesh.getContext("2d");25 ctx.clearRect(0, 0, mesh.width, mesh.height);26 ctx.fillStyle = "rgba(255, 0, 0, 0.5)";27 ctx.fillRect(rect.x, rect.y, rect.width, rect.height);28 ctx.fillRect(rect2.x, rect2.y, rect2.width, rect2.height);29 ctx.fillRect(rect3.x, rect3.y, rect3.width, rect3.height);30});31mesh.addEventListener("mouseout", function(e) {32 var ctx = mesh.getContext("2d");33 ctx.clearRect(0, 0, mesh.width, mesh.height);34});35mesh.addEventListener("mouseup", function(e) {36 var ctx = mesh.getContext("2d");37 ctx.clearRect(0, 0, mesh.width, mesh.height);38});39mesh.addEventListener("mousedown", function(e) {40 var ctx = mesh.getContext("2d");41 ctx.clearRect(0,
Using AI Code Generation
1var canvas = createMeshCanvas(400, 400, 10, 10, 0.1, 0.1, 0.1);2var ctx = canvas.getContext("2d");3ctx.fillStyle = "red";4ctx.fillRect(0, 0, 100, 100);5ctx.fillStyle = "green";6ctx.fillRect(100, 100, 100, 100);7ctx.fillStyle = "blue";8ctx.fillRect(200, 200, 100, 100);9ctx.fillStyle = "yellow";10ctx.fillRect(300, 300, 100, 100);11var img = document.createElement("img");12img.src = canvas.toDataURL();13img.width = 400;14img.height = 400;15document.body.appendChild(img);16import os17import sys18import time19import subprocess20import tempfile21import shutil22import json23import base6424import hashlib25import logging26import argparse27import re28import requests29import threading30import Queue31import random32import string33import traceback34import urllib35import urllib236import urlparse37import mimetypes38import httplib39import socket40import ssl41import gzip42import StringIO43import platform44import ctypes45import ctypes.util46import uuid47import getpass48import zipfile49import zlib50import struct51import csv52import ConfigParser53import cStringIO54from collections import OrderedDict55from datetime import datetime, timedelta56from xml.dom import minidom57from xml.etree import ElementTree58from xml.parsers import expat59from pprint import pprint60from functools import wraps61from PIL import Image62from PIL import ImageChops63from PIL import ImageDraw64from PIL import ImageFont65from PIL import ImageFilter66from PIL import ImageEnhance67from PIL import ImageOps68from PIL import ImageStat69from PIL import ImageSequence70from PIL import ImagePalette71from PIL import ImageColor72from PIL import ImageFile73from PIL import ImagePath74from PIL import ImageGrab75from PIL import BdfFontFile76from PIL import PcfFontFile77from PIL import PpmImagePlugin
Using AI Code Generation
1var wptools = require("wptools");2var meshCanvas = wptools.createMeshCanvas();3meshCanvas.setWidth(800);4meshCanvas.setHeight(600);5meshCanvas.setBackgroundColor("#F0F0F0");6meshCanvas.addMesh();7meshCanvas.setMeshColor("#000000");8meshCanvas.addTriangle(100, 100, 200, 100, 150, 200);9meshCanvas.addTriangle(200, 100, 300, 100, 250, 200);10meshCanvas.addTriangle(300, 100, 400, 100, 350, 200);11meshCanvas.addTriangle(400, 100, 500, 100, 450, 200);12meshCanvas.addTriangle(500, 100, 600, 100, 550, 200);13meshCanvas.addTriangle(600, 100, 700, 100, 650, 200);14meshCanvas.addTriangle(700, 100, 800, 100, 750, 200);15meshCanvas.addTriangle(800, 100, 900, 100, 850, 200);16meshCanvas.addTriangle(900, 100, 1000, 100, 950, 200);17meshCanvas.addTriangle(1000, 100, 1100, 100, 1050, 200);18meshCanvas.addTriangle(1100, 100, 1200, 100, 1150, 200);19meshCanvas.addTriangle(1200, 100, 1300, 100, 1250, 200);
Using AI Code Generation
1var modelPath = 'C:/Users/username/Desktop/model.obj';2var imagePath = 'C:/Users/username/Desktop/model.jpg';3var outputPath = 'C:/Users/username/Desktop/mesh.js';4var meshSize = 500;5var canvasSize = 500;6var textureSize = 500;7var ambientColor = [0.1, 0.1, 0.1];8var directionalColor = [0.9, 0.9, 0.9];9var directionalDirection = [0.5, 0.5, 0.5];10var pointColor = [0.9, 0.9, 0.9];11var pointPosition = [0.5, 0.5, 0.5];12var specularColor = [0.9, 0.9, 0.9];13var specularPosition = [0.5, 0.5, 0.5];14var specularExponent = 20;15var backgroundColor = [0.1, 0.1, 0.1];16var foregroundColor = [0.1, 0.1, 0.1];17var backgroundColor = [0.1, 0.1, 0.1];18var foregroundColor = [0.1, 0.1, 0.1];19var rotation = [0, 0, 0];
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!!