From 782032e6b2f62dc226cb701abe01cc537a8e2d3a Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 29 Dec 2016 14:18:55 -0700 Subject: [PATCH] Added rotation filter --- index.html | 4 +++- scripts/core/commander.hint.js | 34 +-------------------------- scripts/core/init.js | 8 ++++++- scripts/filters/rotate.js | 42 ++++++++++++++++++++++++++++++++++ scripts/filters/stencil.js | 1 + scripts/modules/module.js | 34 ++++++++++++++++++++++++++- scripts/modules/render.js | 10 +++----- scripts/modules/stroke.js | 4 ++-- 8 files changed, 92 insertions(+), 45 deletions(-) create mode 100644 scripts/filters/rotate.js diff --git a/index.html b/index.html index c427b30..7dbe6e2 100644 --- a/index.html +++ b/index.html @@ -30,12 +30,14 @@ + + + - diff --git a/scripts/core/commander.hint.js b/scripts/core/commander.hint.js index 583aaa3..edb5974 100644 --- a/scripts/core/commander.hint.js +++ b/scripts/core/commander.hint.js @@ -22,39 +22,7 @@ function Hint(element) this.message = function(module,cmd) { - var s = this.pad(cmd.content.join(" ")); - - s += cmd.content.join(" ").length == 0 ? ""+module.constructor.name+"" : ""; - - // Params - - var e = 0; - while(e < 10){ - if(!module.parameters[e]){ break; } - var param_name = module.parameters[e].name; - s += cmd[param_name.toLowerCase()]() ? "" : ""+param_name+""; - e += 1; - } - - // Variables - if(module.variables){ - for (var key in module.variables){ - if(cmd.variable(key)){continue;} - s += ""+key+"="+module.variables[key]+" "; - } - } - - return s; - } - - this.pad = function(input) - { - var s = ""; - for (i = 0; i < input.length+2; i++){ - s += "_"; - } - - return ""+s+""; + return module.hint(cmd); } this.default = function() diff --git a/scripts/core/init.js b/scripts/core/init.js index fc15fed..9b2de17 100644 --- a/scripts/core/init.js +++ b/scripts/core/init.js @@ -34,4 +34,10 @@ commander.query("~ "+ronin.timestamp()); commander.query("# "+starting_canvas.render()); commander.query("# layer=render"); commander.query("# layer=main"); -commander.query("> 1 0,0 #000000"); \ No newline at end of file +commander.query("> 1 0,0 #000000"); +// commander.query("# #999"); +// commander.query("> #0000ff"); +// commander.query("_ 0,100 360,100"); +// commander.query("> #ff00ff"); +// commander.query("_ 180,0 180,200"); +// commander.query("%rotate"); \ No newline at end of file diff --git a/scripts/filters/rotate.js b/scripts/filters/rotate.js new file mode 100644 index 0000000..0565e10 --- /dev/null +++ b/scripts/filters/rotate.js @@ -0,0 +1,42 @@ +function Filter_Rotate() +{ + Filter.call(this); + this.parameters = [Angle,Position]; + + this.render = function(cmd) + { + var position = cmd.position() ? cmd.position() : new Position(ronin.surface.size.width/2,ronin.surface.size.height/2); + var angle = cmd.angle() ? cmd.angle().degrees : 90; + + ronin.overlay.clear(); + this.draw(this.context(),angle,position); + ronin.overlay.clear(); + } + + this.preview = function(cmd) + { + if(cmd.position()){ + ronin.overlay.clear(); + ronin.overlay.draw_pointer(cmd.position()); + } + } + + this.draw = function(context = this.context(), angle, position) + { + var w = ronin.surface.size.width; + var h = ronin.surface.size.height; + + ronin.overlay.context().drawImage(context.canvas,0,0,w,h); + + ronin.surface.active_layer.clear(); + + context.save(); + context.translate(position.x,position.y); + context.rotate(angle*Math.PI/180); + + context.drawImage(ronin.overlay.context().canvas, -position.x, -position.y,w,h) + + context.rotate(-angle*Math.PI/180); + context.restore(); + } +} \ No newline at end of file diff --git a/scripts/filters/stencil.js b/scripts/filters/stencil.js index 2ec56a0..d1d9d25 100644 --- a/scripts/filters/stencil.js +++ b/scripts/filters/stencil.js @@ -1,6 +1,7 @@ function Filter_Stencil() { Filter.call(this); + this.parameters = [Angle]; this.render = function(cmd) { diff --git a/scripts/modules/module.js b/scripts/modules/module.js index bfd6c1f..defa29e 100644 --- a/scripts/modules/module.js +++ b/scripts/modules/module.js @@ -27,7 +27,39 @@ function Module(rune) this.hint = function(cmd) { - return "unknown"; + var s = this.pad(cmd.content.join(" ")); + + s += cmd.content.join(" ").length == 0 ? ""+this.constructor.name+"" : ""; + + // Params + + var e = 0; + while(e < 10){ + if(!this.parameters[e]){ break; } + var param_name = this.parameters[e].name; + s += cmd[param_name.toLowerCase()]() ? "" : ""+param_name+""; + e += 1; + } + + // Variables + if(this.variables){ + for (var key in this.variables){ + if(cmd.variable(key)){continue;} + s += ""+key+"="+this.variables[key]+" "; + } + } + + return s; + } + + this.pad = function(input) + { + var s = ""; + for (i = 0; i < input.length+2; i++){ + s += "_"; + } + + return ""+s+""; } this.widget = function() diff --git a/scripts/modules/render.js b/scripts/modules/render.js index 2d95740..b0b1af9 100644 --- a/scripts/modules/render.js +++ b/scripts/modules/render.js @@ -6,14 +6,13 @@ function Render(rune) this.collection = {}; this.collection["stencil"] = new Filter_Stencil(); + this.collection["rotate"] = new Filter_Rotate(); this.active = function(cmd) { var name = cmd.content[0]; - if(!this.collection[name]){ console.log("Unknown filter:"+name); return; } - - cmd.content.shift(); + if(!this.collection[name]){ return; } return this.collection[name].render(cmd); } @@ -21,11 +20,8 @@ function Render(rune) this.passive = function(cmd) { var name = cmd.content[0]; - if(!this.collection[name]){ console.log("Unknown filter:"+name); return; } + if(!this.collection[name]){ return; } - cmd.content.shift(); - - console.log(name); return this.collection[name].preview(cmd); } diff --git a/scripts/modules/stroke.js b/scripts/modules/stroke.js index edf95ae..d83a090 100644 --- a/scripts/modules/stroke.js +++ b/scripts/modules/stroke.js @@ -52,8 +52,8 @@ function Stroke(rune) ronin.surface.context().moveTo(pos1.x,pos1.y); ronin.surface.context().lineTo(pos2.x,pos2.y); ronin.surface.context().lineCap="round"; - ronin.surface.context().lineWidth = 1; - ronin.surface.context().strokeStyle = new Color("#ff0000").rgba(); + ronin.surface.context().lineWidth = 10; + ronin.surface.context().strokeStyle = ronin.brush.color.rgba(); ronin.surface.context().stroke(); ronin.surface.context().closePath(); }