Expand description

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

Building a canvas

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

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:

The following example takes the WinitCanvas we built and draws a morphing triangle.

use ferrux_canvas::canvas::Canvas;
use ferrux_canvas::color;
use winit::event::Event;
let event_loop = winit::event_loop::EventLoop::new();
let mut x: i32 = 1;
let mut incrementing = true;

event_loop.run(move |event, _, control_flow| {
  match event {
    Event::MainEventsCleared => {
    Event::RedrawRequested(_) => {
      if !(1..100).contains(&x) {
        incrementing = !incrementing;
      x += if incrementing { 1 } else { -1 };
      canvas.draw_triangle((100, (100 - x) as u32), (100 - x as u32, 100),
                           (200 - x as u32, 200 - x as u32), palette::WHITE);
    _ => (),


The Canvas trait and all its implementations

Color tools to draw on the canvas