Skip to content

brain_render_worker.py

Rufus Pearce edited this page Dec 17, 2025 · 6 revisions

brain_render_worker.py (938 lines)

An offscreen rendering engine running in its own QThread that paints the entire brain visualization to a QImage buffer. The main thread simply blits this cached image during paintEvent, dramatically improving UI responsiveness. The worker receives immutable state snapshots and handles all the complex drawing logic—connections with animated pulses, neurons with various shapes, localized labels, and visual effects for learning events.

RenderState Dataclass:

  • Immutable snapshot containing positions, states, colors, weights, and animation parameters
  • Created on main thread via create_render_state_from_widget() helper
  • Includes pre-calculated localized neuron labels to avoid i18n lookups during render

Rendering Pipeline:

request_render(state) — throttled to ~10 FPS maximum Draws connections with pulse effects, weight-based thickness, and directional indicators Draws neurons as circles, polygons, or special connector shapes Handles hover highlights and Hebbian animation effects

####Animation Support:

  • Traveling activation pulses along connections
  • Ambient pulsing based on connection weight
  • Communication glow packets for activity visualization
  • Weight change animations highlighting Hebbian learning updates

Clone this wiki locally