Crates.io docs.rs Rust

FerruX Canvas

Ferrux Canvas is an abstraction layer over the Pixels crate. It manages the pixel buffer exposing simple operations to draw pixels, lines and figures in the screen. In its current state it only works with Winit.

The list of current goals is listed in the repository's project.

Usage

Building a canvas

Right now, the only Canvas provided is WinitCanvas, which requires a winit Window, which will need itself an EventLoop reference.

rust let event_loop = winit::event_loop::EventLoop::new(); let window = winit::window::Window::new(&event_loop)?; let canvas = ferrux_canvas::canvas::winit::WinitCanvas::new(&window)?;

Running a canvas

The main flow to use a canvas is: * Use the drawing functions like [draw_line] and [draw_triangle]. * Call the [render] method to print it on screen. * Use [reset_frame] to clear the current buffer and draw a new frame.

The following example takes the [WinitCanvas] we built and draws a morphing triangle. ```rust let mut x: i32 = 1; let mut incrementing = true;

eventloop.run(move |event, _, controlflow| { match event { Event::MainEventsCleared => { window.requestredraw(); } Event::RedrawRequested() => { if !(1..100).contains(&x) { incrementing = !incrementing; } x += if incrementing { 1 } else { -1 }; canvas.drawtriangle((100, (100 - x) as u32), (100 - x as u32, 100), (200 - x as u32, 200 - x as u32), palette::WHITE); canvas.filltriangle((100, (100 - x) as u32), (100 - x as u32, 100), (200 - x as u32, 200 - x as u32), Color::fromrgba("2303b0dd")); canvas.render().unwrap(); canvas.resetframe(); } _ => (), } }); ```

About

The FerruX Canvas is a tool developed while creating the FerruXengine, an attempt of 3D graphics engine I was trying to make. I made this canvas to ease the use of the Pixels buffer used by the engine. As the tool proved useful for other possible future projects I was thinking of, and a couple of mutuals of mine thought that they could use it too, it was decided to extract it as its own library.

License

Licensed, at your option, under either of:

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.