How to use blob2 method in wpt

Best JavaScript code snippet using wpt

spring_main.js

Source:spring_main.js Github

copy

Full Screen

1// This is the main JS file.2window.onload = init;3const WIDTH = 964; //Current canvas width4const HEIGHT = 546; //Current canvas height5var frameRate = 1/40; //seconds6var frameDelay = frameRate * 1000; //ms7var loopTimer;8var mouse = {x:0, y:0};9var gravity = 1;10var bounce_factor = 0.8;11var k = -20;12var spring_length = 10;13var b = -0.5;14// A test blob15var center = {16 pos: {x: 450, y: 250},17 velocity: {x: 0, y: 0},18 mass: 1, //kg19 rad: 5 // 1px = 1cm20};21var blob = {22 pos: {x: 450, y: 200},23 velocity: {x: 0, y: 0},24 mass: 1, //kg25 rad: 5 // 1px = 1cm26};27var blob2 = {28 pos: {x: 485, y: 215},29 velocity: {x: 0, y: 0},30 mass: 1, //kg31 rad: 5 // 1px = 1cm32};33var blob3 = {34 pos: {x: 500 , y: 250},35 velocity: {x: 0, y: 0},36 mass: 1, //kg37 rad: 5 // 1px = 1cm38};39var blob4 = {40 pos: {x: 485 , y: 285},41 velocity: {x: 0, y: 0},42 mass: 1, //kg43 rad: 5 // 1px = 1cm44};45var blob5 = {46 pos: {x: 450, y: 300},47 velocity: {x: 0, y: 0},48 mass: 1, //kg49 rad: 5 // 1px = 1cm50};51var blob6 = {52 pos: {x: 415, y: 285},53 velocity: {x: 0, y: 0},54 mass: 1, //kg55 rad: 5 // 1px = 1cm56};57var blob7 = {58 pos: {x: 400, y: 250},59 velocity: {x: 0, y: 0},60 mass: 1, //kg61 rad: 5 // 1px = 1cm62};63var blob8 = {64 pos: {x: 415, y: 215},65 velocity: {x: 0, y: 0},66 mass: 1, //kg67 rad: 5 // 1px = 1cm68};69//var Cd = 0.47; // Dimensionless70//var rho = 1.22; // kg / m^371//var A = Math.PI * blob.rad * blob.rad / (10000); // m^272//var ag = 9.81; // m / s^273var mouse = {x: 0, y: 0, isDown: false};74var getMousePosition = function(e) {75 mouse.x = e.pageX - canvas.offsetLeft;76 if (mouse.isDown)77 {78 block.x = mouse.x;79 }80};81function init(){82 // Initialize WebGL.83 canvas = document.getElementById("gl-canvas");84 ctx = canvas.getContext("2d"); //Rendering in 2D85 canvas.onmousemove = getMousePosition;86 canvas.onmousedown = function(e) {87 if (e.which == 1) {88 getMousePosition(e);89 mouse.isDown = true;90 blob.x = mouse.x;91 }92 };93 canvas.onmouseup = function(e) {94 if (e.which == 1) {95 mouse.isDown = false;96 }97 };98 ctx.fillStyle = 'blue'; //Sets the filled color for the blob99 ctx.strokeStyle = '#000000'; //Sets the outline color for the blob100 loopTimer = setInterval(loop, frameDelay);101}102/*103function getMousePosition(event) {104 mouse.x = event.clientX - canvas.offsetLeft; //Get the x-coordinate of the mouse105 mouse.y = event.clientY - canvas.offsetTop; //Get the y-coordinate of the mouse106 blob.pos.x = mouse.x; //Set mouse.x as the blob's x-coordinate107 blob.pos.y = mouse.y; //Set mouse.y as the blob's y-coordinate108 blob.velocity.x = 0; //Reset the blob's velocity.x109 blob.velocity.y = 0; //Reset the blob's velocity.y110 /*111 else if (mouse.x < blob2.pos.x + 15 && mouse.x < blob2.pos.x - 15112 && mouse.y < blob2.pos.y + 15 && mouse.x < blob2.pos.y - 15) {113 blob2.pos.x = mouse.x; //Set mouse.x as the blob's x-coordinate114 blob2.pos.y = mouse.y; //Set mouse.y as the blob's y-coordinate115 blob2.velocity.x = 0; //Reset the blob's velocity.x116 blob2.velocity.y = 0; //Reset the blob's velocity.y117 }118 //For testing purposes119 var coords = "X coords: " + mouse.x + ", Y coords: " + mouse.y;120 console.log(coords); //Print the coordinates to the console121}122*/123var loop = function() {124 /*125 blob.velocity.y += gravity; //Set the blob's new velocity.y126 blob.pos.x += blob.velocity.x; //Set the blob's new x-coordinate127 blob.pos.y += blob.velocity.y; //Set the blob's new y-coordinate128 blob2.velocity.y += gravity; //Set the blob's new velocity.y129 blob2.pos.x += blob.velocity.x; //Set the blob's new x-coordinate130 blob2.pos.y += blob.velocity.y; //Set the blob's new y-coordinate131 //Example code I found132 /*if ( ! mouse.isDown) {133 // Do physics134 // Drag force: Fd = -1/2 * Cd * A * rho * v * v135 var Fx = -0.5 * Cd * A * rho * ball.velocity.x * ball.velocity.x * ball.velocity.x / Math.abs(ball.velocity.x);136 var Fy = -0.5 * Cd * A * rho * ball.velocity.y * ball.velocity.y * ball.velocity.y / Math.abs(ball.velocity.y);137 Fx = (isNaN(Fx) ? 0 : Fx);138 Fy = (isNaN(Fy) ? 0 : Fy);139 // Calculate acceleration ( F = ma )140 var ax = Fx / ball.mass;141 var ay = ag + (Fy / ball.mass);142 // Integrate to get velocity143 ball.velocity.x += ax*frameRate;144 ball.velocity.y += ay*frameRate;145 // Integrate to get position146 ball.position.x += ball.velocity.x*frameRate*100;147 ball.position.y += ball.velocity.y*frameRate*100;148 }*/149 /*150 // Handle collisions with the perimeter of the canvas151 if (blob.pos.y > HEIGHT - blob.rad || blob.pos.x > WIDTH - blob.rad || blob.pos.x < blob.rad) {152 blob.pos.y = HEIGHT - blob.rad;153 //blob.pos.x = WIDTH/2;154 blob.velocity.x = 0; //Set the blob's velocity x155 blob.velocity.y *= -bounce_factor; //Set the blob's velocity y156 }157 if (blob2.pos.y > HEIGHT - blob2.rad || blob2.pos.x > WIDTH - blob2.rad || blob2.pos.x < blob2.rad) {158 blob2.pos.y = HEIGHT - blob2.rad;159 //blob.pos.x = WIDTH/2;160 blob2.velocity.x = 0; //Set the blob's velocity x161 blob2.velocity.y *= -bounce_factor; //Set the blob's velocity y162 }163 */164 if ( mouse.isDown )165 {166 var F_spring = k * ( (blob.pos.y - center.pos.y) - spring_length );167 var F_damper = b * ( blob.velocity.y - center.velocity.y );168 var a = ( F_spring + F_damper ) / center.mass;169 blob.velocity.y += a * frameRate;170 blob.pos.y += blob.velocity.y * frameRate;171 }172 // Draw the blob173 ctx.clearRect(0,0,WIDTH,HEIGHT);174 ctx.save();175 //ctx.translate(center.pos.x, center.pos.y);176 ctx.beginPath();177 ctx.arc(center.pos.x, center.pos.y, center.rad, 0, Math.PI*2, true); //Create the blob using arcs178 ctx.fill(); //Fill the blob179 ctx.beginPath();180 ctx.arc(blob.pos.x, blob.pos.y, blob.rad, 0, Math.PI*2, true); //Create the blob using arcs181 ctx.fill(); //Fill the blobb182 ctx.beginPath();183 ctx.arc(blob2.pos.x, blob2.pos.y, blob2.rad, 0, Math.PI*2, true); //Create the blob using arcs184 ctx.fill(); //Fill the blob185 ctx.beginPath();186 ctx.arc(blob3.pos.x, blob3.pos.y, blob3.rad, 0, Math.PI*2, true); //Create the blob using arcs187 ctx.fill(); //Fill the blob188 ctx.beginPath();189 ctx.arc(blob4.pos.x, blob4.pos.y, blob4.rad, 0, Math.PI*2, true); //Create the blob using arcs190 ctx.fill(); //Fill the blob191 ctx.beginPath();192 ctx.arc(blob5.pos.x, blob5.pos.y, blob5.rad, 0, Math.PI*2, true); //Create the blob using arcs193 ctx.fill(); //Fill the blob194 ctx.beginPath();195 ctx.arc(blob6.pos.x, blob6.pos.y, blob6.rad, 0, Math.PI*2, true); //Create the blob using arcs196 ctx.fill(); //Fill the blob197 ctx.beginPath();198 ctx.arc(blob7.pos.x, blob7.pos.y, blob7.rad, 0, Math.PI*2, true); //Create the blob using arcs199 ctx.fill(); //Fill the blob200 ctx.beginPath();201 ctx.arc(blob8.pos.x, blob8.pos.y, blob8.rad, 0, Math.PI*2, true); //Create the blob using arcs202 ctx.fill(); //Fill the blob203 ctx.beginPath();204 ctx.moveTo(center.pos.x, center.pos.y);205 ctx.lineTo(blob.pos.x, blob.pos.y);206 ctx.stroke();207 ctx.beginPath();208 ctx.moveTo(center.pos.x, center.pos.y);209 ctx.lineTo(blob2.pos.x, blob2.pos.y);210 ctx.stroke();211 ctx.beginPath();212 ctx.moveTo(center.pos.x, center.pos.y);213 ctx.lineTo(blob3.pos.x, blob3.pos.y);214 ctx.stroke();215 ctx.beginPath();216 ctx.moveTo(center.pos.x, center.pos.y);217 ctx.lineTo(blob4.pos.x, blob4.pos.y);218 ctx.stroke();219 ctx.beginPath();220 ctx.moveTo(center.pos.x, center.pos.y);221 ctx.lineTo(blob5.pos.x, blob5.pos.y);222 ctx.stroke();223 ctx.beginPath();224 ctx.moveTo(center.pos.x, center.pos.y);225 ctx.lineTo(blob6.pos.x, blob6.pos.y);226 ctx.stroke();227 ctx.beginPath();228 ctx.moveTo(center.pos.x, center.pos.y);229 ctx.lineTo(blob7.pos.x, blob7.pos.y);230 ctx.stroke();231 ctx.beginPath();232 ctx.moveTo(center.pos.x, center.pos.y);233 ctx.lineTo(blob8.pos.x, blob8.pos.y);234 ctx.stroke();235 ctx.beginPath();236 ctx.moveTo(blob.pos.x, blob.pos.y);237 ctx.lineTo(blob2.pos.x, blob2.pos.y);238 ctx.stroke();239 ctx.beginPath();240 ctx.moveTo(blob2.pos.x, blob2.pos.y);241 ctx.lineTo(blob3.pos.x, blob3.pos.y);242 ctx.stroke();243 ctx.beginPath();244 ctx.moveTo(blob3.pos.x, blob3.pos.y);245 ctx.lineTo(blob4.pos.x, blob4.pos.y);246 ctx.stroke();247 ctx.beginPath();248 ctx.moveTo(blob4.pos.x, blob4.pos.y);249 ctx.lineTo(blob5.pos.x, blob5.pos.y);250 ctx.stroke();251 ctx.beginPath();252 ctx.moveTo(blob5.pos.x, blob5.pos.y);253 ctx.lineTo(blob6.pos.x, blob6.pos.y);254 ctx.stroke();255 ctx.beginPath();256 ctx.moveTo(blob6.pos.x, blob6.pos.y);257 ctx.lineTo(blob7.pos.x, blob7.pos.y);258 ctx.stroke();259 ctx.beginPath();260 ctx.moveTo(blob7.pos.x, blob7.pos.y);261 ctx.lineTo(blob8.pos.x, blob8.pos.y);262 ctx.stroke();263 ctx.beginPath();264 ctx.moveTo(blob8.pos.x, blob8.pos.y);265 ctx.lineTo(blob.pos.x, blob.pos.y);266 ctx.stroke();267 ctx.closePath();268 ctx.restore();...

