diff options
author | Minteck <contact@minteck.org> | 2022-10-10 20:51:39 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-10-10 20:51:39 +0200 |
commit | 108525534c28013cfe1897c30e4565f9893f3766 (patch) | |
tree | dd3e5132971f96ab5f05e7f3f8f6dbbf379a19bd /includes/rainbow.php | |
parent | 2162eaa06f7e4764eb3dcfe130ec2c711d0c62ab (diff) | |
download | pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.tar.gz pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.tar.bz2 pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.zip |
Update
Diffstat (limited to 'includes/rainbow.php')
-rw-r--r-- | includes/rainbow.php | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/includes/rainbow.php b/includes/rainbow.php deleted file mode 100644 index c710be0..0000000 --- a/includes/rainbow.php +++ /dev/null @@ -1,97 +0,0 @@ -<?php - -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.php"; -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/score.php"; - -function rgbToHsl($r, $g, $b) { - $oldR = $r; - $oldG = $g; - $oldB = $b; - - $r /= 255; - $g /= 255; - $b /= 255; - - $max = max($r, $g, $b); - $min = min($r, $g, $b); - - $l = ($max + $min) / 2; - $d = $max - $min; - - if ($d == 0) { - $h = $s = 0; - } else { - $s = $d / (1 - abs(2 * $l - 1)); - - switch ($max) { - case $r: - $h = 60 * fmod((($g - $b) / $d), 6); - if ($b > $g) { - $h += 360; - } - break; - - case $g: - $h = 60 * (($b - $r) / $d + 2); - break; - - case $b: - $h = 60 * (($r - $g) / $d + 4); - break; - } - } - - return array(round($h, 2), round($s, 2), round($l, 2)); -} - -function rainbow(): array { - $members = scoreOrderGlobal(); - $data = []; - - foreach ($members as $member) { - $data[$member["name"]] = [ - "_data" => $member - ]; - - if (isset($member["color"])) { - $data[$member["name"]]["rgb"] = [ - hexdec(substr($member["color"], 0, 2)), - hexdec(substr($member["color"], 2, 2)), - hexdec(substr($member["color"], 4, 2)) - ]; - $data[$member["name"]]["hsl"] = rgbToHsl( - $data[$member["name"]]["rgb"][0], - $data[$member["name"]]["rgb"][1], - $data[$member["name"]]["rgb"][2] - ); - } else { - $data[$member["name"]]["rgb"] = [255, 255, 255]; - $data[$member["name"]]["hsl"] = rgbToHsl(255, 255, 255); - } - } - - return $data; -} - -function getMembersByColor(): array { - $members = rainbow(); - uasort($members, function ($a, $b) { - return $a['hsl'][0] - $b['hsl'][0]; - }); - $members = [ - ...array_filter($members, function ($i) { - return $i['hsl'][2] < 0.9 || $i['hsl'][1] > 0.2; - }), - ...array_filter($members, function ($i) { - return $i['hsl'][2] >= 0.9 || $i['hsl'][1] <= 0.2; - }) - ]; - - $sorted = []; - foreach ($members as $data) { - $data["_data"]["hue"] = $data["hsl"][0]; - $sorted[] = $data["_data"]; - } - - return $sorted; -}
\ No newline at end of file |