Crate unsvg

Source
Expand description

The unsvg crate provides a very simple interface for drawing images.

See below for an example:

use unsvg::{Image, COLORS};

fn main() -> Result<(), String> {
    let mut img: Image = Image::new(200, 200);
    let (x1, y1) = (10, 10);
    // Second point's x and y coordinates.
    let (x2, y2) = img.draw_simple_line(x1, y1, 120, 100, COLORS[1])?;
    // Third point's x and y coordinates.
    let (x3, y3) = img.draw_simple_line(x2, y2, 240, 100, COLORS[2])?;
    let _ = img.draw_simple_line(x3, y3, 0, 100, COLORS[3])?;

    img.save_svg("path_to.svg")?;

    Ok(())
}

Note that unsvg’s underlying SVG library uses floats to represent x and y coordinates. unsvg, on the other hand, expects signed integer coordinate values. This design decision was made to ensure consistent, deterministic behaviour for all coordinate inputs, which is not a given when using floats due to float imprecision.

Structs§

Color
A 8-bit RGB color.
Image
This represents an image that’s being constructed. Use the new function to create one.

Statics§

COLORS
This contains 16 simple colors which users can select from. These correspond to the 16 colors available in the original Logo language. The colors are:

Functions§

get_end_coordinates
Tells you where a line will end, given a starting point, direction, and length. This is used by draw_simple_line to get the end point of a line.