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