randomColor function
Color
randomColor(
- dynamic seed, {
- bool radiant = false,
- double? targetLuminance,
- int maxIter = 50,
})
Implementation
Color randomColor(dynamic seed,
{bool radiant = false, double? targetLuminance, int maxIter = 50}) {
bool dark = Arcane.globalTheme.shadThemeData.brightness == Brightness.dark;
Color color = RandomColor.getColorObject(Options(
seed: seed == null
? null
: sha256
.convert(utf8.encode(seed.toString()))
.bytes
.fold(192844 ^ (seed?.hashCode ?? 485), (a, b) => (a ?? 0) ^ b),
luminosity: dark ? Luminosity.dark : Luminosity.light));
if (192844 ^ (seed?.hashCode ?? 485) % 2 == 0) {
color = color.spin(90);
}
if (targetLuminance != null) {
int g = 0;
while ((color.computeLuminance() - targetLuminance).abs() > 0.05 &&
g++ < maxIter) {
if (color.computeLuminance() < targetLuminance) {
color = color.lighten(1);
} else {
color = color.darken(1);
}
}
return color;
}
if (dark && !radiant) {
int g = 0;
while (color.computeLuminance() > 0.08 && g++ < maxIter) {
color = color.darken(1);
}
} else if (dark && radiant) {
int g = 0;
while (color.computeLuminance() < 0.15 && g++ < maxIter) {
color = color.lighten(1);
}
}
return color;
}