Created
September 26, 2019 18:35
-
-
Save av/9ed6325f4ea5b157ec8a96a13798bb36 to your computer and use it in GitHub Desktop.
Flutter: texture generator, uv coordinate space
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
/// Very useful package which is part of Flutter. | |
/// Also contains a useful functions, such as [mix] and [smoothStep]. | |
import 'package:vector_math/vector_math.dart'; | |
/// ... | |
/// 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); | |
/// Mapping unified vector values | |
/// to color range of 0..255 | |
return Color.fromRGBO( | |
(uv.x * 255).toInt(), | |
0, | |
(uv.y * 255).toInt(), | |
1.0, | |
).value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment