UNPKG

agentscape

Version:

Agentscape is a library for creating agent-based simulations. It provides a simple API for defining agents and their behavior, and for defining the environment in which the agents interact. Agentscape is designed to be flexible and extensible, allowing

84 lines (83 loc) 2.53 kB
import { Angle, Color } from '../../numbers'; import { AgentSet, CellGrid } from '../../structures'; import { Agent, Cell } from '../../entities'; import { AgentStyle } from '../../entities/Agent'; export interface Render2DConstructor { root: HTMLElement; renderWidth: number; renderHeight: number; worldWidth: number; id?: string; title?: string; autoPlay?: boolean; frameRate?: number; onCellClick?: (position: [number, number], renderer: Render2D) => void; } export type ColorFunction<U extends Agent | Cell> = (entity: U) => { fill: Color; stroke?: Color; }; export type StyleFunction<T extends Agent> = (entity: T) => AgentStyle; export declare class Render2D { renderWidth: number; renderHeight: number; ctx: CanvasRenderingContext2D; frameRate: number; cellWidth: number; cellHeight: number; constructor(opts: Render2DConstructor); clear(): void; drawCellGrid<T extends Cell>(world: CellGrid<T>, opts?: { colorFunction?: ColorFunction<T>; }): void; /** * Draws agents on the canvas * @param agents */ drawAgentSet<T extends Agent>(agents: AgentSet<T>, opts?: { colorFunction?: ColorFunction<T>; styleFunction?: StyleFunction<T>; }): void; drawAgent<T extends Agent>(agent: T, opts?: { colorFunction?: ColorFunction<T>; styleFunction?: StyleFunction<T>; }): void; drawCircle(x: number, y: number, options?: { radius?: number; rotation?: Angle; fill?: Color; stroke?: Color; lineWidth?: number; showRotation?: boolean; }): void; /** * Draws a unit rectangle centered at x,y */ drawRectangle(x: number, y: number, options?: { width?: number; height?: number; rotation?: Angle; fill?: Color; stroke?: Color; lineWidth?: number; }): void; drawLine(x1: number, y1: number, x2: number, y2: number, stroke: Color, options?: { lineWidth?: number; }): void; drawTriangle(x: number, y: number, options?: { width?: number; rotation?: Angle; fill?: Color; stroke?: Color; lineWidth?: number; }): void; drawPolygon(points: [number, number][], options?: { fill?: Color; stroke?: Color; lineWidth?: number; }): void; drawPolyline(points: [number, number][], stroke: Color, options?: { lineWidth?: number; }): void; } export default Render2D;