|
@@ -217,6 +217,24 @@ class Line extends Drawable {
|
|
|
ctx.lineWidth = this.lineWidth
|
|
|
ctx.stroke();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ in(x,y){
|
|
|
+ let lineAngle = Math.atan2(this.height, this.width);
|
|
|
+ let mouseAngle = Math.atan2(y - this.y, x - this.x);
|
|
|
+ let lineTurnAngle = mouseAngle - lineAngle;
|
|
|
+ let rotX = Math.cos(lineTurnAngle) * distance(x,y,this.x,this.y);
|
|
|
+ let rotY = Math.sin(lineTurnAngle) * distance(x,y,this.x,this.y);
|
|
|
+
|
|
|
+ if (rotX > 0 && rotX < this.distanceTo(this.x + this.width, this.y + this.height) && (rotY > -this.lineWidth / 2)
|
|
|
+ && (rotY < this.lineWidth / 2)) {
|
|
|
+ console.log(true)
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ console.log(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -233,6 +251,31 @@ class Rectangle extends Drawable {
|
|
|
this.draw();
|
|
|
}
|
|
|
|
|
|
+ // invertColor(hex){
|
|
|
+ // function padZero(str, len) {
|
|
|
+ // len = len || 2;
|
|
|
+ // var zeros = new Array(len).join('0');
|
|
|
+ // return (zeros + str).slice(-len);
|
|
|
+ // }
|
|
|
+ // if (hex.indexOf('#') === 0) {
|
|
|
+ // hex = hex.slice(1);
|
|
|
+ // }
|
|
|
+ // // convert 3-digit hex to 6-digits.
|
|
|
+ // if (hex.length === 3) {
|
|
|
+ // hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
|
|
+ // }
|
|
|
+ // if (hex.length !== 6) {
|
|
|
+ // throw new Error('Invalid HEX color.');
|
|
|
+ // }
|
|
|
+ // // invert color components
|
|
|
+ // var r = (255 - parseInt(hex.slice(0, 2), 16)).toString(16),
|
|
|
+ // g = (255 - parseInt(hex.slice(2, 4), 16)).toString(16),
|
|
|
+ // b = (255 - parseInt(hex.slice(4, 6), 16)).toString(16);
|
|
|
+ // // pad each with zeros and return
|
|
|
+ // return '#' + padZero(r) + padZero(g) + padZero(b);
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
draw(selected){
|
|
|
ctx.beginPath();
|
|
|
ctx.moveTo(this.x, this.y);
|
|
@@ -240,13 +283,13 @@ class Rectangle extends Drawable {
|
|
|
ctx.fillStyle = this.color;
|
|
|
ctx.fillRect(this.x, this.y, this.width, this.height);
|
|
|
|
|
|
- if (selected){
|
|
|
+ if (selected){
|
|
|
ctx.rect(this.x, this.y, this.width, this.height);
|
|
|
- ctx.closePath();
|
|
|
+ ctx.lineWidth = 2;
|
|
|
ctx.stroke();
|
|
|
- }
|
|
|
+
|
|
|
+ }
|
|
|
ctx.closePath();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -314,7 +357,8 @@ class Ellipse extends Drawable {
|
|
|
// console.log(this.ry)
|
|
|
ctx.moveTo(this.x, this.y);
|
|
|
ctx.fillStyle = this.color;
|
|
|
- ctx.ellipse(this.x + this.width/2, this.y + this.height/2, this.width/2, this.height/2, 0, 0, 2 * Math.PI);
|
|
|
+ // ctx.ellipse(this.x + this.width/2, this.y + this.height/2, this.width/2, this.height/2, 0, 0, 2 * Math.PI);
|
|
|
+ ctx.ellipse(this.x + this.rx, this.y + this.ry, this.rx, this.ry, 0, 0, 2 * Math.PI);
|
|
|
ctx.fill()
|
|
|
ctx.closePath();
|
|
|
}
|
|
@@ -338,7 +382,10 @@ document.getElementById('delete').onclick = () =>{
|
|
|
Drawable.drawAll()
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+undo.onclick = function(){
|
|
|
+ Drawable.instances.pop()
|
|
|
+ Drawable.drawAll()
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
|
@@ -348,11 +395,7 @@ document.getElementById('delete').onclick = () =>{
|
|
|
////canvas.onmousemove = function(e){
|
|
|
////}
|
|
|
|
|
|
-//undo.onclick = function(){
|
|
|
- //Drawable.instances.pop()
|
|
|
- ////Drawable.instances = []
|
|
|
- //Drawable.drawAll()
|
|
|
-//}
|
|
|
+
|
|
|
|
|
|
|
|
|
|