Fix centering of plasma
Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
parent
688084094a
commit
d534eb36cd
|
@ -26,6 +26,10 @@ var currentEffect queue.QueueItem
|
||||||
var globalEffectChannel = make(chan queue.QueueItem, 1024)
|
var globalEffectChannel = make(chan queue.QueueItem, 1024)
|
||||||
var universeCount int = 0
|
var universeCount int = 0
|
||||||
|
|
||||||
|
var overrideEffect queue.QueueItem
|
||||||
|
var overrideFlag = make(chan queue.QueueItem, 1)
|
||||||
|
var previousEffect queue.QueueItem
|
||||||
|
|
||||||
func foreverLoop() {
|
func foreverLoop() {
|
||||||
for /*ever*/ {
|
for /*ever*/ {
|
||||||
time.Sleep(40 * time.Millisecond) //25fps
|
time.Sleep(40 * time.Millisecond) //25fps
|
||||||
|
@ -55,7 +59,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf("Starting webserver on port %d\n", listenPort)
|
fmt.Printf("Starting webserver on port %d\n", listenPort)
|
||||||
webserver.HandleHTTP(globalEffectChannel, listenPort)
|
webserver.HandleHTTP(globalEffectChannel, listenPort, overrideFlag)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
PanelIP := os.Getenv("PANEL_IP")
|
PanelIP := os.Getenv("PANEL_IP")
|
||||||
|
@ -113,17 +117,33 @@ func main() {
|
||||||
e.Effect = "plasma"
|
e.Effect = "plasma"
|
||||||
e.Speed = 40
|
e.Speed = 40
|
||||||
globalEffectChannel <- e
|
globalEffectChannel <- e
|
||||||
|
e.Effect = "queue"
|
||||||
|
overrideEffect = e
|
||||||
go func() {
|
go func() {
|
||||||
for /*ever*/ {
|
for /*ever*/ {
|
||||||
if currentEffect.Duration > 0 {
|
if len(overrideFlag) > 0 {
|
||||||
currentEffect.Duration -= 40
|
e = <-overrideFlag
|
||||||
} else {
|
if e.Effect == "queue" {
|
||||||
if len(globalEffectChannel) > 0 {
|
fmt.Printf("Returning to queue : %s\n", currentEffect.Effect)
|
||||||
lastEffect := currentEffect
|
overrideEffect = e
|
||||||
currentEffect = <-globalEffectChannel
|
currentEffect = previousEffect
|
||||||
if lastEffect != currentEffect {
|
} else {
|
||||||
fmt.Printf("New effect selected : %s\n", currentEffect.Effect)
|
fmt.Printf("Overriding with : %s\n", e.Effect)
|
||||||
|
previousEffect = currentEffect
|
||||||
|
overrideEffect = e
|
||||||
|
currentEffect = e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if overrideEffect.Effect == "queue" {
|
||||||
|
if currentEffect.Duration > 0 {
|
||||||
|
currentEffect.Duration -= 40
|
||||||
|
} else {
|
||||||
|
if len(globalEffectChannel) > 0 {
|
||||||
|
lastEffect := currentEffect
|
||||||
|
currentEffect = <-globalEffectChannel
|
||||||
|
if lastEffect != currentEffect {
|
||||||
|
fmt.Printf("New effect selected : %s\n", currentEffect.Effect)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,13 +93,14 @@ func PlasmaPanel(w int, h int, speed uint16) [][]RGBcolor {
|
||||||
}
|
}
|
||||||
|
|
||||||
offset := 0.5 // center offset
|
offset := 0.5 // center offset
|
||||||
scale := math.Pi * 2.0 / float64(w)
|
scaleW := math.Pi * 2.0 / float64(w)
|
||||||
|
scaleH := math.Pi * 2.0 / float64(h)
|
||||||
|
|
||||||
for y := 0; y < h; y++ {
|
for y := 0; y < h; y++ {
|
||||||
for x := 0; x < w; x++ {
|
for x := 0; x < w; x++ {
|
||||||
u := math.Cos((float64(x) + offset) * scale)
|
u := math.Cos((float64(x) + offset) * scaleW)
|
||||||
v := math.Cos((float64(y) + offset) * scale)
|
v := math.Cos((float64(y) + offset) * scaleH)
|
||||||
j := math.Cos(offset * scale) // 2D - No Z
|
j := math.Cos(offset * scaleW) // 2D - No Z
|
||||||
e := (u + v + j + 3.0) / 6.0
|
e := (u + v + j + 3.0) / 6.0
|
||||||
r, g, b := colorPlasmaFromFloatVal(palletteOffset + e)
|
r, g, b := colorPlasmaFromFloatVal(palletteOffset + e)
|
||||||
var rgb [3]byte
|
var rgb [3]byte
|
||||||
|
|
Loading…
Reference in New Issue