#canvas #tk

canrust

A Rust library for drawing shapes onto a canvas

5 stable releases

new 1.2.1 Aug 3, 2020
1.1.0 Jul 31, 2020
1.0.2 Jul 30, 2020

#145 in Images

MIT license

71KB
1.5K SLoC

canrust

A port of Tk's Canvas, written in Rust and SFML, aiming to provide simple and Python-like syntax.

Example:

example

use canrust::canvas::{Canvas, Color}; 

fn main() {
      // Create a canvas:
      // size, name, background color
      let mut canvas = Canvas::new((800, 600), "Canvas", Color::WHITE);
      
      // create shapes:
      // laser eyes go brrrrr
      canvas.create_circle((1., 1.), 20., Color::BLACK, None, None).unwrap();
      canvas.create_rectangle((20., 20.), (30., 80.), Color::BLACK, None, None).unwrap();
      canvas.create_line((18., 20.), (18., 80), 2., Color::RED, None, None).unwrap();
      canvas.create_line((32., 20.), (32. 80.), 2., Color::RED, None, None).unwrap();
      
      // call the mainloop, objects will keep rendering as long as the program is running
      canvas.mainloop()
}

Dependencies

  • SFML 2.5
  • CSFML 2.5

Installation

Add this line to your Cargo.toml

[dependencies]
canrust = "1.0"

lib.rs:

This crate is a port of Tk's Canvas, written using SFML, aiming to provide simple and tkinter-like syntax.

Example:

use canrust::canvas::{Canvas, Color}; fn main() { // Create a canvas:
    // size, name, background color
    let mut canvas = Canvas::new((800, 600), "Canvas", Color::WHITE);
    
    // create shapes:
    canvas.create_circle((1., 1.), 20., Color::BLACK, None, None).unwrap();
    canvas.create_rectangle((20., 20.), (30., 80.), Color::BLACK, None, None).unwrap();
    canvas.create_line((18., 20.), (18., 80.), 2., Color::RED, None, None).unwrap();
    canvas.create_line((32., 20.), (32. 80.), 2., Color::RED, None, None).unwrap();
    
    // call mainloop, objects will be rendered as long as the program is running
    canvas.mainloop()
}

Dependencies

  • SFML 2.5
  • CSFML 2.5

Installation

Add this to your Cargo.toml file:

[dependencies]
canrust = "1.1.1"

Dependencies

~575KB