Best JavaScript code snippet using wpt
bubbles.js
Source:bubbles.js
1var BUBBLES_ARRAY = new Array();2var BUBBLES_CANVAS_CONTEXT = null;3var BUBBLES_X_START = 30;4var BUBBLES_X_END = 518;5var BUBBLES_GAP = ((BUBBLES_X_END - BUBBLES_X_START) / 25);6var BUBBLES_Y_START = 26;7var BUBBLES_Y_END = 522;8var BUBBLES_SIZE = 3;9var BUBBLES_COUNTER = 0;10var SUPER_BUBBLES = [];11var SUPER_BUBBLES_SIZE = 8;12var SUPER_BUBBLES_BLINK = false;13var SUPER_BUBBLES_BLINK_STATE = 0;14var SUPER_BUBBLES_BLINK_TIMER = -1;15var SUPER_BUBBLES_BLINK_SPEED = 525;16function initBubbles() { 17 BUBBLES_COUNTER = 0;18 BUBBLES_ARRAY.length = 0;19 var canvas = document.getElementById('canvas-bubbles');20 canvas.setAttribute('width', '550');21 canvas.setAttribute('height', '550');22 if (canvas.getContext) { 23 BUBBLES_CANVAS_CONTEXT = canvas.getContext('2d');24 }25}26function getBubblesCanevasContext() { 27 return BUBBLES_CANVAS_CONTEXT;28}29function drawBubbles() { 30 var ctx = getBubblesCanevasContext();31 ctx.fillStyle = "#dca5be";32 33 for (var line = 1, linemax = 29, i = 0, s = 0; line <= linemax; line ++) { 34 var y = getYFromLine(line);35 for (var x = BUBBLES_X_START, xmax = BUBBLES_X_END, bubble = 1 ; x < xmax; bubble ++, x += BUBBLES_GAP) { 36 if (canAddBubble(line, bubble)) { 37 var type = "";38 var size = "";39 if (isSuperBubble(line, bubble)) { 40 type = "s";41 size = SUPER_BUBBLES_SIZE;42 SUPER_BUBBLES[s] = line + ";" + bubble + ";" + parseInt(correctionX(x, bubble)) + "," + parseInt(y) + ";0";43 s ++;44 } else { 45 type = "b";46 size = BUBBLES_SIZE;47 }48 BUBBLES_COUNTER ++;49 ctx.beginPath();50 ctx.arc(correctionX(x, bubble), y, size, 0, 2 * Math.PI, false);51 ctx.fill();52 ctx.closePath();53 54 BUBBLES_ARRAY.push( parseInt(correctionX(x, bubble)) + "," + parseInt(y) + ";" + line + ";" + bubble + ";" + type + ";0" );55 i ++;56 }57 }58 }59}60function stopBlinkSuperBubbles() { 61 clearInterval(SUPER_BUBBLES_BLINK_TIMER);62 SUPER_BUBBLES_BLINK_TIMER = -1;63 SUPER_BUBBLES_BLINK = false;64}65function blinkSuperBubbles() { 66 if (SUPER_BUBBLES_BLINK === false) { 67 SUPER_BUBBLES_BLINK = true;68 SUPER_BUBBLES_BLINK_TIMER = setInterval('blinkSuperBubbles()', SUPER_BUBBLES_BLINK_SPEED);69 } else { 70 71 if (SUPER_BUBBLES_BLINK_STATE === 0) { 72 SUPER_BUBBLES_BLINK_STATE = 1;73 } else { 74 SUPER_BUBBLES_BLINK_STATE = 0;75 }76 77 var clone = SUPER_BUBBLES.slice(0);78 79 for (var i = 0, imax = clone.length; i < imax; i ++) { 80 81 var s = clone[i];82 83 if ( s.split(";")[3] === "0" ) { 84 85 var sx = parseInt(s.split(";")[2].split(",")[0]);86 var sy = parseInt(s.split(";")[2].split(",")[1]);87 88 if (SUPER_BUBBLES_BLINK_STATE === 1) { 89 eraseBubble("s", sx, sy);90 } else { 91 var ctx = getBubblesCanevasContext();92 ctx.fillStyle = "#dca5be";93 ctx.beginPath();94 ctx.arc(sx, sy, SUPER_BUBBLES_SIZE, 0, 2 * Math.PI, false);95 ctx.fill();96 ctx.closePath();97 }98 }99 }100 }101}102function setSuperBubbleOnXY( x, y, eat ) { 103 for (var i = 0, imax = SUPER_BUBBLES.length; i < imax; i ++) { 104 var bubbleParams = SUPER_BUBBLES[i].split( ";" );105 var testX = parseInt(bubbleParams[2].split( "," )[0]);106 var testY = parseInt(bubbleParams[2].split( "," )[1]);107 if ( testX === x && testY === y ) { 108 SUPER_BUBBLES[i] = SUPER_BUBBLES[i].substr( 0, SUPER_BUBBLES[i].length - 1 ) + "1";109 break;110 }111 }112}113function getBubbleOnXY( x, y ) { 114 var bubble = null;115 for (var i = 0, imax = BUBBLES_ARRAY.length; i < imax; i ++) { 116 var bubbleParams = BUBBLES_ARRAY[i].split( ";" );117 var testX = parseInt(bubbleParams[0].split( "," )[0]);118 var testY = parseInt(bubbleParams[0].split( "," )[1]);119 if ( testX === x && testY === y ) { 120 bubble = BUBBLES_ARRAY[i];121 break;122 }123 }124 return bubble;125}126function eraseBubble(t, x, y) { 127 var ctx = getBubblesCanevasContext();128 var size = "";129 if (t === "s") { 130 size = SUPER_BUBBLES_SIZE;131 } else { 132 size = BUBBLES_SIZE;133 }134 ctx.clearRect(x - size, y - size, (size + 1) * 2, (size + 1) * 2);135}136function isSuperBubble(line, bubble) { 137 if ( (line === 23 || line === 4) && (bubble === 1 || bubble === 26)) { 138 return true;139 }140 141 return false;142}143function canAddBubble(line, bubble) { 144 145 if ( ( ( line >= 1 && line <= 4) || (line >= 9 && line <= 10) || (line >= 20 && line <= 22) || (line >= 26 && line <= 28) ) && (bubble === 13 || bubble === 14)) {146 return false;147 } else if ( ( (line >= 2 && line <= 4) || (line >= 21 && line <= 22) ) && ( (bubble >= 2 && bubble <= 5) || (bubble >= 7 && bubble <= 11) || (bubble >= 16 && bubble <= 20) || (bubble >= 22 && bubble <= 25) ) ) { 148 return false;149 } else if ( ( line >= 6 && line <= 7 ) && ( (bubble >= 2 && bubble <= 5) || (bubble >= 7 && bubble <= 8) || (bubble >= 10 && bubble <= 17) || (bubble >= 19 && bubble <= 20) || (bubble >= 22 && bubble <= 25) ) ) { 150 return false;151 } else if ( ( line === 8 ) && ( (bubble >= 7 && bubble <= 8) || (bubble >= 13 && bubble <= 14) || (bubble >= 19 && bubble <= 20) ) ) { 152 return false;153 } else if ( (( line >= 9 && line <= 19) ) && ( (bubble >= 1 && bubble <= 5) || (bubble >= 22 && bubble <= 26) ) ) { 154 return false;155 } else if ( ( line === 11 || line === 17 ) && ( (bubble >= 7 && bubble <= 20) ) ) { 156 return false;157 } else if ( ( line === 9 || line === 10 ) && ( (bubble === 12 || bubble === 15) ) ) { 158 return false;159 } else if ( ( (line >= 12 && line <= 13) || (line >= 15 && line <= 16) ) && ( (bubble === 9 || bubble === 18) ) ) { 160 return false;161 } else if ( line === 14 && ( (bubble >= 7 && bubble <= 9) || (bubble >= 18 && bubble <= 20) ) ) { 162 return false;163 } else if ( (line === 18 || line === 19) && ( bubble === 9 || bubble === 18) ) { 164 return false;165 } else if ( ( line >= 9 && line <= 10 ) && ( (bubble >= 7 && bubble <= 11) || (bubble >= 16 && bubble <= 20) ) ) { 166 return false;167 } else if ( (( line >= 11 && line <= 13) || (line >= 15 && line <= 19) ) && ( (bubble >= 7 && bubble <= 8) || (bubble >= 19 && bubble <= 20) ) ) { 168 return false;169 } else if ( ( (line >= 12 && line <= 16) || (line >= 18 && line <= 19) ) && ( bubble >= 10 && bubble <= 17) ) { 170 return false;171 } else if ( (line === 23) && ( (bubble >= 4 && bubble <= 5) || (bubble >= 22 && bubble <= 23) ) ) { 172 return false;173 } else if ( (line >= 24 && line <= 25) && ( (bubble >= 1 && bubble <= 2) || (bubble >= 4 && bubble <= 5) || (bubble >= 7 && bubble <= 8) || (bubble >= 10 && bubble <= 17) || (bubble >= 19 && bubble <= 20) || (bubble >= 22 && bubble <= 23) || (bubble >= 25 && bubble <= 26) ) ) { 174 return false;175 } else if ( (line === 26) && ( (bubble >= 7 && bubble <= 8) || (bubble >= 19 && bubble <= 20) ) ) { 176 return false;177 } else if ( (line >= 27 && line <= 28) && ( (bubble >= 2 && bubble <= 11) || (bubble >= 16 && bubble <= 25) ) ) { 178 return false;179 }180 181 return true;182}183function correctionX(x, bubble) { 184 185 if (bubble === 3) { 186 return x + 1;187 } else if (bubble === 6) { 188 return x + 1;189 } else if (bubble === 15) { 190 return x + 1;191 } else if (bubble === 18) { 192 return x + 1;193 } else if (bubble === 21) { 194 return x + 2;195 } else if (bubble === 24) { 196 return x + 2;197 } else if (bubble === 26) { 198 return x + 1;199 }200 return x;201}202function getYFromLine(line) { 203 var y = BUBBLES_Y_START;204 if (line < 8) { 205 y = BUBBLES_Y_START + ( (line - 1) * 18 );206 } else if (line > 7 && line < 15) { 207 y = 150 + ( (line - 8) * 18 );208 } else if (line > 14 && line < 21) { 209 y = 256 + ( (line - 14) * 18 );210 } else if (line > 20 && line < 26) { 211 y = 362 + ( (line - 20) * 18 );212 } else if (line > 25 && line < 29) { 213 y = 452 + ( (line - 25) * 18 );214 } else if (line === 29) { 215 y = BUBBLES_Y_END;216 }217 return y;...
bubble.js
Source:bubble.js
1'use strict';2function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }3var Bubbles = function () {4 function Bubbles(_settings) {5 _classCallCheck(this, Bubbles);6 this.bRuning = false;7 this.canvas = document.getElementById('canvas');8 this.ctx = this.canvas.getContext('2d');9 this.canvas.height = window.innerHeight;10 this.canvas.width = window.innerWidth;11 this.canvasbg = document.getElementById('canvasbg');12 this.ctxbg = this.canvasbg.getContext('2d');13 this.canvasbg.height = window.innerHeight;14 this.canvasbg.width = window.innerWidth;15 this.aBubbles = [];16 this.aBgBubbles = [];17 }18 Bubbles.prototype.addBubble = function addBubble() {19 this.aBubbles.push(new Bubble());20 };21 Bubbles.prototype.addBgBubble = function addBgBubble() {22 this.aBgBubbles.push(new Bubble('rgba(192, 57, 43,0.5)', 3.5)); // Color for the bubbles in the back23 };24 Bubbles.prototype.update = function update() {25 for (var i = this.aBubbles.length - 1; i >= 0; i--) {26 this.aBubbles[i].update();27 if (!this.aBubbles[i].life) this.aBubbles.splice(i, 1);28 }29 for (var i = this.aBgBubbles.length - 1; i >= 0; i--) {30 this.aBgBubbles[i].update();31 if (!this.aBgBubbles[i].life) this.aBgBubbles.splice(i, 1);32 }33 if (this.aBubbles.length < window.innerWidth / 4) this.addBubble();34 if (this.aBgBubbles.length < window.innerWidth / 12) this.addBgBubble();35 };36 Bubbles.prototype.draw = function draw() {37 this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);38 this.ctxbg.clearRect(0, 0, this.canvas.width, this.canvas.height);39 for (var i = this.aBgBubbles.length - 1; i >= 0; i--) {40 this.aBgBubbles[i].draw(this.ctxbg);41 }42 for (var i = this.aBubbles.length - 1; i >= 0; i--) {43 this.aBubbles[i].draw(this.ctx);44 }45 };46 Bubbles.prototype.run = function run() {47 this.update();48 this.draw();49 if (this.bRuning) requestAnimationFrame(this.run.bind(this));50 };51 Bubbles.prototype.start = function start() {52 this.bRuning = true;53 this.run();54 };55 Bubbles.prototype.stop = function stop() {56 this.bRuning = false;57 };58 return Bubbles;59}();60var Bubble = function () {61 function Bubble() {62 var _c = arguments.length <= 0 || arguments[0] === undefined ? 'rgba(241, 196, 15,0.7)' : arguments[0]; // Color for the bubbles on the front63 var _y = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];64 _classCallCheck(this, Bubble);65 this.r = rand(20, 120);66 this.life = true;67 this.x = rand(-this.r, window.innerWidth);68 this.y = rand(window.innerHeight + this.r, window.innerHeight + this.r + 20);69 this.vy = rand(.1, .5) + _y;70 this.vr = 0;71 this.vx = rand(-3, 3);72 this.c = _c;73 }74 Bubble.prototype.update = function update() {75 this.vy += .07;76 this.vr += .012;77 this.y -= this.vy;78 this.x += this.vx;79 if (this.r > 1) this.r -= this.vr;80 if (this.r <= 1) this.life = false;81 };82 Bubble.prototype.draw = function draw(ctx) {83 ctx.beginPath();84 ctx.arc(this.x, this.y, this.r, 0, 2 * Math.PI);85 ctx.fillStyle = this.c;86 ctx.fill();87 };88 return Bubble;89}();90var rand = function rand(min, max) {91 return Math.random() * (max - min) + min;92};93var onresize = function onresize() {94 oBubbles.canvasbg.width = window.innerWidth;oBubbles.canvasbg.height = window.innerHeight;oBubbles.canvas.width = window.innerWidth;oBubbles.canvas.height = window.innerHeight;95};96var oBubbles = undefined;97var init = function init() {98 oBubbles = new Bubbles();99 oBubbles.start();100};101window.onresize = onresize;...
dataReducer.js
Source:dataReducer.js
1import {2 SET_BUBBLES,3 WIPE_BUBBLES,4 LIKE_BUBBLE,5 UNLIKE_BUBBLE,6 LOADING_DATA,7 DELETE_BUBBLE,8 POST_BUBBLE,9 SET_BUBBLE,10 SUBMIT_COMMENT,11} from "../types";12const initialState = {13 bubbles: [],14 bubble: {},15 loading: false,16};17export default function (state = initialState, action) {18 let index;19 switch (action.type) {20 case LOADING_DATA:21 return {22 ...state,23 loading: true,24 };25 case SET_BUBBLE:26 state.bubble = action.payload;27 return state;28 case WIPE_BUBBLES:29 state.bubbles = [];30 return {31 ...state,32 };33 case SET_BUBBLES:34 return {35 ...state,36 bubbles: [...state.bubbles, ...action.payload],37 loading: false,38 };39 case LIKE_BUBBLE:40 case UNLIKE_BUBBLE:41 index = state.bubbles.findIndex(42 (bubble) => bubble.bubbleId === action.payload.bubbleId43 );44 state.bubbles[index] = action.payload;45 if (state.bubble.bubbleId === action.payload.bubbleId) {46 state.bubble = {47 ...state.bubble,48 likeCount: action.payload.likeCount,49 };50 }51 return {52 ...state,53 bubbles: [...state.bubbles],54 bubble: { ...state.bubble },55 };56 case DELETE_BUBBLE:57 index = state.bubbles.findIndex(58 (bubble) => bubble.bubbleId === action.payload59 );60 state.bubbles.splice(index, 1);61 return {62 ...state,63 };64 case POST_BUBBLE:65 return {66 ...state,67 bubbles: [action.payload, ...state.bubbles],68 };69 case SUBMIT_COMMENT:70 // index = state.bubbles.findIndex(71 // (bubble) => bubble.bubbleId === action.payload.bubbleId72 // );73 // state.bubbles[index].commentCount = {74 // ...state.bubbles[index],75 // commentCount: state.bubbles[index].commentCount + 1,76 // };77 return {78 ...state,79 bubbles: [...state.bubbles].map((bubble) => {80 if (bubble.bubbleId === action.payload.bubbleId) {81 return {82 ...bubble,83 commentCount: bubble.commentCount + 1,84 };85 }86 return bubble;87 }),88 bubble: {89 ...state.bubble,90 commentCount: state.bubble.commentCount + 1,91 comments: [action.payload, ...state.bubble.comments],92 },93 };94 default:95 return state;96 }...
Using AI Code Generation
1var page = require('webpage').create();2 console.log("Status: " + status);3 if(status === "success") {4 page.render('google.png');5 }6 phantom.exit();7});8var page = require('webpage').create();9 console.log("Status: " + status);10 if(status === "success") {11 page.render('google.png');12 }13 phantom.exit();14});15var page = require('webpage').create();16 console.log("Status: " + status);17 if(status === "success") {18 page.render('google.png');19 }20 phantom.exit();21});22var page = require('webpage').create();23 console.log("Status: " + status);24 if(status === "success") {25 page.render('google.png');26 }27 phantom.exit();28});29var page = require('webpage').create();30 console.log("Status: " + status);31 if(status === "success") {32 page.render('google.png');33 }34 phantom.exit();35});36var page = require('webpage').create();37 console.log("Status: " + status);38 if(status === "success") {39 page.render('google.png');40 }41 phantom.exit();42});43var page = require('webpage').create();44 console.log("Status: " + status);45 if(status === "success") {46 page.render('google.png');47 }48 phantom.exit();49});
Using AI Code Generation
1var wptools = require('wptools');2wptools.bubbles('Barack Obama', function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wptools = require('wptools');10wptools.get('Barack Obama', function(err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wptools = require('wptools');18wptools.get('Barack Obama', function(err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wptools = require('wptools');26wptools.get('Barack Obama', function(err, data) {27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wptools = require('wptools');34wptools.get('Barack Obama', function(err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wptools = require('wptools');42wptools.get('Barack Obama', function(err, data) {43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var wptools = require('wptools');50wptools.get('Barack Obama', function(err, data) {51 if (err) {52 console.log(err);53 } else {54 console.log(data);55 }56});57var wptools = require('wptools');58wptools.get('Barack Obama', function(err, data) {59 if (err) {
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) throw err;4 console.log(data);5});6{ bubbles: 7 { 0: 8 label: '' },9 label: '' },
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3 if (err) return console.error(err);4 wpt.getBubbles(data.data.runs[1].firstView.bubbles, function(err, data) {5 if (err) return console.error(err);6 console.log(data);7 });8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');11 if (err) return console.error(err);12 wpt.getWaterfall(data.data.runs[1].firstView.images.waterfall, function(err, data) {13 if (err) return console.error(err);14 console.log(data);15 });16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');19 if (err) return console.error(err);20 wpt.getScreenShot(data.data.runs[1].firstView.images.screenShot, function(err, data) {21 if (err) return console.error(err);22 console.log(data);23 });24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');27 if (err) return console.error(err);28 wpt.getHAR(data.data.runs[1].firstView
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!!