olamjs
v1.1.0
Published
A lightweight implementation of vectors and entity system
Downloads
22
Readme
A tiny TypeScript toolkit for vectors, entities, and update loops.
This project is intended for personal use and simple creative coding workflows. It is not focused on advanced optimization or high-performance scenarios.
Installation
npm install olamjsWhat Is Included
- Vector math primitives (in
src/vectors.ts) - A base
Entityabstraction with update/debug helpers EntityManagerfor add, update, draw, and cleanup loops- Canvas helper utilities for setup and drawing
- Small general-purpose utilities (angles, random helpers, range mapping, image loading)
Quick Usage
import { Entity, EntityManager, setUpCanvas, drawCircle } from "olamjs";
const canvas = document.querySelector("canvas") as HTMLCanvasElement;
const { ctx } = setUpCanvas(canvas);
class Dot extends Entity {
constructor(x: number, y: number) {
super(x, y);
}
draw(ctx: CanvasRenderingContext2D): void {
drawCircle(ctx, this.position.x, this.position.y, 8, {
fill: "#2d6cdf",
stroke: "#0f2f6b",
lineWidth: 2,
});
}
}
const entities = new EntityManager<Dot>();
entities.add(new Dot(120, 80));
let last = performance.now();
function frame(now: number) {
const dt = (now - last) / 1000;
last = now;
ctx.clearRect(0, 0, canvas.width, canvas.height);
entities.updateAll(dt);
entities.drawAll(ctx);
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);API Overview
Current package root exports from src/index.ts:
- Canvas:
setUpCanvas,drawCircle,drawLine,drawText - Utilities:
TWO_PI,HALF_PI,DEG_TO_RAD_RATIO,degToRad,radToDeg,randomRangeInt,randomRangeFloat,randomChoice,loadImage,mapRange - Entities:
Entity(abstract),EntityManager
The vector class implementation is located in src/vectors.ts.
Documentation
Detailed documentation is available in the docs directory, including API reference and usage examples.
Development
npm run build
npm run dev