-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotscreen.go
More file actions
67 lines (56 loc) · 1.06 KB
/
dotscreen.go
File metadata and controls
67 lines (56 loc) · 1.06 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
)
var dotPoisitions []uint = []uint{1, 8, 2, 16, 4, 32, 64, 128}
func getPixel(width int, height int, data *[]byte, x int, y int) byte {
if x >= width || x < 0 {
return 0
}
if y >= height || y < 0 {
return 0
}
return (*data)[y*width+x]
}
func PrintImage(width, height int, data *[]byte, invert bool) {
var pixel byte
var ch uint
var sx, sy, xlimit, ylimit int
xChunk := width / 2
yChunk := height / 5
if width%2 != 0 {
xChunk++
}
if height%5 != 0 {
yChunk++
}
targetPixelValue := byte(0)
if invert {
targetPixelValue = 1
}
for y := 0; y < yChunk; y++ {
for x := 0; x < xChunk; x++ {
ch = 0
sx = x * 2
sy = y * 5
xlimit = min(2, width-sx)
ylimit = min(4, height-sy)
for i := 0; i < xlimit; i++ {
for j := 0; j < ylimit; j++ {
pixel = getPixel(width, height, data, sx+i, sy+j)
if pixel != targetPixelValue {
ch |= dotPoisitions[i+(j*2)]
}
}
}
fmt.Printf("%c", (ch + 0x2800))
}
fmt.Print("\n")
}
}
func min(a, b int) int {
if a < b {
return a
}
return b
}