Giter Club home page Giter Club logo

widemeadows.rotatedgrid's Introduction

Rotated grids in .NET

๐ŸŽจ For halftone dithering and more.

This project provides an enumerator for creating 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.

This is a port of the rotated-grid Rust crate. The following screenshot is taken from that repo; this repository does not contain any visualization code.

CMYK grid examples

Examples

Enumeration on an aligned grid (0 degrees rotation). The points are evenly spaced by dx=2 and dy=3, centered inside a 10ร—7 rectangle. No offset is used.

const float width = 10.0F;
const float height = 7.0F;

var grid = new GridPositionIterator(width, height, 2.0F, 3.0F, 0.0F, 0.0F, Angle.Zero);

var coordinates = new List<GridCoord>();
while (grid.MoveNext())
{
    coordinates.Add(grid.Current);
}

coordinates.Count.Should().Be(15);
coordinates.Should().ContainInOrder(
    // First row
    new GridCoord(1.0F, 0.5F),
    new GridCoord(3.0F, 0.5F),
    new GridCoord(5.0F, 0.5F),
    new GridCoord(7.0F, 0.5F),
    new GridCoord(9.0F, 0.5F),
    // Second row row
    new GridCoord(1.0F, 3.5F),
    new GridCoord(3.0F, 3.5F),
    new GridCoord(5.0F, 3.5F),
    new GridCoord(7.0F, 3.5F),
    new GridCoord(9.0F, 3.5F),
    // Third row
    new GridCoord(1.0F, 6.5F),
    new GridCoord(3.0F, 6.5F),
    new GridCoord(5.0F, 6.5F),
    new GridCoord(7.0F, 6.5F),
    new GridCoord(9.0F, 6.5F)
    );

Enumeration on a rotated grid; in the example below, 45 degrees rotation are used:

const float width = 10.0F;
const float height = 7.0F;
const float angle = 45.0F;

var grid = new GridPositionIterator(width, height, 2.0F, 2.0F, 0.0F, 0.0F, Angle.FromDegrees(angle));

var coordinates = new List<GridCoord>();
while (grid.MoveNext())
{
    coordinates.Add(grid.Current);
}

coordinates.Count.Should().Be(17);
coordinates.Should().ContainInOrder(
    // First row
    new GridCoord(0.7573595F, 2.0857863F),
    new GridCoord(2.1715730F, 0.6715729F),
    // Second row
    new GridCoord(0.7573595F, 4.9142137F),
    new GridCoord(2.1715730F, 3.5000000F),
    new GridCoord(3.5857863F, 2.0857863F),
    new GridCoord(5.0000000F, 0.6715729F),
    // Third row
    new GridCoord(2.1715730F, 6.3284273F),
    new GridCoord(3.5857863F, 4.9142137F),
    new GridCoord(5.0000000F, 3.5000000F),
    new GridCoord(6.4142137F, 2.0857863F),
    new GridCoord(7.8284273F, 0.6715729F),
    // Fourth row
    new GridCoord(5.0000000F, 6.3284273F),
    new GridCoord(6.4142137F, 4.9142137F),
    new GridCoord(9.2426405F, 2.0857863F),
    // Fifth row
    new GridCoord(7.8284273F, 6.3284273F),
    new GridCoord(9.2426405F, 4.9142137F)
);

widemeadows.rotatedgrid's People

Contributors

sunsided 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.