pixel_canvas/
lib.rs

1#![deny(missing_docs)]
2
3//! This crate is designed to make it easy to build interactive computer art
4//! with just a pixel buffer. For inspiration, consider looking at
5//! <https://shadertoy.com> and <http://www.iquilezles.org/www/index.htm>,
6//! there are a lot of cool art pieces to see and explanations of fun techniques!
7//!
8//! # Usage
9//!
10//! To make a piece of art, you create and configure a [`Canvas`] object, and
11//! then you ask it to [`render`] with your code. The canvas will do state
12//! management and hand you an image to modify. Whatever modifications you make
13//! to the image will be displayed on the screen.
14//!
15//! [`Canvas`]: struct.Canvas.html
16//! [`render`]: struct.Canvas.html#method.render
17//!
18//! # Example
19//!
20//! ```rust,no_run
21//! use pixel_canvas::{Canvas, Color, input::MouseState};
22//!
23//! fn main() {
24//!     // Configure the window that you want to draw in. You can add an event
25//!     // handler to build interactive art. Input handlers for common use are
26//!     // provided.
27//!     let canvas = Canvas::new(512, 512)
28//!         .title("Tile")
29//!         .state(MouseState::new())
30//!         .input(MouseState::handle_input);
31//!     // The canvas will render for you at up to 60fps.
32//!     canvas.render(|mouse, image| {
33//!         // Modify the `image` based on your state.
34//!         let width = image.width() as usize;
35//!         for (y, row) in image.chunks_mut(width).enumerate() {
36//!             for (x, pixel) in row.iter_mut().enumerate() {
37//!                 let dx = x as i32 - mouse.x;
38//!                 let dy = y as i32 - mouse.y;
39//!                 let dist = dx * dx + dy * dy;
40//!                 *pixel = Color {
41//!                     r: if dist < 128 * 128 { dy as u8 } else { 0 },
42//!                     g: if dist < 128 * 128 { dx as u8 } else { 0 },
43//!                     b: (x * y) as u8,
44//!                 }
45//!             }
46//!         }
47//!     });
48//! }
49//! ```
50
51pub mod canvas;
52pub mod color;
53pub mod image;
54pub mod input;
55pub mod math;
56pub mod prelude;
57pub mod vector;
58
59#[doc(inline)]
60pub use prelude::*;