0x4dae7e6c…ca59sent to0xd9e4f99f…039b·#17,582,837·view on Etherscan
const canvas=document.getElementById('snex');const ctx=canvas.getContext('2d');const snake=[];const segmentSize=50;const segmentSpacing=2;const snakeSpeed=100;const followDelay=8;let canvasWidth=0;let canvasHeight=0;let startedAt=0;let fgHeartbeat=250;const initialY=canvasHeight/2-(segmentSize+segmentSpacing)*Math.floor(snakeLength/2);const palette=['#00a5e3','#8dd7bf','#ff96c5','#ff5768','#ffbf65','#fc6238','#ffd872','#f2d4cc','#e77577','#6c88c4','#c05780','#ff828b','#e7c582','#00b0ba','#0065a2','#00cdac','#ff6f68','#ffdacc','#ff60a8','#cff800','#ff5c77','#4dd091','#ffec59','#ffa23a','#74737a','#ffffff','#292929'];function paramsInitialization(){for(let i=0;i<snakeLength;i+=1){const x=canvasWidth/2;const y=initialY-(segmentSize+segmentSpacing)*i;snake.unshift({x,y,delay:i*followDelay})}startedAt=Date.now();canvasWidth=canvas.width=window.innerWidth;canvasHeight=canvas.height=window.innerHeight}function heartbeat(){return new Promise(resolve=>{const tail=snake[0];const nextTail=snake[1];const tailDirectionX=nextTail.x-tail.x;const tailDirectionY=nextTail.y-tail.y;tail.x+=tailDirectionX/followDelay;tail.y+=tailDirectionY/followDelay;const head=snake[snake.length-1];const targetX=head.x+(Math.random()*2-1)*(canvasWidth/4);const targetY=head.y+(Math.random()*2-1)*(canvasHeight/4);const dx=targetX-head.x;const dy=targetY-head.y;const distance=Math.sqrt(dx*dx+dy*dy);const stepSize=snakeSpeed/followDelay;const stepX=(dx/distance)*stepSize;const stepY=(dy/distance)*stepSize;head.x+=stepX;head.y+=stepY;head.x=Math.max(segmentSize/2,Math.min(canvasWidth-segmentSize/2,head.x));head.y=Math.max(segmentSize/2,Math.min(canvasHeight-segmentSize/2,head.y));for(let i=1;i<snake.length-1;i+=1){const segment=snake[i];const nextSegment=snake[i+1];const directionX=nextSegment.x-segment.x;const directionY=nextSegment.y-segment.y;segment.x+=directionX/followDelay;segment.y+=directionY/followDelay}ctx.clearRect(0,0,canvasWidth,canvasHeight);let colIndex=0;let colLength=tokenColors.length;for(let i=0;i<(snakeLength-1);i+=1){const segment=snake[i];const size=segmentSize;if(colIndex==(colLength-0)){colIndex=0;boolDebugColors=false}let colDef=palette[tokenColors[colIndex]];ctx.beginPath();ctx.arc(segment.x,segment.y,size/2,0,Math.PI*2);ctx.fillStyle=colDef;ctx.fill();ctx.closePath();colIndex+=1}resolve(0)})}async function update(){const resolve=await heartbeat();requestAnimationFrame(update)}async function main(){paramsInitialization();if(snakeLength>0){update()}}main();