Canvas API
context
canvas api 의 좌표 시스템
fillRect(x, y, w, h) 함수
strokeRect(x, y, w, h) 함수
예시
// ~/app.js
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");
canvas.width = 800;
canvas.height = 800;
ctx.rect(50, 50, 100, 100);
ctx.rect(150, 150, 100, 100);
ctx.fill();
ctx.rect(250, 250, 100, 100);
ctx.stroke();
paths
// ~/ app.js
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");
canvas.width = 800;
canvas.height = 800;
ctx.rect(50, 50, 100, 100);
ctx.rect(150, 150, 100, 100);
ctx.fill();
ctx.rect(250, 250, 100, 100);
ctx.stroke();
ctx.rect(350, 350, 100, 100);
ctx.fillStyle = "red";
setTimeout(() => {
ctx.fill();
}, 1000);
// ~/ app.js
...(생략)
ctx.rect(50, 50, 100, 100);
ctx.rect(150, 150, 100, 100);
ctx.fill();
ctx.rect(250, 250, 100, 100);
ctx.stroke();
ctx.beginPath();
ctx.rect(350, 350, 100, 100);
ctx.fillStyle = "red";
setTimeout(() => {
ctx.fill();
}, 1000);