var canvas,ctx,pixels,editor,width=256,height=256,mouseX=0,mouseY=0,funct=function(){};function parse(){var t=document.getElementById("output").value;try{funct=new Function("i","t","x","y","mx","my","return "+t)}catch(t){console.log(t)}}function genImg(){try{for(var t=Date.now(),e=0;e<width*height;e++){var n=funct(e,t,e%width,Math.floor(e/width),mouseX,mouseY);Math.floor(Math.floor(n)/16777216);pixels.data[4*e+0]=n>>16&255,pixels.data[4*e+1]=n>>8&255,pixels.data[4*e+2]=255&n,pixels.data[4*e+3]=256}ctx.putImageData(pixels,0,0)}catch(t){console.log(t)}window.requestAnimationFrame(genImg)}window.addEventListener("load",(function(){(editor=ace.edit("input")).setTheme("ace/theme/xcode"),editor.session.setMode("ace/mode/javascript"),(canvas=document.getElementById("canvas")).width=width,canvas.height=height,canvas.style.zoom=2,ctx=canvas.getContext("2d"),pixels=ctx.createImageData(width,height),compile(),window.addEventListener("mousemove",(function(t){var e=canvas.getBoundingClientRect();mouseX=(t.pageX-2*e.x)/2,mouseY=(t.pageY-2*e.y)/2})),editor.session.on("change",compile),genImg()}));var lib={};function compile(){var t=editor.getValue();try{var e=new Function("i","t","x","y","mx","my",t);document.getElementById("output").value=e("i","t","x","y","mx","my"),parse()}catch(t){document.getElementById("output").value=t}}lib.mod=function(t,e){return`((((${t})%(${e}))+(${e}))%(${e}))`},lib.shortFloor=function(t){return`(${t}|0)`},lib.floor=function(t){return`(${t}-${lib.mod(t,1)})`},lib.ceil=function(t){return`((${t}+1)|0)`},lib.round=function(t){return`((${t}+0.5)|0)`},lib.negative=function(t){return`((${t})>>>31)`},lib.isZero=function(t){return`((${t})/(${t})^1)`},lib.lt=function(t,e){return lib.negative(lib.floor(`((${t})-(${e}))`))},lib.shortLt=function(t,e){return lib.negative(`(${t})-(${e})`)},lib.lte=function(t,e){return`(${lib.lt(t,e)}|${lib.eq(t,e)})`},lib.gt=function(t,e){return lib.negative(lib.floor(`((${e})-(${t}))`))},lib.shortGt=function(t,e){return lib.negative(`(${e})-(${t})`)},lib.gte=function(t,e){return`(${lib.gt(t,e)}|${lib.eq(t,e)})`},lib.eq=function(t,e){return lib.isZero(`(${t})-(${e})`)},lib.lerp=function(t,e,n){return`((1-${n})*(${t})+(${n})*(${e}))`},lib.checkerboard=function(t,e,n){return`((${lib.floor(`${t}/${n}`)}+(${lib.floor(`${e}/${n}`)}))%2)`},lib.triangle=function(t,e,n,i){var o=[`(${i[0]}-${e[0]})`,`(${i[1]}-${e[1]})`],$=[`(${n[0]}-${e[0]})`,`(${n[1]}-${e[1]})`],r=[`(${t[0]}-${e[0]})`,`(${t[1]}-${e[1]})`],l=`((${o[0]}**2)+(${o[1]}**2))`,u=`((${o[0]}*${$[0]})+(${o[1]}*${$[1]}))`,a=`((${o[0]}*${r[0]})+(${o[1]}*${r[1]}))`,c=`((${$[0]}**2)+(${$[1]}**2))`,s=`((${$[0]}*${r[0]})+(${$[1]}*${r[1]}))`,d=`(${l}*${c}-${u}**2)`,b=`((${c}*${a}-${u}*${s})/${d})`,m=`((${l}*${s}-${u}*${a})/${d})`;return`(${lib.gte(b,0)} & ${lib.gte(m,0)} & ${lib.lt(`${b}+${m}`,1)})`},lib.circle=function(t,e,n){return`(${lib.lt(`(x-${t})**2+(y-${e})**2`,`(${n})**2`)})`},lib.fromRgb=function(t,e,n){return`(((${t}<<16)+(${e}<<8))+${n})`};