farba

Crates.iofarba
lib.rsfarba
version0.1.1
sourcesrc
created_at2023-04-13 00:59:55.991971
updated_at2023-04-13 23:12:33.399083
descriptionA CPU graphics library written in pure Rust
homepage
repositoryhttps://github.com/wowkster/farba
max_upload_size
id837755
size292,443
Adrian Wowk (wowkster)

documentation

README

Farba

Crates.io GitHub

A CPU graphics library written in pure Rust

The library is not concerned with displaying the image. It only fills up the memory with pixels. It's up to you what to do with those pixels.

The name is pronounced as "farba" (how its spelled) which is a Ukrainian word for "paint" ("фарба").

Examples

3D Cube

$ cargo run --example 3d_cube --features="window"

Flag of Japan

$ cargo run --example flag_of_japan --features="image"
use farba::{Canvas, RGBAColor};

const CANVAS_WIDTH: usize = 900;
const CANVAS_HEIGHT: usize = 600;

fn main() {
    let mut canvas = Canvas::new(CANVAS_WIDTH, CANVAS_HEIGHT);

    // Taken from https://upload.wikimedia.org/wikipedia/en/9/9e/Flag_of_Japan.svg
    canvas.fill(RGBAColor::WHITE);
    canvas.circle(
        (CANVAS_WIDTH / 2) as i32,
        (CANVAS_HEIGHT / 2) as i32,
        180,
        RGBAColor::from_rgb(0xBC, 0x00, 0x2D),
    );

    canvas.save_to_file("./examples/flag_of_japan.png");
}

Rectangles

$ cargo run --example rectangle --features="image"
use farba::{Canvas, RGBAColor};

fn main() {
    let mut canvas = Canvas::new(400, 400);

    canvas.fill(RGBAColor::WHITE);

    // Left eye
    canvas.rect(80, 80, 30, 80, RGBAColor::BLACK);

    // Right eye
    canvas.rect(290, 80, 30, 80, RGBAColor::BLACK);

    // Mouth
    canvas.rect(80, 260, 30, 60, RGBAColor::BLACK);
    canvas.rect(290, 260, 30, 60, RGBAColor::BLACK);
    canvas.rect(80, 290, 240, 30, RGBAColor::BLACK);

    canvas.save_to_file("./examples/rectangle.png");
}
Commit count: 23

cargo fmt