<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<script src="script.js"></script>
</body>
</html>
// Tạo một canvas
const canvas = document.createElement('canvas');
canvas.width = 500;
canvas.height = 300;
document.body.appendChild(canvas);
const ctx = canvas.getContext('2d');
// Vẽ đường thẳng đầu tiên (màu đỏ, độ rộng 2)
ctx.beginPath();
ctx.moveTo(50, 50);
ctx.lineTo(450, 50);
ctx.strokeStyle = 'red';
ctx.lineWidth = 2;
ctx.stroke();
// Vẽ đường thẳng thứ hai (màu xanh, độ rộng 4)
ctx.beginPath();
ctx.moveTo(50, 150);
ctx.lineTo(450, 150);
ctx.strokeStyle = 'blue';
ctx.lineWidth = 4;
ctx.stroke();
// Vẽ đường thẳng thứ ba (màu xanh lá cây, độ rộng 6)
ctx.beginPath();
ctx.moveTo(50, 250);
ctx.lineTo(450, 250);
ctx.strokeStyle = 'green';
ctx.lineWidth = 6;
ctx.stroke();