Full Screen

Full Screen

bouncing_ball.js

Source:bouncing_ball.js Github

copy

Full Screen

1// This is the main JS file.2window.onload = init;3const WIDTH = 964; //Current canvas width4const HEIGHT = 546; //Current canvas height5var frameRate = 1/40; //seconds6var frameDelay = frameRate * 1000; //ms7var loopTimer;8var mouse = {x:0, y:0};9var gravity = 0.5;10var bounce_factor = 0.8;11var k = -20;12var spring_length = 10;13var b = -0.5;14// A test blob15var center = {16 pos: {x: 450, y: 250},17 velocity: {x: 0, y: 0},18 mass: 0.1, //kg19 rad: 10 // 1px = 1cm20};21var blob = {22 pos: {x: 450, y: 200},23 velocity: {x: 0, y: 0},24 mass: 0.1, //kg25 rad: 10 // 1px = 1cm26};27var blob2 = {28 pos: {x: 485, y: 215},29 velocity: {x: 0, y: 0},30 mass: 0.1, //kg31 rad: 10 // 1px = 1cm32};33var blob3 = {34 pos: {x: 500 , y: 250},35 velocity: {x: 0, y: 0},36 mass: 0.1, //kg37 rad: 10 // 1px = 1cm38};39var blob4 = {40 pos: {x: 485 , y: 285},41 velocity: {x: 0, y: 0},42 mass: 0.1, //kg43 rad: 10 // 1px = 1cm44};45var blob5 = {46 pos: {x: 450, y: 300},47 velocity: {x: 0, y: 0},48 mass: 0.1, //kg49 rad: 10 // 1px = 1cm50};51var blob6 = {52 pos: {x: 415, y: 285},53 velocity: {x: 0, y: 0},54 mass: 0.1, //kg55 rad: 10 // 1px = 1cm56};57var blob7 = {58 pos: {x: 400, y: 250},59 velocity: {x: 0, y: 0},60 mass: 0.1, //kg61 rad: 10 // 1px = 1cm62};63var blob8 = {64 pos: {x: 415, y: 215},65 velocity: {x: 0, y: 0},66 mass: 0.1, //kg67 rad: 10 // 1px = 1cm68};69//var Cd = 0.47; // Dimensionless70//var rho = 1.22; // kg / m^371//var A = Math.PI * blob.rad * blob.rad / (10000); // m^272//var ag = 9.81; // m / s^273var mouse = {x: 0, y: 0, isDown: false};74var getMousePosition = function(e) {75 mouse.x = e.pageX - canvas.offsetLeft;76 if (mouse.isDown)77 {78 block.x = mouse.x;79 }80};81function init(){82 // Initialize WebGL.83 canvas = document.getElementById("gl-canvas");84 ctx = canvas.getContext("2d"); //Rendering in 2D85 canvas.onmousemove = getMousePosition;86 canvas.onmousedown = function(e) {87 if (e.which == 1) {88 getMousePosition(e);89 mouse.isDown = true;90 blob.x = mouse.x;91 }92 };93 canvas.onmouseup = function(e) {94 if (e.which == 1) {95 mouse.isDown = false;96 }97 };98 ctx.fillStyle = 'blue'; //Sets the filled color for the blob99 ctx.strokeStyle = '#000000'; //Sets the outline color for the blob100 loopTimer = setInterval(loop, frameDelay);101}102/*103function getMousePosition(event) {104 mouse.x = event.clientX - canvas.offsetLeft; //Get the x-coordinate of the mouse105 mouse.y = event.clientY - canvas.offsetTop; //Get the y-coordinate of the mouse106 blob.pos.x = mouse.x; //Set mouse.x as the blob's x-coordinate107 blob.pos.y = mouse.y; //Set mouse.y as the blob's y-coordinate108 blob.velocity.x = 0; //Reset the blob's velocity.x109 blob.velocity.y = 0; //Reset the blob's velocity.y110 /*111 else if (mouse.x < blob2.pos.x + 15 && mouse.x < blob2.pos.x - 15112 && mouse.y < blob2.pos.y + 15 && mouse.x < blob2.pos.y - 15) {113 blob2.pos.x = mouse.x; //Set mouse.x as the blob's x-coordinate114 blob2.pos.y = mouse.y; //Set mouse.y as the blob's y-coordinate115 blob2.velocity.x = 0; //Reset the blob's velocity.x116 blob2.velocity.y = 0; //Reset the blob's velocity.y117 }118 //For testing purposes119 var coords = "X coords: " + mouse.x + ", Y coords: " + mouse.y;120 console.log(coords); //Print the coordinates to the console121}122*/123var loop = function() {124 /*125 blob.velocity.y += gravity; //Set the blob's new velocity.y126 blob.pos.x += blob.velocity.x; //Set the blob's new x-coordinate127 blob.pos.y += blob.velocity.y; //Set the blob's new y-coordinate128 blob2.velocity.y += gravity; //Set the blob's new velocity.y129 blob2.pos.x += blob.velocity.x; //Set the blob's new x-coordinate130 blob2.pos.y += blob.velocity.y; //Set the blob's new y-coordinate131 //Example code I found132 /*if ( ! mouse.isDown) {133 // Do physics134 // Drag force: Fd = -1/2 * Cd * A * rho * v * v135 var Fx = -0.5 * Cd * A * rho * ball.velocity.x * ball.velocity.x * ball.velocity.x / Math.abs(ball.velocity.x);136 var Fy = -0.5 * Cd * A * rho * ball.velocity.y * ball.velocity.y * ball.velocity.y / Math.abs(ball.velocity.y);137 Fx = (isNaN(Fx) ? 0 : Fx);138 Fy = (isNaN(Fy) ? 0 : Fy);139 // Calculate acceleration ( F = ma )140 var ax = Fx / ball.mass;141 var ay = ag + (Fy / ball.mass);142 // Integrate to get velocity143 ball.velocity.x += ax*frameRate;144 ball.velocity.y += ay*frameRate;145 // Integrate to get position146 ball.position.x += ball.velocity.x*frameRate*100;147 ball.position.y += ball.velocity.y*frameRate*100;148 }*/149/*150 // Handle collisions with the perimeter of the canvas151 if (blob.pos.y > HEIGHT - blob.rad || blob.pos.x > WIDTH - blob.rad || blob.pos.x < blob.rad) {152 blob.pos.y = HEIGHT - blob.rad;153 //blob.pos.x = WIDTH/2;154 blob.velocity.x = 0; //Set the blob's velocity x155 blob.velocity.y *= -bounce_factor; //Set the blob's velocity y156 }157 if (blob2.pos.y > HEIGHT - blob2.rad || blob2.pos.x > WIDTH - blob2.rad || blob2.pos.x < blob2.rad) {158 blob2.pos.y = HEIGHT - blob2.rad;159 //blob.pos.x = WIDTH/2;160 blob2.velocity.x = 0; //Set the blob's velocity x161 blob2.velocity.y *= -bounce_factor; //Set the blob's velocity y162 }163 */164 if ( ! mouse.isDown )165 {166 var F_spring = k * ( (blob.pos.y - center.pos.y) - spring_length );167 var F_damper = b * ( blob.velocity.y - center.velocity.y );168 var a = ( F_spring + F_damper ) / center.mass;169 blob.velocity.y += a * frameRate;170 blob.pos.y += blob.velocity.y * frameRate;171 }172 // Draw the blob173 ctx.clearRect(0,0,WIDTH,HEIGHT);174 ctx.save();175 //ctx.translate(center.pos.x, center.pos.y);176 ctx.beginPath();177 ctx.arc(center.pos.x, center.pos.y, center.rad, 0, Math.PI*2, true); //Create the blob using arcs178 ctx.fill(); //Fill the blob179 ctx.beginPath();180 ctx.arc(blob.pos.x, blob.pos.y, blob.rad, 0, Math.PI*2, true); //Create the blob using arcs181 ctx.fill(); //Fill the blobb182 ctx.beginPath();183 ctx.arc(blob2.pos.x, blob2.pos.y, blob2.rad, 0, Math.PI*2, true); //Create the blob using arcs184 ctx.fill(); //Fill the blob185 ctx.beginPath();186 ctx.arc(blob3.pos.x, blob3.pos.y, blob3.rad, 0, Math.PI*2, true); //Create the blob using arcs187 ctx.fill(); //Fill the blob188 ctx.beginPath();189 ctx.arc(blob4.pos.x, blob4.pos.y, blob4.rad, 0, Math.PI*2, true); //Create the blob using arcs190 ctx.fill(); //Fill the blob191 ctx.beginPath();192 ctx.arc(blob5.pos.x, blob5.pos.y, blob5.rad, 0, Math.PI*2, true); //Create the blob using arcs193 ctx.fill(); //Fill the blob194 ctx.beginPath();195 ctx.arc(blob6.pos.x, blob6.pos.y, blob6.rad, 0, Math.PI*2, true); //Create the blob using arcs196 ctx.fill(); //Fill the blob197 ctx.beginPath();198 ctx.arc(blob7.pos.x, blob7.pos.y, blob7.rad, 0, Math.PI*2, true); //Create the blob using arcs199 ctx.fill(); //Fill the blob200 ctx.beginPath();201 ctx.arc(blob8.pos.x, blob8.pos.y, blob8.rad, 0, Math.PI*2, true); //Create the blob using arcs202 ctx.fill(); //Fill the blob203 ctx.beginPath();204 ctx.moveTo(center.pos.x, center.pos.y);205 ctx.lineTo(blob.pos.x, blob.pos.y);206 ctx.stroke();207 ctx.beginPath();208 ctx.moveTo(center.pos.x, center.pos.y);209 ctx.lineTo(blob2.pos.x, blob2.pos.y);210 ctx.stroke();211 ctx.beginPath();212 ctx.moveTo(center.pos.x, center.pos.y);213 ctx.lineTo(blob3.pos.x, blob3.pos.y);214 ctx.stroke();215 ctx.beginPath();216 ctx.moveTo(center.pos.x, center.pos.y);217 ctx.lineTo(blob4.pos.x, blob4.pos.y);218 ctx.stroke();219 ctx.beginPath();220 ctx.moveTo(center.pos.x, center.pos.y);221 ctx.lineTo(blob5.pos.x, blob5.pos.y);222 ctx.stroke();223 ctx.beginPath();224 ctx.moveTo(center.pos.x, center.pos.y);225 ctx.lineTo(blob6.pos.x, blob6.pos.y);226 ctx.stroke();227 ctx.beginPath();228 ctx.moveTo(center.pos.x, center.pos.y);229 ctx.lineTo(blob7.pos.x, blob7.pos.y);230 ctx.stroke();231 ctx.beginPath();232 ctx.moveTo(center.pos.x, center.pos.y);233 ctx.lineTo(blob8.pos.x, blob8.pos.y);234 ctx.stroke();235 ctx.beginPath();236 ctx.moveTo(blob.pos.x, blob.pos.y);237 ctx.lineTo(blob2.pos.x, blob2.pos.y);238 ctx.stroke();239 ctx.beginPath();240 ctx.moveTo(blob2.pos.x, blob2.pos.y);241 ctx.lineTo(blob3.pos.x, blob3.pos.y);242 ctx.stroke();243 ctx.beginPath();244 ctx.moveTo(blob3.pos.x, blob3.pos.y);245 ctx.lineTo(blob4.pos.x, blob4.pos.y);246 ctx.stroke();247 ctx.beginPath();248 ctx.moveTo(blob4.pos.x, blob4.pos.y);249 ctx.lineTo(blob5.pos.x, blob5.pos.y);250 ctx.stroke();251 ctx.beginPath();252 ctx.moveTo(blob5.pos.x, blob5.pos.y);253 ctx.lineTo(blob6.pos.x, blob6.pos.y);254 ctx.stroke();255 ctx.beginPath();256 ctx.moveTo(blob6.pos.x, blob6.pos.y);257 ctx.lineTo(blob7.pos.x, blob7.pos.y);258 ctx.stroke();259 ctx.beginPath();260 ctx.moveTo(blob7.pos.x, blob7.pos.y);261 ctx.lineTo(blob8.pos.x, blob8.pos.y);262 ctx.stroke();263 ctx.beginPath();264 ctx.moveTo(blob8.pos.x, blob8.pos.y);265 ctx.lineTo(blob.pos.x, blob.pos.y);266 ctx.stroke();267 ctx.closePath();268 ctx.restore();...

