Best JavaScript code snippet using wpt
CameraControls.js
Source:CameraControls.js
1public var mouseScrolling = true;2public var movespeed = 20.0;3public var zoomspeed = 50.0;4// FIXME : replace with huge galaxy-size trigger to keep EVERYTHING inside5public var viewBounds = 70.0;6public var scrollDeadzone = 0.9;7public var panDeadzone = 0.25;8public var minZoom = 1.0;9public var maxZoom = 50.0;10private var zoomAmt = 10.0;11private var cam : Camera;12private var moveVec : Vector3;13private var zoomVec : Vector3;14private var original_rot : Quaternion;15private var original_zoom : float;16private var delta = 0.017;17private var lastRealtime = 0.0;18function Start()19{20 cam = Camera.main;21 22 original_rot = transform.rotation;23 original_zoom = transform.position.y;24 25 zoomAmt = original_zoom;26 lastRealtime = Time.realtimeSinceStartup;27}28function Update()29{30 // use pause-independent delta31 delta = Time.realtimeSinceStartup - lastRealtime;32 lastRealtime = Time.realtimeSinceStartup;33 34 moveVec = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));35 36 // keyboard controls override mouse edge scolling 37 if(mouseScrolling && !Input.GetMouseButton(0) &&38 moveVec.x == 0 && moveVec.z == 0) {39 moveVec = MouseMotion(scrollDeadzone) * movespeed * delta;40 }41 else if (Input.GetButton("Pan")) {42 moveVec = MouseMotion(panDeadzone) * movespeed * 3.0 * delta;43 }44 else {45 moveVec *= movespeed * delta;46 }47 48 // don't calculate if there's no point49 if(moveVec.sqrMagnitude > 0) {50 moveVec = transform.TransformDirection(moveVec);51 moveVec.y = 0;52 }53 // Zooming code54 // we have to keep track of our own distance from the zoom point (zoomAmt)55 zoomVec = Vector3.zero;56 if( Input.GetAxis("Zoom") != 0.0 )57 {58 //var zoomAmt = 1.0 + (-Input.GetAxis("Zoom") * zoomspeed * Time.deltaTime);59 //distance = Mathf.Max(minZoom, Mathf.Min(maxZoom, distance * zoomAmt));f60 var zoomAdjust = Input.GetAxis("Zoom") * zoomspeed * delta * zoomAmt;61 62 if( (zoomAmt - zoomAdjust > minZoom) &&63 (zoomAmt - zoomAdjust < maxZoom) )64 {65 zoomAmt -= zoomAdjust;66 zoomVec = new Vector3(0,0,zoomAdjust);67 }68 }69 70 // adjust panning speed based on zoom amount71 //zoomVec *= (zoomAmt * 0.1);72 moveVec *= (zoomAmt / 2);73 74 if(transform.position.x < -viewBounds && moveVec.x < 0) moveVec.x = 0;75 else if(transform.position.x > viewBounds && moveVec.x > 0) moveVec.x = 0;76 if(transform.position.z < -viewBounds && moveVec.z < 0) moveVec.z = 0;77 else if(transform.position.z > viewBounds && moveVec.z > 0) moveVec.z = 0;78 79 //if(cam.transform.position.y < -viewBounds && zoomVec.y < 0) zoomVec.y = 0;80 //else if(cam.transform.position.y > viewBounds && zoomVec.y > 0) zoomVec.y = 0;81 82 83 if(Input.GetButton("SpeedUp")) moveVec *= 3;84 85 transform.Translate(moveVec, Space.World);86 87 //iTween.Stop();88 //iTween.MoveTo(gameObject, transform.TransformPoint(zoomVec), 0.2);89 transform.Translate(zoomVec, Space.Self);90 /*91 if(transform.position.y < minZoom) transform.position.y = minZoom;92 else if(transform.position.y > maxZoom) transform.position.y = maxZoom;93 */94}95function MouseMotion(deadzone : float) : Vector3 {96 var moveVec = new Vector3();97 var cursor = new Vector2();98 var realmouse_x = Mathf.Clamp(Input.mousePosition.x, 0, Screen.width);99 var realmouse_y = Mathf.Clamp(Input.mousePosition.y, 0, Screen.height);100 cursor.x = (realmouse_x - Screen.width/2) / (Screen.width/2);101 cursor.y = (realmouse_y - Screen.height/2) / (Screen.height/2);102 var turnx = 0.0;103 var turny = 0.0;104 // clamp the cursor to the deadzone105 if(cursor.x > deadzone) {106 turnx = (cursor.x - deadzone) / (1.0 - deadzone);107 }108 else if (cursor.x < -deadzone) {109 turnx = (cursor.x + deadzone) / (1.0 - deadzone);110 }111 else {112 turnx = 0.0;113 }114 if(cursor.y > deadzone) {115 turny = (cursor.y - deadzone) / (1.0 - deadzone);116 }117 else if (cursor.y < -deadzone) {118 turny = (cursor.y + deadzone) / (1.0 - deadzone);119 }120 else {121 turny = 0.0;122 }123 124 /*125 var turn_direction = Vector3 (-turny, turnx, Input.GetAxis("Roll"));126 //var turn_direction = Vector3 (Input.GetAxis("Vertical"), Input.GetAxis("Vertical"), Input.GetAxis("Roll"));127 puppet.Turn(turn_direction);128 var camera_bounce = 0.02;129 //cam.transform.position.x = -turnx * camera_bounciness;130 cam.transform.localPosition = new Vector3(turnx * camera_bounce, 0.1 + turny * camera_bounce, -0.3);131 */132 133 return new Vector3(turnx, 0, turny);134}135function Reset()136{137 transform.rotation = original_rot;138 transform.position.y = original_zoom;139}140function SetZoom(value : float) {141 zoomAmt = value;142}143function GetZoom() {144 return zoomAmt;...
game.js
Source:game.js
1class Position {23 constructor(x, y) {4 this.x = x;5 this.y = y;6 }78 set(x, y) {9 this.x = x;10 this.y = y;11 }1213 set(pos) {14 this.set(pos.x, pos.y);15 }1617 add(x, y) {18 this.x += x;19 this.y += y;20 }2122 add(pos) {23 this.add(pos.x, pos.y);24 }2526 sub(x, y) {27 this.add(-x, -y);28 }2930 sub(pos) {31 this.sub(pos.x, pos.y);32 }3334 mul(a) {35 this.x *= a;36 this.y *= a;37 }38}3940function key_code(letter) {41 return letter.charCodeAt(0) - 'a'.charCodeAt(0) + key_a;42}4344class Invader {4546 static count_x = 8;47 static count_y = 5;48 static width = 50;49 static height = 40;50 static offset_x = Invader.width + 20;51 static offset_y = Invader.height + 20;52 static colors = ["red", "green", "blue", "purple", "brown"];53 static move_direction = 1;54 static speed = 0.5;5556 static left_border = 50;57 static right_border = canvas.width - Invader.left_border;5859 static check_bounds(invaders) {60 let turn_direction = 0;61 for(let i of invaders) {62 if(i != null) {63 if(i.pos.x < Invader.left_border) {64 turn_direction = 1;65 }66 if(i.pos.x + Invader.width > Invader.right_border) {67 turn_direction = -1;68 }69 }70 }71 if(turn_direction != 0) {72 Invader.move_direction = turn_direction;73 }74 }7576 constructor(x, y, color) {77 this.pos = new Position(x, y);78 this.color = color;79 }8081 draw() {82 context.fillStyle = this.color;83 context.fillRect(this.pos.x, this.pos.y, Invader.width, Invader.height);84 }8586 update() {87 this.pos.x += Invader.move_direction * Invader.speed;88 }89}9091class Player {9293 static width = 70;94 static height = 40; 95 static color = "green";96 static speed = 5;97 static lives = 3;9899 constructor(x, y) {100 this.pos = new Position(x, y);101 this.lives = Player.lives;102 }103104 draw() {105 context.fillStyle = Player.color;106 context.fillRect(this.pos.x, this.pos.y, Player.width, Player.height);107 }108109 update() {110 if(isKeyPressed[key_code('a')] || isKeyPressed[key_left]) {111 this.pos.x -= Player.speed;112 }113 if(isKeyPressed[key_code('d')] || isKeyPressed[key_right]) {114 this.pos.x += Player.speed;115 }116 }117}118119class Bullet {120121 static speed = 10;122 static width = 5;123 static height = 30;124125 constructor(x, y, direction) {126 this.pos = new Position(x,y);127 this.direction = direction;128 }129130 draw() {131 context.fillStyle = 'black'132 context.fillRect(this.pos.x, this.pos.y, Bullet.width, Bullet.height);133 }134135 update() {136 this.pos.y -= this.direction * Bullet.speed;137 }138139 static check_bounds(bullets) {140 for(let i = 0; i < bullets.length; i ++) {141 const b = bullets[i];142 if(b != null && (b.pos.y < -Bullet.height || b.pos.y > canvas.height)) {143 bullets[i] = null;144 }145 }146 }147148 static shoot(x, y, direction, bullets) {149 for(let i = 0; i < bullets.length; i ++) {150 if(bullets[i] == null) {151 bullets[i] = new Bullet(x, y, direction);152 return;153 }154 }155 bullets.push(new Bullet(x, y, direction));156 }157}158159let invaders = [];160for(let y = 0; y < Invader.count_y; y ++) {161 for(let x = 0; x < Invader.count_x; x ++) {162 invaders.push(new Invader(x * Invader.offset_x, y * Invader.offset_y, Invader.colors[y]));163 }164}165166let player = new Player(canvas.width / 2 - Player.width / 2, canvas.height - Player.height);167168let bullets = [];169170function check_collisions() {171 for(let i = 0; i < bullets.length; i ++) {172 let bul = bullets[i];173 if(bul != null) {174 for(let j = 0; j < invaders.length; j ++ ) {175 let inv = invaders[j];176 if(inv != null && areColliding(177 inv.pos.x, inv.pos.y, Invader.width, Invader.height, 178 bul.pos.x, bul.pos.y, Bullet.width, Bullet.height)) {179 bullets[i] = null;180 invaders[j] = null;181 }182 }183 }184 }185}186187188function update() {189 Invader.check_bounds(invaders);190 for(let i of invaders) {191 if(i != null)192 i.update();193 }194195 Bullet.check_bounds(bullets);196 for(let b of bullets) {197 if(b != null)198 b.update();199 }200201 player.update();202203 check_collisions();204}205206function draw() {207 for(const i of invaders) {208 if(i != null)209 i.draw();210 }211212 for(const b of bullets) {213 if(b != null)214 b.draw();215 }216217 player.draw();218}219220function keydown(code) {221 if(code == 32) {222 Bullet.shoot(player.pos.x + Player.width / 2, player.pos.y, 1, bullets);223 }224}
...
WindType.js
Source:WindType.js
1const Orientation = require("./Orientation");2module.exports = {3 NORTH_WIND: {4 name: "NORTH_WIND",5 direction: Orientation.NORTH,6 },7 EAST_WIND: {8 name: "EAST_WIND",9 direction: Orientation.EAST,10 },11 WEST_WIND: {12 name: "WEST_WIND",13 direction: Orientation.WEST,14 },15 SOUTH_WIND: {16 name: "SOUTH_WIND",17 direction: Orientation.SOUTH,18 },19 WHIRLWIND_CLOCKWISE_SE: {20 name: "WHIRLWIND_CLOCKWISE_SE",21 direction: Orientation.WEST,22 turn_direction: Orientation.WEST.right,23 clockwise: true,24 },25 WHIRLWIND_CLOCKWISE_SW: {26 name: "WHIRLWIND_CLOCKWISE_SW",27 direction: Orientation.NORTH,28 turn_direction: Orientation.NORTH.right,29 clockwise: true,30 },31 WHIRLWIND_CLOCKWISE_NW: {32 name: "WHIRLWIND_CLOCKWISE_NW",33 direction: Orientation.EAST,34 turn_direction: Orientation.EAST.right,35 clockwise: true,36 },37 WHIRLWIND_CLOCKWISE_NE: {38 name: "WHIRLWIND_CLOCKWISE_NE",39 direction: Orientation.SOUTH,40 turn_direction: Orientation.SOUTH.right,41 clockwise: true,42 },43 WHIRLWIND_COUNTER_CLOCKWISE_SE: {44 name: "WHIRLWIND_COUNTER_CLOCKWISE_SE",45 direction: Orientation.NORTH,46 turn_direction: Orientation.NORTH.left,47 clockwise: false,48 },49 WHIRLWIND_COUNTER_CLOCKWISE_SW: {50 name: "WHIRLWIND_COUNTER_CLOCKWISE_SW",51 direction: Orientation.EAST,52 turn_direction: Orientation.EAST.left,53 clockwise: false,54 },55 WHIRLWIND_COUNTER_CLOCKWISE_NW: {56 name: "WHIRLWIND_COUNTER_CLOCKWISE_NW",57 direction: Orientation.SOUTH,58 turn_direction: Orientation.SOUTH.left,59 clockwise: false,60 },61 WHIRLWIND_COUNTER_CLOCKWISE_NE: {62 name: "WHIRLWIND_COUNTER_CLOCKWISE_NE",63 direction: Orientation.WEST,64 turn_direction: Orientation.WEST.left,65 clockwise: false,66 },...
Using AI Code Generation
1var wpt = require('./wpt.js');2var wpt1 = new wpt(0,0);3var wpt2 = new wpt(0,1);4var wpt3 = new wpt(1,1);5var wpt4 = new wpt(1,0);6console.log(wpt1.turn_direction(wpt2,wpt3));7console.log(wpt1.turn_direction(wpt2,wpt4));8console.log(wpt1.turn_direction(wpt3,wpt4));9console.log(wpt1.turn_direction(wpt4,wpt3));10console.log(wpt1.turn_direction(wpt4,wpt2));11console.log(wpt1.turn_direction(wpt3,wpt2));
Using AI Code Generation
1var wpt = require('./wpt.js');2var wpt1 = new wpt(1,1);3var wpt2 = new wpt(2,2);4var wpt3 = new wpt(1,2);5var wpt4 = new wpt(2,1);6console.log(wpt1.turn_direction(wpt2));7console.log(wpt1.turn_direction(wpt3));8console.log(wpt1.turn_direction(wpt4));9function wpt(x,y) {10 this.x = x;11 this.y = y;12}13wpt.prototype.turn_direction = function(wpt) {14 var xdiff = wpt.x - this.x;15 var ydiff = wpt.y - this.y;16 if (xdiff == 0 && ydiff == 1) return "N";17 if (xdiff == 1 && ydiff == 0) return "E";18 if (xdiff == 0 && ydiff == -1) return "S";19 if (xdiff == -1 && ydiff == 0) return "W";20 return "undefined";21}22module.exports = wpt;23{24}
Using AI Code Generation
1var wpt = require('./wpt');2var lat1 = 37.7699298;3var lng1 = -122.4469157;4var lat2 = 37.7699298;5var lng2 = -122.4469157;6var lat3 = 37.7683909618189;7var lng3 = -122.510894536972;8var lat4 = 37.7699298;9var lng4 = -122.4469157;10var lat5 = 37.7699298;11var lng5 = -122.4469157;12var lat6 = 37.7683909618189;13var lng6 = -122.510894536972;14var lat7 = 37.7699298;15var lng7 = -122.4469157;16var lat8 = 37.7699298;17var lng8 = -122.4469157;18var lat9 = 37.7683909618189;19var lng9 = -122.510894536972;20var lat10 = 37.7699298;21var lng10 = -122.4469157;22var lat11 = 37.7699298;23var lng11 = -122.4469157;24var lat12 = 37.7683909618189;25var lng12 = -122.510894536972;26var lat13 = 37.7699298;27var lng13 = -122.4469157;28var lat14 = 37.7699298;29var lng14 = -122.4469157;30var lat15 = 37.7683909618189;31var lng15 = -122.510894536972;32var lat16 = 37.7699298;33var lng16 = -122.4469157;34var lat17 = 37.7699298;35var lng17 = -122.4469157;36var lat18 = 37.7683909618189;37var lng18 = -122.510894536972;38var lat19 = 37.7699298;39var lng19 = -122.4469157;40var lat20 = 37.7699298;41var lng20 = -122.4469157;42var lat21 = 37.7683909618189;43var lng21 = -122.510894536972;
Using AI Code Generation
1var wpt = require('./wpt.js');2var turn_direction = wpt.turn_direction;3var p1 = {lat: 0, lon: 0};4var p2 = {lat: 1, lon: 1};5var p3 = {lat: 2, lon: 2};6var direction = turn_direction(p1, p2, p3);7console.log(direction);8var turn_direction = function(p1, p2, p3) {9 var direction = "";10 var p2x = p2.lon;11 var p2y = p2.lat;12 var p1x = p1.lon;13 var p1y = p1.lat;14 var p3x = p3.lon;15 var p3y = p3.lat;16 var val = (p2y - p1y) * (p3x - p2x) - (p2x - p1x) * (p3y - p2y);17 if (val == 0) {18 direction = "colinear";19 } else if (val > 0) {20 direction = "clockwise";21 } else {22 direction = "counterclockwise";23 }24 return direction;25}26module.exports = {27}
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10var wpt = new WebPageTest('www.webpagetest.org');11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('wpt');18var wpt = new WebPageTest('www.webpagetest.org');19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('wpt');26var wpt = new WebPageTest('www.webpagetest.org');27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('wpt');34var wpt = new WebPageTest('www.webpagetest.org');35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42var wpt = new WebPageTest('www.webpagetest.org');43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }
Using AI Code Generation
1var wpt = require('wpt');2var turn = new wpt.turn_direction(2, 2, 2, 2, 2, 2, 2, 2, 2, 2);3console.log(turn);4var wpt = require('wpt');5var turn = new wpt.turn_direction(2, 2, 2, 2, 2, 2, 2, 2, 2, 2);6console.log(turn);7var wpt = require('wpt');8var turn = new wpt.turn_direction(2, 2, 2, 2, 2, 2, 2, 2, 2, 2);9console.log(turn);10var wpt = require('wpt');11var turn = new wpt.turn_direction(2, 2, 2, 2, 2, 2, 2, 2, 2, 2);12console.log(turn);13var wpt = require('wpt');14var turn = new wpt.turn_direction(2, 2, 2, 2, 2, 2, 2, 2, 2, 2);15console.log(turn);16var wpt = require('wpt');17var turn = new wpt.turn_direction(2, 2, 2, 2, 2, 2, 2, 2, 2, 2);18console.log(turn);19var wpt = require('wpt');20var turn = new wpt.turn_direction(2, 2, 2, 2, 2, 2, 2, 2, 2, 2);21console.log(turn);22var wpt = require('wpt');23var turn = new wpt.turn_direction(2, 2, 2, 2, 2, 2, 2, 2, 2, 2);24console.log(turn);
Using AI Code Generation
1var wpt = require('wpt');2var wp = new wpt();3var direction = wp.turn_direction(0,0,0,0,0,0,0,0);4console.log(direction);5var wpt = require('wpt');6var wp = new wpt();7var direction = wp.turn_direction(0,0,0,0,0,0,0,0);8console.log(direction);9var wpt = require('wpt');10var wp = new wpt();11var direction = wp.turn_direction(0,0,0,0,0,0,0,0);12console.log(direction);13var wpt = require('wpt');14var wp = new wpt();15var direction = wp.turn_direction(0,0,0,0,0,0,0,0);16console.log(direction);17var wpt = require('wpt');18var wp = new wpt();19var direction = wp.turn_direction(0,0,0,0,0,0,0,0);20console.log(direction);21var wpt = require('wpt');22var wp = new wpt();23var direction = wp.turn_direction(0,0,0,0,0,0,0,0);24console.log(direction);25var wpt = require('wpt');26var wp = new wpt();27var direction = wp.turn_direction(0,0,0,0,0,0,0,0);28console.log(direction);29var wpt = require('wpt');30var wp = new wpt();31var direction = wp.turn_direction(0,0,0,0,0,0,0,0);32console.log(direction);33var wpt = require('wpt');
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new wpt('API_KEY');3wpt.turn_direction(37.772324,-122.214897, function(err, response){4 if(err) return console.log(err);5 console.log(response);6});7wpt.turn_direction(37.772324,-122.214897, function(err, response){8 if(err) return console.log(err);9 console.log(response);10});
Using AI Code Generation
1var wptools = require('wptools');2wptools.turn_direction(40.728, -73.989, '5th Ave', function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9wptools.turn_direction(40.728, -73.989, '5th Ave', function(err, data) {10 if (err) {11 console.log(err);12 } else {13 console.log(data);14 }15});16wptools.turn_direction(40.728, -73.989, '5th Ave', function(err, data) {17 if (err) {18 console.log(err);19 } else {20 console.log(data);21 }22});23wptools.turn_direction(40.728, -73.989, '5th Ave', function(err, data) {24 if (err) {25 console.log(err);26 } else {27 console.log(data);28 }29});30wptools.turn_direction(40.728, -73.989, '5th Ave', function(err, data) {31 if (err) {32 console.log(err);33 } else {
Using AI Code Generation
1var wpt = require('./wpt.js');2var lat1 = 37.777;3var lon1 = -122.418;4var lat2 = 37.777;5var lon2 = -122.419;6var lat3 = 37.778;7var lon3 = -122.419;8var lat4 = 37.778;9var lon4 = -122.418;10var lat5 = 37.777;11var lon5 = -122.418;12var turn = wpt.turn_direction(lat1, lon1, lat2, lon2, lat3, lon3);13console.log(turn);14turn = wpt.turn_direction(lat2, lon2, lat3, lon3, lat4, lon4);15console.log(turn);16turn = wpt.turn_direction(lat3, lon3, lat4, lon4, lat5, lon5);17console.log(turn);18turn = wpt.turn_direction(lat4, lon4, lat5, lon5, lat1, lon1);19console.log(turn);20turn = wpt.turn_direction(lat5, lon5, lat1, lon1, lat2, lon2);21console.log(turn);22exports.turn_direction = function(lat1, lon1, lat2, lon2, lat3, lon3) {23 var turn = 0;24 var y1 = (lon2 - lon1) * Math.cos((lat2 + lat1) / 2);25 var y2 = (lon3 - lon2) * Math.cos((lat3 + lat2) / 2);26 var x1 = lat2 - lat1;27 var x2 = lat3 - lat2;
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!!