From ded226c16fb7e82b0b61ec0670b66fc262f6ad8a Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 29 Dec 2016 09:57:53 -0700 Subject: [PATCH] Improved stencil --- scripts/filters/filter.js | 4 +-- scripts/filters/stencil.js | 71 +++++++++++++++++++------------------- scripts/modules/render.js | 10 ++++-- 3 files changed, 45 insertions(+), 40 deletions(-) diff --git a/scripts/filters/filter.js b/scripts/filters/filter.js index ffafc6e..15a4781 100644 --- a/scripts/filters/filter.js +++ b/scripts/filters/filter.js @@ -3,12 +3,12 @@ function Filter() this.name = "Unknown"; this.parameters = []; - this.render = function(p) + this.render = function(cmd) { console.log("render: Nothing here."); } - this.preview = function(p) + this.preview = function(cmd) { console.log("render: Nothing here."); } diff --git a/scripts/filters/stencil.js b/scripts/filters/stencil.js index 3def11f..2ec56a0 100644 --- a/scripts/filters/stencil.js +++ b/scripts/filters/stencil.js @@ -2,39 +2,40 @@ function Filter_Stencil() { Filter.call(this); - this.render = function() + this.render = function(cmd) { - this.draw(); + this.draw(this.context(),cmd.angle() ? cmd.angle().degrees : 20); + ronin.overlay.clear(); } - this.preview = function() + this.preview = function(cmd) { - + ronin.overlay.clear(); + this.draw(ronin.overlay.context(),cmd.angle() ? cmd.angle().degrees : 20); } - this.draw = function() + this.draw = function(context = this.context(), angle = 20) { - var context = this.context(); var w = ronin.surface.size.width; var h = ronin.surface.size.height; context.translate(w/2,h/2); - context.rotate(20*Math.PI/180); + context.rotate(angle*Math.PI/180); - this.line(-w,0,w,0); + this.line(context,-w,0,w,0); - this.line(w*0.4,-h,w*0.4,h); - this.line(-w*0.4,-h,-w*0.4,h); + this.line(context,w*0.4,-h,w*0.4,h); + this.line(context,-w*0.4,-h,-w*0.4,h); - this.line(-w,h*0.25,w,h*0.25); - this.line(-w,-h*0.25,w,-h*0.25); + this.line(context,-w,h*0.25,w,h*0.25); + this.line(context,-w,-h*0.25,w,-h*0.25); - this.line(w*0.1,0,w*0.1,h); - this.line(-w*0.1,0,-w*0.1,-h); + this.line(context,w*0.1,0,w*0.1,h); + this.line(context,-w*0.1,0,-w*0.1,-h); - this.circle(w*0.4,-h*0.25,w*0.05,1,1.5); - this.circle(-w*0.4,h*0.25,w*0.05,0,0.5); + this.circle(context,w*0.4,-h*0.25,w*0.05,1,1.5); + this.circle(context,-w*0.4,h*0.25,w*0.05,0,0.5); context.font = "5px Arial"; context.fillStyle = "#000000"; @@ -44,32 +45,30 @@ function Filter_Stencil() context.fillStyle = "#000000"; context.fillText("GRID",(-w*0.4)-20,-10); - context.rotate(-20*Math.PI/180); + context.rotate(-angle*Math.PI/180); context.translate(-w/2,-h/2); } - this.line = function(x1,x2,y1,y2) + this.line = function(context,x1,x2,y1,y2) { - this.context().beginPath(); - - this.context().moveTo(x1,x2); - this.context().lineTo(y1,y2); - - this.context().lineCap="round"; - this.context().lineWidth = 0.5; - this.context().strokeStyle = "#000"; - this.context().stroke(); - this.context().closePath(); + context.beginPath(); + context.moveTo(x1,x2); + context.lineTo(y1,y2); + context.lineCap="round"; + context.lineWidth = 0.5; + context.strokeStyle = "#000"; + context.stroke(); + context.closePath(); } - this.circle = function(x,y,r,c1,c2) + this.circle = function(context,x,y,r,c1,c2) { - this.context().beginPath(); - this.context().arc(x,y,r,c1*Math.PI,c2*Math.PI); - this.context().lineCap="round"; - this.context().lineWidth = 0.5; - this.context().strokeStyle = "#000"; - this.context().stroke(); - this.context().closePath(); + context.beginPath(); + context.arc(x,y,r,c1*Math.PI,c2*Math.PI); + context.lineCap="round"; + context.lineWidth = 0.5; + context.strokeStyle = "#000"; + context.stroke(); + context.closePath(); } } \ No newline at end of file diff --git a/scripts/modules/render.js b/scripts/modules/render.js index 4f14120..2d95740 100644 --- a/scripts/modules/render.js +++ b/scripts/modules/render.js @@ -15,12 +15,18 @@ function Render(rune) cmd.content.shift(); - return this.collection[name].render(cmd.content); + return this.collection[name].render(cmd); } this.passive = function(cmd) { - + var name = cmd.content[0]; + if(!this.collection[name]){ console.log("Unknown filter:"+name); return; } + + cmd.content.shift(); + + console.log(name); + return this.collection[name].preview(cmd); } }