-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path26.html
More file actions
51 lines (45 loc) · 1.52 KB
/
Copy path26.html
File metadata and controls
51 lines (45 loc) · 1.52 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enhanced Drawing App</title>
<style>
canvas {
border: 2px solid black;
}
</style>
</head>
<body>
<h1>Enhanced Drawing App</h1>
<canvas id="canvas" width="500" height="500"></canvas>
<br>
Color:
<input type="color" id="colorPicker">
Brush Size:
<input type="range" min="1" max="50" value="5" id="brushSize">
<br><br>
<button onclick="clearCanvas()">Clear Canvas</button>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let isDrawing = false;
canvas.addEventListener('mousedown', () => isDrawing = true);
canvas.addEventListener('mouseup', () => isDrawing = false);
canvas.addEventListener('mousemove', draw);
function draw(e) {
if (!isDrawing) return;
ctx.lineWidth = document.getElementById('brushSize').value;
ctx.lineCap = 'round';
ctx.strokeStyle = document.getElementById('colorPicker').value;
ctx.lineTo(e.clientX - canvas.offsetLeft, e.clientY - canvas.offsetTop);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(e.clientX - canvas.offsetLeft, e.clientY - canvas.offsetTop);
}
function clearCanvas() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
</script>
</body>
</html>