[][src]Crate draw

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 a Circle or Line.
  • Style defines the fill and stroke of a drawing.

The general flow for creating a piece of art is:

  1. Create a Canvas
  2. Create Drawing objects and add them to the Canvas display_list.
  3. Position and style the drawings
  4. Render and save the Canvas to whatever output format you want. (SVG, PNG, etc...)

Basic Example

use draw::{Canvas, Drawing, Shape, Style, Fill, Stroke, RGB};
use draw::render::{self, svg::SvgRenderer};

// create a canvas to draw on
let mut canvas = Canvas::new(100, 100);

// create a rectangle
let mut rect = Drawing::new(Shape::Rectangle {
    width: 50,
    height: 50,

// move it around
rect.position.x = 25.0;
rect.position.y = 25.0;

// give it a cool style
rect.style = Style {
    fill: Some(Fill {
        color: RGB::new(0, 0, 0),
    stroke: Some(Stroke {
        width: 2,
        color: RGB::new(255, 0, 0),

// add it to the canvas

// save the canvas as an svg
.expect("Failed to save");


pub use crate::canvas::Canvas;
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;



Top level container for a drawing.


Renders Canvas objects to bytes, allows for saving to disk.


Shape data


Vector object styles; Fill and Stroke data



A sorted Vec of Drawings, ordered from bottom to top.


A drawing composes a Shape, a DisplayList, a Position, and a Style. It's a complete sub-tree of an overall piece of art.

Type Definitions


Drawings are stored in a vector; this usize is a handle to access the child


An alias for float positioning. Note that SVGs look crisper when objects are positioned on integer bounds, so you may just want to stick to whole numbers. A more advanced version of this library would just directly use Point2<T>, but I decided to prioritze readability. We may want to revist that at some point. todo: I disagree with myself. Let consumers handle this.


An alias for RGB