UNPKG

turtle-canvas

Version:
1 lines 2.11 kB
(function(b){function a(b,d){if({}.hasOwnProperty.call(a.cache,b))return a.cache[b];var e=a.resolve(b);if(!e)throw new Error('Failed to resolve module '+b);var c={id:b,require:a,filename:b,exports:{},loaded:!1,parent:d,children:[]};d&&d.children.push(c);var f=b.slice(0,b.lastIndexOf('/')+1);return a.cache[b]=c.exports,e.call(c.exports,c,c.exports,f,b),c.loaded=!0,a.cache[b]=c.exports}a.modules={},a.cache={},a.resolve=function(b){return{}.hasOwnProperty.call(a.modules,b)?a.modules[b]:void 0},a.define=function(b,c){a.modules[b]=c};var c=function(a){return a='/',{title:'browser',version:'v0.10.35',browser:!0,env:{},argv:[],nextTick:b.setImmediate||function(a){setTimeout(a,0)},cwd:function(){return a},chdir:function(b){a=b}}}();a.define('/lib/turtle-canvas.js',function(b,c,d,e){'use strict';var a=function(a){this.dir=0,this.x=0,this.y=0,this.draw=!0,this.cvs=document.getElementById(a)||a,this.ctx=this.cvs.getContext('2d'),this.states=[],this.ctx.beginPath()};a.prototype.penup=function(){return this.draw=!1,this},a.prototype.pendown=function(){return this.draw=!0,this},a.prototype.moveTo=function(a,b){return this.x=a,this.y=b,this.ctx.beginPath(),this.ctx.moveTo(this.x,this.y),this},a.prototype.forward=function(a){return this.x+=a*Math.cos(this.dir),this.y+=a*Math.sin(this.dir),this.draw?this.ctx.lineTo(this.x,this.y):this.ctx.moveTo(this.x,this.y),this},a.prototype.back=function(a){return this.x+=a*Math.cos(this.dir-Math.PI),this.y+=a*Math.sin(this.dir-Math.PI),this.draw?this.ctx.lineTo(this.x,this.y):this.ctx.moveTo(this.x,this.y),this},a.prototype.left=function(a){return this.dir-=a*(Math.PI/180),this},a.prototype.right=function(a){return this.dir+=a*(Math.PI/180),this},a.prototype.save=function(){return this.states.push({x:this.x,y:this.y,dir:this.dir}),this},a.prototype.restore=function(){var a=this.states.pop();return this.x=a?a.x:this.x,this.y=a?a.y:this.y,this.dir=a?a.dir:this.dir,this},a.prototype.fill=function(){return this.ctx.fill(),this},a.prototype.stroke=function(){return this.ctx.stroke(),this},b.exports=a}),b.TURTLE=a('/lib/turtle-canvas.js')}.call(this,this))