Expand description
draw
is a simple 2D vector drawing library.
Canvas
is a container that defines the size and top-level components of your drawing.Drawing
defines the position, style, and sub-components of a drawing.Shape
defines the geometry of an individual shape such as aCircle
orLine
.Style
defines the fill and stroke of a drawing.
The general flow for creating a piece of art is:
- Create a
Canvas
- Create
Drawing
objects and add them to the Canvasdisplay_list
. - Position and style the drawings
- Render and save the
Canvas
to whatever output format you want. (SVG, PNG, etc…)
§Basic Example
use draw::*;
// create a canvas to draw on
let mut canvas = Canvas::new(100, 100);
// create a new drawing
let mut rect = Drawing::new()
// give it a shape
.with_shape(Shape::Rectangle {
width: 50,
height: 50,
})
// move it around
.with_xy(25.0, 25.0)
// give it a cool style
.with_style(Style::stroked(5, Color::black()));
// add it to the canvas
canvas.display_list.add(rect);
// save the canvas as an svg
render::save(
&canvas,
"tests/svg/basic_end_to_end.svg",
SvgRenderer::new(),
)
.expect("Failed to save");
Re-exports§
pub use crate::canvas::Canvas;
pub use crate::drawing::DisplayList;
pub use crate::drawing::Drawing;
pub use crate::render::svg::SvgRenderer;
pub use crate::shape::LineBuilder;
pub use crate::shape::Shape;
pub use crate::style::Color;
pub use crate::style::Fill;
pub use crate::style::Stroke;
pub use crate::style::Style;
Modules§
- canvas
- Top level container for a drawing.
- drawing
- render
- Renders Canvas objects to bytes, allows for saving to disk.
- shape
- Shape data
- style
- Vector object styles; Fill and Stroke data