How to use transform2 method in wpt

Best JavaScript code snippet using wpt

engine.js

Source:engine.js Github

copy

Full Screen

1//jshint maxerr: 100002//CONSTRUCT DOCUMENT3document.body.innerHTML = "<canvas id=\"canvas\"></canvas>" + document.body.innerHTML;4document.head.innerHTML += "<meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width\"><style>canvas{margin:0;border:0;padding:0;}body{margin:0;overflow:hidden;}</style>";5//CLASSES6class Transform {7 constructor(x, y, r) {8 this.x = x;9 this.y = y;10 this.r = r;11 }12}13class FillRenderer {14 constructor(color1, color2, alpha, dir) {15 this.type = "fillRenderer";16 this.color1 = color1;17 this.color2 = color2;18 this.dir = dir;19 this.alpha = alpha;20 }21}22class ImageRenderer {23 constructor(image, alpha, x, y, w, h, hf, vf) {24 this.type = "imageRenderer";25 this.image = image;26 this.x = x;27 this.y = y;28 this.w = w;29 this.h = h;30 this.hf = hf;31 this.vf = vf;32 this.alpha = alpha;33 }34}35class BorderRenderer {36 constructor(color, alpha, lw) {37 this.type = "borderRenderer";38 this.color = color;39 this.lw = lw;40 this.alpha = alpha;41 }42}43class Text {44 constructor(font, text, size) {45 this.type = "text";46 this.text = text;47 this.font = font;48 this.x = x;49 this.y = y;50 this.size = size;51 }52}53class Polygon {54 constructor(tris) {55 this.type = "polygon";56 this.tris = tris;57 }58}59class Tri {60 constructor(points, borders) {61 this.type = "tri";62 this.borders = borders;63 this.points = points;64 }65}66var e = {67 methods: {68 setDimensions: null,69 renderImage: null,70 renderText: null,71 renderPolygon: null,72 calcDistance: null,73 randomNum: null,74 calcAngle: null,75 calcRotationalX: null,76 calcRotationalY: null,77 detectCollision: null,78 clearCanvas: null79 },80 data: {81 w: window.innerWidth,82 h: window.innerHeight,83 element: document.getElementById("canvas"),84 cx: document.getElementById("canvas").getContext("2d"),85 cw: window.innerWidth,86 ch: window.innerHeight,87 mouse: {88 x: 0,89 y: 0,90 clicking: false91 },92 pressedKeys: [93 ],94 camera: {95 x: 0,96 y: 0,97 zoom: 198 }99 }100};101//FUNCTIONS102e.methods.setDimensions = (w, h) => {103 if(w === "full") {104 e.data.element.width = window.innerWidth;105 e.data.w = window.innerWidth;106 e.data.element.height = window.innerHeight;107 e.data.h = window.innerHeight;108 } else {109 e.data.w = w;110 e.data.h = h;111 e.data.element.width = w;112 e.data.element.height = h;113 }114},115e.methods.renderImage = (transform, imageRenderer) => {116 if(transform.x + (imageRenderer.w / 2) >= e.data.camera.x && e.data.camera.x + (e.data.w * e.data.camera.zoom) >= transform.x - (imageRenderer.w / 2) && transform.y - (imageRenderer.h / 2) <= e.data.camera.y && e.data.camera.y - (e.data.h * e.data.camera.zoom) <= transform.y + (imageRenderer.h / 2)) {117 var fc = {118 x: 1,119 y: -1120 };121 e.data.cx.save();122 if(imageRenderer.hf) {123 e.data.cx.scale(-1, 1);124 fc.x = -1;125 } else {126 e.data.cx.scale(1, 1);127 }128 if(imageRenderer.vf) {129 e.data.cx.scale(1, 1);130 fc.y = 1;131 } else {132 e.data.cx.scale(1, -1);133 }134 e.data.cx.globalAlpha = imageRenderer.alpha;135 e.data.cx.translate(((transform.x - e.data.camera.x) / e.data.camera.zoom) * fc.x, ((transform.y - e.data.camera.y) / e.data.camera.zoom) * fc.y);136 e.data.cx.rotate(transform.r * fc.x * fc.y * (Math.PI / 180));137 e.data.cx.drawImage(imageRenderer.image, ((imageRenderer.x / e.data.camera.zoom) * fc.x) - ((imageRenderer.w / e.data.camera.zoom) / 2), ((imageRenderer.y / e.data.camera.zoom) * fc.y) - ((imageRenderer.h / e.data.camera.zoom) / 2), imageRenderer.w / e.data.camera.zoom, imageRenderer.h / e.data.camera.zoom);138 e.data.cx.restore();139 }140},141e.methods.renderText = (transform, text, fillRenderer) => {142 if(transform.x + (text.text.length * text.size) >= e.data.camera.x && e.data.camera.x + (e.data.w * e.data.camera.zoom) >= transform.x && transform.y <= e.data.camera.y && e.data.camera.y - (e.data.h * e.data.camera.zoom) <= transform.y) {143 e.data.cx.save();144 e.data.cx.translate((transform.x - e.data.camera.x) / e.data.camera.zoom, (transform.y - e.data.camera.y) / e.data.camera.zoom);145 e.data.cx.rotate(transform.r * (Math.PI / 180));146 e.data.cx.globalAlpha = fillRenderer.alpha;147 e.data.cx.font = (text.size / e.data.camera.zoom) + "px " + text.font;148 e.data.cx.fillStyle = fillRenderer.color1;149 e.data.cx.fillText(text.text, text.x / e.data.camera.zoom, text.y / e.data.camera.zoom);150 e.data.cx.restore();151 }152},153e.methods.renderPolygon = (transform, polygon, fillRenderer, borderRenderer) => {154 e.data.cx.save();155 e.data.cx.translate((transform.x - e.data.camera.x) / e.data.camera.zoom, (transform.y - e.data.camera.y) / e.data.camera.zoom);156 e.data.cx.rotate(transform.r * (Math.PI / 180));157 let tri = 0;158 for(tri = 0; tri < polygon.tris.length; tri++) {159 e.data.cx.beginPath();160 e.data.cx.moveTo(polygon.tris[tri].points[0].x / e.data.camera.zoom, polygon.tris[tri].points[0].y / e.data.camera.zoom);161 let point = 0;162 for(point = 0; point < polygon.tris[tri].borders; point++) {163 if(point === 2) {164 e.data.cx.lineTo(polygon.tris[tri].points[0].x / e.data.camera.zoom, polygon.tris[tri].points[0].y / e.data.camera.zoom);165 } else {166 e.data.cx.lineTo(polygon.tris[tri].points[point + 1].x / e.data.camera.zoom, polygon.tris[tri].points[point + 1].y / e.data.camera.zoom);167 }168 if(borderRenderer !== null) {169 e.data.cx.globalAlpha = borderRenderer.alpha;170 e.data.cx.lineWidth = borderRenderer.lw / e.data.camera.zoom;171 e.data.cx.strokeStyle = borderRenderer.color;172 e.data.cx.stroke();173 } else {174 e.data.cx.globalAlpha = 0;175 e.data.cx.lineWidth = 0;176 e.data.cx.stroke();177 }178 }179 e.data.cx.beginPath();180 for(point = 0; point < 3; point++) {181 if(point === 2) {182 e.data.cx.lineTo(polygon.tris[tri].points[0].x / e.data.camera.zoom, polygon.tris[tri].points[0].y / e.data.camera.zoom);183 } else {184 e.data.cx.lineTo(polygon.tris[tri].points[point + 1].x / e.data.camera.zoom, polygon.tris[tri].points[point + 1].y / e.data.camera.zoom);185 }186 e.data.cx.globalAlpha = 0;187 e.data.cx.lineWidth = 0;188 e.data.cx.stroke();189 }190 if(fillRenderer !== null) {191 e.data.cx.globalAlpha = fillRenderer.alpha;192 e.data.cx.fillStyle = fillRenderer.color1;193 e.data.cx.fill();194 }195 }196 e.data.cx.restore();197};198e.methods.calcDistance = (transform1, transform2) => {199 return Math.sqrt(Math.pow(transform1.x - transform2.x, 2) + Math.pow(transform1.y - transform2.y, 2));200},201e.methods.randomNum = (min, max) => {202 return Math.floor((Math.random() * (Math.abs(min - max) + 1)) + min);203},204e.methods.calcAngle = (transform1, transform2) => {205 return Math.round(Math.atan2(transform1.y - transform2.y, transform1.x - transform2.x) * 57.2958) + 180;206},207e.methods.calcRotationalVector = (angle) => {208 return new Transform(Math.cos((angle) / 57.2958), Math.sin((angle) / 57.2958));209},210e.methods.addTransform = (transform1, transform2) => {211 return new Transform(transform1.x + transform2.x, transform1.y + transform2.y, transform1.r + transform2.r);212};213e.methods.detectCollision = (transform1, polygon1, transform2, polygon2) => {214 if(polygon1 === null) {215 let tri = 0;216 for(tri = 0; tri < polygon2.tris.length; tri++) {217 let angleTotal = 0;218 let point = 0;219 for(point = 0; point < 3; point++) {220 if(point < 2) {221 if(Math.abs(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) - e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y))) > 180) {222 if(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) < 180) {223 angleTotal += Math.abs((e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) + 360) - e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y)));224 } else {225 angleTotal += Math.abs(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) - (e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y)) + 360));226 }227 } else {228 angleTotal += Math.abs(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) - e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y)));229 }230 } else {231 if(Math.abs(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) - e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y))) > 180) {232 if(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) < 180) {233 angleTotal += Math.abs((e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) + 360) - e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y)));234 } else {235 angleTotal += Math.abs(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) - (e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y)) + 360));236 }237 } else {238 angleTotal += Math.abs(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) - e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y)));239 }240 }241 }242 if(angleTotal === 360) {243 return true;244 }245 }246 return false;247 } else {248 let testTri = 0;249 for(testTri = 0; testTri < polygon1.tris.length; testTri++) {250 let testPoint = 0;251 for(testPoint = 0; testPoint < polygon1.tris[testTri].points.length; testPoint++) {252 let tri = 0;253 for(tri = 0; tri < polygon2.tris.length; tri++) {254 let angleTotal = 0;255 let point = 0;256 for(point = 0; point < 3; point++) {257 if(point < 2) {258 if(Math.abs(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) - e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y))) > 180) {259 if(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) < 180) {260 angleTotal += Math.abs((e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) + 360) - e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y)));261 } else {262 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) - (e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y)) + 360));263 }264 } else {265 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) - e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y)));266 }267 } else {268 if(Math.abs(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) - e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y))) > 180) {269 if(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) < 180) {270 angleTotal += Math.abs((e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) + 360) - e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y)));271 } else {272 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) - (e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y)) + 360));273 }274 } else {275 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) - e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y)));276 }277 }278 }279 if(angleTotal === 360) {280 return true;281 }282 }283 }284 }285 for(testTri = 0; testTri < polygon2.tris.length; testTri++) {286 let testPoint = 0;287 for(testPoint = 0; testPoint < polygon2.tris[testTri].points.length; testPoint++) {288 let tri = 0;289 for(tri = 0; tri < polygon1.tris.length; tri++) {290 let angleTotal = 0;291 let point = 0;292 for(point = 0; point < 3; point++) {293 if(point < 2) {294 if(Math.abs(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point].x, transform1.y + polygon1.tris[tri].points[point].y)) - e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point + 1].x, transform1.y + polygon1.tris[tri].points[point + 1].y))) > 180) {295 if(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point].x, transform1.y + polygon1.tris[tri].points[point].y)) < 180) {296 angleTotal += Math.abs((e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point].x, transform1.y + polygon1.tris[tri].points[point].y)) + 360) - e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point + 1].x, transform1.y + polygon1.tris[tri].points[point + 1].y)));297 } else {298 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point].x, transform1.y + polygon1.tris[tri].points[point].y)) - (e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point + 1].x, transform1.y + polygon1.tris[tri].points[point + 1].y)) + 360));299 }300 } else {301 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point].x, transform1.y + polygon1.tris[tri].points[point].y)) - e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point + 1].x, transform1.y + polygon1.tris[tri].points[point + 1].y)));302 }303 } else {304 if(Math.abs(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[2].x, transform1.y + polygon1.tris[tri].points[2].y)) - e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[0].x, transform1.y + polygon1.tris[tri].points[0].y))) > 180) {305 if(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[2].x, transform1.y + polygon1.tris[tri].points[2].y)) < 180) {306 angleTotal += Math.abs((e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[2].x, transform1.y + polygon1.tris[tri].points[2].y)) + 360) - e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[0].x, transform1.y + polygon1.tris[tri].points[0].y)));307 } else {308 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[2].x, transform1.y + polygon1.tris[tri].points[2].y)) - (e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[0].x, transform1.y + polygon1.tris[tri].points[0].y)) + 360));309 }310 } else {311 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[2].x, transform1.y + polygon1.tris[tri].points[2].y)) - e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[0].x, transform1.y + polygon1.tris[tri].points[0].y)));312 }313 }314 }315 if(angleTotal === 360) {316 return true;317 }318 }319 }320 }321 return false;322 }323};324e.methods.clearCanvas = (fillRenderer) => {325 e.data.cx.fillStyle = fillRenderer.color1;326 e.data.cx.globalAlpha = 1;327 e.data.cx.fillRect(0, 0, e.data.w, e.data.h);328};329//ADD EVENT LISTENERS330document.addEventListener("keydown", (eObj) => {331 if(!e.data.pressedKeys.includes(eObj.key)) {332 e.data.pressedKeys.push(eObj.key);333 }334});335document.addEventListener("keyup", (eObj) => {336 e.data.pressedKeys.splice(e.data.pressedKeys.indexOf(eObj.key), 1);337});338document.addEventListener("mousemove", (eObj) => {339 e.data.mouse.x = eObj.clientX;340 e.data.mouse.y = eObj.clientY * -1;341});342document.addEventListener("mousedown", () => {343 e.data.mouse.clicking = true;344});345document.addEventListener("mouseup", () => {346 e.data.mouse.clicking = false;347});348//SET FULL CANVAS DIMENSIONS349e.data.element.width = window.innerWidth;350e.data.element.height = window.innerHeight;351//RESCALE CANVAS TO PROPER Y...

