|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Artack\Color; |
|
6
|
|
|
|
|
7
|
|
|
use Artack\Color\Color\CMYK; |
|
8
|
|
|
use Artack\Color\Color\HEX; |
|
9
|
|
|
use Artack\Color\Color\HSL; |
|
10
|
|
|
use Artack\Color\Color\HSV; |
|
11
|
|
|
use Artack\Color\Color\RGB; |
|
12
|
|
|
use Artack\Color\Converter\CMYKToRGBConverter; |
|
13
|
|
|
use Artack\Color\Converter\ConverterInterface; |
|
14
|
|
|
use Artack\Color\Converter\HEXToRGBConverter; |
|
15
|
|
|
use Artack\Color\Converter\HSLToRGBConverter; |
|
16
|
|
|
use Artack\Color\Converter\HSVToRGBConverter; |
|
17
|
|
|
use Artack\Color\Converter\RGBToCMYKConverter; |
|
18
|
|
|
use Artack\Color\Converter\RGBToHEXConverter; |
|
19
|
|
|
use Artack\Color\Converter\RGBToHSLConverter; |
|
20
|
|
|
use Artack\Color\Converter\RGBToHSVConverter; |
|
21
|
|
|
use Artack\Color\Transition\HSVTransition; |
|
22
|
|
|
use Artack\Color\Transition\RGBTransition; |
|
23
|
|
|
use Artack\Color\Transition\TransitionInterface; |
|
24
|
|
|
use Fhaculty\Graph\Graph; |
|
25
|
|
|
use Fhaculty\Graph\Vertex; |
|
26
|
|
|
|
|
27
|
|
|
class Factory |
|
28
|
|
|
{ |
|
29
|
|
|
const GRAPH_EDGE_KEY_CONVERTER = 'converter'; |
|
30
|
|
|
|
|
31
|
924 |
|
public static function createConverter(): Converter |
|
32
|
|
|
{ |
|
33
|
924 |
|
return new Converter(new ConverterGraph(self::getConverterGraph())); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
7 |
|
public static function createTransition(): Transition |
|
37
|
|
|
{ |
|
38
|
7 |
|
return new Transition(self::getTransitions(), self::createConverter()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return ConverterInterface[] |
|
43
|
|
|
*/ |
|
44
|
924 |
|
private static function getConverters(): array |
|
45
|
|
|
{ |
|
46
|
|
|
return [ |
|
47
|
924 |
|
new RGBToHSVConverter(), |
|
48
|
924 |
|
new HSVToRGBConverter(), |
|
49
|
924 |
|
new RGBToHEXConverter(), |
|
50
|
924 |
|
new HEXToRGBConverter(), |
|
51
|
924 |
|
new CMYKToRGBConverter(), |
|
52
|
924 |
|
new RGBToCMYKConverter(), |
|
53
|
924 |
|
new HSLToRGBConverter(), |
|
54
|
924 |
|
new RGBToHSLConverter(), |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
924 |
|
private static function getColors(): array |
|
59
|
|
|
{ |
|
60
|
|
|
return [ |
|
61
|
924 |
|
RGB::class, |
|
62
|
|
|
HSV::class, |
|
63
|
|
|
HSL::class, |
|
64
|
|
|
HEX::class, |
|
65
|
|
|
CMYK::class, |
|
66
|
|
|
]; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return TransitionInterface[] |
|
71
|
|
|
*/ |
|
72
|
7 |
|
private static function getTransitions(): array |
|
73
|
|
|
{ |
|
74
|
|
|
return [ |
|
75
|
7 |
|
new RGBTransition(), |
|
76
|
7 |
|
new HSVTransition(), |
|
77
|
|
|
]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
924 |
|
private static function getConverterGraph(): Graph |
|
81
|
|
|
{ |
|
82
|
924 |
|
$graph = new Graph(); |
|
83
|
|
|
|
|
84
|
|
|
/** @var Vertex[] $vertices */ |
|
85
|
924 |
|
$vertices = []; |
|
86
|
|
|
|
|
87
|
924 |
|
foreach (self::getColors() as $color) { |
|
88
|
924 |
|
$vertices[$color] = $graph->createVertex($color); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
924 |
|
foreach (self::getConverters() as $converter) { |
|
92
|
924 |
|
$vertices[$converter::supportsFrom()]->createEdgeTo($vertices[$converter::supportsTo()])->setAttribute(self::GRAPH_EDGE_KEY_CONVERTER, $converter); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
924 |
|
return $graph; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|