Example 1 — Example
Typical usage.
JavaScript
console.log("const ctx = canvas.getContext('2d');");
console.log("ctx.fillRect(0, 0, 10, 10);");How It Works
- getContext. Obtain a drawing context.
- fillRect. Draw a rectangle.
The Canvas API draws 2D (or WebGL) graphics via <canvas> and getContext('2d').
console.log("const ctx = canvas.getContext('2d');");
console.log("ctx.fillRect(0, 0, 10, 10);");Typical usage.
console.log("const ctx = canvas.getContext('2d');");
console.log("ctx.fillRect(0, 0, 10, 10);");Check support.
console.log("Canvas — verify browser/Node support");CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful