Giter VIP home page Giter VIP logo

rotated-grid's Introduction

Rotated grids in Rust

🎨 For halftone dithering and more.


This crate provides a generator for enumerating grid coordinates at a specified frequency along a rotated grid. This can come in useful e.g. when you want to create halftone dithering grids for CMYK processing:

CMYK grid examples

See e.g. my opencv-cartoon-effect repo for an almost-real-world usage example.

Usage example

use rotated_grid::{Angle, GridPositionIterator, GridCoordinate};

const WIDTH: usize = 16;
const HEIGHT: usize = 10;

fn main() {
    let halftone_grids = [
        ("Cyan", 15.0),
        ("Magenta", 75.0),
        ("Yellow", 0.0),
        ("Black", 45.0),
    ];
    
    for (name, angle) in halftone_grids {
        println!("{name} at {angle}°", name = name, angle = angle);
    
        let grid = GridPositionIterator::new(
            WIDTH as _,
            HEIGHT as _,
            7.0,
            7.0,
            0.0,
            0.0,
            Angle::<f64>::from_degrees(angle),
        );
    
        let (_, expected_max) = grid.size_hint();
        let mut count = 0;
    
        for GridCoordinate { x, y } in grid {
            println!("{x}, {y}", x = x, y = y);
            count += 1;
        }
    
        assert!(count <= expected_max.unwrap())
    }
}

You can run the example application using

cargo run --package cmyk

rotated-grid's People

Contributors

sunsided avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.