How to use blob1 method in wpt

Best JavaScript code snippet using wpt

core.js

Source:core.js Github

copy

Full Screen

1Number.prototype.mod = function(n) {2 return ((this % n) + n) % n;3};4Array.prototype.peek = function() {5 return this[this.length - 1];6};7var CORE = (function(global, game) {8 var module = {};9 var keys = {10 space: 32,11 q: 81,12 w: 87,13 };14 var splitSize = 60;15 //Given an angle value that was gotten from valueAndleBased(),16 //returns a new value that scales it appropriately.17 // Note: Unused18 module.paraAngleValue = function(angleValue, range) {19 return (15 / (range[1])) * (angleValue * angleValue) - (range[1] / 6);20 };21 // Note: Unused22 module.valueAngleBased = function(angle, range) {23 var leftValue = (angle - range[0]).mod(360);24 var rightValue = (module.rangeToAngle(range) - angle).mod(360);25 var bestValue = Math.min(leftValue, rightValue);26 if (bestValue <= range[1]) {27 return module.paraAngleValue(bestValue, range);28 }29 var banana = -1;30 return banana;31 };32 module.computeDistance = function(x1, y1, x2, y2) {33 var xdis = x1 - x2; // <--- FAKE AmS OF COURSE!34 var ydis = y1 - y2;35 var distance = Math.sqrt(xdis * xdis + ydis * ydis);36 return distance;37 };38 // Note: Unused39 module.computeDistanceFromCircleEdge = function(x1, y1, x2, y2, s2) {40 var tempD = module.computeDistance(x2, y2, x1, y1);41 var offsetX = 0;42 var offsetY = 0;43 var ratioX = tempD / (x2 - x1);44 var ratioY = tempD / (y2 - y1);45 offsetX = x2 - (s2 / ratioX);46 offsetY = y2 - (s2 / ratioY);47 return module.computeDistance(x1, y1, offsetX, offsetY);48 };49 module.filterCells = function(predicate, list) {50 var dotList = [];51 var interNodes = game.getMemoryCells();52 Object.keys(list).forEach(function(element, index) {53 if (predicate(element)) {54 dotList.push(interNodes[element]);55 }56 });57 return dotList;58 };59 module.compareSize = function(player1, player2, ratio) {60 if (player1.size * player1.size * ratio < player2.size * player2.size) {61 return true;62 }63 return false;64 };65 module.canSplit = function(player) {66 return player.size > splitSize;67 };68 module.mightSplit = function(player1, player2) {69 return module.compareSize(player1, player2, 2.30) && !module.compareSize(player1, player2, 9);70 };71 module.splitRatio = function(player) {72 return player.size / splitSize;73 };74 module.getPlayerMass = function(player) {75 var sum = 0;76 for (var k = 0; k < player.length; k++) {77 sum += player[k].size;78 }79 return sum;80 }81 module.processEverything = function(listToUse) {82 Object.keys(listToUse).forEach(function(element, index) {83 module.computeAngleRanges(listToUse[element], game.getPlayer()[0]);84 });85 };86 module.getAll = function() {87 var dotList = [];88 var player = game.getPlayer();89 var interNodes = game.getMemoryCells();90 dotList = module.filterCells(function(element) {91 var isMe = false;92 for (var i = 0; i < player.length; i++) {93 if (interNodes[element].id == player[i].id) {94 isMe = true;95 break;96 }97 }98 for (var i = 0; i < player.length; i++) {99 if (!isMe) {100 return true;101 }102 return false;103 }104 }, interNodes);105 return dotList;106 };107 module.getAllViruses = function(blob) {108 var dotList = [];109 var player = game.getPlayer();110 var interNodes = game.getMemoryCells();111 dotList = module.filterCells(function(element) {112 var isMe = false;113 for (var i = 0; i < player.length; i++) {114 if (interNodes[element].id == player[i].id) {115 isMe = true;116 break;117 }118 }119 if (!isMe && interNodes[element].isVirus() && module.compareSize(interNodes[element], blob, 1.30)) {120 return true;121 }122 return false;123 }, interNodes);124 return dotList;125 };126 module.getTeam = function(red, green, blue) {127 if (red > green && red > blue) {128 return 0;129 } else if (green > red && green > blue) {130 return 1;131 }132 return 2;133 };134 module.isItMe = function(player, cell2) {135 if (getMode() == ":teams") {136 var currentColor = player[0].color;137 var currentRed = parseInt(currentColor.substring(1,3), 16);138 var currentGreen = parseInt(currentColor.substring(3,5), 16);139 var currentBlue = parseInt(currentColor.substring(5,7), 16);140 var currentTeam = game.getTeam(currentRed, currentGreen, currentBlue);141 var cellColor = cell2.color;142 var cellRed = parseInt(cellColor.substring(1,3), 16);143 var cellGreen = parseInt(cellColor.substring(3,5), 16);144 var cellBlue = parseInt(cellColor.substring(5,7), 16);145 var cellTeam = game.getTeam(cellRed, cellGreen, cellBlue);146 if (currentTeam == cellTeam) {147 return true;148 }149 //console.log("COLOR: " + color);150 } else {151 for (var i = 0; i < player.length; i++) {152 if (cell2.id == player[i].id) {153 return true;154 }155 }156 }157 return false;158 };159 module.getAllThreats = function(blob) {160 var dotList = [];161 var player = game.getPlayer();162 var interNodes = game.getMemoryCells();163 dotList = module.filterCells(function(element) {164 var isMe = module.isItMe(player, interNodes[element]);165 if (!isMe && (!interNodes[element].isVirus() && module.compareSize(blob, interNodes[element], 1.30))) {166 return true;167 }168 return false;169 }, interNodes);170 return dotList;171 };172 module.getAllFood = function(blob) {173 var elementList = [];174 var dotList = [];175 var player = game.getPlayer();176 var interNodes = game.getMemoryCells();177 return module.filterCells(function(element) {178 var isMe = module.isItMe(player, interNodes[element]);179 if (isMe) {180 return false;181 }182 if (interNodes[element].isFood()) {183 return true;184 }185 if (interNodes[element].isVirus()) {186 return false;187 }188 if (interNodes[element].isPlayer()) {189 // Ignore players for now190 return false;191 }192 if (module.compareSize(interNodes[element], blob, 1.30)) {193 return true;194 }195 return false;196 }, interNodes);197 };198 module.clusterFood = function(foodList, blobSize) {199 var clusters = [];200 var addedCluster = false;201 //1: x202 //2: y203 //3: size or value204 //4: Angle, not set here.205 for (var i = 0; i < foodList.length; i++) {206 addedCluster = false;207 for (var j = 0; j < clusters.length; j++) {208 if (module.computeDistance(foodList[i].x, foodList[i].y, clusters[j].x, clusters[j].y) < blobSize * 1.5) {209 clusters[j] = clusters[j] || {};210 clusters[j].x = (foodList[i].x + clusters[j].x) / 2;211 clusters[j].y = (foodList[i].y + clusters[j].y) / 2;212 clusters[j].size += foodList[i].size;213 addedCluster = true;214 break;215 }216 }217 if (!addedCluster) {218 clusters.push({219 x: foodList[i].x,220 y: foodList[i].y,221 size: foodList[i].size,222 value: 0223 });224 }225 }226 return clusters;227 };228 module.getAngle = function(x1, y1, x2, y2) {229 //Handle vertical and horizontal lines.230 if (x1 == x2) {231 if (y1 < y2) {232 return 271;233 //return 89;234 } else {235 return 89;236 }237 }238 return (Math.round(Math.atan2(-(y1 - y2), -(x1 - x2)) / Math.PI * 180 + 180));239 };240 module.slope = function(x1, y1, x2, y2) {241 var m = (y1 - y2) / (x1 - x2);242 return m;243 };244 module.slopeFromAngle = function(degree) {245 if (degree === 270) {246 degree = 271;247 } else if (degree === 90) {248 degree = 91;249 }250 return Math.tan((degree - 180) / 180 * Math.PI);251 };252 //Given two points on a line, finds the slope of a perpendicular line crossing it.253 module.inverseSlope = function(x1, y1, x2, y2) {254 var m = module.slope(x1, y1, x2, y2);255 return (-1) / m;256 };257 //Given a slope and an offset, returns two points on that line.258 module.pointsOnLine = function(slope, useX, useY, distance) {259 var b = useY - slope * useX;260 var r = Math.sqrt(1 + slope * slope);261 var newX1 = (useX + (distance / r));262 var newY1 = (useY + ((distance * slope) / r));263 var newX2 = (useX + ((-distance) / r));264 var newY2 = (useY + (((-distance) * slope) / r));265 return [266 [newX1, newY1],267 [newX2, newY2]268 ];269 };270 module.followAngle = function(angle, useX, useY, distance) {271 var slope = module.slopeFromAngle(angle);272 var coords = module.pointsOnLine(slope, useX, useY, distance);273 var side = (angle - 90).mod(360);274 if (side < 180) {275 return coords[1];276 } else {277 return coords[0];278 }279 };280 //Using a line formed from point a to b, tells if point c is on S side of that line.281 module.isSideLine = function(a, b, c) {282 if ((b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]) > 0) {283 return true;284 }285 return false;286 };287 //angle range2 is within angle range2288 //an Angle is a point and a distance between an other point [5, 40]289 module.angleRangeIsWithin = function(range1, range2) {290 if (range2[0] == (range2[0] + range2[1]).mod(360)) {291 return true;292 }293 //console.log("r1: " + range1[0] + ", " + range1[1] + " ... r2: " + range2[0] + ", " + range2[1]);294 var distanceFrom0 = (range1[0] - range2[0]).mod(360);295 var distanceFrom1 = (range1[1] - range2[0]).mod(360);296 if (distanceFrom0 < range2[1] && distanceFrom1 < range2[1] && distanceFrom0 < distanceFrom1) {297 return true;298 }299 return false;300 };301 module.angleRangeIsWithinInverted = function(range1, range2) {302 var distanceFrom0 = (range1[0] - range2[0]).mod(360);303 var distanceFrom1 = (range1[1] - range2[0]).mod(360);304 if (distanceFrom0 < range2[1] && distanceFrom1 < range2[1] && distanceFrom0 > distanceFrom1) {305 return true;306 }307 return false;308 };309 module.angleIsWithin = function(angle, range) {310 var diff = (module.rangeToAngle(range) - angle).mod(360);311 if (diff >= 0 && diff <= range[1]) {312 return true;313 }314 return false;315 };316 module.rangeToAngle = function(range) {317 return (range[0] + range[1]).mod(360);318 };319 module.anglePair = function(range) {320 return (range[0] + ", " + module.rangeToAngle(range) + " range: " + range[1]);321 };322 module.computeAngleRanges = function(blob1, blob2) {323 var mainAngle = module.getAngle(blob1.x, blob1.y, blob2.x, blob2.y);324 var leftAngle = (mainAngle - 90).mod(360);325 var rightAngle = (mainAngle + 90).mod(360);326 var blob1Left = module.followAngle(leftAngle, blob1.x, blob1.y, blob1.size);327 var blob1Right = module.followAngle(rightAngle, blob1.x, blob1.y, blob1.size);328 var blob2Left = module.followAngle(rightAngle, blob2.x, blob2.y, blob2.size);329 var blob2Right = module.followAngle(leftAngle, blob2.x, blob2.y, blob2.size);330 var blob1AngleLeft = module.getAngle(blob2.x, blob2.y, blob1Left[0], blob1Left[1]);331 var blob1AngleRight = module.getAngle(blob2.x, blob2.y, blob1Right[0], blob1Right[1]);332 var blob2AngleLeft = module.getAngle(blob1.x, blob1.y, blob2Left[0], blob2Left[1]);333 var blob2AngleRight = module.getAngle(blob1.x, blob1.y, blob2Right[0], blob2Right[1]);334 var blob1Range = (blob1AngleRight - blob1AngleLeft).mod(360);335 var blob2Range = (blob2AngleRight - blob2AngleLeft).mod(360);336 var tempLine = module.followAngle(blob2AngleLeft, blob2Left[0], blob2Left[1], 400);337 //drawLine(blob2Left[0], blob2Left[1], tempLine[0], tempLine[1], 0);338 if ((blob1Range / blob2Range) > 1) {339 game.drawPoint(blob1Left[0], blob1Left[1], 3, "");340 game.drawPoint(blob1Right[0], blob1Right[1], 3, "");341 game.drawPoint(blob1.x, blob1.y, 3, "" + blob1Range + ", " + blob2Range + " R: " + (Math.round((blob1Range / blob2Range) * 1000) / 1000));342 }343 //drawPoint(blob2.x, blob2.y, 3, "" + blob1Range);344 };345 module.debugAngle = function(angle, text) {346 var player = game.getPlayer();347 var line1 = game.followAngle(angle, player[0].x, player[0].y, 300);348 game.drawLine(player[0].x, player[0].y, line1[0], line1[1], 5);349 game.drawPoint(line1[0], line1[1], 5, "" + text);350 };351 //TODO: Don't let this function do the radius math.352 module.getEdgeLinesFromPoint = function(blob1, blob2, radius) {353 var px = blob1.x;354 var py = blob1.y;355 var cx = blob2.x;356 var cy = blob2.y;357 //var radius = blob2.size;358 /*if (blob2.isVirus()) {359 radius = blob1.size;360 } else if(mightSplit(blob1, blob2)) {361 radius += splitDistance;362 } else {363 radius += blob1.size * 2;364 }*/365 var shouldInvert = false;366 if (module.computeDistance(px, py, cx, cy) <= radius) {367 radius = module.computeDistance(px, py, cx, cy) - 5;368 shouldInvert = true;369 }370 var dx = cx - px;371 var dy = cy - py;372 var dd = Math.sqrt(dx * dx + dy * dy);373 var a = Math.asin(radius / dd);374 var b = Math.atan2(dy, dx);375 var t = b - a376 var ta = {377 x: radius * Math.sin(t),378 y: radius * -Math.cos(t)379 }380 t = b + a381 var tb = {382 x: radius * -Math.sin(t),383 y: radius * Math.cos(t)384 }385 var angleLeft = module.getAngle(cx + ta.x, cy + ta.y, px, py);386 var angleRight = module.getAngle(cx + tb.x, cy + tb.y, px, py);387 var angleDistance = (angleRight - angleLeft).mod(360);388 if (shouldInvert) {389 var temp = angleLeft;390 angleLeft = (angleRight + 180).mod(360);391 angleRight = (temp + 180).mod(360);392 angleDistance = (angleRight - angleLeft).mod(360);393 }394 return [angleLeft, angleDistance, [cx + tb.x, cy + tb.y],395 [cx + ta.x, cy + ta.y]396 ];397 };398 module.invertAngle = function(range) {399 var angle1 = module.rangeToAngle(badAngles[i]);400 var angle2 = (badAngles[i][0] - angle1).mod(360);401 return [angle1, angle2];402 };403 module.addWall = function(listToUse, blob) {404 if (blob.x < global.getMapStartX() + 1000) {405 //LEFT406 //console.log("Left");407 listToUse.push([[135, true], [225, false]]);408 var lineLeft = module.followAngle(135, blob.x, blob.y, 190 + blob.size);409 var lineRight = module.followAngle(225, blob.x, blob.y, 190 + blob.size);410 game.drawLine(blob.x, blob.y, lineLeft[0], lineLeft[1], 5);411 game.drawLine(blob.x, blob.y, lineRight[0], lineRight[1], 5);412 game.drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob.x, blob.y, 5);413 }414 if (blob.y < global.getMapStartY() + 1000) {415 //TOP416 //console.log("TOP");417 listToUse.push([[225, true], [315, false]]);418 var lineLeft = module.followAngle(225, blob.x, blob.y, 190 + blob.size);419 var lineRight = module.followAngle(315, blob.x, blob.y, 190 + blob.size);420 drawLine(blob.x, blob.y, lineLeft[0], lineLeft[1], 5);421 drawLine(blob.x, blob.y, lineRight[0], lineRight[1], 5);422 drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob.x, blob.y, 5);423 }424 if (blob.x > global.getMapEndX() - 1000) {425 //RIGHT426 //console.log("RIGHT");427 listToUse.push([[315, true], [45, false]]);428 var lineLeft = module.followAngle(315, blob.x, blob.y, 190 + blob.size);429 var lineRight = module.followAngle(45, blob.x, blob.y, 190 + blob.size);430 game.drawLine(blob.x, blob.y, lineLeft[0], lineLeft[1], 5);431 game.drawLine(blob.x, blob.y, lineRight[0], lineRight[1], 5);432 game.drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob.x, blob.y, 5);433 }434 if (blob.y > global.getMapEndY() - 1000) {435 //BOTTOM436 //console.log("BOTTOM");437 listToUse.push([[45, true], [135, false]]);438 var lineLeft = module.followAngle(45, blob.x, blob.y, 190 + blob.size);439 var lineRight = module.followAngle(135, blob.x, blob.y, 190 + blob.size);440 game.drawLine(blob.x, blob.y, lineLeft[0], lineLeft[1], 5);441 game.drawLine(blob.x, blob.y, lineRight[0], lineRight[1], 5);442 game.drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob.x, blob.y, 5);443 }444 return listToUse;445 };446 //listToUse contains angles in the form of [angle, boolean].447 //boolean is true when the range is starting. False when it's ending.448 //range = [[angle1, true], [angle2, false]]449 module.getAngleIndex = function(listToUse, angle) {450 if (listToUse.length === 0) {451 return 0;452 }453 for (var i = 0; i < listToUse.length; i++) {454 if (angle <= listToUse[i][0]) {455 return i;456 }457 }458 return listToUse.length;459 };460 module.addAngle = function(listToUse, range) {461 //#1 Find first open element462 //#2 Try to add range1 to the list. If it is within other range, don't add it, set a boolean.463 //#3 Try to add range2 to the list. If it is withing other range, don't add it, set a boolean.464 //TODO: Only add the new range at the end after the right stuff has been removed.465 var startIndex = 1;466 if (listToUse.length > 0 && !listToUse[0][1]) {467 startIndex = 0;468 }469 var startMark = module.getAngleIndex(listToUse, range[0][0]);470 var startBool = startMark.mod(2) != startIndex;471 var endMark = module.getAngleIndex(listToUse, range[1][0]);472 var endBool = endMark.mod(2) != startIndex;473 var removeList = [];474 if (startMark != endMark) {475 //Note: If there is still an error, this would be it.476 var biggerList = 0;477 if (endMark == listToUse.length) {478 biggerList = 1;479 }480 for (var i = startMark; i < startMark + (endMark - startMark).mod(listToUse.length + biggerList); i++) {481 removeList.push((i).mod(listToUse.length));482 }483 } else if (startMark < listToUse.length && endMark < listToUse.length) {484 var startDist = (listToUse[startMark][0] - range[0][0]).mod(360);485 var endDist = (listToUse[endMark][0] - range[1][0]).mod(360);486 if (startDist < endDist) {487 for (var i = 0; i < listToUse.length; i++) {488 removeList.push(i);489 }490 }491 }492 removeList.sort(function(a, b){return b-a});493 for (var i = 0; i < removeList.length; i++) {494 listToUse.splice(removeList[i], 1);495 }496 if (startBool) {497 listToUse.splice(module.getAngleIndex(listToUse, range[0][0]), 0, range[0]);498 }499 if (endBool) {500 listToUse.splice(module.getAngleIndex(listToUse, range[1][0]), 0, range[1]);501 }502 return listToUse;503 };504 module.getAngleRange = function(blob1, blob2, index, radius) {505 var angleStuff = module.getEdgeLinesFromPoint(blob1, blob2, radius);506 var leftAngle = angleStuff[0];507 var rightAngle = module.rangeToAngle(angleStuff);508 var difference = angleStuff[1];509 game.drawPoint(angleStuff[2][0], angleStuff[2][1], 3, "");510 game.drawPoint(angleStuff[3][0], angleStuff[3][1], 3, "");511 //console.log("Adding badAngles: " + leftAngle + ", " + rightAngle + " diff: " + difference);512 var lineLeft = module.followAngle(leftAngle, blob1.x, blob1.y, 150 + blob1.size - index * 10);513 var lineRight = module.followAngle(rightAngle, blob1.x, blob1.y, 150 + blob1.size - index * 10);514 if (blob2.isVirus()) {515 game.drawLine(blob1.x, blob1.y, lineLeft[0], lineLeft[1], 6);516 game.drawLine(blob1.x, blob1.y, lineRight[0], lineRight[1], 6);517 game.drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob1.x, blob1.y, 6);518 } else if(getCells().hasOwnProperty(blob2.id)) {519 game.drawLine(blob1.x, blob1.y, lineLeft[0], lineLeft[1], 0);520 game.drawLine(blob1.x, blob1.y, lineRight[0], lineRight[1], 0);521 game.drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob1.x, blob1.y, 0);522 } else {523 game.drawLine(blob1.x, blob1.y, lineLeft[0], lineLeft[1], 3);524 game.drawLine(blob1.x, blob1.y, lineRight[0], lineRight[1], 3);525 game.drawArc(lineLeft[0], lineLeft[1], lineRight[0], lineRight[1], blob1.x, blob1.y, 3);526 }527 return [leftAngle, difference];528 };529 //Given a list of conditions, shift the angle to the closest available spot respecting the range given.530 module.shiftAngle = function(listToUse, angle, range) {531 //TODO: shiftAngle needs to respect the range! DONE?532 for (var i = 0; i < listToUse.length; i++) {533 if (module.angleIsWithin(angle, listToUse[i])) {534 //console.log("Shifting needed!");535 var angle1 = listToUse[i][0];536 var angle2 = module.rangeToAngle(listToUse[i]);537 var dist1 = (angle - angle1).mod(360);538 var dist2 = (angle2 - angle).mod(360);539 if (dist1 < dist2) {540 if (module.angleIsWithin(angle1, range)) {541 return angle1;542 } else {543 return angle2;544 }545 } else {546 if (module.angleIsWithin(angle2, range)) {547 return angle2;548 } else {549 return angle1;550 }551 }552 }553 }554 //console.log("No Shifting Was needed!");555 return angle;556 };557 module.splitCell = function() {558 module.keyDownAndUp(keys.space);559 };560 module.keyDownAndUp = function(key) {561 module.keyDown(key);562 module.keyUp(key);563 };564 module.keyUp = function(key) {565 jQuery(window).trigger(jQuery.Event('keyup', { keyCode: key, which: key}));566 };567 module.keyDown = function(key) {568 jQuery(window).trigger(jQuery.Event('keydown', { keyCode: key, which: key}));569 };570 return module;571})(window, GAME);...

Full Screen

Full Screen

parallax.js

Source:parallax.js Github

copy

Full Screen

1(function(win, d) {2 var $ = d.querySelector.bind(d);3 var blob0 = $('#blob-0');4 var blob1 = $('#blob-1');5 var blob2 = $('#blob-2');6 var blob3 = $('#blob-3');7 var blob4 = $('#blob-4');8 var blob5 = $('#blob-5');9 var blob6 = $('#blob-6');10 var blob7 = $('#blob-7');11 var blob8 = $('#blob-8');12 var blob9 = $('#blob-9');13 var bloba = $('#blob-a');14 var blobcontainer = $('#blob-container');15 var mainBG = $('section#content');16 function onResize () {17 updateElements(win.scrollY);18 }19 function onScroll (evt) {20 updateElements(win.scrollY);21 }22 function updateElements (yPos) {23 // blob0.style.visibility="hidden";24 // blob1.style.visibility="hidden";25 // blob2.style.visibility="hidden";26 // blob3.style.visibility="hidden";27 // blob4.style.visibility="hidden";28 // blob5.style.visibility="hidden";29 // blob6.style.visibility="hidden";30 // blob7.style.visibility="hidden";31 // blob8.style.visibility="hidden";32 // blob9.style.visibility="hidden";33 34 if(yPos < blob0.style.bottom) {35 blob0.style.visibility="visible";36 blob1.style.visibility="hidden";37 blob2.style.visibility="hidden";38 blob3.style.visibility="hidden";39 blob4.style.visibility="hidden";40 blob5.style.visibility="hidden";41 blob6.style.visibility="hidden";42 blob7.style.visibility="hidden";43 blob8.style.visibility="hidden";44 blob9.style.visibility="hidden";45 bloba.style.visibility="hidden";46 }else if (yPos < blob1.style.bottom) {47 //blob1.style.top = pos(yOffset, -blob1.style.height, relativeY, 0) + 'px';48 blob0.style.visibility="hidden";49 blob1.style.visibility="visible";50 blob2.style.visibility="hidden";51 blob3.style.visibility="hidden";52 blob4.style.visibility="hidden";53 blob5.style.visibility="hidden";54 blob6.style.visibility="hidden";55 blob7.style.visibility="hidden";56 blob8.style.visibility="hidden";57 blob9.style.visibility="hidden";58 bloba.style.visibility="hidden";59 }else {60 //blob0.style.visibility="hidden";61 // blob1.style.visibility="hidden";62 // blob2.style.visibility="hidden";63 // blob3.style.visibility="hidden";64 // blob4.style.visibility="hidden";65 // blob5.style.visibility="hidden";66 // blob6.style.visibility="hidden";67 // blob7.style.visibility="hidden";68 // blob8.style.visibility="hidden";69 // blob9.style.visibility="hidden";70 // bloba.style.visibility="visible";71 }72 73 var relativeY = yPos / 3000;74 // var yOffset = blob0.style.height;75 blob0.style.top = '0px';76 77 blobcontainer.style.top = '0px';78 79 blob2.style.display="none";80 // blob1.style.top = blob0.style.height;81 // blob2.style.top = blob0.style.height + blob1.style.height;82 blob3.style.top = yPos + 'px';83 // blob4.style.top = blob3.style.bottom;84 // blob5.style.top = blob4.style.bottom;85 // blob6.style.top = blob5.style.bottom;86 // blob7.style.top = blob6.style.bottom;87 // blob8.style.top = blob7.style.bottom;88 // blob9.style.top = blob8.style.bottom;89 // bloba.style.top = blob9.style.bottom;90 91 blob1.style.top = '900px';92 // blob2.style.top = '1800px';93 // blob3.style.top = '2700px';94 // blob4.style.top = '3600px';95 // blob5.style.top = '4500px';96 // blob6.style.top = '5400px';97 // blob7.style.top = '6300px';98 // blob8.style.top = '7200px';99 // blob9.style.top = '8100px';100 bloba.style.top = '9000px';101 102 //mainBG.style.backgroundPosition = 'center ' + pos(0, -600, relativeY, 0) + 'px';103 // blob1.style.top = pos(yOffset, -blob1.style.height, relativeY, 0) + 'px';104 // yOffset += blob1.style.height;105 // blob2.style.top = pos(yOffset, -blob2.style.height, relativeY, 0) + 'px';106 // yOffset += blob2.style.height;107 // blob3.style.top = pos(yOffset, -900, relativeY, 0) + 'px';108 // yOffset += blob3.style.height;109 // blob4.style.top = pos(yOffset, -3900, relativeY, 0) + 'px';110 // yOffset += blob4.style.height;111 // blob5.style.top = pos(yOffset, -2900, relativeY, 0) + 'px';112 // //blob5.style.left = -40 + 'px';113 // blob6.style.top = pos(yOffset, -4900, relativeY, 0) + 'px';114 // //blob6.style.left = 325 + 'px';115 // blob7.style.top = pos(yOffset, -1900, relativeY, 0) + 'px';116 // //blob7.style.left = 725 + 'px';117 // blob8.style.top = pos(yOffset, -700, relativeY, 0) + 'px';118 // //blob8.style.left = 570 + 'px';119 // blob9.style.top = pos(yOffset, -6000, relativeY, 0) + 'px';120 // //blob9.style.left = 640 + 'px';121 // bloba.style.top = blob0.style.height + 'px'122 }123 function pos(base, range, relY, offset) {124 return base + limit(0, 1, relY - offset) * range;125 }126 function prefix(obj, prop, value) {127 var prefs = ['webkit', 'moz', 'o', 'ms'];128 for (var pref in prefs) {129 obj[prefs[pref] + prop] = value;130 }131 }132 function limit(min, max, value) {133 return Math.max(min, Math.min(max, value));134 }135 (function() {136 updateElements(win.scrollY);137 // blob1.classList.add('force-show');138 // blob2.classList.add('force-show');139 // blob3.classList.add('force-show');140 // blob4.classList.add('force-show');141 // blob5.classList.add('force-show');142 // blob6.classList.add('force-show');143 // blob7.classList.add('force-show');144 // blob8.classList.add('force-show');145 // blob9.classList.add('force-show');146 // bloba.classList.add('force-show');147 })();148 win.addEventListener('resize', onResize, false);149 win.addEventListener('scroll', onScroll, false);150 win.addEventListener('wheel', onScroll, false);...

Full Screen

Full Screen

blob.js

Source:blob.js Github

copy

Full Screen

1//A class for all circles2function Blob(position, size, velocity) {3 this.position = position;4 this.size = size;5 this.mass = size*size; //Mass is proportional to area. Size is radius6 this.velocity = velocity;7}8//A class for the Player. Inherits from Blob.9function Player(position, size, velocity) {10 Blob.call(this, position, size, velocity);11 this.accelerationMagnitude = 0.2;12}13//A class for repulsor objects. Inherits from Blob.14function Repulsor(position, size, velocity) {15 Blob.call(this, position, size, velocity);16}17//A function to check if two blobs are within eating distance18//If they are, eating occurs. Big blob eats small blob.19//The common area between the two blobs is removed from the smaller blob and20//added to the bigger blob. Momentum is conserved.21Blob.eatCheck = function (blob1, blob2) {22 if (checkOverlap(blob1, blob2)) {23 var blob1MomentumOld = Vector.mult(blob1.velocity, blob1.mass);24 var blob2MomentumOld = Vector.mult(blob2.velocity, blob2.mass);25 var d = Vector.dist(blob1.position, blob2.position);26 if (blob2.size > blob1.size) {27 var massDiff = calcMassDiff(blob1.size, blob2.size, d);28 if (blob1.mass <= 13 || massDiff == blob1.size * blob1.size) {29 blob2.velocity = Vector.add(30 blob1MomentumOld,31 blob2MomentumOld32 ).mult(1 / (blob1.mass + blob2.mass));33 blob2.mass += blob1.mass;34 blob2.size = Math.sqrt(blob2.mass);35 blob1.mass = 0;36 blob1.size = 0;37 }38 else {39 blob2.mass += (massDiff);40 blob2.size = Math.sqrt(blob2.mass);41 blob1.mass -= (massDiff);42 blob1.size = Math.sqrt(blob1.mass);43 blob2.velocity = blob2MomentumOld.mult(1 / blob2.mass);44 blob1.velocity = blob1MomentumOld.mult(1 / blob1.mass);45 }46 }47 else {48 var massDiff = calcMassDiff(blob2.size, blob1.size, d);49 if (blob2.mass <= 13 || massDiff == blob2.size * blob2.size) {50 blob1.velocity = Vector.add(51 blob1MomentumOld,52 blob2MomentumOld53 ).mult(1 / (blob1.mass + blob2.mass));54 blob1.mass += blob2.mass;55 blob1.size = Math.sqrt(blob1.mass);56 blob2.mass = 0;57 blob2.size = 0;58 }59 else {60 blob2.mass -= (massDiff);61 blob2.size = Math.sqrt(blob2.mass);62 blob1.mass += (massDiff);63 blob1.size = Math.sqrt(blob1.mass);64 blob2.velocity = blob2MomentumOld.mult(1 / blob2.mass);65 blob1.velocity = blob1MomentumOld.mult(1 / blob1.mass);66 }67 }68 }69}70//A function to calculate the common area between two circles.71//r = Radius of smaller circle.72//R = Radius of bigger circle.73//d = distance between their centers.74//Taken from http://mathworld.wolfram.com/Circle-CircleIntersection.html75function calcMassDiff(r, R, d) {76 if (d < R - r)77 return r*r;78 var massDiff = r*r*Math.acos((d*d + r*r - R*R)/(2*d*r));79 massDiff += R*R*Math.acos((d*d + R*R - r*r)/(2*d*R));80 massDiff -= 0.5*Math.sqrt((-d+r+R) * (d+r-R) * (d-r+R) * (d+r+R));81 //Division by Pi is because mass here is simply r * r, not area.82 massDiff /= Math.PI;83 return massDiff;84} 85//Enables bouncing86Blob.prototype.bounceCheck = function () {87 var pos = this.position;88 var size = this.size;89 if ((pos.x + size) >= Screen.width) {90 this.velocity.x = -this.velocity.x;91 this.position.x = Screen.width - size;92 }93 else if ((pos.x - size) <= 0) {94 this.velocity.x = -this.velocity.x;95 this.position.x = size;96 }97 if ((pos.y + size) >= Screen.height) {98 this.velocity.y = -this.velocity.y;99 this.position.y = Screen.height - size;100 }101 else if ((pos.y - size) <= 0) {102 this.velocity.y = -this.velocity.y;103 this.position.y = size;104 }105}106Player.prototype = Object.create(Blob.prototype);107Player.prototype.constructor = Player;108Repulsor.prototype = Object.create(Blob.prototype);109Repulsor.prototype.constructor = Repulsor;110//Function to control the player111//This ejects a mass 1/20th the player's mass, and the player's mass is only 19/20th of the original now.112//Ejection observes conservation of momentum and mass.113Player.prototype.accelerate = function (clickPos) {114 var fromClickToCurPos = Vector.subtract(this.position, clickPos).unit();115 var ejectedMass = new Blob(Vector.subtract(this.position, Vector.mult(116 fromClickToCurPos, Math.sqrt(this.mass/20) + Math.sqrt(this.mass) + Render.playerLineWidth + Render.enemyLineWidth)117 ), Math.sqrt(this.mass/20), Vector.mult(fromClickToCurPos, -19/5).add(this.velocity));118 this.mass = this.mass*19/20;119 this.size = Math.sqrt(this.mass);120 this.velocity.add(fromClickToCurPos.mult(this.accelerationMagnitude));121 return ejectedMass;122}123//Function to repel a blob124//Observes Newton's Third and Second Laws and momentum is conserved.125//Force of repulsion = (M * m)/((dist/2.5)^4)126Repulsor.prototype.repel = function (blob) {127 var dist = Vector.dist(this.position, blob.position);128 var fromRepulsorToBlob = Vector.subtract(blob.position, this.position).unit();129 blob.velocity.add(Vector.mult(130 fromRepulsorToBlob,131 this.mass / Math.pow(dist / 2.5, 4)132 ));133 this.velocity.add(Vector.mult(134 fromRepulsorToBlob,135 (blob.mass * -1) / Math.pow(dist / 2.5, 4)136 ));137}138//Function to check overlap of two blobs139function checkOverlap(blob1, blob2) {140 var dist = Vector.dist(blob1.position, blob2.position);141 if (dist < blob1.size + blob2.size)142 return true;143 else144 return false;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1function test() {2 var xhr = new XMLHttpRequest();3 xhr.responseType = 'blob';4 xhr.onload = function(e) {5 if (this.status == 200) {6 var blob = new Blob([this.response], {type: "application/pdf"});7 var blobURL = window.URL.createObjectURL(blob);8 }9 };10 xhr.send();11}12function test2() {13 var xhr = new XMLHttpRequest();14 xhr.responseType = 'arraybuffer';15 xhr.onload = function(e) {16 if (this.status == 200) {17 var blob = new Blob([this.response], {type: "application/pdf"});18 var blobURL = window.URL.createObjectURL(blob);19 }20 };21 xhr.send();22}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./blob2.js');2wpt.getSpeedIndex(url, function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var blob1 = require('blob1');2var blob = new blob1.Blob(['Hello World']);3console.log(blob.toString());4var blob2 = require('blob2');5var blob = new blob2.Blob(['Hello World']);6console.log(blob.toString());7var blob3 = require('blob3');8var blob = new blob3.Blob(['Hello World']);9console.log(blob.toString());10var blob4 = require('blob4');11var blob = new blob4.Blob(['Hello World']);12console.log(blob.toString());13var blob5 = require('blob5');14var blob = new blob5.Blob(['Hello World']);15console.log(blob.toString());16var blob6 = require('blob6');17var blob = new blob6.Blob(['Hello World']);18console.log(blob.toString());19var blob7 = require('blob7');20var blob = new blob7.Blob(['Hello World']);21console.log(blob.toString());22var blob8 = require('blob8');23var blob = new blob8.Blob(['Hello World']);24console.log(blob.toString());25var blob9 = require('blob9');26var blob = new blob9.Blob(['Hello World']);27console.log(blob.toString());28var blob10 = require('blob10');29var blob = new blob10.Blob(['Hello World']);30console.log(blob.toString());31var blob11 = require('blob11');32var blob = new blob11.Blob(['Hello World']);33console.log(blob.toString());34var blob12 = require('blob12');35var blob = new blob12.Blob(['Hello World']);36console.log(blob.toString());37var blob13 = require('blob13');38var blob = new blob13.Blob(['Hello World']);39console.log(blob.toString());40var blob14 = require('blob14');

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const wpt = new WebPageTest('www.webpagetest.org', 'A.6a3d3e3f3f3f3f3f3f3f3f3f3f3f3f3f');3 videoParams: {4 }5}, function(err, data) {6 if (err) {7 console.error(err);8 } else {9 console.log(data);10 }11});12const wpt = require('webpagetest');13const wpt = new WebPageTest('www.webpagetest.org', 'A.6a3d3e3f3f3f3f3f3f3f3f3f3f3f3f3f');14 videoParams: {15 }16}, function(err, data) {17 if (err) {18 console.error(err);19 } else {20 console.log(data);21 }22});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.9f6d5c5f7b5f5d5d5d5d5d5d5d5d5d5d5');3 console.log(data);4});5var wpt = require('webpagetest');6var wpt = new WebPageTest('www.webpagetest.org', 'A.9f6d5c5f7b5f5d5d5d5d5d5d5d5d5d5');7 console.log(data);8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org', 'A.9f6d5c5f7b5f5d5d5d5d5d5d5d5d5d5');11 console.log(data);12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org', 'A.9f6d5c5f7b5f5d5d5d5d5d5d5d5d5d5');15 console.log(data);16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org', 'A.9f6d5c5f7b5f5d5

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