Created
September 29, 2019 10:54
-
-
Save av/aa5ea6542373395e24e81eeb1f8f9c17 to your computer and use it in GitHub Desktop.
Flutter: gradient stripes over x-axis
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) { | |
/// Compute unified vector, values of its components | |
/// will be between 0 and 1 | |
var uv = Vector2(x / size.width, y / size.height); | |
var xTiles = 10.0; | |
/// First of all, we scale uv.xxx ten times: | |
/// 0..1 * 10 -> 0..10 | |
/// | |
/// Then, for a particular position, it would look like: | |
/// 0.24 * 10 -> 2.4 | |
/// | |
/// Taking a fraction, would clamp resulting value back to | |
/// unit range: | |
/// frac(2.4) -> 0.4 | |
/// | |
/// So, below we will have 10 gradient stripes over x-axis. | |
return toColorInt(frac(uv.xxx * xTiles)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment