-
Notifications
You must be signed in to change notification settings - Fork 18
/
make-color-names.php
49 lines (39 loc) · 1.04 KB
/
make-color-names.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* ColorNames class generator.
*/
function makeColors(string $file)
{
if (($lines = @file_get_contents($file)) === false) {
throw new RuntimeException("Couldn't open colors file: " . $file);
}
foreach (explode("\n", $lines) as $line) {
if (!preg_match('/^[ \t]*(\d+)[ \t]+(\d+)[ \t]+(\d+)[ \t]+([\w ]+)\R?$/', $line, $match)) {
continue;
}
[$_, $r, $g, $b, $name] = $match;
yield $name => fn () => printf('%d, %d, %d', $r, $g, $b);
}
}
$filename = $argv[1] ?: 'colors.txt';
if (! file_exists($filename)) {
throw new RuntimeException("File not exist: " . $filename);
}
echo "<?php
declare(strict_types=1);\n";
?>
namespace Tkui;
/**
* DON'T EDIT THIS CLASS !
*
* It was generated by make-color-names.php script.
*/
class ColorNames
{
/** @var array<string, array{int, int, int}> */
public static array $color = [
<?php foreach (makeColors($filename) as $name => $rgb): ?>
'<?= strtolower($name) ?>' => [<?php $rgb() ?>],
<?php endforeach ?>
];
}