-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawRect.go
More file actions
34 lines (29 loc) · 879 Bytes
/
DrawRect.go
File metadata and controls
34 lines (29 loc) · 879 Bytes
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
package gographics
import (
"image"
)
func DrawRect(img *image.Paletted, vec1, vec2 [2]int, col uint8) {
DrawLine(img, [2]int{vec1[0], vec1[1]}, [2]int{vec2[0], vec1[1]}, col) // top line
DrawLine(img, [2]int{vec1[0], vec2[1]}, [2]int{vec2[0], vec2[1]}, col) // bottom line
DrawLine(img, [2]int{vec1[0], vec1[1]}, [2]int{vec1[0], vec2[1]}, col) // left line
DrawLine(img, [2]int{vec2[0], vec1[1]}, [2]int{vec2[0], vec2[1]}, col) // right
}
func DrawFilledRect(img *image.Paletted, vec1, vec2 [2]int, col uint8) {
// swap x1 and x2 if x1 is larger than x2
if vec1[0] > vec2[0] {
x := vec1[0]
vec1[0] = vec2[0]
vec2[0] = x
}
// swap y1 and y2 if y1 is larger than y2
if vec1[1] > vec2[1] {
y := vec1[1]
vec1[1] = vec2[1]
vec2[1] = y
}
for i := vec1[0]; i < vec2[0]; i++ {
for k := vec1[1]; k < vec2[1]; k++ {
img.SetColorIndex(i, k, col)
}
}
}