Repository navigation
Expand file tree
/
Copy pathAssignment.html
More file actions
67 lines (60 loc) · 1.66 KB
/
Copy pathAssignment.html
File metadata and controls
67 lines (60 loc) · 1.66 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
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Canvas Drawing</title>
<style>
body {
text-align: center;
font-family: Arial, sans-serif;
}
canvas {
border: 1px solid black;
display: block;
margin: 20px auto;
}
</style>
</head>
<body>
<h2>Canvas Drawing</h2>
<canvas id="myCanvas" width="500" height="400"></canvas>
<br>
<button onclick="clearCanvas()">Clear Canvas</button>
<script>
// Get the canvas and context
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
// Draw Blue Rectangle
ctx.fillStyle = "blue";
ctx.fillRect(50, 50, 150, 100);
// Draw Red Circle
ctx.fillStyle = "red";
ctx.beginPath();
ctx.arc(300, 100, 50, 0, Math.PI * 2);
ctx.fill();
// Draw Green Triangle
ctx.fillStyle = "green";
ctx.beginPath();
ctx.moveTo(200, 250);
ctx.lineTo(150, 350);
ctx.lineTo(250, 350);
ctx.closePath();
ctx.fill();
// Draw Yellow Line
ctx.strokeStyle = "yellow";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(canvas.width, canvas.height);
ctx.stroke();
// Function to clear the canvas
function clearCanvas() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
</script>
<script>
console.log("Anthony Sagastume");
</script>
</body>
</html>