-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.go
48 lines (42 loc) · 1.02 KB
/
draw.go
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
package main
import (
"image"
"image/color"
)
func isBoxPixel(x, y int, r image.Rectangle) bool {
return x == r.Min.X || x == r.Min.X || x == r.Max.X || y == r.Min.Y || y == r.Max.Y ||
x == r.Min.X+1 || x == r.Max.X-1 || y == r.Min.Y+1 || y == r.Max.Y-1
}
func box(img *image.RGBA, r image.Rectangle, c color.Color) {
for dx := r.Min.X; dx <= r.Max.X; dx++ {
for dy := r.Min.Y; dy <= r.Max.Y; dy++ {
if isBoxPixel(dx, dy, r) {
img.Set(dx, dy, c)
}
}
}
}
func square(img *image.RGBA, p image.Point, s int, c color.Color) {
for dx := p.X - s; dx < p.X+s; dx++ {
for dy := p.Y - s; dy < p.Y+s; dy++ {
img.Set(dx, dy, c)
}
}
}
func cross(img *image.RGBA, p image.Point, c color.Color) {
crossByXY(img, p.X, p.Y, c)
}
func crossByXY(img *image.RGBA, x, y int, c color.Color) {
img.Set(x-2, y, c)
img.Set(x-1, y, c)
img.Set(x, y, c)
img.Set(x+1, y, c)
img.Set(x+2, y, c)
img.Set(x, y-3, c)
img.Set(x, y-2, c)
img.Set(x, y-1, c)
img.Set(x, y, c)
img.Set(x, y+1, c)
img.Set(x, y+2, c)
img.Set(x, y+3, c)
}