How to use xpos method in wpt

Best JavaScript code snippet using wpt

myscript_org.js

Source:myscript_org.js Github

copy

Full Screen

1$(document).ready(function() {2 var divTemp = document.getElementById("divNums");3 for (var i = 8; i >= 1; i--) {4 divTemp.innerHTML = divTemp.innerHTML + "<div style='line-height:65px;'>" + i + "</div>";5 }6 var divTemp = document.getElementById("divChars");7 var charArray = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];8 for (var i = 1; i <= 8; i++) {9 divTemp.innerHTML = divTemp.innerHTML + "<span style='width:65px;display:inline-block;text-align:center'>" + charArray[i - 1] + "</span>";10 }11 12});13$(function() {14 // Initializing chess board15 setDefaultAttributes4Boxes();16 setDefaultAttributes4Symbols();17 $("div.box").mousedown(function() {18 var curX = $(this).attr("XPos");19 var curY = $(this).attr("YPos");20 var tmpChessSymbols = $(".chessSymbols");21 var bInit = true;22 for (var i = 0; i < tmpChessSymbols.length; i++) {23 if ($(tmpChessSymbols[i]).attr("XPos") === curX) {24 if ($(tmpChessSymbols[i]).attr("YPos") === curY) {25 bInit = false;26 break;27 }28 }29 }30 if (bInit) {31 initializeBoxes();32 }33 });34 $(".chessSymbols").mousedown(function() {35 initializeBoxes();36 calculateDPath(this);37 colorOwn(this);38 $("div.higlightedBoxes").droppable({39 drop: function(event, ui) {40 //$("div.higlightedBoxes").droppable('destroy');41 }42 });43 $("div.enemyBoxes").droppable({44 drop: function(event, ui) {45 //$("div.higlightedBoxes").droppable('destroy');46 }47 }); 48 });49 $(".chessSymbols").mouseup(function() {50 $(this).draggable({51 revert: function(obj) {52 if (obj) {53 // Let's change the child54 var tmpBoxes = $("div.box");55 var child = null;56 for (var i = 0; i < tmpBoxes.length; i++) {57 // Find the previous box who owns the child and detach the child58 var curXPos = $(this).attr("XPos");59 var curYPos = $(this).attr("YPos");60 if ($(tmpBoxes[i]).attr("XPos") === curXPos) {61 if ($(tmpBoxes[i]).attr("YPos") === curYPos) {62 child = $(tmpBoxes[i]).children().detach();63 break;64 }65 }66 }67 for (var i = 0; i < tmpBoxes.length; i++) {68 // Find the new box who owns the child and atach the child69 var curXPos = $(obj).attr("XPos");70 var curYPos = $(obj).attr("YPos");71 if ($(tmpBoxes[i]).attr("XPos") === curXPos) {72 if ($(tmpBoxes[i]).attr("YPos") === curYPos) {73 if ($(tmpBoxes[i]).hasClass('enemyBoxes')){74 $(tmpBoxes[i]).children().fadeOut(1000);75 setTimeout(function(){76 $(tmpBoxes[i]).children().detach(); 77 $(child).css('left', 0);78 $(child).css('top', 0);79 $(tmpBoxes[i]).prepend(child); 80 },1000);81 82 }else{83 $(child).css('left', 0);84 $(child).css('top', 0);85 $(tmpBoxes[i]).prepend(child);86 }87 break;88 }89 }90 }91 // Let's set new positions92 $(this).attr("XPos", $(obj).attr("XPos"));93 $(this).attr("YPos", $(obj).attr("YPos"));94 $(this).draggable('destroy');95 initializeBoxes();96 return false;97 }98 return true;99 }100 }101 );102 });103 $("div.box").hover(function() {104 //console.log("(" + $(this).attr("XPos") + "," + $(this).attr("YPos") + ")") ;105 });106});107function setDefaultAttributes4Symbols() {108 /* Here are the attributes and thier propable values,109 * 1. Symbol type = {ROOK, KNIGHT, BISHOP, KING, QUEEN, PAWN}110 * 2. Team = {Black, White}111 * 3. XPos = {a,b,c,d,e,f,g,h}112 * 4. YPos = {1,2,3,4,5,6,7,8}113 * */114 // Black team115 //******************************************************************116 var divTemp = $("#div8 div .chessSymbols");117 for (var i = 1; i <= divTemp.length; i++) {118 // For rooks119 if ((i === 1) || (i === 8)) {120 if (i === 1) {121 $(divTemp[i - 1]).attr({122 Type: "ROOK",123 Team: "BLACK",124 XPos: "a",125 YPos: 8126 });127 } else {128 $(divTemp[i - 1]).attr({129 Type: "ROOK",130 Team: "BLACK",131 XPos: "h",132 YPos: 8133 });134 }135 }136 // For knights137 else if ((i === 2) || (i === 7)) {138 if (i === 2) {139 $(divTemp[i - 1]).attr({140 Type: "KNIGHT",141 Team: "BLACK",142 XPos: "b",143 YPos: 8144 });145 } else {146 $(divTemp[i - 1]).attr({147 Type: "KNIGHT",148 Team: "BLACK",149 XPos: "g",150 YPos: 8151 });152 }153 }154 // For bishops155 else if ((i === 3) || (i === 6)) {156 if (i === 3) {157 $(divTemp[i - 1]).attr({158 Type: "BISHOP",159 Team: "BLACK",160 XPos: "c",161 YPos: 8162 });163 } else {164 $(divTemp[i - 1]).attr({165 Type: "BISHOP",166 Team: "BLACK",167 XPos: "f",168 YPos: 8169 });170 }171 }172 // For queen173 else if (i === 4) {174 $(divTemp[i - 1]).attr({175 Type: "QUEEN",176 Team: "BLACK",177 XPos: "d",178 YPos: 8179 });180 }181 // For king182 else {183 $(divTemp[i - 1]).attr({184 Type: "KING",185 Team: "BLACK",186 XPos: "e",187 YPos: 8188 });189 }190 }191 divTemp = $("#div7 div .chessSymbols");192 for (var i = 1; i <= divTemp.length; i++) {193 var xPosS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];194 $(divTemp[i - 1]).attr({195 Type: "PAWN",196 Team: "BLACK",197 XPos: xPosS[i - 1],198 YPos: 7199 });200 }201 // White team202 //******************************************************************203 divTemp = $("#div1 div .chessSymbols");204 for (var i = 1; i <= divTemp.length; i++) {205 // For rooks206 if ((i === 1) || (i === 8)) {207 if (i === 1) {208 $(divTemp[i - 1]).attr({209 Type: "ROOK",210 Team: "WHITE",211 XPos: "a",212 YPos: 1213 });214 } else {215 $(divTemp[i - 1]).attr({216 Type: "ROOK",217 Team: "WHITE",218 XPos: "h",219 YPos: 1220 });221 }222 }223 // For knights224 else if ((i === 2) || (i === 7)) {225 if (i === 2) {226 $(divTemp[i - 1]).attr({227 Type: "KNIGHT",228 Team: "WHITE",229 XPos: "b",230 YPos: 1231 });232 } else {233 $(divTemp[i - 1]).attr({234 Type: "KNIGHT",235 Team: "WHITE",236 XPos: "g",237 YPos: 1238 });239 }240 }241 // For bishops242 else if ((i === 3) || (i === 6)) {243 if (i === 3) {244 $(divTemp[i - 1]).attr({245 Type: "BISHOP",246 Team: "WHITE",247 XPos: "c",248 YPos: 1249 });250 } else {251 $(divTemp[i - 1]).attr({252 Type: "BISHOP",253 Team: "WHITE",254 XPos: "f",255 YPos: 1256 });257 }258 }259 // For queen260 else if (i === 4) {261 $(divTemp[i - 1]).attr({262 Type: "QUEEN",263 Team: "WHITE",264 XPos: "d",265 YPos: 1266 });267 }268 // For king269 else {270 $(divTemp[i - 1]).attr({271 Type: "KING",272 Team: "WHITE",273 XPos: "e",274 YPos: 1275 });276 }277 }278 divTemp = $("#div2 div .chessSymbols");279 for (var i = 1; i <= divTemp.length; i++) {280 var xPosS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];281 $(divTemp[i - 1]).attr({282 Type: "PAWN",283 Team: "WHITE",284 XPos: xPosS[i - 1],285 YPos: 2286 });287 }288}289function setDefaultAttributes4Boxes() {290 /* Here are the attributes and thier propable values,291 * 1. XPos = {a,b,c,d,e,f,g,h}292 * 2. YPos = {1,2,3,4,5,6,7,8}293 * */294 for (var i = 1; i <= 8; i++) {295 var divTemp = $("#div" + i + " div.box");296 for (var j = 0; j < divTemp.length; j++) {297 var xPosS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];298 $(divTemp[j]).attr({299 XPos: xPosS[j],300 YPos: i301 });302 }303 }304}305function calculateDPath(chessSymbol) {306 /* This is the process of this method.307 * Major is calculating the path of a chess symbol.308 * 1. Identify the symbol type309 * 2. Get it's current location on the board.310 * 3. Calculating the paths, "where it can go"311 * I. When finding the path search for blocks312 * II. Color where the paths are313 * III.Color the enemy boxes314 */315 if ($(chessSymbol).attr("Type") === "ROOK") {316 // Where is he now? (curXPos,curYPos)317 var curXPos = convertRealXPos($(chessSymbol).attr("XPos"));318 var curYPos = parseInt($(chessSymbol).attr("YPos"));319 // Let's find out where he can go320 if ((curXPos - 1) !== 0) {321 for (var i = curXPos - 1; i > 0; i--) {322 var reObj = isHereSomeone(i, curYPos);323 if (reObj.is) {324 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {325 colorMe(i, curYPos, true);326 }327 break;328 }329 colorMe(i, curYPos, false);330 }331 for (var i = curXPos + 1; i <= 8; i++) {332 var reObj = isHereSomeone(i, curYPos);333 if (reObj.is) {334 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {335 colorMe(i, curYPos, true);336 }337 break;338 }339 colorMe(i, curYPos, false);340 }341 } else {342 for (var i = 2; i <= 8; i++) {343 var reObj = isHereSomeone(i, curYPos);344 if (reObj.is) {345 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {346 colorMe(i, curYPos, true);347 }348 break;349 }350 colorMe(i, curYPos, false);351 }352 }353 if ((curYPos - 1) !== 0) {354 for (var i = curYPos - 1; i > 0; i--) {355 var reObj = isHereSomeone(curXPos, i);356 if (reObj.is) {357 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {358 colorMe(curXPos, i, true);359 }360 break;361 }362 colorMe(curXPos, i, false);363 }364 for (var i = (curYPos + 1); i <= 8; i++) {365 var reObj = isHereSomeone(curXPos, i);366 if (reObj.is) {367 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {368 colorMe(curXPos, i, true);369 }370 break;371 }372 colorMe(curXPos, i, false);373 }374 } else {375 for (var i = 2; i <= 8; i++) {376 var reObj = isHereSomeone(curXPos, i);377 if (reObj.is) {378 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {379 colorMe(curXPos, i, true);380 }381 break;382 }383 colorMe(curXPos, i, false);384 }385 }386 }387 else if ($(chessSymbol).attr("Type") === "KNIGHT") {388 // Where is he now? (curXPos,curYPos)389 var curXPos = convertRealXPos($(chessSymbol).attr("XPos"));390 var curYPos = parseInt($(chessSymbol).attr("YPos"));391 // Logic #1392 if (curXPos - 2 > 0) {393 if (curYPos + 1 < 9) {394 var reObj = isHereSomeone(curXPos - 2, curYPos + 1);395 if (reObj.is) {396 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {397 colorMe(curXPos - 2, curYPos + 1, true);398 }399 } else {400 colorMe(curXPos - 2, curYPos + 1, false);401 }402 }403 if (curYPos - 1 > 0) {404 var reObj = isHereSomeone(curXPos - 2, curYPos - 1);405 if (reObj.is) {406 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {407 colorMe(curXPos - 2, curYPos - 1, true);408 }409 } else {410 colorMe(curXPos - 2, curYPos - 1, false);411 }412 }413 }414 // Logic #2415 if (curXPos + 2 > 0) {416 if (curYPos + 1 < 9) {417 var reObj = isHereSomeone(curXPos + 2, curYPos + 1);418 if (reObj.is) {419 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {420 colorMe(curXPos + 2, curYPos + 1, true);421 }422 } else {423 colorMe(curXPos + 2, curYPos + 1, false);424 }425 }426 if (curYPos - 1 > 0) {427 var reObj = isHereSomeone(curXPos + 2, curYPos - 1);428 if (reObj.is) {429 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {430 colorMe(curXPos + 2, curYPos - 1, true);431 }432 } else {433 colorMe(curXPos + 2, curYPos - 1, false);434 }435 }436 }437 // Logic #3438 if (curYPos - 2 > 0) {439 if (curXPos + 1 < 9) {440 var reObj = isHereSomeone(curXPos + 1, curYPos - 2);441 if (reObj.is) {442 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {443 colorMe(curXPos + 1, curYPos - 2, true);444 }445 } else {446 colorMe(curXPos + 1, curYPos - 2, false);447 }448 }449 if (curXPos - 1 > 0) {450 var reObj = isHereSomeone(curXPos - 1, curYPos - 2);451 if (reObj.is) {452 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {453 colorMe(curXPos - 1, curYPos - 2, true);454 }455 } else {456 colorMe(curXPos - 1, curYPos - 2, false);457 }458 }459 }460 // Logic #4461 if (curYPos + 2 > 0) {462 if (curXPos + 1 < 9) {463 var reObj = isHereSomeone(curXPos + 1, curYPos + 2);464 if (reObj.is) {465 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {466 colorMe(curXPos + 1, curYPos + 2, true);467 }468 } else {469 colorMe(curXPos + 1, curYPos + 2, false);470 }471 }472 if (curXPos - 1 > 0) {473 var reObj = isHereSomeone(curXPos - 1, curYPos + 2);474 if (reObj.is) {475 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {476 colorMe(curXPos - 1, curYPos + 2, true);477 }478 } else {479 colorMe(curXPos - 1, curYPos + 2, false);480 }481 }482 }483 }484 else if ($(chessSymbol).attr("Type") === "BISHOP") {485 // Where is he now? (curXPos,curYPos)486 var curXPos = convertRealXPos($(chessSymbol).attr("XPos"));487 var curYPos = parseInt($(chessSymbol).attr("YPos"));488 // Between [0-90] degrees489 var tmpYPos = curYPos;490 for (var x = curXPos + 1; x <= 8; x++) {491 tmpYPos++;492 if (tmpYPos > 8)493 break;494 var reObj = isHereSomeone(x, tmpYPos);495 if (reObj.is) {496 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {497 colorMe(x, tmpYPos, true);498 }499 break;500 } else {501 colorMe(x, tmpYPos, false);502 }503 }504 // Between [90-180] degrees505 tmpYPos = curYPos;506 for (var x = curXPos - 1; x >= 1; x--) {507 tmpYPos++;508 if (tmpYPos > 8)509 break;510 var reObj = isHereSomeone(x, tmpYPos);511 if (reObj.is) {512 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {513 colorMe(x, tmpYPos, true);514 }515 break;516 } else {517 colorMe(x, tmpYPos, false);518 }519 }520 // Between [180-270] degrees521 tmpYPos = curYPos;522 for (var x = curXPos - 1; x >= 1; x--) {523 tmpYPos--;524 if (tmpYPos < 1)525 break;526 var reObj = isHereSomeone(x, tmpYPos);527 if (reObj.is) {528 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {529 colorMe(x, tmpYPos, true);530 }531 break;532 } else {533 colorMe(x, tmpYPos, false);534 }535 }536 // Between [270-360] degrees537 tmpYPos = curYPos;538 for (var x = curXPos + 1; x <= 8; x++) {539 tmpYPos--;540 if (tmpYPos < 1)541 break;542 var reObj = isHereSomeone(x, tmpYPos);543 if (reObj.is) {544 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {545 colorMe(x, tmpYPos, true);546 }547 break;548 } else {549 colorMe(x, tmpYPos, false);550 }551 }552 }553 else if ($(chessSymbol).attr("Type") === "QUEEN") {554 // Where is she now? (curXPos,curYPos)555 var curXPos = convertRealXPos($(chessSymbol).attr("XPos"));556 var curYPos = parseInt($(chessSymbol).attr("YPos"));557 // Queen has rook qualities558 if ((curXPos - 1) !== 0) {559 for (var i = curXPos - 1; i > 0; i--) {560 var reObj = isHereSomeone(i, curYPos);561 if (reObj.is) {562 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {563 colorMe(i, curYPos, true);564 }565 break;566 }567 colorMe(i, curYPos, false);568 }569 for (var i = curXPos + 1; i <= 8; i++) {570 var reObj = isHereSomeone(i, curYPos);571 if (reObj.is) {572 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {573 colorMe(i, curYPos, true);574 }575 break;576 }577 colorMe(i, curYPos, false);578 }579 } else {580 for (var i = 2; i <= 8; i++) {581 var reObj = isHereSomeone(i, curYPos);582 if (reObj.is) {583 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {584 colorMe(i, curYPos, true);585 }586 break;587 }588 colorMe(i, curYPos, false);589 }590 }591 if ((curYPos - 1) !== 0) {592 for (var i = curYPos - 1; i > 0; i--) {593 var reObj = isHereSomeone(curXPos, i);594 if (reObj.is) {595 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {596 colorMe(curXPos, i, true);597 }598 break;599 }600 colorMe(curXPos, i, false);601 }602 for (var i = (curYPos + 1); i <= 8; i++) {603 var reObj = isHereSomeone(curXPos, i);604 if (reObj.is) {605 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {606 colorMe(curXPos, i, true);607 }608 break;609 }610 colorMe(curXPos, i, false);611 }612 } else {613 for (var i = 2; i <= 8; i++) {614 var reObj = isHereSomeone(curXPos, i);615 if (reObj.is) {616 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {617 colorMe(curXPos, i, true);618 }619 break;620 }621 colorMe(curXPos, i, false);622 }623 }624 // ------------------------------------------------------------------------------625 // Queen has bishop qualities626 // Between [0-90] degrees627 var tmpYPos = curYPos;628 for (var x = curXPos + 1; x <= 8; x++) {629 tmpYPos++;630 if (tmpYPos > 8)631 break;632 var reObj = isHereSomeone(x, tmpYPos);633 if (reObj.is) {634 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {635 colorMe(x, tmpYPos, true);636 }637 break;638 } else {639 colorMe(x, tmpYPos, false);640 }641 }642 // Between [90-180] degrees643 tmpYPos = curYPos;644 for (var x = curXPos - 1; x >= 1; x--) {645 tmpYPos++;646 if (tmpYPos > 8)647 break;648 var reObj = isHereSomeone(x, tmpYPos);649 if (reObj.is) {650 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {651 colorMe(x, tmpYPos, true);652 }653 break;654 } else {655 colorMe(x, tmpYPos, false);656 }657 }658 // Between [180-270] degrees659 tmpYPos = curYPos;660 for (var x = curXPos - 1; x >= 1; x--) {661 tmpYPos--;662 if (tmpYPos < 1)663 break;664 var reObj = isHereSomeone(x, tmpYPos);665 if (reObj.is) {666 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {667 colorMe(x, tmpYPos, true);668 }669 break;670 } else {671 colorMe(x, tmpYPos, false);672 }673 }674 // Between [270-360] degrees675 tmpYPos = curYPos;676 for (var x = curXPos + 1; x <= 8; x++) {677 tmpYPos--;678 if (tmpYPos < 1)679 break;680 var reObj = isHereSomeone(x, tmpYPos);681 if (reObj.is) {682 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {683 colorMe(x, tmpYPos, true);684 }685 break;686 } else {687 colorMe(x, tmpYPos, false);688 }689 }690 }691 else if ($(chessSymbol).attr("Type") === "KING") {692 // Where is he now? (curXPos,curYPos)693 var curXPos = convertRealXPos($(chessSymbol).attr("XPos"));694 var curYPos = parseInt($(chessSymbol).attr("YPos"));695 // #Logic 1 in current X position696 if (curYPos + 1 < 9) {697 var reObj = isHereSomeone(curXPos, curYPos + 1);698 if (reObj.is) {699 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {700 colorMe(curXPos, curYPos + 1, true);701 }702 } else {703 colorMe(curXPos, curYPos + 1, false);704 }705 }706 if (curYPos - 1 > 0) {707 var reObj = isHereSomeone(curXPos, curYPos - 1);708 if (reObj.is) {709 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {710 colorMe(curXPos, curYPos - 1, true);711 }712 } else {713 colorMe(curXPos, curYPos - 1, false);714 }715 }716 // #Logic 2 in (current X + 1) position717 if (curXPos + 1 < 9) {718 // Case 1: current Y719 var reObj = isHereSomeone(curXPos + 1, curYPos);720 if (reObj.is) {721 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {722 colorMe(curXPos + 1, curYPos, true);723 }724 } else {725 colorMe(curXPos + 1, curYPos, false);726 }727 // Case 2: (current Y + 1)728 reObj = isHereSomeone(curXPos + 1, curYPos + 1);729 if (reObj.is) {730 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {731 colorMe(curXPos + 1, curYPos + 1, true);732 }733 } else {734 colorMe(curXPos + 1, curYPos + 1, false);735 }736 // Case 3: (current Y - 1)737 reObj = isHereSomeone(curXPos + 1, curYPos - 1);738 if (reObj.is) {739 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {740 colorMe(curXPos + 1, curYPos - 1, true);741 }742 } else {743 colorMe(curXPos + 1, curYPos - 1, false);744 }745 }746 // #Logic 3 in (current X - 1) position747 if (curXPos + 1 < 9) {748 // Case 1: current Y749 var reObj = isHereSomeone(curXPos - 1, curYPos);750 if (reObj.is) {751 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {752 colorMe(curXPos - 1, curYPos, true);753 }754 } else {755 colorMe(curXPos - 1, curYPos, false);756 }757 // Case 2: (current Y + 1)758 reObj = isHereSomeone(curXPos - 1, curYPos + 1);759 if (reObj.is) {760 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {761 colorMe(curXPos - 1, curYPos + 1, true);762 }763 } else {764 colorMe(curXPos - 1, curYPos + 1, false);765 }766 // Case 3: (current Y - 1)767 reObj = isHereSomeone(curXPos - 1, curYPos - 1);768 if (reObj.is) {769 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {770 colorMe(curXPos - 1, curYPos - 1, true);771 }772 } else {773 colorMe(curXPos - 1, curYPos - 1, false);774 }775 }776 }777 else {778 // Where is he now? (curXPos,curYPos)779 var curXPos = convertRealXPos($(chessSymbol).attr("XPos"));780 var curYPos = parseInt($(chessSymbol).attr("YPos"));781 if (curYPos + 1 < 9) {782 if ($(chessSymbol).attr("Team") === "WHITE") {783 var reObj = isHereSomeone(curXPos, curYPos + 1);784 if (!reObj.is) {785 colorMe(curXPos, curYPos + 1, false);786 if (curYPos === 2) {787 reObj = isHereSomeone(curXPos, curYPos + 2);788 if (!reObj.is) {789 colorMe(curXPos, curYPos + 2, false);790 }791 }792 }793 }794 if (curXPos - 1 > 0) {795 reObj = isHereSomeone(curXPos - 1, curYPos + 1);796 if (reObj.is) {797 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {798 colorMe(curXPos - 1, curYPos + 1, true);799 }800 }801 }802 if (curXPos + 1 < 9) {803 reObj = isHereSomeone(curXPos + 1, curYPos + 1);804 if (reObj.is) {805 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {806 colorMe(curXPos + 1, curYPos + 1, true);807 }808 }809 }810 }811 if (curYPos - 1 > 0) {812 if ($(chessSymbol).attr("Team") === "BLACK") {813 var reObj = isHereSomeone(curXPos, curYPos - 1);814 if (!reObj.is) {815 colorMe(curXPos, curYPos - 1, false);816 if (curYPos === 7) {817 reObj = isHereSomeone(curXPos, curYPos - 2);818 if (!reObj.is) {819 colorMe(curXPos, curYPos - 2, false);820 }821 }822 }823 }824 if (curXPos - 1 > 0) {825 reObj = isHereSomeone(curXPos - 1, curYPos - 1);826 if (reObj.is) {827 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {828 colorMe(curXPos - 1, curYPos - 1, true);829 }830 }831 }832 if (curXPos + 1 < 9) {833 reObj = isHereSomeone(curXPos + 1, curYPos - 1);834 if (reObj.is) {835 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {836 colorMe(curXPos + 1, curYPos - 1, true);837 }838 }839 }840 }841 }842}843function convertRealXPos(charXPos) {844 switch (charXPos) {845 case "a":846 {847 return 1;848 break;849 }850 case "b":851 {852 return 2;853 break;854 }855 case "c":856 {857 return 3;858 break;859 }860 case "d":861 {862 return 4;863 break;864 }865 case "e":866 {867 return 5;868 break;869 }870 case "f":871 {872 return 6;873 break;874 }875 case "g":876 {877 return 7;878 break;879 }880 case "h":881 {882 return 8;883 break;884 }885 }886}887function isHereSomeone(xPos, yPos) {888 var chessSymbols = $(".chessSymbols");889 var returnObject = new Object();890 returnObject.who = null;891 returnObject.is = false;892 for (var i = 0; i < chessSymbols.length; i++) {893 if ((convertRealXPos($(chessSymbols[i]).attr("XPos")) === xPos) &&894 (parseInt($(chessSymbols[i]).attr("YPos")) === yPos)) {895 returnObject.is = true;896 returnObject.who = $(chessSymbols[i]);897 return returnObject;898 }899 }900 return returnObject;901}902function initializeBoxes() {903 $("div.higlightedBoxes").droppable('destroy');904 $("div.enemyBoxes").droppable('destroy');905 var divBoxes = $(".higlightedBoxes");906 for (var i = 0; i < divBoxes.length; i++) {907 $(divBoxes[i]).removeClass("higlightedBoxes");908 }909 divBoxes = $(".enemyBoxes");910 for (var i = 0; i < divBoxes.length; i++) {911 $(divBoxes[i]).removeClass("enemyBoxes");912 }913 divBoxes = $(".colorOwnBox");914 for (var i = 0; i < divBoxes.length; i++) {915 $(divBoxes[i]).removeClass("colorOwnBox");916 } 917}918function colorMe(xPos, yPos, enemy) {919 var divName = "#div" + yPos + " div.box";920 var divBoxes = $(divName);921 for (var i = 0; i < divBoxes.length; i++) {922 if ((i + 1) === xPos) {923 if (!enemy) {924 $(divBoxes[i]).addClass("higlightedBoxes");925 } else {926 $(divBoxes[i]).addClass("enemyBoxes");927 }928 break;929 }930 }931}932function colorOwn(Me) {933 // Where am I now? (curXPos,curYPos)934 var curXPos = convertRealXPos($(Me).attr("XPos"));935 var curYPos = parseInt($(Me).attr("YPos"));936 var divName = "#div" + curYPos + " div.box";937 var divBoxes = $(divName);938 for (var i = 0; i < divBoxes.length; i++) {939 if ((i + 1) === curXPos) {940 $(divBoxes[i]).addClass("colorOwnBox");941 break;942 }943 }...

Full Screen

Full Screen

Alphabet.js

Source:Alphabet.js Github

copy

Full Screen

1function colors(){2 palettebluepink = [3 color(248, 73, 41), //red4 color(69, 97, 220), //blue5 color(59, 50, 89), //drk blue6 color(251, 151, 162), //pink7 color(201, 208, 234), //light blue8 color(240, 206, 181), //tan9 color(81, 216, 236),10 color(61, 77, 191) //drk blue11 ]12}13//------A-----------14function LetterA(xPos, yPos) {15 this.xPos = xPos;16 this.yPos = yPos;17 push();18 translate(this.xPos, this.yPos);19 noFill();20 strokeWeight(letterstroke);21 stroke(palettebluepink[1]);22 line(letterwidth / 2, 0, 0, letterheight);23 stroke(palettebluepink[6]);24 line(letterwidth / 2, 0, letterwidth, letterheight);25 stroke(palettebluepink[5]);26 line(letterwidth * .26, letterxheight, letterwidth * .66, letterxheight); //crossbar27 pop();28}29//-----B-------30function LetterB(xPos, yPos) {31 this.xPos = xPos;32 this.yPos = yPos;33 push();34 translate(this.xPos, this.yPos);35 noFill();36 strokeWeight(letterstroke);37 stroke(palettebluepink[2]);38 line(0, 0, 0, letterheight); //left39 stroke(palettebluepink[0]);40 rect(0, 0, letterwidth, letterxheight, 0, letterrounding, letterrounding, 0); //top round41 stroke(palettebluepink[4]);42 rect(0, letterxheight, letterwidth, letterxheight, 0, letterrounding, letterrounding, 0); //bottom round43 pop();44}45//-----C---------46function LetterC(xPos, yPos) { //define arguments and then use them inside the function to be updated in draw47 this.xPos = xPos;48 this.yPos = yPos;49 push();50 translate(this.xPos, this.yPos);51 ellipseMode(CENTER);52 noFill();53 strokeWeight(letterstroke);54 angleMode(DEGREES);55 stroke(palettebluepink[6]);56 arc(letterwidth / 2, letterheight / 2.5, letterwidth, letterheight * .8, 180, 350);57 stroke(palettebluepink[0]);58 arc(letterwidth / 2, letterheight - letterheight / 2.5, letterwidth, letterheight * .8, 360, 180);59 stroke(palettebluepink[2]);60 line(0, letterheight * .4, 0, letterheight * .6); //left straight line61 strokeWeight(letterstrokeB);62 stroke(240, 90);63 angleMode(DEGREES);64 arc(letterwidth / 2, letterheight / 3, letterwidth / 1.7, letterwidth / 1.7, 180, 360); //G65 pop();66}67//---------D--------68function LetterD(xPos, yPos) {69 this.xPos = xPos;70 this.yPos = yPos;71 push();72 translate(this.xPos, this.yPos);73 noFill();74 strokeWeight(letterstroke);75 stroke(palettebluepink[5]);76 rect(0, 0, letterwidth, letterheight, 0, letterrounding, letterrounding, 0);77 pop();78}79//-----E-------80function LetterE(xPos, yPos) {81 this.xPos = xPos;82 this.yPos = yPos;83 push();84 translate(this.xPos, this.yPos);85 noFill();86 strokeWeight(letterstroke);87 stroke(palettebluepink[5]);88 line(0, 0, 0, letterheight);89 stroke(palettebluepink[6]);90 line(0, letterheight, letterwidth, letterheight); //bottom91 stroke(palettebluepink[3]);92 line(0, 0, letterwidth, 0); //top93 stroke(palettebluepink[2]);94 line(0, letterxheight, letterwidth, letterxheight); //center95 strokeWeight(letterstrokeB);96 stroke(240, 90);97 line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N98 pop();99}100//-----F-------101function LetterF(xPos, yPos) {102 this.xPos = xPos;103 this.yPos = yPos;104 push();105 translate(this.xPos, this.yPos);106 noFill();107 strokeWeight(letterstroke);108 stroke(palettebluepink[1]);109 line(0, 0, 0, letterheight);110 stroke(palettebluepink[0]);111 line(0, 0, letterwidth, 0); //top bar112 stroke(palettebluepink[3]);113 line(0, letterxheight, letterwidth, letterxheight); //bottombar114 pop();115}116//-----G---------117function LetterG(xPos, yPos) {118 this.xPos = xPos;119 this.yPos = yPos;120 push();121 translate(this.xPos, this.yPos);122 noFill();123 strokeWeight(letterstroke);124 stroke(palettebluepink[1]);125 angleMode(DEGREES);126 arc(letterwidth / 2, letterheight / 2.5, letterwidth, letterheight * .8, 180, 350);127 stroke(palettebluepink[2]);128 arc(letterwidth / 2, letterheight - letterheight / 2.5, letterwidth, letterheight * .8, 360, 180);129 stroke(palettebluepink[7]);130 line(letterwidth / 2, letterxheight, letterwidth, letterxheight); //cross line131 stroke(palettebluepink[4]);132 line(0,letterheight * .45, 0, letterheight * .55); //left straight line133 pop();134}135//-----H-------136function LetterH(xPos, yPos) {137 this.xPos = xPos;138 this.yPos = yPos;139 push();140 translate(this.xPos, this.yPos);141 noFill();142 strokeWeight(letterstroke);143 stroke(palettebluepink[5]);144 line(0, 0, 0, letterheight); //left145 stroke(palettebluepink[6]);146 line(0, letterxheight, letterwidth, letterxheight); //top bar147 stroke(palettebluepink[1]);148 line(letterwidth, 0, letterwidth, letterheight); //right149 strokeWeight(letterstrokeB);150 stroke(240, 90);151 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N152 pop();153}154//-----I-------155function LetterI(xPos, yPos) {156 this.xPos = xPos;157 this.yPos = yPos;158 push();159 translate(this.xPos, this.yPos);160 noFill();161 strokeWeight(letterstroke);162 stroke(palettebluepink[6]);163 line(0, 0, letterwidth, 0); //top164 line(0, letterheight, letterwidth, letterheight); //bottom165 stroke(palettebluepink[3]);166 line(letterwidth / 2, 0, letterwidth / 2, letterheight); //long167 stroke(palettebluepink[2]);168 // line(0, letterxheight, letterwidth, letterxheight); //center169 // strokeWeight(letterstrokeB);170 // stroke(240, 90);171 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N172 pop();173}174//-----J-------175function LetterJ(xPos, yPos) {176 this.xPos = xPos;177 this.yPos = yPos;178 push();179 translate(this.xPos, this.yPos);180 noFill();181 strokeWeight(letterstroke);182 stroke(palettebluepink[6]);183 line(0, 0, letterwidth, 0); //top184 stroke(palettebluepink[4]);185 // arc(0, letterxheight, letterwidth, letterxheight, PI + (QUARTER_PI / 3), OPEN);186 angleMode(DEGREES);187 arc(letterwidth / 2, letterheight - letterheight / 2.5, letterwidth, letterheight * .8, 360, 180);188 stroke(palettebluepink[3]);189 line(letterwidth, 0, letterwidth, letterxheight); //long190 stroke(palettebluepink[2]);191 pop();192}193//-----K-------194function LetterK(xPos, yPos) {195 this.xPos = xPos;196 this.yPos = yPos;197 push();198 translate(this.xPos, this.yPos);199 noFill();200 strokeWeight(letterstroke);201 stroke(palettebluepink[6]);202 line(0, 0, 0, letterheight); //left203 stroke(palettebluepink[7]);204 line(0, letterxheight, letterwidth, 0); //towards top205 stroke(palettebluepink[0]);206 line(letterwidth * .5, letterheight*.4, letterwidth, letterheight); //bottom207 pop();208}209//-----L-------210function LetterL(xPos, yPos) {211 this.xPos = xPos;212 this.yPos = yPos;213 push();214 translate(this.xPos, this.yPos);215 noFill();216 strokeWeight(letterstroke);217 stroke(palettebluepink[5]);218 line(0, 0, 0, letterheight);219 stroke(palettebluepink[6]);220 line(0, letterheight, letterwidth, letterheight); //top bar221 strokeWeight(letterstrokeB);222 stroke(240, 90);223 line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N224 pop();225}226//------M-----227function LetterM(xPos, yPos) {228 this.xPos = xPos;229 this.yPos = yPos;230 push();231 translate(this.xPos, this.yPos);232 noFill();233 strokeWeight(letterstroke);234 stroke(palettebluepink[0]);235 line(0, 0, 0, letterheight); //left236 stroke(palettebluepink[2]);237 line(0, 0, letterwidth * .6, letterxheight); //across bottom left238 stroke(palettebluepink[5]);239 line(letterwidth, 0, letterwidth, letterheight); //right240 stroke(palettebluepink[3]);241 line(letterwidth, 0, letterwidth * .4, letterxheight); //across bottom left242 // strokeWeight(letterstrokeB);243 // stroke(240, 90);244 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight); //N245 pop();246}247//------N-----248function LetterN(xPos, yPos) {249 this.xPos = xPos;250 this.yPos = yPos;251 push();252 translate(this.xPos, this.yPos);253 noFill();254 strokeWeight(letterstroke);255 stroke(palettebluepink[5]);256 line(0, 0, 0, letterheight);257 stroke(palettebluepink[0]);258 line(0, 0, letterwidth, letterheight);259 stroke(palettebluepink[2]);260 line(letterwidth, 0, letterwidth, letterheight);261 strokeWeight(letterstrokeB);262 stroke(240, 90);263 line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight); //N264 pop();265}266//------O------267function LetterO(xPos, yPos) {268 this.xPos = xPos;269 this.yPos = yPos;270 push();271 translate(this.xPos, this.yPos);272 rectMode(CORNER);273 ellipseMode(CENTER);274 noFill();275 strokeWeight(letterstroke);276 stroke(palettebluepink[5]);277 rect(0, 0, letterwidth, letterheight, letterrounding, letterrounding, letterrounding, letterrounding);278 strokeWeight(letterstrokeB);279 stroke(240, 90);280 angleMode(DEGREES);281 arc(letterwidth / 2, letterheight / 3, letterwidth / 1.7, letterwidth / 1.7, 180, 360); //O282 pop();283}284//-----P-------285function LetterP(xPos, yPos) {286 this.xPos = xPos;287 this.yPos = yPos;288 push();289 translate(this.xPos, this.yPos);290 noFill();291 strokeWeight(letterstroke);292 stroke(palettebluepink[2]);293 line(0, 0, 0, letterheight); //left294 stroke(palettebluepink[0]);295 rect(0, 0, letterwidth, letterxheight, 0, letterrounding, letterrounding, 0);296 // line(0, letterxheight, letterwidth, letterxheight); //top bar297 // line(letterwidth, 0, letterwidth, letterheight); //right298 // strokeWeight(letterstrokeB);299 // stroke(240, 90);300 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N301 pop();302}303//------Q------304function LetterQ(xPos, yPos) {305 this.xPos = xPos;306 this.yPos = yPos;307 push();308 translate(this.xPos, this.yPos);309 rectMode(CORNER);310 ellipseMode(CENTER);311 noFill();312 strokeWeight(letterstroke);313 stroke(palettebluepink[5]);314 rect(0, 0, letterwidth, letterheight, letterrounding, letterrounding, letterrounding, letterrounding);315 stroke(palettebluepink[0]);316 line(letterwidth / 2, letterxheight, letterwidth, letterheight);317 strokeWeight(letterstrokeB);318 stroke(240, 90);319 angleMode(DEGREES);320 arc(letterwidth / 2, letterheight / 3, letterwidth / 1.7, letterwidth / 1.7, 180, 360); //O321 pop();322}323//-----R-------324function LetterR(xPos, yPos) {325 this.xPos = xPos;326 this.yPos = yPos;327 push();328 translate(this.xPos, this.yPos);329 noFill();330 strokeWeight(letterstroke);331 stroke(palettebluepink[6]);332 line(0, 0, 0, letterheight); //left333 stroke(palettebluepink[7]);334 rect(0, 0, letterwidth, letterxheight, 0, letterrounding, letterrounding, 0); //rounded335 stroke(palettebluepink[0]);336 line(letterwidth * .7, letterxheight, letterwidth, letterheight);337 // line(0, letterxheight, letterwidth, letterxheight); //top bar338 // line(letterwidth, 0, letterwidth, letterheight); //right339 // strokeWeight(letterstrokeB);340 // stroke(240, 90);341 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N342 pop();343}344//-----S-------345function LetterS(xPos, yPos) {346 this.xPos = xPos;347 this.yPos = yPos;348 push();349 translate(this.xPos, this.yPos);350 noFill();351 strokeWeight(letterstroke);352 stroke(palettebluepink[2]);353 bezier(letterwidth, 0, 0, 0, letterwidth, letterheight, 0, letterheight); //temporary354 pop();355}356//-----T-------357function LetterT(xPos, yPos) {358 this.xPos = xPos;359 this.yPos = yPos;360 push();361 translate(this.xPos, this.yPos);362 noFill();363 strokeWeight(letterstroke);364 stroke(palettebluepink[6]);365 line(0, 0, letterwidth, 0); //top366 stroke(palettebluepink[6]);367 // line(0, letterheight, letterwidth, letterheight); //bottom368 stroke(palettebluepink[3]);369 line(letterwidth / 2, 0, letterwidth / 2, letterheight); //long370 stroke(palettebluepink[2]);371 // line(0, letterxheight, letterwidth, letterxheight); //center372 // strokeWeight(letterstrokeB);373 // stroke(240, 90);374 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N375 pop();376}377//------U-----------378function LetterU(xPos, yPos) {379 this.xPos = xPos;380 this.yPos = yPos;381 push();382 translate(this.xPos, this.yPos);383 noFill();384 strokeWeight(letterstroke);385 stroke(palettebluepink[6]);386 line(0, 0, 0, letterxheight);387 stroke(palettebluepink[1]);388 line(letterwidth, 0, letterwidth, letterxheight);389 stroke(palettebluepink[0]);390 angleMode(DEGREES);391 stroke(palettebluepink[4]);392 arc(letterwidth / 2, letterheight - letterheight / 2.5, letterwidth, letterheight * .8, 360, 180);393 pop();394}395//------V-----------396function LetterV(xPos, yPos) {397 this.xPos = xPos;398 this.yPos = yPos;399 push();400 translate(this.xPos, this.yPos);401 noFill();402 strokeWeight(letterstroke);403 stroke(palettebluepink[6]);404 line(letterwidth / 2, letterheight, 0, 0);405 stroke(palettebluepink[1]);406 line(letterwidth / 2, letterheight, letterwidth, 0);407 pop();408}409//------W-----410function LetterW(xPos, yPos) {411 this.xPos = xPos;412 this.yPos = yPos;413 push();414 translate(this.xPos, this.yPos);415 noFill();416 strokeWeight(letterstroke);417 stroke(palettebluepink[0]);418 line(0, 0, 0, letterheight); //left419 stroke(palettebluepink[2]);420 line(0, letterheight, letterwidth * .6, letterxheight); //across bottom left421 stroke(palettebluepink[5]);422 line(letterwidth, 0, letterwidth, letterheight); //right423 stroke(palettebluepink[3]);424 line(letterwidth, letterheight, letterwidth * .4, letterxheight); //across bottom left425 // strokeWeight(letterstrokeB);426 // stroke(240, 90);427 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight); //N428 pop();429}430//------X-----431function LetterX(xPos, yPos) {432 this.xPos = xPos;433 this.yPos = yPos;434 push();435 translate(this.xPos, this.yPos);436 noFill();437 strokeWeight(letterstroke);438 stroke(palettebluepink[5]);439 line(letterwidth, 0, 0, letterheight);440 stroke(palettebluepink[0]);441 line(0, 0, letterwidth, letterheight);442 stroke(palettebluepink[2]);443 strokeWeight(letterstrokeB);444 stroke(240, 90);445 line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight); //N446 pop();447}448//-----Y---------449function LetterY(xPos, yPos) {450 this.xPos = xPos;451 this.yPos = yPos;452 push();453 translate(this.xPos, this.yPos);454 noFill();455 strokeWeight(letterstroke);456 stroke(palettebluepink[0]);457 angleMode(DEGREES);458 459 arc(letterwidth / 2, 0, letterwidth, letterheight * .8, 360,180);460 stroke(palettebluepink[1]);461 line(letterwidth / 2, letterheight, letterwidth / 2,letterheight * .4); //left straight line462 pop();463}464//-----Z-------465function LetterZ(xPos, yPos) {466 this.xPos = xPos;467 this.yPos = yPos;468 push();469 translate(this.xPos, this.yPos);470 noFill();471 strokeWeight(letterstroke);472 stroke(palettebluepink[6]);473 line(0, 0, letterwidth, 0); //top474 stroke(palettebluepink[2]);475 line(0, letterheight, letterwidth, letterheight); //bottom476 stroke(palettebluepink[3]);477 line(letterwidth, 0,0,letterheight); //across478 pop();...

Full Screen

Full Screen

animations.js

Source:animations.js Github

copy

Full Screen

1var tID;2var sleepID;3var xpos = 0;4var ypos = 0;5var isHole = false;6var isSleep = false;7var isAnimating = false;89const interval = 100; //100 ms of interval for the setInterval()10const xdiff = 167;11const ydiff = 125;1213const xbase = 0; 14const ybase = 0;15const xhole = 1*xdiff; 16const yhole = 0;1718const seal = document.getElementById("seal");1920const sleepTimer = 30*1000;2122idle();2324// play random animation when idle25function startSleepTimer() {26 sleepID = setTimeout(function() {27 startSleep();28 }, sleepTimer);29}3031seal.onmouseenter = function() {32 if (isAnimating) return;33 if (!isSleep && !isHole) {34 clearTimeout(sleepID);35 blink();36}}3738seal.onclick = function() {3940 fetch('https://icanhazdadjoke.com/')41 .then(response => {42 return response.json()43 })44 .then(data => {45 // Work with JSON data here46 alert("boop");47 })48 .catch(err => {49 // Do something for an error here50 })5152 if(isAnimating) return;53 clearTimeout(sleepID);54 if (isSleep) {55 wake();56 } else if (isHole) {57 playHoleAnimation();58 } else {59 playRandomAnimation();60 }61}6263function playHoleAnimation() {64 switch(Math.floor(Math.random()*2)) {65 case 0:66 holeMorph();67 break;68 case 1:69 holePeek();70 break;71 default:72 }73}7475function playRandomAnimation() {76 // rand math floor of 4 different options77 switch(Math.floor(Math.random()*6)) {78 case 0:79 scream();80 break;81 case 1:82 lookAround();83 break;84 case 2:85 sneeze();86 break;87 case 3:88 beg();89 break;90 case 4:91 dive();92 break;93 case 5:94 flappy();95 break;96 default:97 blink();98 }99}100101// ANIMATIONS==============================102103// idle animation, starts sleep timer104function idle() {105 clearInterval(tID);106 startSleepTimer();107 isAnimating = false;108 isHole = false;109 xpos = xbase + xdiff;110 ypos = ybase;111 tID = setInterval( () => {112 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 113 if (xpos == xbase) {114 xpos = xpos + xdiff;115 } else {116 xpos = xbase;117 }118 }, 2*interval); 119}120121// sets bg as a hole122function beHole(){123 clearInterval(tID);124 clearTimeout(sleepID);125 isHole = true;126 isAnimating = false;127 xpos = 0;128 ypos = 14*ydiff;129 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 130}131132// blinks once then goes to idle133function blink() {134 clearInterval(tID);135 clearTimeout(sleepID);136 xpos = 1*xdiff;137 ypos = 1*ydiff;138 tID = setInterval ( () => {139 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 140 if (xpos == xbase) {141 idle();142 } else {143 xpos = xbase;144 ypos = ybase;145 }146 }, interval); 147}148149// transition into sleep position and plays rockrub150function startSleep() {151 isAnimating = true;152 clearInterval(tID);153 clearTimeout(sleepID);154 xpos = 0*xdiff;155 ypos = 7*ydiff;156 tID = setInterval ( () => {157 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 158 if (xpos == 6*xdiff) {159 rockRub();160 } else {161 xpos = xpos + xdiff;162 }163 }, interval); 164}165166// rubs rock for random time then plays sleep loop167// can be interrupted168function rockRub() {169 isSleep = true;170 isAnimating = false;171 clearInterval(tID);172 const delay = Math.ceil(Math.random()*5 + 2);173 var i = 0;174 xpos = 0*xdiff;175 ypos = 8*ydiff;176 tID = setInterval ( () => {177 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 178 if (xpos == 0*xdiff) {179 xpos = 1*xdiff;180 } else {181 if(i < delay) {182 xpos = 0*xdiff;183 i++;184 } else {185 sleepLoop();186 }187 }188 }, interval*5); 189}190191// sleeping loop192function sleepLoop() {193 clearInterval(tID);194 var i = 0;195 xpos = 0*xdiff;196 ypos = 9*ydiff;197 tID = setInterval ( () => {198 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 199 if (xpos == 0*xdiff) {200 xpos = 1*xdiff;201 } else {202 xpos = 0*xdiff;203 }204 }, interval*5); 205}206207// sets isSleep to false at end of animation208function wake() {209 isAnimating = true;210 clearInterval(tID);211 xpos = 0*xdiff;212 ypos = 10*ydiff;213 tID = setInterval ( () => {214 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 215 if (xpos == 6*xdiff) {216 xpos = xbase;217 ypos = ybase; 218 isSleep = false; 219 idle(); 220 } else {221 xpos = xpos + xdiff;222 }223 }, interval); 224}225226function holeMorph() {227 isAnimating = true;228 clearInterval(tID);229 xpos = 0*xdiff;230 ypos = 15*ydiff;231 tID = setInterval ( () => {232 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 233 if (xpos == 4*xdiff) {234 xpos = xbase;235 ypos = ybase; 236 isHole = false; 237 idle(); 238 } else {239 xpos = xpos + xdiff;240 }241 }, interval); 242}243244function holePeek() {245 isAnimating = true;246 clearInterval(tID);247 xpos = 1*xdiff;248 ypos = 16*ydiff;249 tID = setInterval ( () => {250 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 251 if (xpos == 0*xdiff) {252 beHole();253 } else if (xpos == 3*xdiff) {254 xpos = 0*xdiff;255 } else {256 xpos = xpos + xdiff;257 }258 }, interval*5); 259}260261function scream() {262 isAnimating = true;263 clearInterval(tID);264 xpos = 0*xdiff;265 ypos = 12*ydiff;266267 tID = setInterval ( () => {268 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 269 if (xpos == 4*xdiff) {270 idle();271 } else {272 if (xpos == 2*xdiff) {273 fetch('https://icanhazdadjoke.com/', {274 method: 'GET',275 headers: {276 'Accept': 'text/plain',277 },278 })279 .then((res) => res.text())280 .then((data) => alert(data)); 281 }282 xpos = xpos + xdiff;283 }284 }, interval); 285}286287function lookAround() {288 isAnimating = true;289 clearInterval(tID);290 xpos = 1*xdiff;291 ypos = 6*ydiff;292 tID = setInterval ( () => {293 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 294 if (xpos >= 2*xdiff) {295 xpos = 0*xdiff;296 } else if (xpos == 0*xdiff) {297 idle();298 } else {299 xpos = xpos + xdiff;300 }301 }, interval*5); 302}303304function sneeze() {305 isAnimating = true;306 clearInterval(tID);307 xpos = 0*xdiff;308 ypos = 11*ydiff;309 tID = setInterval ( () => {310 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 311 if (xpos == 4*xdiff) {312 idle();313 } else {314 xpos = xpos + xdiff;315 }316 }, interval); 317}318319function dive() {320 isAnimating = true;321 clearInterval(tID);322 xpos = 0*xdiff;323 ypos = 13*ydiff;324 tID = setInterval ( () => {325 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 326 if (xpos == 6*xdiff) {327 beHole();328 } else {329 xpos = xpos + xdiff;330 }331 }, interval); 332}333334function beg() {335 isAnimating = true;336 clearInterval(tID);337 xpos = 0*xdiff;338 ypos = 2*ydiff;339 tID = setInterval ( () => {340 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 341 if (xpos == 3*xdiff) {342 begLoop();343 } else {344 xpos = xpos + xdiff;345 }346 }, interval); 347}348function begLoop() {349 clearInterval(tID);350 xpos = 0*xdiff;351 ypos = 3*ydiff;352 const delay = 3 + Math.ceil(Math.random()*4);353 var i = 0;354 tID = setInterval ( () => {355 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 356 if (xpos == 0*xdiff) {357 xpos = 1*xdiff;358 } else {359 if (i < delay) {360 i++;361 xpos = 0*xdiff;362 } else {363 exitBeg();364 }365 }366 }, interval); 367}368function exitBeg() {369 clearInterval(tID);370 xpos = 0*xdiff;371 ypos = 4*ydiff;372 tID = setInterval ( () => {373 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 374 if (xpos == 2*xdiff) {375 idle();376 } else {377 xpos = xpos + xdiff;378 }379 }, interval); 380}381382// can be interrupted anytime383function flappy() {384 clearInterval(tID);385 xpos = 0*xdiff;386 ypos = 5*ydiff;387 tID = setInterval ( () => {388 seal.style.backgroundPosition = `-${xpos}px -${ypos}px`; 389 if (xpos == 2*xdiff) {390 xpos = 1*xdiff;391 } else {392 xpos = 2*xdiff;393 }394 }, interval); ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 console.log('Test started: ' + data.data.testId);5 wpt.getTestStatus(data.data.testId, function(err, data) {6 if (err) return console.error(err);7 console.log('Test status: ' + data.data.statusText);8 wpt.getTestResults(data.data.testId, function(err, data) {9 if (err) return console.error(err);10 console.log('First View: ' + data.data.average.firstView.TTFB);11 console.log('Repeat View: ' + data.data.average.repeatView.TTFB);12 });13 });14});

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.xpos = 100;2console.log(wpt.xpos);3wpt.ypos = 200;4console.log(wpt.ypos);5wpt.xpos = 1000;6console.log(wpt.xpos);7wpt.ypos = 2000;8console.log(wpt.ypos);9wpt.xpos = 10000;10console.log(wpt.xpos);11wpt.ypos = 20000;12console.log(wpt.ypos);13wpt.xpos = 100000;14console.log(wpt.xpos);15wpt.ypos = 200000;16console.log(wpt.ypos);17wpt.xpos = 1000000;18console.log(wpt.xpos);19wpt.ypos = 2000000;20console.log(wpt.ypos);21wpt.xpos = 10000000;22console.log(wpt.xpos);23wpt.ypos = 20000000;24console.log(wpt.ypos);25wpt.xpos = 100000000;26console.log(wpt.xpos);27wpt.ypos = 200000000;28console.log(wpt.ypos);29wpt.xpos = 1000000000;30console.log(wpt.xpos);31wpt.ypos = 2000000000;32console.log(wpt.ypos);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new wpt('API_KEY');3 if (err) {4 console.log("Error: " + err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10var wpt = new wpt('API_KEY');11 if (err) {12 console.log("Error: " + err);13 } else {14 console.log(data);15 }16});17var wpt = require('wpt');18var wpt = new wpt('API_KEY');19 if (err) {20 console.log("Error: " + err);21 } else {22 console.log(data);23 }24});25var wpt = require('wpt');26var wpt = new wpt('API_KEY');27 if (err) {28 console.log("Error: " + err);29 } else {30 console.log(data);31 }32});33var wpt = require('wpt');34var wpt = new wpt('API_KEY');35 if (err) {36 console.log("Error: " + err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42var wpt = new wpt('API_KEY');43 if (err) {44 console.log("Error: " + err);45 } else {46 console.log(data);47 }48});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var test = new wpt(options);5 if (err) return console.error(err);6 console.log(data);7 test.getTestStatus(data.data.testId, function(err, data) {8 if (err) return console.error(err);9 console.log(data);10 test.getTestResults(data.data.testId, function(err, data) {11 if (err) return console.error(err);12 console.log(data);13 });14 });15});16test.getTestResults(data.data.testId, function(err, data) {17 if (err) return console.error(err);18 console.log(data);19 });20test.getTestResults(data.data.testId, function(err, data) {21 if (err) return console.error(err);22 console.log(data);23 test.getTestStatus(data.data.testId, function(err, data) {24 if (err) return console.error(err);25 console.log(data);26 });27 });28test.getTestResults(data.data.testId, function(err, data) {29 if (err) return console.error(err);30 console.log(data);31 test.getTestStatus(data.data.testId, function(err, data) {32 if (err) return console.error(err);33 console.log(data);34 test.getTestResults(data.data.testId, function(err, data) {35 if (err) return console.error(err);36 console.log(data);37 });38 });39 });40test.getTestResults(data.data.testId, function(err, data) {41 if (err) return console.error(err);42 console.log(data);43 test.getTestStatus(data.data.testId, function(err, data) {44 if (err) return console.error(err);45 console.log(data);46 test.getTestResults(data.data.testId, function(err, data) {47 if (err) return console.error(err);48 console.log(data);49 test.getTestStatus(data.data.testId, function(err, data) {50 if (err) return console.error(err);51 console.log(data);52 });53 });54 });55 });56test.getTestResults(data.data.testId, function(err

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = new Wpt();2wpt.xpos();3var Wpt = function() {4 this.xpos = function() {5 }6}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new wpt(config.apiKey);3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10var wpt = new wpt(config.apiKey);11var test = wpt.testResults('1234567890', function(err, data) {12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 }17});18var wpt = require('wpt');19var wpt = new wpt(config.apiKey);20var test = wpt.testStatus('1234567890', function(err, data) {21 if (err) {22 console.log(err);23 } else {24 console.log(data);25 }26});27var wpt = require('wpt');28var wpt = new wpt(config.apiKey);29var test = wpt.testLocations(function(err, data) {30 if (err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36var wpt = require('wpt');37var wpt = new wpt(config.apiKey);38var test = wpt.getTesters(function(err, data) {39 if (err) {40 console.log(err);41 } else {42 console.log(data);43 }44});45var wpt = require('wpt');46var wpt = new wpt(config.apiKey);47var test = wpt.getLocations(function(err, data) {48 if (err) {49 console.log(err);50 } else {51 console.log(data);52 }53});

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