Skip to content

Instantly share code, notes, and snippets.

@av
Created September 26, 2019 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save av/9ed6325f4ea5b157ec8a96a13798bb36 to your computer and use it in GitHub Desktop.
Save av/9ed6325f4ea5b157ec8a96a13798bb36 to your computer and use it in GitHub Desktop.
Flutter: texture generator, uv coordinate space
/// 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