Full Screen

Full Screen

blob2.js

Source:blob2.js Github

copy

Full Screen

1console.assert(nodeBundle);2const web3 = nodeBundle.web3;3const anchor = nodeBundle.anchor;4const Buffer = nodeBundle.buffer.Buffer;5const blob2Idl = await fetch("../target/idl/blob2.json").then(r => r.json());6const blob2PrgramIdDevnet = "J6h7RJ9EwLxvEYLqDDvtF1S8GxijChuy5zRKy1NNpU1P";7export async function create(anchorProvider) {8 const blob2 = new anchor.Program(blob2Idl, blob2PrgramIdDevnet, anchorProvider);9 return blob2;10}11export async function readKeyJson(blob2, payer, base, key) {12 let value = await readKeyString(blob2, payer, base, key);13 if (value != null) {14 return JSON.parse(value);15 } else {16 return null;17 }18}19export async function writeKeyJson(blob2, payer, base, key, value) {20 return writeKeyString(blob2, payer, base, key, JSON.stringify(value));21}22export async function readKeyString(blob2, payer, base, key) {23 let bytes = await readKeyBytes(blob2, payer, base, key);24 if (bytes != null) {25 return anchor.utils.bytes.utf8.decode(bytes);26 } else {27 return null;28 }29}30export async function writeKeyString(blob2, payer, base, key, value) {31 return await writeKeyBytes(blob2, payer, base, key, Buffer.from(value));32}33export async function readKeyBytes(blob2, payer, base, key) {34 let provider = blob2.provider;35 const [ storageReference, storageReferenceBumpSeed ] = await storageReferenceForKey(blob2, base, key);36 let storage = await getStorage(blob2, storageReference);37 return storage;38}39export async function writeKeyBytes(blob2, payer, base, key, value) {40 let provider = blob2.provider;41 const [ storageReference, storageReferenceBumpSeed ] = await storageReferenceForKey(blob2, base, key);42 {43 let storageReferenceAccountInfo = await provider.connection.getAccountInfo(storageReference);44 if (storageReferenceAccountInfo == null) {45 await initStorage(blob2, payer, base, key);46 }47 }48 let storageReferenceValue = await blob2.account.storageReference.fetch(storageReference);49 let storage = storageReferenceValue.storage;50 51 const [ nextStorage, nextStorageBumpSeed ] = await anchor.web3.PublicKey.findProgramAddress(52 [53 "next",54 storage.toBuffer()55 ],56 blob2.programId57 );58 console.assert(typeof value != "string");59 await blob2.rpc.set(value, {60 accounts: {61 payer: payer.publicKey,62 storageReference: storageReference,63 storage: storage,64 nextStorage: nextStorage,65 systemProgram: anchor.web3.SystemProgram.programId66 },67 signers: [68 payer69 ],70 });71}72async function initStorage(blob2, payer, base, key) {73 let provider = blob2.provider;74 const [ storageReference, storageReferenceBumpSeed ] = await storageReferenceForKey(blob2, base, key);75 const [ initialStorage, initialStorageBumpSeed ] = await anchor.web3.PublicKey.findProgramAddress(76 [77 "init",78 storageReference.toBuffer()79 ],80 blob2.programId81 );82 console.log(payer);83 await blob2.rpc.init(Buffer.from(key), storageReferenceBumpSeed, {84 accounts: {85 payer: payer.publicKey,86 storageReference: storageReference,87 initialStorage: initialStorage,88 systemProgram: anchor.web3.SystemProgram.programId89 },90 signers: [91 payer92 ],93 });94}95async function getStorage(blob2, storageReference) {96 let provider = blob2.provider;97 {98 let storageReferenceAccountInfo = await provider.connection.getAccountInfo(storageReference);99 if (storageReferenceAccountInfo == null) {100 return null;101 }102 }103 let storageReferenceValue = await blob2.account.storageReference.fetch(storageReference);104 let storage = storageReferenceValue.storage;105 let storageAccountInfo = await provider.connection.getAccountInfo(storage);106 let storageData = storageAccountInfo.data;107 let header = storageData[0];108 let payload = storageData.slice(1);109 if (header == 0) {110 return null;111 } else {112 return payload;113 }114}115async function storageReferenceForKey(blob2, base, key) {116 const [ storageReference, storageReferenceBumpSeed ] = await anchor.web3.PublicKey.findProgramAddress(117 [118 "key",119 base.publicKey.toBuffer(),120 key,121 ],122 blob2.programId123 );124 return [ storageReference, storageReferenceBumpSeed ];...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6');3var testOptions = {4};5wpt.runTest(testUrl, testOptions, function(err, data) {6 if (err) return console.error(err);7 console.log('Test submitted to WebPageTest! Check back here for results.');8 console.log('Test ID: ' + data.data.testId);9});10var wpt = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org', 'A.1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6');12var testOptions = {13};14wpt.runTest(testUrl, testOptions, function(err, data) {15 if (err) return console.error(err);16 console.log('Test submitted to WebPageTest! Check back here for results.');17 console.log('Test ID: ' + data.data.testId);18});19 at Request._callback (C:\Users\user\AppData\Roaming\npm\node_modules\webpagetest\lib\wpt.js:66:31)20 at self.callback (C:\Users\user\AppData\Roaming\npm\node_modules\webpagetest\node_modules\request\request.js:186:22)21 at emitTwo (events.js:87:13)22 at Request.emit (events.js:172:7)23 at Request.onRequestError (C:\Users\user\AppData

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org');3var options = {4};5api.runTest(url, options, function(err, data) {6 if (err) return console.error(err);7 console.log('Test started: ' + data.data.testId);8 console.log('View your test at: ' + data.data.userUrl);9 api.getTestResults(data.data.testId, function(err, data) {10 if (err) return console.error(err);11 console.log('Test completed');12 console.log(data.data.median.firstView);13 });14});

Full Screen

Using AI Code Generation

copy

Full Screen

1var blob2 = require('blob2');2var blob = new blob2.Blob(['Hello, World!']);3var reader = new blob2.FileReader();4reader.addEventListener('loadend', function() {5 console.log(reader.result);6});7reader.readAsArrayBuffer(blob);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.3b3f7b3e3f3b3c3d3e3c3d3e3c3d3e3c');3 videoParams: {4 },5}, function(err, data) {6 if (err) return console.error(err);7 console.log('Test submitted. Polling results...');8 wpt.getTestResults(data.data.testId, function(err, data) {9 if (err) return console.error(err);10 console.log(data);11 });12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org', 'A.3b3f7b3e3f3b3c3d3e3c3d3e3c3d3e3c');15 videoParams: {16 },17}, function(err, data) {18 if (err) return console.error(err);19 console.log('Test submitted. Polling results...');20 wpt.getTestResults(data.data.testId, 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.3b3f7b3e3f3b3c3d3e3c3d3e3c3d3e3c');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1b6e8e6d9c6d0f6e0d6c8a6a9a9a9a9a');3}, function(err, data) {4 if (err) return console.error(err);5 console.log('Test status:', data.statusText);6 console.log('Test ID:', data.data.testId);7});8var wpt = require('webpagetest');9var wpt = new WebPageTest('www.webpagetest.org', 'A.1b6e8e6d9c6d0f6e0d6c8a6a9a9a9a9a');10}, function(err, data) {11 if (err) return console.error(err);12 console.log('Test status:', data.statusText);13 console.log('Test ID:', data.data.testId);14});15var wpt = require('webpagetest');16var wpt = new WebPageTest('www.webpagetest.org', 'A.1b6e8e6d9c6d0f6e0d6c8a6a9a9a9a9a');17}, function(err, data) {18 if (err) return console.error(err);19 console.log('Test status:', data.statusText);20 console.log('Test ID:', data.data.testId);21});

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