-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitmap.go
48 lines (41 loc) · 822 Bytes
/
bitmap.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
// Copyright 2020 Andrew Ekstedt
// This program is licensed under the GNU Affero General
// Public License v3.0. See LICENSE for details.
package main
type Bitmap [height]uint16
const width = 10
const height = 8
func (b *Bitmap) Set(x, y int8, v bool) {
if v {
b[y] |= 1 << uint(x)
} else {
b[y] &^= 1 << uint(x)
}
}
func (b *Bitmap) At(x, y int8) bool {
return (b[y]>>uint(x))&1 != 0
}
func (b Bitmap) Union(q Bitmap) Bitmap {
for i := range b {
b[i] |= q[i]
}
return b
}
func (b *Bitmap) String() string {
var s []byte
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
if b.At(int8(x), int8(y)) {
s = append(s, "[]"...)
} else {
if y%2 == 0 {
s = append(s, ". "...)
} else {
s = append(s, " ,"...)
}
}
}
s = append(s, '\n')
}
return string(s)
}