drawing_stuff/
lib.rs

1//! `drawing-stuff` is a collection of utilities to make drawing onto a canvas / pixel buffer easy.
2//!
3//! This version of the library is definetely not fully featured and also not fully documented as its mostly thought for my personal use.
4//!
5//! # Examples
6//!
7//! ```
8//! use drawing_stuff::canvas::Canvas;
9//! use drawing_stuff::color::{RGB, WHITE};
10//!
11//! const WIDTH: usize = 1080;
12//! const HEIGHT: usize = 720;
13//!
14//! fn main() {
15//!     let mut canvas = Canvas::new(WIDTH, HEIGHT);
16//!
17//!     // get color of pixel
18//!     canvas.get(200, 100);
19//!
20//!     // set color of pixel
21//!     canvas.set(200, 100, RGB { r: 255, g: 255, b: 255 });
22//!
23//!     // draw single pixel
24//!     canvas.draw_pixel(200, 100, WHITE);
25//!
26//!     // draw line
27//!     canvas.draw_line(200, 100, 500, 700, WHITE);
28//!
29//!     // draw circle
30//!     canvas.draw_circle(200, 100, 15, WHITE);
31//!     canvas.draw_circle_solid(200, 100, 15, WHITE);
32//!
33//!     // draw polygon
34//!     let vertices = vec![(200, 100), (500, 700), (300, 800)]; // clockwise
35//!     canvas.draw_polygon(&vertices, WHITE);
36//!     canvas.draw_polygon_solid(&vertices, true, WHITE);
37//! }
38//! ```
39//!
40//! ## Creating custom drawables
41//!
42//! ```
43//! use drawing_stuff::canvas::{Canvas, Draw};
44//! use drawing_stuff::color::{RGBA, WHITE};
45//!
46//! pub struct Circle {
47//!     pub center: (isize, isize),
48//!     pub radius: u32,
49//!     pub solid: bool,
50//!
51//!     pub color: RGBA,
52//! }
53//!
54//! impl Draw for Circle {
55//!     fn draw(&self, canvas: &mut Canvas) {
56//!        match self.solid {
57//!           true => canvas.draw_circle_solid(self.center.0, self.center.1, self.radius, self.color),
58//!           false => canvas.draw_circle(self.center.0, self.center.1, self.radius, self.color),
59//!       }
60//!     }
61//! }
62//!
63//! const WIDTH: usize = 1080;
64//! const HEIGHT: usize = 720;
65//!
66//! fn main() {
67//!     let mut canvas = Canvas::new(WIDTH, HEIGHT);
68//!
69//!     let circle = Circle {
70//!         center: (200, 100),
71//!         radius: 15,
72//!         solid: true,
73//!         color: WHITE,
74//!     };
75//!
76//!     canvas.draw(&circle);
77//!     // or
78//!     circle.draw(&mut canvas);
79//! }
80//! ```
81
82pub mod canvas;
83pub mod color;
84pub mod drawables;