How to use animationFrames method in wpt

Best JavaScript code snippet using wpt

MarGame.ts

Source:MarGame.ts Github

copy

Full Screen

1class MarGame {2 isoGroup: Phaser.Group;3 textGroup: Phaser.Group;4 hudGroup: Phaser.Group;5 game: Phaser.Game;6 cursorPos: Phaser.Plugin.Isometric.Point3 = new Phaser.Plugin.Isometric.Point3();7 bootState;8 client: GameClient;9 debugMessages: DebugMessage[] = [];10 world: World;11 animationFrames: any = {};12 tileIndicator: TileIndicator;13 constructor() {14 let self = this;15 this.game = new Phaser.Game(RENDERER_WIDTH, RENDERER_HEIGHT, Phaser.AUTO, 'game', null, true, false);16 this.bootState = {17 preload: function () {18 if (DEBUG) {19 console.log("[MAR] Loading sprites.png as JSONHash");20 }21 this.game.load.atlasJSONHash("sheet", "./images/sprites.png", "./images/sprites.json").onLoadComplete.add(function () {22 self.game.time.advancedTiming = true;23 //Add and enable the isometric plug-in.24 if (DEBUG) {25 console.log("[MAR] Enabling isometric plugin");26 }27 self.game.plugins.add(new Phaser.Plugin.Isometric(self.game));28 //This is used to set a game canvas-based offset for the 0, 0, 0 isometric coordinate - by default29 //this point would be at screen coordinates 0, 0 (top left) which is usually undesirable.30 self.game.iso.anchor.setTo(0.5, 0);31 //Bounds will be overwritten to fit world when changing world32 self.game.world.setBounds(0, 0, 2200, 1100);33 //Make camera more or less centered (tested on 1080 screen)34 self.game.camera.x = 280;35 self.game.camera.y = 90;36 self.game.scale.scaleMode = Phaser.ScaleManager.RESIZE;37 self.game.scale.pageAlignHorizontally = true;38 self.game.scale.pageAlignVertically = true;39 self.game.stage.disableVisibilityChange = true;40 self.client = new GameClient();41 //Grab focus when clicked (For chrome, Opera)42 self.game.input.onDown.add(function () {43 document.getElementById("game").focus();44 if (DEBUG) {45 console.log("Grabbed focus of #game");46 }47 });48 self.isoGroup = mar.game.add.group();49 self.textGroup = mar.game.add.group();50 self.hudGroup = mar.game.add.group();51 self.hudGroup.fixedToCamera = true;52 });53 },54 create: function () {55 if (DEBUG) {56 console.log("[MAR] create");57 }58 self.initialiseAnimations();59 self.initialiseStaticHud();60 },61 update: function () {62 self.game.scale.refresh();63 //Update the cursor position.64 self.game.iso.unproject(self.game.input.activePointer.position, self.cursorPos);65 //Loop through all tiles and test to see if the 3D position from above intersects with the automatically generated IsoSprite tile bounds.66 self.isoGroup.forEach(function (tile: Tile) {67 if (tile instanceof Tile) {68 let inBounds = tile.isoBounds.containsXY(self.cursorPos.x, self.cursorPos.y);69 //If it does, do a little animation and tint change.70 if (!tile.selected && inBounds) {71 tile.selected = true;72 tile.onHover();73 //Dispatch tile over for objects74 self.isoGroup.forEach(function (obj: GameObject) {75 if (obj instanceof GameObject && obj.onTileHover != undefined && obj.isAt(tile.tileX, tile.tileY)) {76 obj.onTileHover();77 }78 }, 1);79 }80 //If not, revert back to how it was.81 else if (tile.selected && !inBounds) {82 tile.selected = false;83 tile.onExit();84 //Dispatch tile exit objects85 self.isoGroup.forEach(function (obj: GameObject) {86 if (obj.onTileExit != undefined && obj.isAt(tile.tileX, tile.tileY)) {87 obj.onTileExit();88 }89 }, 0);90 }91 }92 }, 0);93 //Enable dragging the camera94 if (this.game.input.activePointer.isDown) {95 if (this.game.origDragPoint) {96 // move the camera by the amount the mouse has moved since last update97 this.game.camera.x += this.game.origDragPoint.x - this.game.input.activePointer.position.x;98 this.game.camera.y += this.game.origDragPoint.y - this.game.input.activePointer.position.y;99 }100 // set new drag origin to current position101 this.game.origDragPoint = this.game.input.activePointer.position.clone();102 } else {103 this.game.origDragPoint = null;104 }105 self.game.iso.topologicalSort(self.isoGroup);106 },107 render: function () {108 for (let i = 0; i < self.debugMessages.length; i++) {109 self.game.debug.text(self.debugMessages[i].getMessage(), self.debugMessages[i].x,110 self.debugMessages[i].y)111 }112 }113 };114 this.game.state.add('Boot', this.bootState);115 this.game.state.start('Boot');116 }117 public addDebugMessage(debugMsg: DebugMessage) {118 this.debugMessages.push(debugMsg)119 }120 private initialiseAnimations() {121 //Walk =-------------------------------------------------------122 //East123 this.animationFrames.walk_e_start = [];124 for (let i = 0; i < 10; i++) {125 this.animationFrames.walk_e_start.push("cubot/walk_e/" + ("0000" + i).slice(-4));126 }127 this.animationFrames.walk_e = [];128 for (let i = 10; i < 30; i++) {129 this.animationFrames.walk_e.push("cubot/walk_e/" + ("0000" + i).slice(-4));130 }131 this.animationFrames.harvester_walk_e_start = [];132 for (let i = 0; i < 10; i++) {133 this.animationFrames.harvester_walk_e_start.push("harvester/walk_e/" + ("0000" + i).slice(-4));134 }135 this.animationFrames.harvester_walk_e = [];136 for (let i = 10; i < 30; i++) {137 this.animationFrames.harvester_walk_e.push("harvester/walk_e/" + ("0000" + i).slice(-4));138 }139 //North140 this.animationFrames.walk_n_start = [];141 for (let i = 0; i < 10; i++) {142 this.animationFrames.walk_n_start.push("cubot/walk_n/" + ("0000" + i).slice(-4));143 }144 this.animationFrames.walk_n = [];145 for (let i = 10; i < 30; i++) {146 this.animationFrames.walk_n.push("cubot/walk_n/" + ("0000" + i).slice(-4));147 }148 this.animationFrames.harvester_walk_n_start = [];149 for (let i = 0; i < 10; i++) {150 this.animationFrames.harvester_walk_n_start.push("harvester/walk_n/" + ("0000" + i).slice(-4));151 }152 this.animationFrames.harvester_walk_n = [];153 for (let i = 10; i < 30; i++) {154 this.animationFrames.harvester_walk_n.push("harvester/walk_n/" + ("0000" + i).slice(-4));155 }156 //South157 this.animationFrames.walk_s_start = [];158 for (let i = 0; i < 10; i++) {159 this.animationFrames.walk_s_start.push("cubot/walk_s/" + ("0000" + i).slice(-4));160 }161 this.animationFrames.walk_s = [];162 for (let i = 10; i < 30; i++) {163 this.animationFrames.walk_s.push("cubot/walk_s/" + ("0000" + i).slice(-4));164 }165 this.animationFrames.harvester_walk_s_start = [];166 for (let i = 0; i < 10; i++) {167 this.animationFrames.harvester_walk_s_start.push("harvester/walk_s/" + ("0000" + i).slice(-4));168 }169 this.animationFrames.harvester_walk_s = [];170 for (let i = 10; i < 30; i++) {171 this.animationFrames.harvester_walk_s.push("harvester/walk_s/" + ("0000" + i).slice(-4));172 }173 //West174 this.animationFrames.walk_w_start = [];175 for (let i = 0; i < 10; i++) {176 this.animationFrames.walk_w_start.push("cubot/walk_w/" + ("0000" + i).slice(-4));177 }178 this.animationFrames.walk_w = [];179 for (let i = 10; i < 30; i++) {180 this.animationFrames.walk_w.push("cubot/walk_w/" + ("0000" + i).slice(-4));181 }182 this.animationFrames.harvester_walk_w_start = [];183 for (let i = 0; i < 10; i++) {184 this.animationFrames.harvester_walk_w_start.push("harvester/walk_w/" + ("0000" + i).slice(-4));185 }186 this.animationFrames.harvester_walk_w = [];187 for (let i = 10; i < 30; i++) {188 this.animationFrames.harvester_walk_w.push("harvester/walk_w/" + ("0000" + i).slice(-4));189 }190 //Dig =-------------------------------------------------------191 this.animationFrames.dig_e = [];192 for (let i = 1; i <= 41; i++) {193 this.animationFrames.dig_e.push("cubot/dig_e/" + ("0000" + i).slice(-4));194 }195 this.animationFrames.dig_n = [];196 for (let i = 1; i <= 41; i++) {197 this.animationFrames.dig_n.push("cubot/dig_n/" + ("0000" + i).slice(-4));198 }199 this.animationFrames.dig_s = [];200 for (let i = 1; i <= 41; i++) {201 this.animationFrames.dig_s.push("cubot/dig_s/" + ("0000" + i).slice(-4));202 }203 this.animationFrames.dig_w = [];204 for (let i = 1; i <= 41; i++) {205 this.animationFrames.dig_w.push("cubot/dig_w/" + ("0000" + i).slice(-4));206 }207 //Biomass =-------------------------------------------------------208 this.animationFrames.biomassIdle = [];209 for (let i = 1; i < 60; i++) {210 this.animationFrames.biomassIdle.push("objects/biomass/idle/" + ("0000" + i).slice(-4));211 }212 //Vault screen213 this.animationFrames.vaultDoorScreen = [];214 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/1");215 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/2");216 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/3");217 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/4");218 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/5");219 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/6");220 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/1");221 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/1");222 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/1");223 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/1");224 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/1");225 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/1");226 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/1");227 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/1");228 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/1");229 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/1");230 this.animationFrames.vaultDoorScreen.push("objects/VaultDoorScreen/1");231 }232 private initialiseStaticHud() {233 //todo fix the compass sprite so the Y axis is facing the other way234 //this.game.add.sprite(0, this.game.camera.height - 150, "sheet", "ui/compass", this.hudGroup);235 this.addDebugMessage(new WorldIndicator(10, 20));236 this.tileIndicator = new TileIndicator(10, 40);237 this.addDebugMessage(this.tileIndicator);238 }239}240abstract class DebugMessage {241 public x: number;242 public y: number;243 constructor(x: number, y: number) {244 this.x = x;245 this.y = y;246 }247 abstract getMessage(): string;248}249/**250 * Indicates hovered tile251 */252class TileIndicator extends DebugMessage {253 public tileType: string;254 public tileX: number;255 public tileY: number;256 getMessage(): string {257 if (this.tileType != undefined) {258 return this.tileX + ", " + this.tileY + " : " + this.tileType;259 } else {260 return "";261 }262 }263}264/**265 * Indicates current World266 */267class WorldIndicator extends DebugMessage {268 getMessage(): string {269 if (mar.world != undefined) {270 return "World: " + mar.client.dimension + "(" + Number(mar.client.worldX).toString(16).toUpperCase() + ", " +271 Number(mar.client.worldY).toString(16).toUpperCase() + ")";272 } else {273 return "Loading..."274 }275 }...

Full Screen

Full Screen

sorting-algorithms.js

Source:sorting-algorithms.js Github

copy

Full Screen

1export function mergeSort(barsData) {2 let animationFrames = [];3 let dataLength = barsData.length-1;4 let sorted = [];5 function addFrame({compare = []}) {6 animationFrames.push({7 arr: [...barsData],8 compare,9 sorted: [...sorted]10 });11 }12 function mergeSort(arr, start, end) {13 if (start < end) {14 let mid = parseInt((start + end) / 2);15 mergeSort(arr, start, mid);16 mergeSort(arr, mid + 1, end);17 merge({arr, start, mid, end});18 }19 }20 function merge({arr, start, mid, end}) {21 let arr2 = [...arr];22 let [i, j, k] = [start, mid + 1, start];23 while (i <= mid && j <= end) {24 addFrame({compare: [j,k]});25 if (!start && end === dataLength) sorted.push(k);26 if (arr2[i] <= arr2[j]) {27 arr[k++] = arr2[i++];28 }29 else {30 arr.splice(j, 1);31 arr.splice(k++, 0, arr2[j++]);32 }33 addFrame({compare: [j,k]});34 }35 while (i <= mid) {36 if (!start && end === dataLength) sorted.push(k);37 addFrame({compare: [j,k]});38 arr[k++] = arr2[i++];39 }40 while (j <= end) {41 if (!start && end === dataLength) sorted.push(k);42 addFrame({compare: [j,k]});43 arr.splice(j, 1);44 arr.splice(k++, 0, arr2[j++]);45 }46 }47 addFrame({})48 mergeSort(barsData, 0, dataLength);49 addFrame({})50 return {51 animationFrames,52 renderFrame: (frameIndex, width) => {53 let frame = animationFrames[frameIndex];54 let {compare, sorted} = frame;55 return frame.arr.map((height, index) => `<div class="bar${compare.includes(index) ? ' comparing' : ''}${sorted.includes(index) ? ' sorted' : ''}" style="height: ${height}px; width: ${width}px"></div>`).join("");56 }57 };58}59export function quickSort(barsData) {60 let animationFrames = [];61 let sorted = [];62 function addFrame({compare = [], pivot}) {63 animationFrames.push({64 arr: [...barsData],65 compare,66 pivot,67 sorted: [...sorted]68 })69 }70 function swap(i, j) {71 [barsData[i], barsData[j]] = [barsData[j], barsData[i]];72 }73 function partition(low, high) {74 let pivot = barsData[high]; // 어차피 랜덤이므로 맨 뒤에 있는 친구를 pivot으로 선정!75 let i = low - 1;76 const frame = {pivot: high};77 addFrame(frame);78 let j = low;79 for (; j < high; j++) {80 if (barsData[j] <= pivot) {81 addFrame({ ...frame, compare: [i, j]});82 i++;83 addFrame({ ...frame, compare: [i, j]});84 swap(i, j);85 }86 addFrame({ ...frame, compare: [i, j]});87 }88 addFrame({ ...frame, compare: [i, j]});89 swap(i + 1, high);90 addFrame({pivot: i + 1, compare: [i, j]});91 return i + 1;92 }93 function quickSort(low, high) {94 if (low < high) {95 let pi = partition(low, high);96 sorted.push(pi);97 quickSort(low, pi - 1);98 quickSort(pi + 1, high);99 } 100 else sorted.push(low, high);101 }102 addFrame({});103 quickSort(0, barsData.length - 1);104 addFrame({});105 return {106 animationFrames,107 renderFrame: (frameIndex, width) => {108 let frame = animationFrames[frameIndex];109 let {compare, pivot, sorted} = frame;110 return frame.arr.map((bar, index) => `<div class="bar${compare.includes(index) ? ' comparing' : ''}${sorted.includes(index) ? ' sorted' : ''}${pivot == index ? ' pivot' : ''}" style="height: ${bar}px; width: ${width}px"></div>`).join("");111 }112 };113}114export function insertionSort(barsData) {115 let animationFrames = [];116 let sortedBarsData = [];117 function addFrame({compare = []}) {118 animationFrames.push({119 arr: [...barsData, ...sortedBarsData],120 compare121 });122 }123 function insertionSort(){124 while (barsData.length){125 const temp = barsData[0];126 let comparedTo = 0;127 let flag = true;128 while (comparedTo < sortedBarsData.length){129 addFrame({compare: [0, barsData.length + comparedTo]});130 if (temp <= sortedBarsData[comparedTo]){131 barsData.shift();132 sortedBarsData.splice(comparedTo, 0, temp);133 flag = false;134 break;135 }136 else comparedTo++;137 }138 if (flag) sortedBarsData.push(barsData.shift());139 addFrame({});140 }141 }142 insertionSort();143 return {144 animationFrames,145 renderFrame: (frameIndex, width) => {146 let frame = animationFrames[frameIndex];147 let {compare} = frame;148 return frame.arr.map((height, index) => `<div class="bar${compare.includes(index) ? ' comparing' : ''}${frameIndex == animationFrames.length-1 ? ' sorted' : ''}" style="height: ${height}px; width: ${width}px"></div>`).join("");149 }150 };151}152export function selectionSort(barsData) {153 let animationFrames = [];154 let sortedBarsData = [];155 let sortedInd = barsData.length;156 function addFrame({compare = []}) {157 animationFrames.push({158 arr: [...barsData, ...sortedBarsData],159 compare,160 sortedInd: sortedInd161 });162 }163 function selectionSort(){164 addFrame({});165 while (barsData.length) {166 let minIndex = barsData.reduce((minIndex, cur, ind) => {167 addFrame({compare: [minIndex, ind]});168 return barsData[minIndex] >= cur ? ind : minIndex}, 0);169 sortedBarsData.push(barsData[minIndex]);170 barsData.splice(minIndex, 1);171 sortedInd--;172 addFrame({});173 }174 }175 selectionSort();176 return {177 animationFrames,178 renderFrame: (frameIndex, width) => {179 let frame = animationFrames[frameIndex];180 let {compare, sortedInd} = frame;181 return frame.arr.map((height, index) => `<div class="bar${compare.includes(index) ? ' comparing' : ''}${index >= sortedInd ? ' sorted' : ''}" style="height: ${height}px; width: ${width}px"></div>`).join("");182 }183 };184}185export function bubbleSort(barsData) {186 let animationFrames = [];187 let sortedInd = barsData.length;188 function addFrame({compare = []}) {189 animationFrames.push({190 arr : [...barsData],191 compare,192 sortedInd: sortedInd193 });194 }195 function swap(i, j) {196 [barsData[i], barsData[j]] = [barsData[j], barsData[i]];197 }198 function bubbleSort(){199 addFrame({});200 while (sortedInd){201 for (let i = 0; i < sortedInd-1; i++){202 addFrame({compare: [i, i+1]});203 if (barsData[i] > barsData[i+1]) swap(i, i+1);204 }205 sortedInd--;206 addFrame({});207 }208 }209 bubbleSort();210 211 return {212 animationFrames,213 renderFrame: (frameIndex, width) => {214 let frame = animationFrames[frameIndex];215 let {compare, sortedInd} = frame;216 return frame.arr.map((height, index) => `<div class="bar${compare.includes(index) ? ' comparing' : ''}${index >= sortedInd ? ' sorted' : ''}" style="height: ${height}px; width: ${width}px"></div>`).join("");217 }218 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.animationFrames();3var wptools = require('wptools');4wptools.animationFrames();5var wptools = require('wptools');6wptools.animationFrames();7var wptools = require('wptools');8wptools.animationFrames();9var wptools = require('wptools');10wptools.animationFrames();11var wptools = require('wptools');12wptools.animationFrames();13var wptools = require('wptools');14wptools.animationFrames();15var wptools = require('wptools');16wptools.animationFrames();17var wptools = require('wptools');18wptools.animationFrames();19var wptools = require('wptools');20wptools.animationFrames();21var wptools = require('wptools');22wptools.animationFrames();23var wptools = require('wptools');24wptools.animationFrames();25var wptools = require('wptools');26wptools.animationFrames();

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = async function (context, commands) {2 await commands.measure.start('test');3 await commands.wait.byTime(5000);4 await commands.measure.stop();5 return commands.measure.getResults();6};7module.exports = async function (context, commands) {8 await commands.measure.start('wpt');9 await commands.wait.byTime(5000);10 await commands.measure.stop();11 return commands.measure.getResults();12};13module.exports = async function (context, commands) {14 await commands.measure.start('wpt');15 await commands.wait.byTime(5000);16 await commands.measure.stop();17 return commands.measure.getResults();18};19module.exports = async function (context, commands) {20 await commands.measure.start('wpt');21 await commands.wait.byTime(5000);22 await commands.measure.stop();23 return commands.measure.getResults();24};25module.exports = async function (context, commands) {26 await commands.measure.start('wpt');27 await commands.wait.byTime(5000);28 await commands.measure.stop();29 return commands.measure.getResults();30};31module.exports = async function (context, commands) {32 await commands.measure.start('wpt');33 await commands.wait.byTime(5000);34 await commands.measure.stop();35 return commands.measure.getResults();36};37module.exports = async function (context, commands) {38 await commands.measure.start('wpt');39 await commands.wait.byTime(5000);40 await commands.measure.stop();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var assert = require('assert');4var fs = require('fs');5var util = require('util');6var testId;7var testInfo = {8 videoParams: {9 }10};11wpt.runTest(testInfo, function(err, data) {12 if (err) return console.log(err);13 testId = data.data.testId;14 console.log('Test ID: %s', testId);15 wpt.getTestResults(testId, function(err, data) {16 if (err) return console.log(err);17 console.log('Test Results: %s', util.inspect(data, false, null));18 wpt.getTestVideo(testId, function(err, data) {19 if (err) return console.log(err);20 console.log('Test Video: %s', util.inspect(data, false, null));21 fs.writeFile('test.webm', data, 'binary', function(err) {22 if (err) return console.log(err);23 console.log('Video saved');24 });25 });26 });27});28var wpt = require('webpagetest');29var wpt = new WebPageTest('www.webpagetest.org');30var assert = require('assert');31var fs = require('fs');32var util = require('util');33var testId;34var testInfo = {35 videoParams: {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wptdriver');2wpt.animationFrames(function(frames) {3 console.log(frames);4});5var wpt = require('wptdriver');6wpt.animationFrames(function(frames) {7 var frame = frames[0];8 console.log(frame);9});10var wpt = require('wptdriver');11wpt.animationFrames(function(frames) {12 var frame = frames[0];13 console.log(frame.time);14});15var wpt = require('wptdriver');16wpt.animationFrames(function(frames) {17 var frame = frames[0];18 console.log(frame.duration);19});20var wpt = require('wptdriver');21wpt.animationFrames(function(frames) {22 var frame = frames[0];23 console.log(frame.image);24});25var wpt = require('wptdriver');26wpt.animationFrames(function(frames) {27 var frame = frames[0];28 console.log(frame.image.length);29});30var wpt = require('wptdriver');31wpt.animationFrames(function(frames) {32 console.log(frames.length);33});34var wpt = require('wptdriver');35wpt.animationFrames(function(frames) {36 console.log(frames[0].image.length);37});38var wpt = require('wptdriver');39wpt.animationFrames(function(frames) {40 console.log(frames[1].image.length);41});42var wpt = require('wptdriver');43wpt.animationFrames(function(frames) {44 console.log(frames[2].image.length);45});46var wpt = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1function startAnimation() {2 var animation = new Animation();3 animation.startAnimation();4}5function Animation() {6 var that = this;7 var canvas = document.getElementById("canvas");8 var context = canvas.getContext("2d");9 var width = canvas.width;10 var height = canvas.height;11 var x = 0;12 var y = 0;13 var radius = 10;14 var dx = 2;15 var dy = 4;16 var interval = 1000 / 60;17 this.startAnimation = function () {18 var animate = function () {19 draw();20 update();21 setTimeout(animate, interval);22 };23 animate();24 };25 var draw = function () {26 context.clearRect(0, 0, width, height);27 context.beginPath();28 context.arc(x, y, radius, 0, Math.PI * 2, true);29 context.closePath();30 context.fill();31 };32 var update = function () {33 if (x + dx > width - radius || x + dx < radius) {34 dx = -dx;35 }36 if (y + dy > height - radius || y + dy < radius) {37 dy = -dy;38 }39 x += dx;40 y += dy;41 };42}43function init() {44 startAnimation();45}46window.onload = init;47var animate = function () {48 draw();49 update();50 requestAnimationFrame(animate);51};52requestAnimationFrame(animate);

Full Screen

Using AI Code Generation

copy

Full Screen

1var canvas = document.getElementById('canvas');2var context = canvas.getContext('2d');3var width = canvas.width;4var height = canvas.height;5var ballRadius = 20;6var ballX = width/2;7var ballY = height/2;8var ballSpeedX = 5;9var ballSpeedY = 4;10function drawBall() {11 context.beginPath();12 context.arc(ballX, ballY, ballRadius, 0, Math.PI*2, true);13 context.fillStyle = 'red';14 context.fill();15 context.closePath();16}17function clear() {18 context.clearRect(0, 0, width, height);19}20function draw() {21 clear();22 drawBall();23 ballX += ballSpeedX;24 ballY += ballSpeedY;25 if(ballX + ballSpeedX > width-ballRadius || ballX + ballSpeedX < ballRadius) {26 ballSpeedX = -ballSpeedX;27 }28 if(ballY + ballSpeedY > height-ballRadius || ballY + ballSpeedY < ballRadius) {29 ballSpeedY = -ballSpeedY;30 }31}32setInterval(draw, 1000/30);33var canvas = document.getElementById('canvas');34var context = canvas.getContext('2d');35var width = canvas.width;36var height = canvas.height;37var ballRadius = 20;38var ballX = width/2;39var ballY = height/2;40var ballSpeedX = 5;41var ballSpeedY = 4;42function drawBall() {43 context.beginPath();44 context.arc(ballX, ballY, ballRadius, 0, Math.PI*2, true);45 context.fillStyle = 'red';

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var util = require('util');3var options = {host: 'www.webpagetest.org', key: 'A.5d7c2f5c5c5e5b5d5e5f5e5f5e5f5e5e5'};4var test = new wpt(options);5 if (err) {6 console.log('Error: ', err);7 } else {8 var testId = data.data.testId;9 console.log('Test ID: ', testId);10 test.getTestResults(testId, function(err, data) {11 if (err) {12 console.log('Error: ', err);13 } else {14 console.log('Test results: ', util.inspect(data));15 }16 });17 }18});19var wpt = require('webpagetest');20var util = require('util');21var options = {host: 'www.webpagetest.org', key: 'A.5d7c2f5c5c5e5b5d5e5f5e5f5e5f5e5e5'};22var test = new wpt(options);23 if (err) {24 console.log('Error: ', err);25 } else {26 var testId = data.data.testId;27 console.log('Test ID: ', testId);28 test.getTestResults(testId, function(err, data) {29 if (err) {30 console.log('Error: ', err);31 } else {32 console.log('Test results: ', util.inspect(data));33 }34 });35 }36});37var wpt = require('webpagetest');38var util = require('util');39var options = {host: 'www.webpagetest.org', key: 'A.5d7c2f5c5c5e5b5d5e5f5e5f5e5f5e5e5'};40var test = new wpt(options);

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