Full Screen

Full Screen

transform.js

Source:transform.js Github

copy

Full Screen

1/* */ 2"format cjs";3goog.provide('ol.transform');4goog.require('ol.asserts');5/**6 * Collection of affine 2d transformation functions. The functions work on an7 * array of 6 elements. The element order is compatible with the [SVGMatrix8 * interface](https://developer.mozilla.org/en-US/docs/Web/API/SVGMatrix) and is9 * a subset (elements a to f) of a 3x3 martrix:10 * ```11 * [ a c e ]12 * [ b d f ]13 * [ 0 0 1 ]14 * ```15 */16/**17 * @private18 * @type {ol.Transform}19 */20ol.transform.tmp_ = new Array(6);21/**22 * Create an identity transform.23 * @return {!ol.Transform} Identity transform.24 */25ol.transform.create = function() {26 return [1, 0, 0, 1, 0, 0];27};28/**29 * Resets the given transform to an identity transform.30 * @param {!ol.Transform} transform Transform.31 * @return {!ol.Transform} Transform.32 */33ol.transform.reset = function(transform) {34 return ol.transform.set(transform, 1, 0, 0, 1, 0, 0);35};36/**37 * Multiply the underlying matrices of two transforms and return the result in38 * the first transform.39 * @param {!ol.Transform} transform1 Transform parameters of matrix 1.40 * @param {!ol.Transform} transform2 Transform parameters of matrix 2.41 * @return {!ol.Transform} transform1 multiplied with transform2.42 */43ol.transform.multiply = function(transform1, transform2) {44 var a1 = transform1[0];45 var b1 = transform1[1];46 var c1 = transform1[2];47 var d1 = transform1[3];48 var e1 = transform1[4];49 var f1 = transform1[5];50 var a2 = transform2[0];51 var b2 = transform2[1];52 var c2 = transform2[2];53 var d2 = transform2[3];54 var e2 = transform2[4];55 var f2 = transform2[5];56 transform1[0] = a1 * a2 + c1 * b2;57 transform1[1] = b1 * a2 + d1 * b2;58 transform1[2] = a1 * c2 + c1 * d2;59 transform1[3] = b1 * c2 + d1 * d2;60 transform1[4] = a1 * e2 + c1 * f2 + e1;61 transform1[5] = b1 * e2 + d1 * f2 + f1;62 return transform1;63};64/**65 * Set the transform components a-f on a given transform.66 * @param {!ol.Transform} transform Transform.67 * @param {number} a The a component of the transform.68 * @param {number} b The b component of the transform.69 * @param {number} c The c component of the transform.70 * @param {number} d The d component of the transform.71 * @param {number} e The e component of the transform.72 * @param {number} f The f component of the transform.73 * @return {!ol.Transform} Matrix with transform applied.74 */75ol.transform.set = function(transform, a, b, c, d, e, f) {76 transform[0] = a;77 transform[1] = b;78 transform[2] = c;79 transform[3] = d;80 transform[4] = e;81 transform[5] = f;82 return transform;83};84/**85 * Set transform on one matrix from another matrix.86 * @param {!ol.Transform} transform1 Matrix to set transform to.87 * @param {!ol.Transform} transform2 Matrix to set transform from.88 * @return {!ol.Transform} transform1 with transform from transform2 applied.89 */90ol.transform.setFromArray = function(transform1, transform2) {91 transform1[0] = transform2[0];92 transform1[1] = transform2[1];93 transform1[2] = transform2[2];94 transform1[3] = transform2[3];95 transform1[4] = transform2[4];96 transform1[5] = transform2[5];97 return transform1;98};99/**100 * Transforms the given coordinate with the given transform returning the101 * resulting, transformed coordinate. The coordinate will be modified in-place.102 *103 * @param {ol.Transform} transform The transformation.104 * @param {ol.Coordinate|ol.Pixel} coordinate The coordinate to transform.105 * @return {ol.Coordinate|ol.Pixel} return coordinate so that operations can be106 * chained together.107 */108ol.transform.apply = function(transform, coordinate) {109 var x = coordinate[0], y = coordinate[1];110 coordinate[0] = transform[0] * x + transform[2] * y + transform[4];111 coordinate[1] = transform[1] * x + transform[3] * y + transform[5];112 return coordinate;113};114/**115 * Applies rotation to the given transform.116 * @param {!ol.Transform} transform Transform.117 * @param {number} angle Angle in radians.118 * @return {!ol.Transform} The rotated transform.119 */120ol.transform.rotate = function(transform, angle) {121 var cos = Math.cos(angle);122 var sin = Math.sin(angle);123 return ol.transform.multiply(transform,124 ol.transform.set(ol.transform.tmp_, cos, sin, -sin, cos, 0, 0));125};126/**127 * Applies scale to a given transform.128 * @param {!ol.Transform} transform Transform.129 * @param {number} x Scale factor x.130 * @param {number} y Scale factor y.131 * @return {!ol.Transform} The scaled transform.132 */133ol.transform.scale = function(transform, x, y) {134 return ol.transform.multiply(transform,135 ol.transform.set(ol.transform.tmp_, x, 0, 0, y, 0, 0));136};137/**138 * Applies translation to the given transform.139 * @param {!ol.Transform} transform Transform.140 * @param {number} dx Translation x.141 * @param {number} dy Translation y.142 * @return {!ol.Transform} The translated transform.143 */144ol.transform.translate = function(transform, dx, dy) {145 return ol.transform.multiply(transform,146 ol.transform.set(ol.transform.tmp_, 1, 0, 0, 1, dx, dy));147};148/**149 * Creates a composite transform given an initial translation, scale, rotation, and150 * final translation (in that order only, not commutative).151 * @param {!ol.Transform} transform The transform (will be modified in place).152 * @param {number} dx1 Initial translation x.153 * @param {number} dy1 Initial translation y.154 * @param {number} sx Scale factor x.155 * @param {number} sy Scale factor y.156 * @param {number} angle Rotation (in counter-clockwise radians).157 * @param {number} dx2 Final translation x.158 * @param {number} dy2 Final translation y.159 * @return {!ol.Transform} The composite transform.160 */161ol.transform.compose = function(transform, dx1, dy1, sx, sy, angle, dx2, dy2) {162 var sin = Math.sin(angle);163 var cos = Math.cos(angle);164 transform[0] = sx * cos;165 transform[1] = sy * sin;166 transform[2] = -sx * sin;167 transform[3] = sy * cos;168 transform[4] = dx2 * sx * cos - dy2 * sx * sin + dx1;169 transform[5] = dx2 * sy * sin + dy2 * sy * cos + dy1;170 return transform;171};172/**173 * Invert the given transform.174 * @param {!ol.Transform} transform Transform.175 * @return {!ol.Transform} Inverse of the transform.176 */177ol.transform.invert = function(transform) {178 var det = ol.transform.determinant(transform);179 ol.asserts.assert(det !== 0, 32); // Transformation matrix cannot be inverted180 var a = transform[0];181 var b = transform[1];182 var c = transform[2];183 var d = transform[3];184 var e = transform[4];185 var f = transform[5];186 transform[0] = d / det;187 transform[1] = -b / det;188 transform[2] = -c / det;189 transform[3] = a / det;190 transform[4] = (c * f - d * e) / det;191 transform[5] = -(a * f - b * e) / det;192 return transform;193};194/**195 * Returns the determinant of the given matrix.196 * @param {!ol.Transform} mat Matrix.197 * @return {number} Determinant.198 */199ol.transform.determinant = function(mat) {200 return mat[0] * mat[3] - mat[1] * mat[2];...

Full Screen

Full Screen

classns_transform2_d.js

Source:classns_transform2_d.js Github

copy

Full Screen

1var classns_transform2_d =2[3 [ "nsTransform2D", "d7/d34/classns_transform2_d.html#a6ba264ea5491874440f52868da2abf72", null ],4 [ "nsTransform2D", "d7/d34/classns_transform2_d.html#a04347ceca3c02f5da59497267f4af979", null ],5 [ "~nsTransform2D", "d7/d34/classns_transform2_d.html#ad8c3793f533f1b16aa0afe65d391baa2", null ],6 [ "AddScale", "d7/d34/classns_transform2_d.html#af98cf34c0afbcace8f0ce43b9e210ed6", null ],7 [ "GetTranslationCoord", "d7/d34/classns_transform2_d.html#acc4da255c5b4b40165592db8c0017a42", null ],8 [ "SetScale", "d7/d34/classns_transform2_d.html#a62a41f23981a2597a3ce0f2199633ccd", null ],9 [ "SetToTranslate", "d7/d34/classns_transform2_d.html#ac694c14d936ec4df4f906151862875a0", null ],10 [ "TransformCoord", "d7/d34/classns_transform2_d.html#ac68fccfb155525abec9b3b7d23adcc53", null ],11 [ "TransformCoord", "d7/d34/classns_transform2_d.html#abe59b53960a0ac63970b444b40eb69a6", null ]...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var options = {3};4var page = wptools.page('Albert_Einstein', options);5page.get(function(err, info) {6 if (err) {7 console.log(err);8 } else {9 console.log(info);10 }11});12var wptools = require('wptools');13var options = {14};15var page = wptools.page('Albert_Einstein', options);16page.get(function(err, info) {17 if (err) {18 console.log(err);19 } else {20 console.log(info);21 }22});23var wptools = require('wptools');24var options = {25};26var page = wptools.page('Albert_Einstein', options);27page.get(function(err, info) {28 if (err) {29 console.log(err);30 } else {31 console.log(info);32 }33});34var wptools = require('wptools');35var options = {36};37var page = wptools.page('Albert_Einstein', options);38page.get(function(err, info) {39 if (err) {40 console.log(err);41 } else {42 console.log(info);43 }44});45var page = wptools.page(title, options);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.get(function(err, info) {4 if (err) {5 console.log(err);6 }7 else {8 console.log(info);9 }10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var page = wptools.page('Albert_Einstein');4page.get(function(err, resp) {5 if (err) {6 console.log(err);7 } else {8 console.log(resp);9 var json = JSON.stringify(resp);10 fs.writeFile('test.json', json, 'utf8');11 }12});13{14 "extract": "Albert Einstein (/ˈaɪnstaɪn/; German: [ˈalbɛɐ̯t ˈʔaɪnʃtaɪn] (listen); 14 March 1879 – 18 April 1955) was a German-born theoretical physicist. He developed the general theory of relativity, one of the two pillars of modern physics (alongside quantum mechanics). Einstein's work is also known for its influence on the philosophy of science. Einstein is best known in popular culture for his mass–energy equivalence formula E = mc2 (which has been dubbed \"the world's most famous equation\"). He received the 1921 Nobel Prize in Physics \"for his services to theoretical physics, and especially for his discovery of the law of the photoelectric effect\", a pivotal step in the evolution of quantum theory.",15 "description": "German-born theoretical physicist (1879–1955)",

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.get(function(err, resp) {4 page.transform2(resp, function(err, resp) {5 console.log(resp);6 });7});8var wptools = require('wptools');9var page = wptools.page('Albert Einstein');10page.get(function(err, resp) {11 page.transform2(resp, function(err, resp) {12 console.log(resp);13 });14});15var wptools = require('wptools');16var page = wptools.page('Albert Einstein');17page.get(function(err, resp) {18 page.transform2(resp, function(err, resp) {19 console.log(resp);20 });21});22var wptools = require('wptools');23var page = wptools.page('Albert Einstein');24page.get(function(err, resp) {25 page.transform2(resp, function(err, resp) {26 console.log(resp);27 });28});29var wptools = require('wptools');30var page = wptools.page('Albert Einstein');31page.get(function(err, resp) {32 page.transform2(resp, function(err, resp) {33 console.log(resp);34 });35});36var wptools = require('wptools');37var page = wptools.page('Albert Einstein');38page.get(function(err, resp) {39 page.transform2(resp, function(err, resp) {40 console.log(resp);41 });42});43var wptools = require('wptools');44var page = wptools.page('Albert Einstein');45page.get(function(err, resp) {46 page.transform2(resp, function(err, resp) {47 console.log(resp);48 });49});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var transform2 = wptoolkit.transform2;3var fs = require('fs');4var input = fs.readFileSync('input.xml', 'utf-8');5var xslt = fs.readFileSync('xslt.xsl', 'utf-8');6var output = transform2(input, xslt);7console.log(output);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wpt = wptools('Barack Obama');3wpt.get(function(err, doc) {4 var infobox = doc.infobox;5 var transformed = wpt.transform2(infobox);6 console.log(transformed);7});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful