#iterator #iterator-adapter #circle #bresenham #adapter

rasterization

Iterator and iterator adapters for rasterizing a circle and its parts

2 unstable releases

0.2.0 Sep 16, 2024
0.1.0 Sep 8, 2024

#500 in Algorithms

Download history 192/week @ 2024-09-08 181/week @ 2024-09-15 26/week @ 2024-09-22 24/week @ 2024-09-29

235 downloads per month

MIT and GPL-3.0-or-later

38KB
398 lines

Rasterization

This crate provides iterators and adapters for generating sequential coordinates for various shapes of a circle or its parts using Bresenham's algorithm.

Visual examples of different shapes:



Examples

Here's how to use the crate:

use rasterization::{Rasterization, SemicircleFilled, DirectionGradient::Bottom};

let radius = 128_usize;
let iter = SemicircleFilled::<i32>::new(radius)
    .circle()
    .offset(radius as i32, radius as i32);

let iter = SemicircleFilled::<i32>::new(radius)
    .circle_long(-128, 0)
    .offset((radius * 2) as i32, radius as i32);

let iter = SemicircleFilled::<i32>::new(radius)
    .semicircle_top()
    .offset(radius as i32, radius as i32);

let iter = SemicircleFilled::<i32>::new(radius)
    .semicircle_bottom()
    .offset(radius as i32, radius as i32);

let iter = SemicircleFilled::<i32>::new(radius)
    .circle()
    .offset(radius as i32, radius as i32)
    .gradient(radius as i32, radius * 2, Bottom(colorous::BROWN_GREEN));

Installation

Add the following to your Cargo.toml:

[dependencies]
rasterization = "0.2.0"

License

This project is licensed under the MIT License.

Dependencies

~630KB
~12K SLoC