From fd4428aafa5db8782af8d0087f230f1eebff82a8 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Tue, 15 Nov 2016 11:16:06 -0800 Subject: [PATCH] Progress on radial brush. --- README.md | 1 + scripts/ronin.brush.js | 7 +++++-- scripts/ronin.brush.pointer.js | 14 +++++++++++++- scripts/unit.command.js | 8 ++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 700611d..b0161eb 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ $ ! ; Clear temporary storage > 10,0 ; Add pointer at pos > 400x0 ; Add mirror pointer, at 400x > 4 #ff0000 ; Red brush, Size 4 +> 100,100 45' ; Radial brush from position x,y and 45 degrees > ! ; Remove all pointers ``` diff --git a/scripts/ronin.brush.js b/scripts/ronin.brush.js index 7d0d811..075cc70 100644 --- a/scripts/ronin.brush.js +++ b/scripts/ronin.brush.js @@ -19,7 +19,7 @@ function Brush() var pointer = new Pointer(); if(cmd.position()){ - pointer.position = cmd.position(); + pointer.offset = cmd.position(); } if(cmd.rect()){ pointer.mirror = cmd.rect(); @@ -27,7 +27,10 @@ function Brush() if(cmd.noise()){ pointer.noise = cmd.noise(); } - if(cmd.rect() || cmd.position() || cmd.noise()){ + if(cmd.angle()){ + pointer.angle = cmd.angle(); + } + if(cmd.rect() || cmd.position() || cmd.noise() || cmd.angle()){ this.add_pointer(pointer); } if(cmd.color()){ diff --git a/scripts/ronin.brush.pointer.js b/scripts/ronin.brush.pointer.js index b052503..38ef231 100644 --- a/scripts/ronin.brush.pointer.js +++ b/scripts/ronin.brush.pointer.js @@ -4,6 +4,7 @@ function Pointer(offset = new Position(), color = new Color('000000')) this.mirror = null; this.noise = null; this.position_prev = null; + this.angle = null; this.draw = function() { @@ -43,7 +44,18 @@ function Pointer(offset = new Position(), color = new Color('000000')) this.position = function() { - if(this.mirror && this.mirror.width > 0){ + if(this.angle){ + + var deltaX = ronin.brush.position.x - this.offset.x; + var deltaY = ronin.brush.position.y - this.offset.y; + var t = Math.atan2(deltaY, deltaX); + var radius = 45; + var x = Math.cos(t) * radius; + var y = Math.sin(t) * radius; + + return new Position(x + this.offset.x,y + this.offset.y); + } + else if(this.mirror && this.mirror.width > 0){ return new Position(this.mirror.width - (ronin.brush.position.x + this.offset.x), 0 + (ronin.brush.position.y + this.offset.y)); } else if(this.mirror && this.mirror.height > 0){ diff --git a/scripts/unit.command.js b/scripts/unit.command.js index 6af5798..2004b11 100644 --- a/scripts/unit.command.js +++ b/scripts/unit.command.js @@ -58,4 +58,12 @@ function Command(content) } return null; } + + this.angle = function() + { + for (i = 0; i < this.content.length; i++) { + if(this.content[i].indexOf("'") >= 0){ return parseFloat(this.content[i].replace('\'','')); } + } + return null; + } } \ No newline at end of file