Added pointer removal to brush.
This commit is contained in:
parent
39956c106f
commit
4ecae8366a
@ -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)
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user