61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
|
<?php
|
||
|
namespace Seria;
|
||
|
|
||
|
use Index\XNumber;
|
||
|
use Index\Colour\Colour;
|
||
|
use Index\Colour\ColourRGB;
|
||
|
|
||
|
final class Colours {
|
||
|
public const RATIO_GOOD = 0x008000;
|
||
|
public const RATIO_WARN = 0xFFAA00;
|
||
|
public const RATIO_BAD = 0xFF0000;
|
||
|
|
||
|
public const FILE_UP_TO_1GB = 0xA0F5B8;
|
||
|
public const FILE_UP_TO_5GB = 0xBAE9C7;
|
||
|
public const FILE_UP_TO_10GB = 0xCCDDDD;
|
||
|
public const FILE_UP_TO_20GB = 0xCCA1F4;
|
||
|
public const FILE_UP_TO_50GB = 0xDB5FF1;
|
||
|
public const FILE_OVER_50GB = 0xEC32A4;
|
||
|
|
||
|
private static array $colourCache = [];
|
||
|
|
||
|
public static function forRatio(float $ratio): Colour {
|
||
|
$warning = self::cached(self::RATIO_WARN);
|
||
|
|
||
|
$ratio *= 2;
|
||
|
if($ratio > 1)
|
||
|
return Colour::mix(
|
||
|
$warning,
|
||
|
self::cached(self::RATIO_GOOD),
|
||
|
XNumber::easeInQuad($ratio - 1)
|
||
|
);
|
||
|
|
||
|
return Colour::mix(
|
||
|
self::cached(self::RATIO_BAD),
|
||
|
$warning,
|
||
|
XNumber::easeOutQuad($ratio)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
public static function forFileSize(int $bytes): Colour {
|
||
|
// should this ratio as well?
|
||
|
if($bytes >= 53687090000)
|
||
|
return self::cached(self::FILE_OVER_50GB);
|
||
|
if($bytes >= 21474840000)
|
||
|
return self::cached(self::FILE_UP_TO_50GB);
|
||
|
if($bytes >= 10737420000)
|
||
|
return self::cached(self::FILE_UP_TO_20GB);
|
||
|
if($bytes >= 5368709000)
|
||
|
return self::cached(self::FILE_UP_TO_10GB);
|
||
|
if($bytes >= 1073742000)
|
||
|
return self::cached(self::FILE_UP_TO_5GB);
|
||
|
return self::cached(self::FILE_UP_TO_1GB);
|
||
|
}
|
||
|
|
||
|
public static function cached(int $raw): Colour {
|
||
|
if(array_key_exists($raw, self::$colourCache))
|
||
|
return self::$colourCache[$raw];
|
||
|
return self::$colourCache[$raw] = ColourRGB::fromRawRGB($raw);
|
||
|
}
|
||
|
}
|