Skip to content

Instantly share code, notes, and snippets.

@av
Last active September 29, 2019 10:37
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/7816d20b1f30f304c6643518e7b222c6 to your computer and use it in GitHub Desktop.
Save av/7816d20b1f30f304c6643518e7b222c6 to your computer and use it in GitHub Desktop.
Flutter: vector3 to rgba int color
/// Takes a unit Vector3 (all values from 0 to 1)
/// and returns an int representing color in RGBA format
/// Vector3(0, 1, 0) -> 0xff00ff00
int toColorInt(Vector3 vec) {
int r = (vec.r * 255).toInt();
int g = (vec.g * 255).toInt();
int b = (vec.b * 255).toInt();
return (b << 0) | (g << 8) | (r << 16) | (255 << 32);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment