โx
// Get the Canvas element using its ID
const canvas = document.getElementById('myCanvas');
โ
// Check if the browser supports Canvas
if (canvas.getContext) {
// Get the 2D rendering context
const ctx = canvas.getContext('2d');
โ
// Set drawing properties (e.g., fill color, line style)
ctx.fillStyle = 'blue'; // Set fill color to blue
ctx.fillRect(50, 50, 100, 100); // Draw a blue rectangle at (50, 50) with width 100 and height 100
} else {
// Display a message if Canvas is not supported
alert('Canvas is not supported in this browser.');
}