boxes/js/graphics.mjs

26 lines
519 B
JavaScript

const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
export function set_size (w, h) {
canvas.width = w;
canvas.height = h;
}
export function set_color (color) {
ctx.fillStyle = color;
ctx.strokeStyle = color;
}
export function clear (color = "#000") {
set_color(color);
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
export function fill_rect (x, y, w, h) {
ctx.fillRect(x, y, w, h);
}
export function render (target_canvas) {
target_canvas.drawImage(canvas, 0, 0);
}