diff --git a/components/Graphic.jsx b/components/Graphic.jsx index 08cf2555..46686f22 100644 --- a/components/Graphic.jsx +++ b/components/Graphic.jsx @@ -113,13 +113,13 @@ var Graphic = React.createClass({ - reset: function() { - this.refs.canvas.width = this.refs.canvas.width; + reset: function() { + this.refs.canvas.width = this.refs.canvas.width; this.ctx.strokeStyle = "black"; this.ctx.lineWidth = 1; - this.ctx.fillStyle = "none"; + this.ctx.fillStyle = "none"; this.offset = {x:0, y:0}; - }, + }, getPanelWidth: function() { return defaultWidth; @@ -151,9 +151,9 @@ var Graphic = React.createClass({ this.offset = f; }, - setColor: function(c) { - this.ctx.strokeStyle = c; - }, + setColor: function(c) { + this.ctx.strokeStyle = c; + }, getColor: function() { return this.ctx.strokeStyle || "black"; @@ -163,48 +163,48 @@ var Graphic = React.createClass({ this.ctx.lineWidth = c; }, - noColor: function(c) { - this.ctx.strokeStyle = "transparent"; - }, + noColor: function(c) { + this.ctx.strokeStyle = "transparent"; + }, - setRandomColor: function() { - var r = ((205*Math.random())|0), - g = ((155*Math.random())|0), - b = ((255*Math.random())|0); - this.ctx.strokeStyle = "rgb("+r+","+g+","+b+")"; - }, + setRandomColor: function() { + var r = ((205*Math.random())|0), + g = ((155*Math.random())|0), + b = ((255*Math.random())|0); + this.ctx.strokeStyle = "rgb("+r+","+g+","+b+")"; + }, - setRandomFill: function(a) { - a = (typeof a === "undefined") ? 1 : a; - var r = ((255*Math.random())|0), - g = ((255*Math.random())|0), - b = ((255*Math.random())|0); - this.ctx.fillStyle = "rgba("+r+","+g+","+b+","+a+")"; - }, + setRandomFill: function(a) { + a = (typeof a === "undefined") ? 1 : a; + var r = ((255*Math.random())|0), + g = ((255*Math.random())|0), + b = ((255*Math.random())|0); + this.ctx.fillStyle = "rgba("+r+","+g+","+b+","+a+")"; + }, - setFill: function(c) { - this.ctx.fillStyle = c; - }, + setFill: function(c) { + this.ctx.fillStyle = c; + }, getFill: function() { return this.ctx.fillStyle || "transparent"; }, - noFill: function() { - this.ctx.fillStyle = "transparent"; - }, + noFill: function() { + this.ctx.fillStyle = "transparent"; + }, - drawSkeleton: function(curve, offset) { - offset = offset || { x:0, y:0 }; - var pts = curve.points; - this.ctx.strokeStyle = "lightgrey"; - this.drawLine(pts[0], pts[1], offset); - if(pts.length === 3) { this.drawLine(pts[1], pts[2], offset); } - else {this.drawLine(pts[2], pts[3], offset); } - this.ctx.strokeStyle = "black"; - this.drawPoints(pts, offset); + drawSkeleton: function(curve, offset) { + offset = offset || { x:0, y:0 }; + var pts = curve.points; + this.ctx.strokeStyle = "lightgrey"; + this.drawLine(pts[0], pts[1], offset); + if(pts.length === 3) { this.drawLine(pts[1], pts[2], offset); } + else {this.drawLine(pts[2], pts[3], offset); } + this.ctx.strokeStyle = "black"; + this.drawPoints(pts, offset); this.drawCoordinates(curve, offset); - }, + }, drawCoordinates: function(curve, offset) { offset = offset || { x:0, y:0 }; @@ -228,131 +228,131 @@ var Graphic = React.createClass({ this.drawLine(p, plast, offset); }, - drawCurve: function(curve, offset) { - offset = offset || { x:0, y:0 }; - var ox = offset.x + this.offset.x; - var oy = offset.y + this.offset.y; - this.ctx.beginPath(); - var p = curve.points, i; - this.ctx.moveTo(p[0].x + ox, p[0].y + oy); - if(p.length === 3) { - this.ctx.quadraticCurveTo( - p[1].x + ox, p[1].y + oy, - p[2].x + ox, p[2].y + oy - ); - } - if(p.length === 4) { - this.ctx.bezierCurveTo( - p[1].x + ox, p[1].y + oy, - p[2].x + ox, p[2].y + oy, - p[3].x + ox, p[3].y + oy - ); - } - this.ctx.stroke(); - this.ctx.closePath(); - }, + drawCurve: function(curve, offset) { + offset = offset || { x:0, y:0 }; + var ox = offset.x + this.offset.x; + var oy = offset.y + this.offset.y; + this.ctx.beginPath(); + var p = curve.points, i; + this.ctx.moveTo(p[0].x + ox, p[0].y + oy); + if(p.length === 3) { + this.ctx.quadraticCurveTo( + p[1].x + ox, p[1].y + oy, + p[2].x + ox, p[2].y + oy + ); + } + if(p.length === 4) { + this.ctx.bezierCurveTo( + p[1].x + ox, p[1].y + oy, + p[2].x + ox, p[2].y + oy, + p[3].x + ox, p[3].y + oy + ); + } + this.ctx.stroke(); + this.ctx.closePath(); + }, - drawLine: function(p1, p2, offset) { - offset = offset || { x:0, y:0 }; - var ox = offset.x + this.offset.x; - var oy = offset.y + this.offset.y; - this.ctx.beginPath(); - this.ctx.moveTo(p1.x + ox,p1.y + oy); - this.ctx.lineTo(p2.x + ox,p2.y + oy); - this.ctx.stroke(); - }, + drawLine: function(p1, p2, offset) { + offset = offset || { x:0, y:0 }; + var ox = offset.x + this.offset.x; + var oy = offset.y + this.offset.y; + this.ctx.beginPath(); + this.ctx.moveTo(p1.x + ox,p1.y + oy); + this.ctx.lineTo(p2.x + ox,p2.y + oy); + this.ctx.stroke(); + }, - drawPoint: function(p, offset) { + drawPoint: function(p, offset) { this.drawCircle(p, 1, offset); - }, + }, - drawPoints: function(points, offset) { - offset = offset || { x:0, y:0 }; - points.forEach(function(p) { - this.drawCircle(p, 3, offset); - }.bind(this)); - }, + drawPoints: function(points, offset) { + offset = offset || { x:0, y:0 }; + points.forEach(function(p) { + this.drawCircle(p, 3, offset); + }.bind(this)); + }, - drawArc: function(p, offset) { - offset = offset || { x:0, y:0 }; + drawArc: function(p, offset) { + offset = offset || { x:0, y:0 }; var ox = offset.x + this.offset.x; var oy = offset.y + this.offset.y; - this.ctx.beginPath(); - this.ctx.moveTo(p.x + ox, p.y + oy); - this.ctx.arc(p.x + ox, p.y + oy, p.r, p.s, p.e); - this.ctx.lineTo(p.x + ox, p.y + oy); - this.ctx.fill(); - this.ctx.stroke(); - }, + this.ctx.beginPath(); + this.ctx.moveTo(p.x + ox, p.y + oy); + this.ctx.arc(p.x + ox, p.y + oy, p.r, p.s, p.e); + this.ctx.lineTo(p.x + ox, p.y + oy); + this.ctx.fill(); + this.ctx.stroke(); + }, - drawCircle: function(p, r, offset) { - offset = offset || { x:0, y:0 }; + drawCircle: function(p, r, offset) { + offset = offset || { x:0, y:0 }; var ox = offset.x + this.offset.x; var oy = offset.y + this.offset.y; - this.ctx.beginPath(); - this.ctx.arc(p.x + ox, p.y + oy, r, 0, 2*Math.PI); - this.ctx.stroke(); - }, + this.ctx.beginPath(); + this.ctx.arc(p.x + ox, p.y + oy, r, 0, 2*Math.PI); + this.ctx.stroke(); + }, - drawbbox: function(bbox, offset) { - offset = offset || { x:0, y:0 }; + drawbbox: function(bbox, offset) { + offset = offset || { x:0, y:0 }; var ox = offset.x + this.offset.x; var oy = offset.y + this.offset.y; - this.ctx.beginPath(); - this.ctx.moveTo(bbox.x.min + ox, bbox.y.min + oy); - this.ctx.lineTo(bbox.x.min + ox, bbox.y.max + oy); - this.ctx.lineTo(bbox.x.max + ox, bbox.y.max + oy); - this.ctx.lineTo(bbox.x.max + ox, bbox.y.min + oy); - this.ctx.closePath(); - this.ctx.stroke(); - }, + this.ctx.beginPath(); + this.ctx.moveTo(bbox.x.min + ox, bbox.y.min + oy); + this.ctx.lineTo(bbox.x.min + ox, bbox.y.max + oy); + this.ctx.lineTo(bbox.x.max + ox, bbox.y.max + oy); + this.ctx.lineTo(bbox.x.max + ox, bbox.y.min + oy); + this.ctx.closePath(); + this.ctx.stroke(); + }, - drawShape: function(shape, offset) { - offset = offset || { x:0, y:0 }; + drawShape: function(shape, offset) { + offset = offset || { x:0, y:0 }; var ox = offset.x + this.offset.x; var oy = offset.y + this.offset.y; var order = shape.forward.points.length - 1; - this.ctx.beginPath(); - this.ctx.moveTo(ox + shape.startcap.points[0].x, oy + shape.startcap.points[0].y); - this.ctx.lineTo(ox + shape.startcap.points[3].x, oy + shape.startcap.points[3].y); - if(order === 3) { - this.ctx.bezierCurveTo( - ox + shape.forward.points[1].x, oy + shape.forward.points[1].y, - ox + shape.forward.points[2].x, oy + shape.forward.points[2].y, - ox + shape.forward.points[3].x, oy + shape.forward.points[3].y - ); - } else { - this.ctx.quadraticCurveTo( - ox + shape.forward.points[1].x, oy + shape.forward.points[1].y, - ox + shape.forward.points[2].x, oy + shape.forward.points[2].y - ); - } - this.ctx.lineTo(ox + shape.endcap.points[3].x, oy + shape.endcap.points[3].y); - if(order === 3) { - this.ctx.bezierCurveTo( - ox + shape.back.points[1].x, oy + shape.back.points[1].y, - ox + shape.back.points[2].x, oy + shape.back.points[2].y, - ox + shape.back.points[3].x, oy + shape.back.points[3].y - ); - } else { - this.ctx.quadraticCurveTo( - ox + shape.back.points[1].x, oy + shape.back.points[1].y, - ox + shape.back.points[2].x, oy + shape.back.points[2].y - ); - } - this.ctx.closePath(); - this.ctx.fill(); - this.ctx.stroke(); - }, + this.ctx.beginPath(); + this.ctx.moveTo(ox + shape.startcap.points[0].x, oy + shape.startcap.points[0].y); + this.ctx.lineTo(ox + shape.startcap.points[3].x, oy + shape.startcap.points[3].y); + if(order === 3) { + this.ctx.bezierCurveTo( + ox + shape.forward.points[1].x, oy + shape.forward.points[1].y, + ox + shape.forward.points[2].x, oy + shape.forward.points[2].y, + ox + shape.forward.points[3].x, oy + shape.forward.points[3].y + ); + } else { + this.ctx.quadraticCurveTo( + ox + shape.forward.points[1].x, oy + shape.forward.points[1].y, + ox + shape.forward.points[2].x, oy + shape.forward.points[2].y + ); + } + this.ctx.lineTo(ox + shape.endcap.points[3].x, oy + shape.endcap.points[3].y); + if(order === 3) { + this.ctx.bezierCurveTo( + ox + shape.back.points[1].x, oy + shape.back.points[1].y, + ox + shape.back.points[2].x, oy + shape.back.points[2].y, + ox + shape.back.points[3].x, oy + shape.back.points[3].y + ); + } else { + this.ctx.quadraticCurveTo( + ox + shape.back.points[1].x, oy + shape.back.points[1].y, + ox + shape.back.points[2].x, oy + shape.back.points[2].y + ); + } + this.ctx.closePath(); + this.ctx.fill(); + this.ctx.stroke(); + }, - text: function(text, offset) { - offset = offset || { x:0, y:0 }; + text: function(text, offset) { + offset = offset || { x:0, y:0 }; if (this.offset) { offset.x += this.offset.x; offset.y += this.offset.y; } - this.ctx.fillText(text, offset.x, offset.y); - } + this.ctx.fillText(text, offset.x, offset.y); + } }); module.exports = Graphic; diff --git a/components/sections/explanation/code.txt b/components/sections/explanation/code.txt deleted file mode 100644 index 121ca3e6..00000000 --- a/components/sections/explanation/code.txt +++ /dev/null @@ -1,38 +0,0 @@ -/* -void drawFunction() { - pushStyle(); - translate(dim/2,dim/2); - stroke(150); - line(-dim,0,dim,0); - line(0,-dim,0,dim); - - stroke(0); - float r = dim/3; - for(float t=0; t<=5; t+=0.01) { - point(r * sin(t), -r * cos(t)); - } - - fill(0); - - for(float i=0; i<=5; i+=0.5) { - ellipse(r * sin(i), -r * cos(i),3,3); - } - - textAlign(CENTER,CENTER); - - float x=0, y=-r*1.2, nx, ny; - for(float i=0; i<=5; i+=0.5) { - nx = x*cos(i) - y*sin(i); - ny = x*sin(i) + y*cos(i); - text("t="+i, nx, ny); - } - - fill(150); - text("0,0",-10,10); - text("1",r+10,15); - text("-1",-10,r+10); - text("-1",-r-10,15); - text("1",-10,-r-10); - popStyle(); - } - */