TERMINAL ART BBS v0.1.0 - CONNECTED 64000 BAUD
TERMINAL ART
a few lines of Rust | your mouse | 16 colours | nothing to install
$ cargo add terminal_graphics_interactive_
> THE STUDIO
Pick something to start from, change a number, press RUN. Everything you see is drawn into a grid of characters, just like in a real terminal. Your mouse works in the screen: move it, click, drag, right-click.
Ctrl+Enter runs it. Esc then Tab leaves the editor.
loading the studio ...
Move, click, drag and right-click inside the screen. On a phone, touch and drag.
> THE GUIDE
1. THE SHAPE OF A PROGRAM
Every program is a main that ends by showing one thing: a sketch (a formula for every cell) or a world (balls that move).
use terminal_graphics_interactive::prelude::*;
fn main() -> std::io::Result<()> {
sketch(|cell| (cell.x * 0.2 + cell.t).sin())
}
2. A SKETCH: ONE FORMULA FOR EVERY CELL
The formula runs for every cell, every frame. It gets a cell and returns a number from -1.0 to 1.0 (what sin and cos give), which the palette turns into a colour.
- cell.x
- which column this cell is in
- cell.y
- which row, stretched so one step looks as long as one step of x
- cell.t
- seconds since you pressed RUN
- cell.mouse_x
- the column the mouse is over
- cell.mouse_y
- the row the mouse is over, stretched like y
- cell.mouse_down
- true while the left button is held
- cell.width
- how wide the screen is
- cell.height
- how tall the screen is, stretched like y
- cell.dist_to_mouse()
- how far this cell is from the mouse
Use sketch(|cell| ...) for the ocean palette, or sketch_with(palette, |cell| ...) to choose.
3. PALETTES AND COLOURS
Presets: ocean fire rainbow mono used as Palette::fire().
Or make your own, dark to bright: Palette::new(&[Colour::Black, Colour::Red, Colour::BrightYellow]).
Colours: Black Red Green Yellow Blue Magenta Cyan White BrightBlack BrightRed BrightGreen BrightYellow BrightBlue BrightMagenta BrightCyan BrightWhite
4. MATHS
On any decimal (f32), like cell.x.sin():
sin cos tan asin acos atan sinh cosh tanh sqrt cbrt abs floor ceil round trunc fract signum exp ln log10 log2 recip to_radians to_degrees
With one argument, like a.min(b) or a.powf(2.0):
powf atan2 min max hypot rem_euclid copysign
Also a.powi(3) (a whole-number power), a.clamp(low, high) and a.mul_add(b, c).
Constants: PI TAU E FRAC_PI_2 FRAC_PI_3 FRAC_PI_4 FRAC_PI_6 SQRT_2 LN_2 LN_10 (as PI, or std::f32::consts::PI).
5. A WORLD: BALLS THAT MOVE
Chain settings and finish with .run(). Balls bounce off the walls and each other, and a click adds one.
World::new()
.balls(5)
.size(3.5)
.gravity(0.02)
.mouse_pulls()
.trails()
.run()
- .balls(...)
- how many balls to start with (a whole number, up to 64)
- .size(...)
- how big each ball is, as a radius: try 3.5
- .gravity(...)
- a pull downwards each frame: try 0.02, or a negative number to float up
- .mouse_pulls()
- the mouse pulls the balls in; hold the right button to push them away
- .trails()
- balls leave glowing tails
- .palette(...)
- the colours the balls are drawn in
- .run()
- end the chain with this
6. THE RUST RULES (THIS EDITOR IS AS STRICT AS THE REAL COMPILER)
Decimals need a dot: cell.x * 2.0 works, cell.x * 2 does not. Whole numbers are for counts and loops.
let speed = 2.0; // a decimal
let mut total = 0.0;
for i in 0..5 { // i is a whole number
total += (i as f32) * 0.1; // turn it into a decimal with `as f32`
}
if cell.mouse_down { total } else { -total }
You can use let, let mut, if / else, for i in 0..5, and your own functions like fn ring(d: f32) -> f32. Press RUN and the compiler tells you the line and column of any mistake.
7. TAKE IT HOME
This is real Rust. Anything that runs here also compiles in your own project:
$ cargo add terminal_graphics_interactive $ cargo run
Paste your code into src/main.rs and it runs in your own terminal (Windows PowerShell, Linux, macOS), with your real mouse. Use SHARE to send your art to a friend as a link.
> THE PALETTE
A terminal has 16 colours. Between two of them a number is drawn with a shade block, so a palette is smoother than it sounds.
> LINKS
- GitHub repository - source, examples, issues
- crates.io/crates/terminal_graphics_interactive
- docs.rs/terminal_graphics_interactive - API documentation