/* FUNCTIONS */ /* Choose random item from list. */ function choose(n){ return n[Math.floor(Math.random()*(n.length))]; } /* Choose random hex color, brightness range optional. */ function newHex(a,b){ if(typeof a=='undefined'){a=0;} if(typeof b=='undefined'){b=16;} var digits=['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']; var hex='#'; for(var i=0;i<6;i++){ hex+=choose(digits.slice(a,b)); } return hex; } /* Choose random rgba color with given opacity, brightness range optional. */ function newByte(o,a,b){ if(typeof a=='undefined'){a=0;} if(typeof b=='undefined'){b=256;} var digits=[]; for(var i=0;i<256;i++){ digits.push(i); } var byte='rgba('; for(i=0;i<3;i++){ byte+=choose(digits.slice(a,b))+','; } byte+=o+')'; return byte; } /* Generate an obstacle with a specified distribution. */ function newBlock(p){ /* Group group[i] has blocks[i]. */ var group=[0,1,2,2,3,3,3,3,4,4,5,5]; var sample=[]; for(var i=0;i0 && x0 && y3){ if(lvl==1){ span--; lvl=span-2; } else{ lvl--; } } } /* End current gameboard. */ setTimeout(show,10000*speed); setTimeout(newGame,20000*speed); } } /* Retrieves an inner block by its (x,y) coordinates. */ function getByXY(x,y){ for(var i=0;i(Math.pow(span,2))/2){ break; } */ if(goals[edges[i].end.steps]==undefined){ goals[edges[i].end.steps]=[edges[i]]; } else{ goals[edges[i].end.steps].push(edges[i]); } } key=Object.keys(goals); return choose(goals[key[key.length-1]]); /* return choose(goals[key[Math.floor(key.length*lvl/(span-1))]]); */ } /* Make edges clickable. */ function enable(){ for(var i=0;i