electrosim.rendering.draw#

world_vector_to_screen(pos_meters, pixels_per_meter)[source]#

Convert world coordinates (m) to integer screen pixels.

Parameters:
  • pos_meters (numpy.ndarray shape (2,)) – World position in meters.

  • pixels_per_meter (float) – Pixels per meter scale.

Returns:

tuple[int, int] – Pixel coordinates.

Return type:

Tuple[int, int]

screen_vector_to_world(pos_pixels, pixels_per_meter)[source]#

Convert integer screen pixels to world meters as a float array.

Parameters:
  • pos_pixels (tuple[int, int]) – Pixel coordinates.

  • pixels_per_meter (float) – Pixels per meter scale.

Returns:

numpy.ndarray shape (2,) – World position in meters.

Return type:

ndarray

draw_meter_grid(screen, world_size_m, pixels_per_meter)[source]#

Draw a metric grid in meters over the entire world size.

Major lines and colors are controlled via config constants.

Parameters:
  • screen (Surface)

  • world_size_m (ndarray)

  • pixels_per_meter (float)

Return type:

None

draw_glow_at_screen_pos(screen, center_px, base_radius_px, color_rgb, intensity)[source]#

Draw a blurred radial glow using concentric alpha circles.

Parameters:
  • screen (pygame.Surface) – Target surface.

  • center_px (tuple[int, int]) – Center pixel.

  • base_radius_px (int) – Base radius for the core circle.

  • color_rgb (tuple[int,int,int]) – Glow color.

  • intensity (float) – [0,1] normalized intensity, typically |q|/MAX_CHARGE_C.

Return type:

None

draw_particles(screen, particles, pixels_per_meter, selected_index)[source]#

Draw particles as filled circles with optional borders for fixed/selected.

Parameters:
  • screen (pygame.Surface) – Target surface.

  • particles (Iterable[Particle]) – Particles to draw.

  • pixels_per_meter (float) – Scaling from meters to pixels.

  • selected_index (int | None) – Index of selected particle in list order, if any.

Return type:

None

draw_velocity_vectors(screen, particles, pixels_per_meter)[source]#

Draw velocity arrows scaled by a constant factor.

Parameters:
  • screen (pygame.Surface) – Target surface.

  • particles (Iterable[Particle]) – Particles to draw velocity for.

  • pixels_per_meter (float) – Scaling from meters to pixels.

Return type:

None

draw_force_vectors(screen, particles, forces_array, pixels_per_meter)[source]#

Draw force arrows per particle using precomputed forces if available.

Parameters:
  • screen (pygame.Surface) – Target surface.

  • particles (Iterable[Particle]) – Particles to draw forces for.

  • forces_array (numpy.ndarray | None) – Per-particle forces (N) shaped (N,2). If None, nothing is drawn.

  • pixels_per_meter (float) – Scaling from meters to pixels.

Return type:

None

draw_particle_glows(screen, particles, pixels_per_meter)[source]#

Draw glows for all non-neutral particles.

Parameters:
  • screen (pygame.Surface) – Target surface.

  • particles (Iterable[Particle]) – Particles to draw glow for.

  • pixels_per_meter (float) – Scaling from meters to pixels.

Return type:

None

draw_field_grid(screen, particles, world_size_m, pixels_per_meter, grid_step_px, softening_fraction)[source]#

Draw electric field arrows on a pixel grid using selected visualization mode.

Parameters:
  • screen (Surface)

  • particles (Iterable[Particle])

  • world_size_m (ndarray)

  • pixels_per_meter (float)

  • grid_step_px (int)

  • softening_fraction (float)

Return type:

None

draw_trails(screen, particles, pixels_per_meter)[source]#

Render faded line segments approximating recent particle trajectories.

Parameters:
  • screen (Surface)

  • particles (Iterable[Particle])

  • pixels_per_meter (float)

Return type:

None

draw_overlay(screen, font, sim_state, overlay_enabled=True)[source]#

Render a multi-line overlay with FPS, counts, energies, and controls.

Parameters:
  • screen (pygame.Surface) – Target surface.

  • font (pygame.font.Font) – Font used for text rendering.

  • sim_state (dict) – Simulation state values including fps, n, speed_label, dt_s, substeps, energies, and optional profiling timings under key profile.

  • overlay_enabled (bool) – Whether to render the overlay. If False, nothing is drawn.

Return type:

None