Turtle RS
A lightweight and simple Rust library for creating vector graphics (SVG) using "Turtle Graphics" logic, inspired by Python's famous turtle module.
Perfect for learning Rust, teaching algorithmics, or generating geometric patterns programmatically.
Features
- Intuitive Movement: Forward, turn left/right, goto coordinates.
- Pen Control: Pen up/down, change color, adjust line width.
- Built-in Shapes: Square, Triangle, Circle, Star, Polygons.
- SVG Export: Saves your art to clean, scalable SVG files.
- Fluent Interface: Chain methods for cleaner code (e.g.,
t.forward(10).right(90)). - Zero dependencies
Installation
Add the dependency to your Cargo.toml:
Quick Start
Here is how to draw a red triangle and save it:
use ;
Shapes API
Circles and Polygons
t.circle;
t.square;
t.triangle;
ℹ️ Note Shapes such as squares and triangles are regular polygons inscribed in a circle, generated from a polar representation. This approach is ideal for generative art and visualization, but does not aim to replace exact Cartesian geometry.
Parametric Radial Shapes
The core primitive of this crate is the shape method:
t.shape;
This allows the creation of:
- stars
- flowers
- spirals
- organic blobs
- custom generative shapes
Coordinate System
The turtle starts at the top left corner of the canvas (0, 0).
- X increases to the right.
- Y increases downwards (SVG standard).
- Angle 0° points to the East (Right).
Contribution
Contributions are welcome! Feel free to open an Issue or a Pull Request on the repository.
License
This project is licensed under the MIT License.