Terminal Particle Simulator

Terminal Particle Simulator

Real-time particle physics simulation rendered entirely in the terminal using ncurses. Written in C with custom physics and rendering engines.

C, ncurses, CMake
Started: 11/7/2024
Updated: 11/15/2024
graphics,terminal,physics,systems

Overview

A particle physics simulator that runs entirely in your terminal, demonstrating that complex graphics and physics simulations don't require GUI frameworks. Built with C and ncurses, this project showcases low-level graphics programming and real-time physics calculations in a constrained environment.

Features

  • Real-Time Physics - Custom physics engine with particle interactions
  • Terminal Rendering - Uses ncurses for efficient terminal-based graphics
  • Particle System - Support for multiple particle types and behaviors
  • Shape Primitives - Built-in drawing library for ellipses, rectangles, and custom shapes
  • Performance Optimized - Efficient rendering for smooth animation in the terminal

Technical Implementation

Architecture

Source Structure:

  • main.c - Core simulation loop and initialization (8,886 lines)
  • physicslib.c - Physics calculations and particle interactions
  • drawlib.c - Terminal rendering abstractions
  • screen.c - Screen buffer management and rendering
  • primatives.c - Shape drawing utilities (rectangles, ellipses, etc.)
  • ellipse.c - Ellipse rendering algorithms
  • rectangle.c - Rectangle drawing routines

Physics Engine

The custom physics library handles:

  • Particle velocity and acceleration
  • Collision detection and response
  • Force simulation (gravity, friction, etc.)
  • Inter-particle interactions

Rendering System

Uses ncurses for terminal manipulation:

  • Double-buffered rendering for flicker-free animation
  • Custom character-based pixel mapping
  • Efficient screen updates (only redraw changed regions)
  • Cross-platform terminal compatibility

Platform Notes

Currently tested on Linux systems. The ncurses dependency provides terminal manipulation capabilities that may vary across platforms.

Building and Running

git clone https://github.com/DeaSTL/term-particles
cd term-particles
cmake .
make
./bin/TermParticle

Requirements

  • ncurses library
  • GCC or compatible C compiler
  • CMake
  • Make

Why Terminal Graphics?

This project explores the intersection of:

  • Constraint-based Programming - Working within terminal limitations
  • Low-Level Graphics - Understanding rendering without GPU acceleration
  • Systems Programming - Direct memory management and performance optimization
  • Retro Computing - Recreating the feel of early computer graphics

Performance Considerations

Terminal rendering presents unique challenges:

  • Limited "resolution" based on character cells
  • No hardware acceleration
  • Character-based pixel representation
  • Terminal refresh rate limitations

The project demonstrates techniques for achieving smooth animation despite these constraints through efficient buffer management and selective updates.

Use Cases

  • Learning low-level graphics programming
  • Understanding particle physics simulation
  • Exploring ncurses capabilities
  • Creating terminal-based visualizations
  • Demonstrating systems programming concepts