Fix centering of plasma

Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
Martyn 2020-06-28 18:33:42 +02:00
parent 688084094a
commit d534eb36cd
2 changed files with 35 additions and 14 deletions

View File

@ -26,6 +26,10 @@ var currentEffect queue.QueueItem
var globalEffectChannel = make(chan queue.QueueItem, 1024)
var universeCount int = 0
var overrideEffect queue.QueueItem
var overrideFlag = make(chan queue.QueueItem, 1)
var previousEffect queue.QueueItem
func foreverLoop() {
for /*ever*/ {
time.Sleep(40 * time.Millisecond) //25fps
@ -55,7 +59,7 @@ func main() {
}
}
fmt.Printf("Starting webserver on port %d\n", listenPort)
webserver.HandleHTTP(globalEffectChannel, listenPort)
webserver.HandleHTTP(globalEffectChannel, listenPort, overrideFlag)
}()
PanelIP := os.Getenv("PANEL_IP")
@ -113,17 +117,33 @@ func main() {
e.Effect = "plasma"
e.Speed = 40
globalEffectChannel <- e
e.Effect = "queue"
overrideEffect = e
go func() {
for /*ever*/ {
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)
if len(overrideFlag) > 0 {
e = <-overrideFlag
if e.Effect == "queue" {
fmt.Printf("Returning to queue : %s\n", currentEffect.Effect)
overrideEffect = e
currentEffect = previousEffect
} else {
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)
}
}
}
}

View File

@ -93,13 +93,14 @@ func PlasmaPanel(w int, h int, speed uint16) [][]RGBcolor {
}
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 x := 0; x < w; x++ {
u := math.Cos((float64(x) + offset) * scale)
v := math.Cos((float64(y) + offset) * scale)
j := math.Cos(offset * scale) // 2D - No Z
u := math.Cos((float64(x) + offset) * scaleW)
v := math.Cos((float64(y) + offset) * scaleH)
j := math.Cos(offset * scaleW) // 2D - No Z
e := (u + v + j + 3.0) / 6.0
r, g, b := colorPlasmaFromFloatVal(palletteOffset + e)
var rgb [3]byte