agentjs-core
Version:
A comprehensive agent-based modeling framework with built-in p5.js visualization
204 lines • 4.98 kB
TypeScript
/**
* AgentTrailSystem - Movement history visualization
*
* Features:
* - Configurable trail length and fade
* - Trail color based on agent state
* - Performance optimization for many trails
* - State change indicators along trails
* - Historical position markers
*/
/// <reference types="@types/p5-global" />
import type { Agent } from '../core/agents/Agent';
import type { AgentId, Position } from '../types/core';
/** Trail point with metadata */
export interface TrailPoint {
position: Position;
timestamp: number;
agentState?: Record<string, any>;
isStateChange?: boolean;
stateChangeType?: string | undefined;
}
/** Trail configuration */
export interface TrailConfig {
maxLength: number;
fadeSpeed: number;
colorProperty?: string;
showStateChanges: boolean;
showDirectionArrows: boolean;
lineWidth: number;
minAlpha: number;
maxAlpha: number;
smoothingFactor: number;
cullDistance: number;
}
/** Agent trail data */
interface AgentTrail {
agentId: AgentId;
points: TrailPoint[];
lastPosition: Position | null;
lastStateSnapshot: Record<string, any>;
color: Color | null;
isVisible: boolean;
needsUpdate: boolean;
}
/** Trail rendering style */
export interface TrailStyle {
strokeColor: Color;
strokeWeight: number;
alpha: number;
isDashed: boolean;
dashPattern?: number[] | undefined;
}
/**
* AgentTrailSystem - Manages movement trails for all agents
*
* Educational Context: Visualizes agent movement patterns
* and behavioral changes over time, helping users understand
* spatial dynamics and decision-making processes.
*/
export declare class AgentTrailSystem {
/** Trail configuration */
private config;
/** Agent trails map */
private trails;
/** Current timestamp for trail points */
private currentTime;
/** Performance monitoring */
private readonly stats;
/** Color cache for performance */
private colorCache;
/** p5 instance reference for color creation */
private p5Instance;
constructor(config?: Partial<TrailConfig>);
/**
* Set p5 instance for color creation
*/
setP5Instance(p5Instance: p5Instance): void;
/**
* Update trails for all agents
*/
update(agents: Map<AgentId, Agent>, currentTime: number): void;
/**
* Update trail for a specific agent
*/
private updateAgentTrail;
/**
* Create new trail for agent
*/
private createNewTrail;
/**
* Check if a new trail point should be added
*/
private shouldAddTrailPoint;
/**
* Add new trail point
*/
private addTrailPoint;
/**
* Create trail point from position and agent
*/
private createTrailPoint;
/**
* Capture agent state snapshot
*/
private captureAgentState;
/**
* Check if agent state has changed significantly
*/
private hasStateChanged;
/**
* Get state change type for visualization
*/
private getStateChangeType;
/**
* Update trail visual properties
*/
private updateTrailProperties;
/**
* Get color for property value
*/
private getColorForValue;
/**
* Check if trail is visible (basic implementation)
*/
private isTrailVisible;
/**
* Remove old trail points
*/
private cullTrailPoints;
/**
* Render all trails
*/
render(sketch: p5Instance): void;
/**
* Render individual trail
*/
private renderTrail;
/**
* Get trail style for segment
*/
private getTrailStyle;
/**
* Draw dashed line
*/
private drawDashedLine;
/**
* Render state change indicators
*/
private renderStateChangeIndicators;
/**
* Get color for state change type
*/
private getStateChangeColor;
/**
* Render direction arrows
*/
private renderDirectionArrows;
/**
* Draw arrow pointing from start to end
*/
private drawArrow;
/**
* Calculate distance between two positions
*/
private calculateDistance;
/**
* Update performance statistics
*/
private updateStats;
/**
* Get trail for specific agent
*/
getTrail(agentId: AgentId): AgentTrail | undefined;
/**
* Clear trail for specific agent
*/
clearTrail(agentId: AgentId): boolean;
/**
* Clear all trails
*/
clearAllTrails(): void;
/**
* Update configuration
*/
updateConfig(newConfig: Partial<TrailConfig>): void;
/**
* Get configuration
*/
getConfig(): TrailConfig;
/**
* Get performance statistics
*/
getStats(): typeof this.stats;
/**
* Export trail data for analysis
*/
exportTrailData(): Record<AgentId, TrailPoint[]>;
/**
* Destroy the trail system
*/
destroy(): void;
}
export {};
//# sourceMappingURL=AgentTrailSystem.d.ts.map