3 releases
Uses new Rust 2024
| 0.1.3 | Dec 31, 2025 |
|---|---|
| 0.1.2 | Dec 31, 2025 |
| 0.1.1 | Dec 31, 2025 |
#279 in Math
390KB
531 lines
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

Lorenz attractor
X as horizontal axis, Y as vertical

X as horizontal, Z as vertical

Z as horizontal, Y as vertical

Dependencies
~9–14MB
~277K SLoC