-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshapes.js
120 lines (95 loc) · 2.8 KB
/
shapes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
var $input = document.getElementsByTagName('input')[0]
$input.addEventListener("change", () => {
console.log($input.value);
context.fillStyle = $input.value;
context.strokeStyle = $input.value;
});
class Rectangle {
constructor() {
this.$canvas = $tempCanvas;
this.context = this.$canvas.getContext('2d');
}
draw(startX, startY, width, height) {
this.context.strokeStyle = $input.value;
this.context.rect(startX, startY, width, height);
this.context.clearRect(0, 0, $canvas.width, $canvas.height);
this.context.stroke();
};
};
class FreeHand {
constructor() {
this.$canvas = $tempCanvas;
this.context = this.$canvas.getContext('2d');
}
draw(startX, startY, radius, angle, math) {
this.context.lineTo(startX, startY);
this.context.stroke();
this.context.beginPath();
this.context.arc(startX, startY, radius, angle, math);
this.context.fillStyle = $input.value;
this.context.fill();
this.context.beginPath();
this.context.moveTo(startX, startY);
};
};
class Circle {
constructor() {
this.$canvas = $tempCanvas;
this.context = this.$canvas.getContext('2d');
}
draw(startX, startY, radius, angle, math) {
this.context.beginPath();
this.context.arc(startX, startY, radius, angle, math);
this.context.clearRect(0, 0, $canvas.width, $canvas.height);
this.context.stroke();
};
};
class Line {
constructor() {
this.$canvas = $tempCanvas;
this.context = this.$canvas.getContext('2d');
}
draw(startX, startY, endX, endY) {
this.context.clearRect(0, 0, $canvas.width, $canvas.height);
this.context.beginPath();
this.context.moveTo(startX, startY);
this.context.lineTo(endX, endY);
this.context.stroke();
};
};
class Spray {
constructor() {
this.$canvas = $tempCanvas;
this.context = this.$canvas.getContext('2d');
this.density = 40;
this.radius = 20;
}
getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
draw(startX, startY) {
for (var i = this.density; i--;) {
this.offsetX = this.getRandomInt(-this.radius, this.radius);
this.offsetY = this.getRandomInt(-this.radius, this.radius);
this.context.fillRect(startX + this.offsetX, startY + this.offsetY, 1, 1);
}
};
};
class Eraser {
constructor() {
this.$canvas = $tempCanvas;
this.context = this.$canvas.getContext('2d');
}
erase(startX, startY, radius, angle, math) {
this.radius = radius * 2;
this.context.lineWidth = radius * 5;
this.context.strokeStyle = "white";
this.context.lineTo(startX, startY);
this.context.stroke();
this.context.beginPath();
this.context.arc(startX, startY, this.radius, angle, math);
this.context.fill();
this.context.beginPath();
this.context.moveTo(startX, startY);
};
};