diff --git a/scripts/brush.js b/scripts/brush.js index 39717ae..21028ab 100644 --- a/scripts/brush.js +++ b/scripts/brush.js @@ -5,7 +5,7 @@ function Brush() // Commander - this.command = function(p) + this.add = function(p) { if(p.length > 1){ var position = new Position(parseInt(p[0]),parseInt(p[1])); @@ -20,6 +20,11 @@ function Brush() this.add_pointer(pointer); } + this.remove = function(p) + { + this.remove_pointer(new Position(p[0],p[1])); + } + // Pointers this.pointers = [new Pointer(new Position(0,0))]; @@ -29,6 +34,16 @@ function Brush() this.pointers.push(pointer); } + this.remove_pointer = function(target_position) + { + for (i = 0; i < this.pointers.length; i++) { + if(this.pointers[i].offset.is_equal(target_position)){ + this.pointers.splice(i, 1); + break; + } + } + } + // Draw this.draw = function(e) diff --git a/scripts/commander.js b/scripts/commander.js index 6c53cc9..d8de071 100644 --- a/scripts/commander.js +++ b/scripts/commander.js @@ -28,7 +28,11 @@ function Commander(element,element_input) // Brush if(parts[0] == ":+"){ parts.shift(); - brush.command(parts); + brush.add(parts); + } + if(parts[0] == ":-"){ + parts.shift(); + brush.remove(parts); } this.hide(); diff --git a/scripts/main.js b/scripts/main.js index 146f495..87a918a 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -20,11 +20,13 @@ canvas.addEventListener('mouseup', function(e) { var keyboard = new Keyboard(); document.onkeydown = function myFunction(){ keyboard.listen(event); }; -/* brush experiments var mirror_test = new Pointer(); -mirror_test.mirror = new Position(200,0); +mirror_test.mirror = new Position(200,10); brush.add_pointer(mirror_test); +/* brush experiments + + var mirror_test2 = new Pointer(new Position(0,10)); mirror_test2.mirror = new Position(200,0); brush.add_pointer(mirror_test2); diff --git a/scripts/position.js b/scripts/position.js index 474640e..8207143 100644 --- a/scripts/position.js +++ b/scripts/position.js @@ -3,6 +3,12 @@ function Position(x = 0,y = 0) this.x = x; this.y = y; + this.is_equal = function(target) + { + if(target.x == this.x && target.y == this.y){ return true; } + return null; + } + this.distance_to = function(target) { if(!target){ return 0; }