reverse working and alternating pattern added
Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
parent
1c5124b78a
commit
2202ba2fc0
58
main.go
58
main.go
|
@ -8,17 +8,45 @@ import (
|
||||||
"github.com/Hundemeier/go-sacn/sacn"
|
"github.com/Hundemeier/go-sacn/sacn"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func even(number int) bool {
|
||||||
|
return number%2 == 0
|
||||||
|
}
|
||||||
|
|
||||||
func slice_rearrange(rowwidth int, rows int, alternaterows bool, inslice []byte) [][]byte {
|
func slice_rearrange(rowwidth int, rows int, alternaterows bool, inslice []byte) [][]byte {
|
||||||
|
var flippedslice []byte
|
||||||
if alternaterows {
|
if alternaterows {
|
||||||
panic("Alternating rows not yet implemented")
|
flippedslice = make([]byte, len(inslice)+3)
|
||||||
|
for r := 0; r < rows; r++ {
|
||||||
|
rowzero := (r*rowwidth*3)
|
||||||
|
if even(r) {
|
||||||
|
for c := 0; c < (rowwidth)*3; c+=3 {
|
||||||
|
flippedslice[rowzero+c] = inslice[rowzero+c]
|
||||||
|
flippedslice[rowzero+c+1] = inslice[rowzero+c+1]
|
||||||
|
flippedslice[rowzero+c+2] = inslice[rowzero+c+2]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
x := rowwidth*3
|
||||||
|
for c := 0; c < (rowwidth)*3; c+=3 {
|
||||||
|
x = x-3
|
||||||
|
fmt.Println(x)
|
||||||
|
flippedslice[rowzero+x] = inslice[rowzero+c]
|
||||||
|
flippedslice[rowzero+x+1] = inslice[rowzero+c+1]
|
||||||
|
flippedslice[rowzero+x+2] = inslice[rowzero+c+2]/*
|
||||||
|
flippedslice[rowzero+c] = inslice[rowzero+(((rowwidth-1)*3)-c)]
|
||||||
|
flippedslice[rowzero+c+1] = inslice[rowzero+(((rowwidth-1)*3)-c)-1]
|
||||||
|
flippedslice[rowzero+c+2] = inslice[rowzero+(((rowwidth-1)*3)-c)-2]*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
flippedslice = inslice
|
||||||
}
|
}
|
||||||
currentUniverse := 0
|
currentUniverse := 0
|
||||||
currentUniversePosition := 0
|
currentUniversePosition := 0
|
||||||
universes := make([][]byte, (len(inslice)/510)+1)
|
universes := make([][]byte, (len(flippedslice)/510)+1)
|
||||||
currentUniverseSlice := make([]byte, 511)
|
currentUniverseSlice := make([]byte, 511)
|
||||||
currentRowReverse := false;
|
currentRowReverse := false;
|
||||||
for i := range(inslice) {
|
for i := range(flippedslice) {
|
||||||
fmt.Println(i)
|
|
||||||
if currentUniversePosition >= 510 {
|
if currentUniversePosition >= 510 {
|
||||||
fmt.Println("Reached end of universe!")
|
fmt.Println("Reached end of universe!")
|
||||||
universes[currentUniverse] = currentUniverseSlice
|
universes[currentUniverse] = currentUniverseSlice
|
||||||
|
@ -31,13 +59,29 @@ func slice_rearrange(rowwidth int, rows int, alternaterows bool, inslice []byte)
|
||||||
currentUniversePosition = 0
|
currentUniversePosition = 0
|
||||||
currentUniverseSlice = make([]byte, 511)
|
currentUniverseSlice = make([]byte, 511)
|
||||||
}
|
}
|
||||||
currentUniverseSlice[currentUniversePosition] = inslice[i]
|
currentUniverseSlice[currentUniversePosition] = flippedslice[i]
|
||||||
currentUniversePosition += 1
|
currentUniversePosition += 1
|
||||||
}
|
}
|
||||||
universes[currentUniverse] = currentUniverseSlice
|
universes[currentUniverse] = currentUniverseSlice
|
||||||
return universes
|
return universes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func alternate(R0 byte, G0 byte, B0 byte, R1 byte, G1 byte, B1 byte, fromX int, toX int) []byte {
|
||||||
|
ret := make([]byte, toX*3);
|
||||||
|
for i := fromX; i < toX*3; i+=3 {
|
||||||
|
if even(i) {
|
||||||
|
ret[i] = R0
|
||||||
|
ret[i+1] = G0
|
||||||
|
ret[i+2] = B0
|
||||||
|
} else {
|
||||||
|
ret[i] = R1
|
||||||
|
ret[i+1] = G1
|
||||||
|
ret[i+2] = B1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
// gradient returns from fromX to toX fading from (fromR,fromG,fromB) to (toR,toG,toB)
|
// gradient returns from fromX to toX fading from (fromR,fromG,fromB) to (toR,toG,toB)
|
||||||
// at least that's the idea.
|
// at least that's the idea.
|
||||||
func gradient(fromR byte, fromG byte, fromB byte, toR byte, toG byte, toB byte, fromX int, toX int) []byte {
|
func gradient(fromR byte, fromG byte, fromB byte, toR byte, toG byte, toB byte, fromX int, toX int) []byte {
|
||||||
|
@ -64,7 +108,7 @@ func slice512(s []byte) [512]byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func sliceUnlenthed(s [512]byte) []byte {
|
func sliceUnlenthed(s [512]byte) []byte {
|
||||||
ret := make([]byte, 512);
|
ret := make([]byte, 512)
|
||||||
for i := range(s) {
|
for i := range(s) {
|
||||||
ret[i] = s[i]
|
ret[i] = s[i]
|
||||||
}
|
}
|
||||||
|
@ -102,7 +146,7 @@ func main() {
|
||||||
|
|
||||||
//send some random data for 10 seconds
|
//send some random data for 10 seconds
|
||||||
for i := 0; i < 20; i++ {
|
for i := 0; i < 20; i++ {
|
||||||
channels := slice_rearrange(68,4,false,gradient(0,0,255,255,0,0,0,272))
|
channels := slice_rearrange(68,4,true,gradient(255,255,255,0,0,0,0,272))
|
||||||
ch1 <- slice512(channels[0])
|
ch1 <- slice512(channels[0])
|
||||||
ch2 <- slice512(channels[1])
|
ch2 <- slice512(channels[1])
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
Loading…
Reference in New Issue