4 releases

0.3.1 Mar 11, 2023
0.3.0 Aug 3, 2021
0.2.1 Feb 19, 2021
0.2.0 Feb 17, 2021

#116 in Rendering

Download history 21/week @ 2024-07-19 26/week @ 2024-07-26 19/week @ 2024-08-02 23/week @ 2024-08-09 18/week @ 2024-08-16 6/week @ 2024-08-23 11/week @ 2024-08-30 23/week @ 2024-09-06 20/week @ 2024-09-13 42/week @ 2024-09-20 34/week @ 2024-09-27 15/week @ 2024-10-04 16/week @ 2024-10-11 21/week @ 2024-10-18 21/week @ 2024-10-25 30/week @ 2024-11-01

88 downloads per month

Apache-2.0

3.5MB
9K SLoC

flo_draw = "0.3"

flo_draw

If you want to render some 2D graphics in Rust to screen right now without having to deal with the usual palaver involved with setting up a graphics context in a UI framework, flo_draw is the crate you need.

flo_draw also comes with a powerful set of 2D graphics libraries and has a flexible stream-based API that can make light work of many tasks that other libraries can make a meal of.

Motivation

Screenshot

While building FlowBetween, I found I needed a few when it came to rendering graphics: a platform-agnostic API and a way to render bitmap files that's not tied to any one platform. When debugging it, I found another thing I really wanted was a simple way to just throw up a window and start drawing graphics in it. This used to be quite simple in the 1980s (as demonstated in the screenshot) but the rise of the GUI and 3D accelleration has made rendering graphics increasingly difficult.

flo_draw takes the 2D graphics crates created for FlowBetween and adds an API to take all of the hassle out of the task of making them work.

Basic example

Here's a simple example that will open up a window with a triangle in it:

use flo_draw::*;
use flo_canvas::*;

pub fn main() {
    with_2d_graphics(|| {
        let canvas = create_canvas_window();

        canvas.draw(|gc| {
            gc.clear_canvas(Color::Rgba(0.0, 0.0, 0.0, 1.0));
            gc.canvas_height(1000.0);
            gc.center_region(0.0, 0.0, 1000.0, 1000.0);

            // Draw a rectangle...
            gc.new_path();
            gc.move_to(0.0, 0.0);
            gc.line_to(1000.0, 0.0);
            gc.line_to(1000.0, 1000.0);
            gc.line_to(0.0, 1000.0);
            gc.line_to(0.0, 0.0);

            gc.fill_color(Color::Rgba(1.0, 1.0, 0.8, 1.0));
            gc.fill();

            // Draw a triangle on top
            gc.new_path();
            gc.move_to(200.0, 200.0);
            gc.line_to(800.0, 200.0);
            gc.line_to(500.0, 800.0);
            gc.line_to(200.0, 200.0);

            gc.fill_color(Color::Rgba(0.0, 0.0, 0.8, 1.0));
            gc.fill();
        });
    });
}

For more information, you may be interested in the guide, or the examples.

--

Wibble Mandelbrot Wibble

Dependencies

~28MB
~572K SLoC