Skip to content

Instantly share code, notes, and snippets.

@av
Created September 29, 2019 11:35
Show Gist options
  • Save av/e3a5bf5322a6e6a5211df44a300e5c29 to your computer and use it in GitHub Desktop.
Save av/e3a5bf5322a6e6a5211df44a300e5c29 to your computer and use it in GitHub Desktop.
Flutter: checkerboard grid
/// Main area of interest, this function will
/// return color for each particular color on our [ui.Image]
int generatePixel(int x, int y, Size size) {
var tiles = 5.0;
var uv = Vector2(x / size.width, y / size.height);
uv.y /= size.aspectRatio;
var gridUv = frac2(uv * tiles);
/// We have a square with top left and bottom right quarters
/// painter with white and the rest being black.
return (gridUv.x < .5 && gridUv.y < .5) || (gridUv.x > .5 && gridUv.y > .5)
? 0xffffffff
: 0xff000000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment