strange-attractors

Crates.iostrange-attractors
lib.rsstrange-attractors
version0.1.3
created_at2025-12-31 17:12:55.721829+00
updated_at2025-12-31 17:20:33.760556+00
descriptionStudy into strange attractor visualization in a TUI.
homepagehttps://gitlab.com/ngreese/strange-attractors
repository
max_upload_size
id2015022
size884,639
Nathanael G. Reese (ngreese)

documentation

README

Strange Attractors Rust Study

Introduction

This repository's purpose is to perform a small study in modeling strange attractors using Rust.

It is a simple binary that draws a series of points in a TUI interface using the ratatui and crossterm crates.

It is by no means good Rust code, if you want to see that look at my other crates dingus. This is purely an experiment fueled by a spark of passion at 3 AM one night.

Formulae

The formulae used are shown below. They are also documented in the respective structs doc comments.

Henon Map

$$ \begin{aligned} x_{n+1} &= 1 - a x_n^2 + y_n \\ y_{n+1} &= b x_n \end{aligned} $$

Lorenz Attractor

$$ \begin{aligned} \frac{dx}{dt} &= \sigma (y - x) \ \frac{dy}{dt} &= x (\rho - z) - y \ \frac{dz}{dt} &= x y - \beta z \end{aligned} $$

Using a discrete time step $\Delta t$, the next point $(x_{n+1}, y_{n+1}, z_{n+1})$ is computed via Euler integration:

$$ \begin{aligned} x_{n+1} &= x_n + \sigma (y_n - x_n), \Delta t \ y_{n+1} &= y_n + (x_n (\rho - z_n) - y_n), \Delta t \ z_{n+1} &= z_n + (x_n y_n - \beta z_n), \Delta t \end{aligned} $$

Where:

  • $\sigma$ is the Prandtl number,
  • $\rho$ is the Rayleigh number,
  • $\beta$ is a geometric factor.

Components

Project Structure

The project is split up into two primary modules:

  • formulae - Contains structs and functions used to calculate the points of the attractors.
  • tui - Contains the code used to perform the visualization of the attractors.

Attractor Checklist

This project is a WIP and below tracks what features/attractors are implemented.

  • Henon Map
  • TUI Visualizer
  • Lorenz Attractor
  • User input to show different axes
  • Represent Point X, Y, Z values as R, G, B valuesg

Usage

The program can be run using ./stranger <ARGS> with the binary or cargo run -- <ARGS> within the repository. The arguments are as follows:

  • <ATTRACTOR TYPE> - The first argument of the binary is the attractor type. They are as follows:
    • henon - Visualize a Henon map.
    • lorenz - Visualize a Lorenz attractor.
  • --h, --help - Prints the usage information.
  • --p, --parameters <A>,<B>,<C> - Sets the parameters of the respective attractor.
  • --debug - Does not open a TUI window, prints 1000 iterations of the attractor to stdout. Used for debugging.

Controls

The program utilizes user input for various controls:

  • q - Quit the program.
  • +/- - Increase/decrease the time step.
  • 1,2,3 - Select the axis to visualize. (Note: Only used for Lorenz attractor)
  • Spacebar - Toggle point color.

Screenshots

Fun part! Screenshots

The colors of the points when toggled visualize the X, Y, and Z components as R, G, and B respectively.

Henon Map

Henon Map Visualization

Lorenz attractor

X as horizontal axis, Y as vertical

Lorenz Attractor Visualization (X horizontal, Y vertical)

X as horizontal, Z as vertical

Lorenz Attractor Visualization (X horizontal, Z vertical)

Z as horizontal, Y as vertical

Lorenz Attractor Visualization (Z horizontal, Y vertical)

Commit count: 0

cargo fmt