-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.go
177 lines (153 loc) · 3.07 KB
/
image.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package main
import (
"flag"
"image/color"
"image/png"
"log"
"math/rand"
"os"
"simonwaldherr.de/go/golibs/gcurses"
rgbmatrix "simonwaldherr.de/go/rpirgbled"
"time"
)
var (
rows = flag.Int("led-rows", 32, "number of rows supported")
parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels")
chain = flag.Int("led-chain", 16, "number of displays daisy-chained")
brightness = flag.Int("brightness", 99, "brightness (0-100)")
)
type Field struct {
cells [][]int
width int
height int
}
var field *Field
var (
setfps int
setwidth int
setheight int
setduration int
outputlength int
setfilename string
outputfile string
port string
)
func fatal(err error) {
if err != nil {
panic(err)
}
}
func newField(width, height int) *Field {
cells := make([][]int, height)
for cols := range cells {
cells[cols] = make([]int, width)
}
return &Field{cells: cells, width: width, height: height}
}
var config = &rgbmatrix.DefaultConfig
var c *rgbmatrix.Canvas
func randomUint() uint8 {
return uint8(rand.Intn(255))
}
func smallRandomUint() uint8 {
return uint8(rand.Intn(16))
}
func newXY(x, y int) (int, int) {
var xh, yh int
y1 := y
x1 := x
if y < 64 {
yh = y
if x < 32 {
xh = x
x1 = 192 + yh
y1 = 31 - xh
} else if x < 64 {
xh = x - 32
x1 = 191 - yh
y1 = xh
} else if x < 96 {
xh = x - 64
x1 = 64 + yh
y1 = 31 - xh
} else if x < 128 {
xh = x - 96
x1 = 63 - yh
y1 = xh
} else if x < 192 {
x1 = 0
y1 = 0
}
} else if y < 128 {
yh = y - 64
if x < 32 {
xh = x
x1 = 256 + yh
y1 = 31 - xh
} else if x < 64 {
xh = x - 32
x1 = 383 - yh
y1 = xh
} else if x < 96 {
xh = x - 64
x1 = 384 + yh
y1 = 31 - xh
} else if x < 128 {
xh = x - 96
x1 = 511 - yh
y1 = xh
} else if x < 192 {
x1 = 0
y1 = 0
}
} else {
x1 = 0
y1 = 0
}
return x1, y1
}
func (field *Field) printField() string {
file, err := os.Open("./png.png")
if err != nil {
log.Fatal(err)
}
defer file.Close()
img, err := png.Decode(file)
if err != nil {
log.Fatal(os.Stderr, "%s: %v\n", "./png.png", err)
}
for y := 0; y < 128; y++ {
for x := 0; x < 128; x++ {
x1, y1 := newXY(x, y)
oldPixel := img.At(x, y)
r, g, b, _ := oldPixel.RGBA()
c.Set(x1, y1, color.RGBA{uint8(r), uint8(g), uint8(b), 255})
}
}
c.Render()
time.Sleep(time.Minute * 15)
return ""
}
func main() {
writer := gcurses.New()
writer.Start()
flag.IntVar(&setwidth, "w", 80, "terminal width")
flag.IntVar(&setheight, "h", 20, "terminal height")
flag.IntVar(&setduration, "d", -1, "game of life duration")
flag.IntVar(&setfps, "f", 20, "frames per second")
flag.StringVar(&setfilename, "o", "", "open file")
flag.IntVar(&outputlength, "l", 200, "frames")
flag.Parse()
config.Rows = *rows
config.Parallel = *parallel
config.ChainLength = *chain
config.Brightness = *brightness
m, err := rgbmatrix.NewRGBLedMatrix(config)
fatal(err)
c = rgbmatrix.NewCanvas(m)
defer c.Close()
for i := 0; i != setduration; i++ {
time.Sleep(time.Millisecond * 25)
field.printField()
}
}