text: !function(){class t{constructor(t,n){this.x=t,this.y=n}}class n{points=[];constructor(n){this.maxX=n.width,this.minX=0,this.maxY=n.height,this.minY=0,this.rangeX=this.maxX-this.minX,this.rangeY=this.maxY-this.minY,this._currentPos=new t(this.rangeX/2,this.rangeY/2),this._currentOrientation=0,this.points.push(new t(this.rangeX/2,this.rangeY/2)),this.context=n.getContext("2d"),this.context.lineWidth=5,this.context.strokeStyle="#000000"}setToPrimaryColour(){this.context.strokeStyle="#000000"}setToSecondaryColour(){this.context.strokeStyle="#ff00ff"}async redraw(){const t=this.context;t.clearRect(this.minX,this.minY,this.rangeX,this.rangeY),this.setToPrimaryColour(),t.moveTo(this.rangeX/2,this.rangeY/2),t.beginPath();for(let n=0;n<this.points.length;n++){const s=this.points[n];t.lineTo(s.x,s.y)}t.stroke(),t.closePath();const n=this._currentPos;t.moveTo(n.x,n.y),t.beginPath(),t.arc(n.x,n.y,10,-.75*Math.PI-this._currentOrientation,-.25*Math.PI-this._currentOrientation),this.setToSecondaryColour(),t.stroke(),t.closePath()}move(n){const s=Math.sin(this._currentOrientation)*n;this._currentPos.x+=s;const e=Math.cos(this._currentOrientation)*n;this._currentPos.y+=e;const i=this.currentPos.x,r=this.currentPos.y;this.points.push(new t(i,r))}rotate(t){this._currentOrientation+=t/180*Math.PI}get currentPos(){return this._currentPos}reset(){this._currentPos=new t(this.rangeX/2,this.rangeY/2),this._currentOrientation=0,this.context.clearRect(this.minX,this.minY,this.rangeX,this.rangeY),this.points=[],this.points.push(new t(this.rangeX/2,this.rangeY/2)),this.redraw()}}let s;var e;let i;var r;(e=s||(s={})).FORWARD="F",e.BACKWARD="B",e.LEFT="L",e.RIGHT="R",e.REPEAT="RE",e.PROCEDURE_BEGIN="BE",e.BRACKET_OPEN="[",e.BRACKET_CLOSE="]",e.PROCEDURE_END="EN",e.PROCEDURE_TERMINATE="TE",e.IF="IF",e.CALC="CA",e.EQUALS="=",function(t){const n=Object.keys(s).map((t=>s[t]));t.isOfType=function(t){return-1!==n.indexOf(t)}}(s||(s={})),(r=i||(i={})).DIVIDE="/",r.SUBTRACT="-",r.ADD="+",r.MULTIPLY="*",function(t){const n=Object.keys(i).map((t=>i[t]));t.isOfType=function(t){return-1!==n.indexOf(t)}}(i||(i={}));class o{pointer=0;constructor(t){t&&(this.stack=t.trim().split(/\s|(?<=\[)|(?=\])/))}static from(t){const n=new o;return n.stack=t,n}static copy(t){const n=new o;return n.stack=[...t.stack],n}get isDone(){return this.pointer>this.stack.length-1}get currentElement(){return this.stack[this.pointer]}set currentElement(t){this.stack[this.pointer]=t}pop(){return this.stack[this.pointer++]}popUntil(t){const n=[];let s=this.pointer;for(;s<this.stack.length&&this.stack[s]!==t;)n.push(this.stack[s]),s++;return this.pointer=s,n}popCount(t,n=!1){let s;return n?s=this.stack.splice(this.pointer,t):(s=this.stack.slice(this.pointer,this.pointer+t),this.pointer+=t),s}putBack(t){this.stack.splice(this.pointer,0,...t)}insert(t,n=this.pointer){this.stack.splice(n,0,t)}removePrevious(){this.stack.splice(this.pointer-1,1)}terminate(){this.pointer=this.stack.length}reset(){this.pointer=0}}class a{constructor(t,n){this._stack=t,this._args=n}get stack(){return this._stack}get args(){return this._args}get argCount(){return this._args.length}}const c=t=>parseInt(t,10);class h{procedures={};constructor(t){this.myCanvas=t}handleAtomicAction(t,n){const e=c(n);switch(t){case s.FORWARD:this.myCanvas.move(-1*e);break;case s.BACKWARD:this.myCanvas.move(e);break;case s.LEFT:this.myCanvas.rotate(e);break;case s.RIGHT:this.myCanvas.rotate(-1*e)}}async ExecuteCommandStack(t){for(this.tokenStack=new o(t),this.preComputeMathExpressions(this.tokenStack);!this.tokenStack.isDone;)await this.handleCommand()}findEndingBracket(t,n){let e=0;const i=n.stack;for(let n=t+1;n<i.length;n++)if(i[n]===s.BRACKET_OPEN)e++;else if(i[n]===s.BRACKET_CLOSE){if(0==e)return n;e--}}computeCondition(t){const n=t[0],e=t[1],i=t[2];switch(e){case s.EQUALS:return n===i}return!1}computeExpression(t){const n=c(t[0]),s=t[1],e=c(t[2]);switch(s){case i.DIVIDE:return n/e;case i.ADD:return n+e;case i.MULTIPLY:return n*e;case i.SUBTRACT:return n-e}}preComputeMathExpressions(t){for(;!t.isDone;){if(t.pop()===s.CALC){const n=t.popCount(3,!0),s=this.computeExpression(n);isNaN(s)?t.putBack(n):(t.insert(String(s)),t.removePrevious())}}t.reset()}async handleCommand(t=this.tokenStack){const n=t.pop();if(n)if(s.isOfType(n))switch(n){case s.BACKWARD:case s.FORWARD:case s.LEFT:case s.RIGHT:const e=t.pop();"string"==typeof e&&this.handleAtomicAction(n,e);break;case s.REPEAT:const i=t.pop();if("string"==typeof i){const n=c(i)-1,s=t.pointer;t.stack[this.findEndingBracket(s,t)]={index:s,repeat:n}}break;case s.IF:{const n=t.popUntil(s.BRACKET_OPEN);this.computeCondition(n)||t.popUntil(s.BRACKET_CLOSE),t.pop();break}case s.PROCEDURE_BEGIN:{const n=t.pop(),e=c(t.pop()),i=t.popCount(e),r=t.popUntil(s.PROCEDURE_END),h=new a(o.from(r),i);this.procedures[n]=h;break}case s.PROCEDURE_TERMINATE:t.terminate()}else if(Object.keys(this.procedures).includes(n)){const s=this.procedures[n],e=t.popCount(s.argCount),i=o.copy(s.stack);let r=0;for(i.stack.forEach((t=>{if(s.args.includes(t)){const n=s.args.indexOf(t);i.stack[r]=e[n]}r++})),this.preComputeMathExpressions(i);!i.isDone;)await this.handleCommand(i)}else"string"!=typeof n&&(n.repeat>0?(t.pointer=n.index,n.repeat--):(t.pointer--,t.currentElement=s.BRACKET_CLOSE,t.pointer++))}}class p{points=[];constructor(n){this.svgCanvas=n,this.minX=0,this.minY=0,this.maxX=this.svgCanvas.clientWidth,this.maxY=this.svgCanvas.clientHeight,this.rangeX=this.maxX-this.minX,this.rangeY=this.maxY-this.minY,this._currentPos=new t(this.rangeX/2,this.rangeY/2),this._currentOrientation=0,this.points.push(new t(this.rangeX/2,this.rangeY/2))}get currentPos(){return this._currentPos}redraw(){const t=this.svgCanvas;t.innerHTML="";let n='<polyline points="';for(let t=0;t<this.points.length;t++){const s=this.points[t];n+=s.x.toString(),n+=",",n+=s.y.toString(),n+=" "}n+='" style="fill: none; stroke: black;stroke-width:3;" />',t.innerHTML+=n;const s=this._currentPos;let e='<polygon points="0,-10 -10,10 10,10" transform="translate(';e+=s.x.toString(),e+=", ",e+=s.y.toString(),e+=") rotate(",e+=(this._currentOrientation/Math.PI*180).toString(),e+=')" style="fill: none; stroke: #ff00ff;stroke-width:5" />',t.innerHTML+=e}move(n){const s=Math.sin(this._currentOrientation)*n;this._currentPos.x+=s;const e=Math.cos(this._currentOrientation)*n;this._currentPos.y+=e;const i=this.currentPos.x,r=this.currentPos.y;this.points.push(new t(i,r))}rotate(t){this._currentOrientation+=t/180*Math.PI}reset(){this._currentPos=new t(this.rangeX/2,this.rangeY/2),this._currentOrientation=0,this.points=[],this.points.push(new t(this.rangeX/2,this.rangeY/2)),this.redraw()}}console.log("merdas");const u=document.getElementById("execution-form"),l=document.getElementById("command-input"),m=document.getElementById("canvas"),E=document.getElementsByTagName("svg")[0],g=document.getElementById("clear-button"),C=document.getElementById("switch-canvas"),k=document.getElementsByClassName("example-button");if(null!==u&&null!==l&&null!==m&&null!==E&&null!==g){console.log("merdas"),E.style.display="none";let t=new n(m);t.redraw(),C.onclick=s=>{t instanceof n?(m.style.display="none",E.style.display="initial",C.innerText="Switch canvas mode, current: SVG",t=new p(E)):(E.style.display="none",m.style.display="initial",C.innerText="Switch canvas mode, current: CANVAS",t=new n(m)),t.redraw()},u.onsubmit=n=>{n.preventDefault(),setTimeout((async()=>{const n=l.value,s=new h(t);await s.ExecuteCommandStack(n),await t.redraw()}),50)},g.onclick=n=>{n.preventDefault(),t.reset()};const s=["\nF 100\nR 90\nF 100\nR 90\nF 100\nR 90\nF 100\n        ","\nRE 5 [F 100 R 72]\n        ","\nRE 9 [F 100 R 40]\n        ","\nBE koch 2 :st :a\n    IF :st = 0 [ F :a TE ]\n    koch CA :st - 1 CA :a / 3 R 60\n    koch CA :st - 1 CA :a / 3 L 120\n    koch CA :st - 1 CA :a / 3 R 60\n    koch CA :st - 1 CA :a / 3\nEN\n\n\nBE star 2 :st :a\n    RE 3 [ koch :st :a L 120]\nEN\n\nstar 5 300\n        ","\nBE troj 1 :a\n    RE 3 [F :a R 120]\nEN\n\nBE sierp 2 :n :a\n    IF :n = 0 [troj :a TE]\n    troj :a\n\n    sierp CA :n - 1 CA :a / 2\n    F CA :a / 2\n    sierp CA :n - 1 CA :a / 2\n    R 60\n    F CA :a / 2 R 60\n\n    sierp CA :n - 1 CA :a / 2\n    L 60 B CA :a / 2\n    L 60 B CA :a / 2\nEN\n\nBE sierpinski 2 :n :a\n    R 30\n    sierp :n :a\nEN\n\nsierpinski 5 300\n\n        "];for(let t=0;t<k.length;t++){const n=k[t],e=s[t];n.onclick=t=>{l.value=e}}}}();
  //# sourceMappingURL=index.8185b07c.js.map
  