Completed
Push — master ( c3b778...fe23d9 )
by Nicholas
03:04
created

generate::rand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 6
crap 1
1
<?php
2
3
4
namespace projectcleverweb\color;
5
6
7
class generate {
8
	
9 1 View Code Duplication
	public static function rgb_contrast(int $r = 0, int $g = 0, int $b = 0) :array {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
		return [
11 1
			'r' => ($r < 128) ? 255 : 0,
12 1
			'g' => ($g < 128) ? 255 : 0,
13 1
			'b' => ($b < 128) ? 255 : 0
14
		];
15
	}
16
	
17 1
	public static function rgb_invert(int $r = 0, int $g = 0, int $b = 0) :array {
18
		return [
19 1
			'r' => 255 - $r,
20 1
			'g' => 255 - $g,
21 1
			'b' => 255 - $b
22
		];
23
	}
24
	
25 2
	public static function yiq_score(int $r = 0, int $g = 0, int $b = 0) :float {
26 2
		return (($r * 299) + ($g * 587) + ($b * 114)) / 1000;
27
	}
28
	
29 1
	public static function rand(int $min_r = 0, int $max_r = 255, int $min_g = 0, int $max_g = 255, int $min_b = 0, int $max_b = 255) :array {
30
		return [
31 1
			'r' => rand(abs((int) $min_r) % 256, abs((int) $max_r) % 256),
32 1
			'g' => rand(abs((int) $min_g) % 256, abs((int) $max_g) % 256),
33 1
			'b' => rand(abs((int) $min_b) % 256, abs((int) $max_b) % 256)
34
		];
35
	}
36
	
37
	public static function blend(float $r1, float $g1, float $b1, float $a1, float $r2, float $g2, float $b2, float $a2, float $amount = 50.0) :array {
38
		$x1 = convert::_div(100 - $amount, 100);
39
		$x2 = convert::_div($amount, 100);
40
		return [
41
			'r' => round(($r1 * $x1) + ($r2 * $x2), 0),
42
			'g' => round(($g1 * $x1) + ($g2 * $x2), 0),
43
			'b' => round(($b1 * $x1) + ($b2 * $x2), 0),
44
			'a' => ($a1 * $x1) + ($a2 * $x2)
45
		];
46
	}
47
}
48