Passed
Push — main ( b436ac...f1b4ad )
by N.
04:39
created

Element::sätt_pixel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Klass Element.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Klasser\Graf;
11
12
/**
13
 * Klass Element.
14
 */
15
class Element {
16
	public \GdImage $graf;
17
	public int $bredd;
18
	public int $höjd;
19
	public int $gul;
20
	public int $röd;
21
	public int $grön;
22
	public int $blå;
23
	public int $lila;
24
	public int $vit;
25
	public int $svart;
26
	/**
27
	 * @var int[] $gul_v
28
	 */
29
	public array $gul_v;
30
	/**
31
	 * @var int[] $röd_v
32
	 */
33
	public array $röd_v;
34
	/**
35
	 * @var int[] $grön_v
36
	 */
37
	public array $grön_v;
38
39
	/**
40
	 * 3^13 = 3^6*3^7 = 729 * 2187 = 1,594,323
41
	 */
42 11
	public function __construct(int $bredd = 2187, int $höjd = 729) {
43 11
		$this->bredd = $bredd;
44 11
		$this->höjd = $höjd;
45
	}
46
47
	/**
48
	 * Rendera enskild pixel i koordinat x, y med färg.
49
	 */
50 3
	public function sätt_pixel(int $x, int $y, int $färg): void {
51 3
		imagesetpixel($this->graf, $x, $y, $färg);
52
	}
53
54
	/**
55
	 * Rendera rektangel.
56
	 */
57 2
	public function sätt_rektangel(int $x1, int $y1, int $x2, int $y2, int $färg): void {
58 2
		[$x1, $y1] = [max(0, $x1), max(0, $y1)];
59 2
		[$x2, $y2] = [min($x2, $this->bredd), min($y2, $this->höjd)];
60 2
		imagerectangle($this->graf, $x1, $y1, $x2, $y2, $färg);
61
	}
62
63
	/**
64
	 * Rendera fylld rektangel.
65
	 */
66
	public function fyll_rektangel(int $x1, int $y1, int $x2, int $y2, int $färg): void {
67
		[$x1, $y1] = [max(0, $x1), max(0, $y1)];
68
		[$x2, $y2] = [min($x2, $this->bredd), min($y2, $this->höjd)];
69
		imagefilledrectangle($this->graf, $x1, $y1, $x2, $y2, $färg);
70
	}
71
72
	/**
73
	 * Rendera linje.
74
	 */
75 2
	public function sätt_linje(int $x1, int $y1, int $x2, int $y2, int $färg): void {
76 2
		imageline($this->graf, $x1, $y1, $x2, $y2, $färg);
77
	}
78
79
	/**
80
	 * Rendera cirkel.
81
	 */
82
	public function sätt_cirkel(int $x, int $y, int $diam, int $färg): void {
83
		imageellipse($this->graf, $x, $y, $diam, $diam, $färg);
84
	}
85
86
	/**
87
	 * Rendera text.
88
	 */
89 1
	public function sätt_text(int $x, int $y, string $text, int $färg, int $typ = 5): void {
90 1
		imagestring($this->graf, $typ, $x, $y, $text, $färg);
91
	}
92
}
93