seria/public/test.php

42 lines
1.4 KiB
PHP
Raw Normal View History

2022-07-03 23:44:11 +00:00
<!doctype html>
<?php
ini_set('display_errors', 'on');
error_reporting(-1);
function seria_weighted_number(float $num1, float $num2, float $weight): int {
$weight = min(1, max(0, $weight));
return round(($num1 * $weight) + ($num2 * (1 - $weight)));
}
function seria_weighted_colour(int $colour1, int $colour2, float $weight): int {
$colour1 = [ ($colour1 >> 16) & 0xFF, ($colour1 >> 8) & 0xFF, $colour1 & 0xFF ];
$colour2 = [ ($colour2 >> 16) & 0xFF, ($colour2 >> 8) & 0xFF, $colour2 & 0xFF ];
return (seria_weighted_number($colour1[0], $colour2[0], $weight) << 16)
| (seria_weighted_number($colour1[1], $colour2[1], $weight) << 8)
| seria_weighted_number($colour1[2], $colour2[2], $weight);
}
function seria_weighted_colour_hex(int $colour1, int $colour2, float $weight): string {
return sprintf('#%06x', seria_weighted_colour($colour1, $colour2, $weight));
}
function seria_easeInQuad(float $n): float {
return $n * $n;
}
function seria_easeOutQuad(float $n): float {
return 1 - (1 - $n) * (1 - $n);
}
function seria_ratio_colour(float $ratio): string {
$ratio *= 2;
if($ratio > 1)
return seria_weighted_colour_hex(0x008000, 0xFFAA00, seria_easeInQuad($ratio - 1));
return seria_weighted_colour_hex(0xFFAA00, 0xFF0000, seria_easeOutQuad($ratio));
}
for($i = 0; $i <= 100; ++$i) {
$if = $i / 100;
printf('<span style="color: %2$s;">%1$01.2f %2$s</span><br/>', $if, seria_ratio_colour($if));
}