Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
58 lines (48 loc) · 1.5 KB
/
Copy pathmain.js
File metadata and controls
58 lines (48 loc) · 1.5 KB
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
const myCanvas = document.getElementById("myCanvas").getContext("2d");
const canvasPaint = document.getElementById("myCanvas").getBoundingClientRect();
const colorBtn = document.getElementById("colorBtn");
const thicknessBtn = document.getElementById("thicknessBtn");
function mark() {
myCanvas.beginPath()
}
function paint(event) {
if (event.buttons !== 1) return;
myCanvas.lineTo(event.clientX - canvasPaint.left, event.clientY - canvasPaint.top);
myCanvas.stroke();
}
function changeColor(color) {
myCanvas.strokeStyle = color;
}
function changeThickness(width){
myCanvas.lineWidth = width;
}
function getRandomColor() {
const r = Math.floor(Math.random() * 256)
const g = Math.floor(Math.random() * 256)
const b = Math.floor(Math.random() * 256)
const color = `rgb(${r},${g},${b})`;
return color;
}
function randomColor() {
myCanvas.strokeStyle = getRandomColor()
}
function getRandomNumber(min, max) {
return Math.floor(Math.random() * max - min + 1) +min;
}
function randomLetter() {
clearAll();
const letter = getRandomLetter();
myCanvas.strokeStyle = 'blue';
myCanvas.font = '200px Arial';
myCanvas.lineWidth = 8;
myCanvas.strokeText(letter, 450, 250);
}
function getRandomLetter() {
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const index = getRandomNumber(0, letters.length - 1);
const letter = letters[index];
return letter;
}
function clearAll() {
myCanvas.clearRect(0, 0, 1000, 400)
}