diff --git a/_notes.txt b/_notes.txt index ad9b41b..983ebe5 100644 --- a/_notes.txt +++ b/_notes.txt @@ -26,4 +26,7 @@ $ new_name.jpg Cursors = 10 ] += 1 -[ -= 1 \ No newline at end of file +[ -= 1 + + Formatting +; Split into multiple commands \ No newline at end of file diff --git a/index.html b/index.html index 0e80aa9..519aefb 100644 --- a/index.html +++ b/index.html @@ -2,6 +2,7 @@
+ diff --git a/scripts/brush.js b/scripts/brush.js index c6f2f30..7bbf3d4 100644 --- a/scripts/brush.js +++ b/scripts/brush.js @@ -3,6 +3,15 @@ function Brush() this.position = new Position(); this.is_drawing = false; + // Commander + + this.command = function(p) + { + var position = new Position(parseInt(p[0]),parseInt(p[1])); + var pointer = new Pointer(position); + brush.add_pointer(pointer); + } + // Pointers this.pointers = [new Pointer(new Position(0,0))]; diff --git a/scripts/color.js b/scripts/color.js new file mode 100644 index 0000000..2f5c0bf --- /dev/null +++ b/scripts/color.js @@ -0,0 +1,7 @@ +function Color() +{ + this.hex = function() + { + return '#ff0000'; + } +} \ No newline at end of file diff --git a/scripts/commander.js b/scripts/commander.js index 943588f..efec42b 100644 --- a/scripts/commander.js +++ b/scripts/commander.js @@ -19,11 +19,17 @@ function Commander(element,element_input) { var parts = this.element_input.value.split(" "); + // Canvas if(parts[0] == ":@"){ canvas.style.width = parts[1]+"px"; canvas.style.height = parts[2]+"px"; } + // Brush + if(parts[0] == ":+"){ + brush.command(parts.shift()); + } + this.hide(); } diff --git a/scripts/pointer.js b/scripts/pointer.js index 4a0b05c..51415be 100644 --- a/scripts/pointer.js +++ b/scripts/pointer.js @@ -1,6 +1,7 @@ -function Pointer(offset = new Position()) +function Pointer(offset = new Position(), color = new Color()) { this.offset = offset; + this.color = color; this.mirror = null; this.position_prev = null; @@ -21,6 +22,10 @@ function Pointer(offset = new Position()) context.beginPath(); context.moveTo(this.position_prev.x,this.position_prev.y); context.lineTo(this.position().x,this.position().y); + context.lineCap="round"; + var thick = 100 - ((this.position().distance_to(this.position_prev))); + context.lineWidth = thick/20; + context.strokeStyle = this.color.hex(); context.stroke(); this.position_prev = this.position(); diff --git a/scripts/position.js b/scripts/position.js index 69c5910..474640e 100644 --- a/scripts/position.js +++ b/scripts/position.js @@ -5,6 +5,7 @@ function Position(x = 0,y = 0) this.distance_to = function(target) { + if(!target){ return 0; } return Math.sqrt( (this.x-target.x)*(this.x-target.x) + (this.y-target.y)*(this.y-target.y) ); } } \ No newline at end of file