Visualizer - Main visualization system for AgentJS

Features:

  • p5Instance.js integration with TypeScript support
  • Real-time agent rendering with property-based visuals
  • Interactive camera controls (pan/zoom)
  • Performance optimization for 100+ agents
  • Configurable rendering pipeline

Educational Context: Provides visual feedback for agent-based simulations, making complex behaviors observable and understandable.

Constructors

Properties

agents: Map<AgentId, Agent> = ...

Reference to agents map

animationEngine: AnimationEngine

Animation engine for smooth transitions

animationId: null | number = null

Animation frame ID for cleanup

camera: CameraState

Camera state

Visualization configuration

container: null | HTMLElement = null

Canvas container element

definitionVisualizer: AgentDefinitionVisualizer

Real-time agent definition visualizer

environment: null | Environment = null

Reference to environment

frameStats: {
    fps: number;
    frames: number;
    lastTime: number;
} = ...

Performance monitoring

Type declaration

  • fps: number
  • frames: number
  • lastTime: number
heatMapSystem: HeatMapSystem

Heat map system for spatial analysis

networkManager: null | NetworkManager = null

Reference to network manager

p5Instance: null | p5Instance = null

p5Instance.js instance

particleSystem: ParticleEffectsSystem

Particle effects system for visual feedback

previousMouseX: number = 0

Previous mouse coordinates for dragging

previousMouseY: number = 0
trailSystem: AgentTrailSystem

Agent trail system for movement history

Methods

  • Calculate visual properties for an agent

    MVP Visual Design: Uses primary colors and geometric shapes

    • Red: Exploitation/danger states
    • Blue: Support/safety states
    • Green: Growth/empowerment states
    • Yellow: Resources/opportunities
    • Orange: Vulnerability/warning states

    Parameters

    • sketch: p5Instance
    • agent: Agent

    Returns AgentVisuals

  • Draw dashed line for economic connections

    Parameters

    • sketch: p5Instance
    • x1: number
    • y1: number
    • x2: number
    • y2: number
    • dashLength: number

    Returns void

  • Get combined performance statistics

    Returns {
        animation: any;
        heatMaps: any;
        particles: any;
        trails: any;
        visualizer: {
            agents: number;
            fps: number;
            zoom: number;
        };
    }

    • animation: any
    • heatMaps: any
    • particles: any
    • trails: any
    • visualizer: {
          agents: number;
          fps: number;
          zoom: number;
      }
      • agents: number
      • fps: number
      • zoom: number
  • Get agent shape based on type (MVP geometric shapes)

    MVP Design Mapping:

    • Circles: Community members (default)
    • Triangles: Leaders/influencers
    • Squares: Resources/institutions

    Post-MVP: Will be replaced with custom character artwork

    Parameters

    • agentType: string

    Returns "circle" | "square" | "triangle"

  • Get definition extent statistics

    Returns {
        complete: number;
        missing: number;
        partial: number;
    }

    • complete: number
    • missing: number
    • partial: number
  • Get environment boundaries

    Returns null | {
        height: number;
        width: number;
        x: number;
        y: number;
    }

  • Handle mouse wheel events for zooming

    Parameters

    • _sketch: p5Instance
    • event: any

    Returns boolean

  • Initialize visualization with container element

    Parameters

    • containerElement: HTMLElement

    Returns void

  • Render network connections (MVP geometric line visualization)

    MVP Design:

    • Supportive connections: Blue lines (#2563EB)
    • Exploitative connections: Red lines (#DC2626)
    • Economic connections: Green dashed lines (#059669)

    Parameters

    • sketch: p5Instance

    Returns void

  • Render environment background (MVP zone visualization)

    MVP Design:

    • Safe zones: Light blue overlay (rgba(37, 99, 235, 0.1))
    • Danger zones: Light red overlay (rgba(220, 38, 38, 0.1))
    • Resource areas: Light yellow overlay (rgba(254, 240, 138, 0.2))
    • Neutral areas: Default background (#F5F5F4)

    Parameters

    • sketch: p5Instance

    Returns void

  • Render environment zones with MVP color overlays

    Parameters

    • sketch: p5Instance
    • bounds: {
          height: number;
          width: number;
          x: number;
          y: number;
      }
      • height: number
      • width: number
      • x: number
      • y: number

    Returns void