Last active
September 29, 2019 11:32
-
-
Save av/73cc529a89d9b57f11f88bdfdb7f73e6 to your computer and use it in GitHub Desktop.
Flutter: fixed aspect ratio 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; | |
/// Compute uv in same way as in previous examples. | |
var uv = Vector2(x / size.width, y / size.height); | |
/// New twist, [Size.aspectRatio] is essentially [Size.width] | |
/// divided by [Size.height]. | |
/// uv.y /= 2 would make our tiles 2 times taller | |
/// uv.y *= 2 would make tiles 2 times shorter | |
/// uv.y /= size.aspectRatio would make them as many | |
/// times taller or shorter as aspect ratio | |
/// between [Size.width] and [Size.height] | |
uv.y /= size.aspectRatio; | |
return toColorInt((frac2(uv * tiles)).xyx); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment