Created
September 29, 2019 11:35
-
-
Save av/e3a5bf5322a6e6a5211df44a300e5c29 to your computer and use it in GitHub Desktop.
Flutter: checkerboard grid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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