@lucas08911/j2d
v1.0.2
Published
A 2d engine.
Readme
J2D Graphics Library
J2D is a lightweight, object-oriented 2D graphics library built for the HTML5 Canvas API. It provides a simplified interface for rendering shapes, managing canvas dimensions, and clearing the frame buffer, making it ideal for rapid prototyping, game development, and creative coding.
Features
Lightweight: Zero dependencies and a minimal footprint.
ES Modules: Built using modern JavaScript (ESM) for better performance and scoping.
Simplified API: Easy-to-use methods for common drawing tasks.
Installation
Install the package via npm:
npm install @lucas08911/j2dQuick Start
import { J2D } from "@lucas08911/j2d";
// Initialize the engine
const canvas = document.querySelector("#myCanvas");
const engine = new J2D(canvas, window.innerWidth, window.innerHeight);
// Draw a rectangle
engine.drawRect(50, 50, 100, 100, "red");
// Draw a circle
engine.drawCircle(300, 200, 50, "blue");API Reference
new J2D(canvas, width, height) - Initializes the 2D context.
canvas - HTMLCanvasElement
width - Initial width (defaults to window.innerWidth)
height - Initial height (defaults to window.innerHeight)
drawRect(x, y, w, h, color) - Draws a filled rectangle.
drawCircle(x, y, r, color) - Draws a filled circle.
setSize(width, height) - Updates the canvas dimensions dynamically.
clear() - Clears the entire canvas area.
License
This project is licensed under the GPL-3.0-only License.
