const c=["30","20","51","01","62","63","03","64","54","44","34","24","14"],g=(u,t)=>{const e=`${u}${t}`;return c.includes(e)};class v{constructor(t,e,i,s){this.rows=t,this.cols=e,this.pixelSize=i,this.interRoundDelay=s,this.mouseIsDown=!1,this.paused=!1,this.intervalId=null,this.grid=[];for(let r=0;r{this.advanceRound(),this.repaint()},this.interRoundDelay))}stop(){this.intervalId&&(clearInterval(this.intervalId),this.intervalId=null)}getNeighbors(t,e){let i=[];for(let s=t-1;s<=t+1;s++)for(let l=e-1;l<=e+1;l++)s===t&&l===e||this.grid[s]&&this.grid[s][l]&&i.push(this.grid[s][l]);return i}advanceRound(){if(!this.mouseIsDown){for(let t=0;t{i.forEach(s=>{s.lifeStyle=t,s.deathStyle=e,s.forceRepaint=!0})})}setRandomPixelColors(){let t=randomInteger(1,360),e=t+randomInteger(90,270)%360;this.setPixelColors(`hsl(${t}, 100%, 60%)`,`hsl(${e}, 100%, 60%)`)}applyColorsWithin(t,e,i,s,l,o){for(let r=t;r{e.forEach(i=>{i.previousState=i.alive,i.alive=Math.random(){l.forEach(o=>{o.underpopulation=t,o.overpopulation=e,o.reproductionMin=i,o.reproductionMax=s})})}setYinYangMode(){for(let t=0;t{if(t.preventDefault(),this.mouseIsDown){let e,i;if(t.touches){let s=t.target.getBoundingClientRect();e=Math.floor((t.touches[0].pageX-s.left)/this.pixelSize),i=Math.floor((t.touches[0].pageY-s.top)/this.pixelSize)}else e=Math.floor(t.offsetX/this.pixelSize),i=Math.floor(t.offsetY/this.pixelSize);this.grid[i][e].handleClick(),this.paintPixel(i,e)}}),bindMultipleEventListener(this.canvas,["mousedown","touchstart"],t=>{t.preventDefault(),t.target.getBoundingClientRect();let e,i;if(t.touches){let s=t.target.getBoundingClientRect();e=Math.floor((t.touches[0].pageX-s.left)/this.pixelSize),i=Math.floor((t.touches[0].pageY-s.top)/this.pixelSize)}else e=Math.floor(t.offsetX/this.pixelSize),i=Math.floor(t.offsetY/this.pixelSize);this.grid[i][e].handleClick(),this.paintPixel(i,e),this.mouseIsDown=!0}),bindMultipleEventListener(this.canvas,["mouseup","touchend"],t=>{t.preventDefault(),this.mouseIsDown=!1})}}class S{constructor(t){this.alive=t,this.lifeStyle="#000000",this.deathStyle="#F5FFFA",this.underpopulation=2,this.overpopulation=3,this.reproductionMin=3,this.reproductionMax=3,this.neighbors=[],this.nextState=null,this.previousState=null,this.forceRepaint=!0,this.reproductionMaxthis.overpopulation?e=!1:!e&&t>=this.reproductionMin&&t<=this.reproductionMax&&(e=!0),this.nextState=e}update(){this.previousState=this.alive,this.alive=this.nextState,this.nextState=null}handleClick(){this.alive=!0}setPaintStyles(t){t.fillStyle=this.alive?this.lifeStyle:this.deathStyle}}let d=new v(8,46,10,250);document.getElementById("board")?.append(d.canvas);d.start();