Skip to content

Commit

Permalink
implemented All Beacon Animations
Browse files Browse the repository at this point in the history
  • Loading branch information
PercyJW-2 committed Oct 7, 2024
1 parent ef7aafb commit 39bb188
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rgbanimations/utilFuncsMath.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func Sin8(theta uint8) uint8 {
return uint8(y)
}

func Cos8(theta uint8) uint8 {
return Sin8(theta + 64)
}

func Atan28(dy int16, dx int16) uint8 {
if dy == 0 {
if dx >= 0 {
Expand Down
13 changes: 13 additions & 0 deletions rgbanimations/utilFuncsRunners.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var time = uint16(0)
type effectRunnerIFunc func(matrix *keyboard.RGBMatrix, i int, time uint16) (uint8, uint8, uint8)
type effectRunnerDXDYFunc func(matrix *keyboard.RGBMatrix, dx int16, dy int16, time uint16) (uint8, uint8, uint8)
type effectRunnerDXDYDistFunc func(matrix *keyboard.RGBMatrix, dx int16, dy int16, dist uint8, time uint16) (uint8, uint8, uint8)
type effectRunnerSinCosIFunc func(matrix *keyboard.RGBMatrix, sin int8, cos int8, i int, time uint16) (uint8, uint8, uint8)

func effectRunnerI(matrix *keyboard.RGBMatrix, mathFunc effectRunnerIFunc) {
timeScaled := Scale16by8(time, matrix.CurrentSpeed)
Expand Down Expand Up @@ -37,4 +38,16 @@ func effectRunnerDXDYDist(matrix *keyboard.RGBMatrix, mathFunc effectRunnerDXDYD
h, s, v := mathFunc(matrix, dx, dy, dist, timeScaled)
val.R, val.G, val.B, val.A = HSVToRGB(h, s, v)
}
time++
}

func effectRunnerSinCosI(matrix *keyboard.RGBMatrix, mathFunc effectRunnerSinCosIFunc) {
timeScaled := Scale16by8(time, matrix.CurrentSpeed)
cosValue := int8(Cos8(uint8(time)) - 128)
sinValue := int8(Sin8(uint8(time)) - 128)
for i, val := range matrix.LedMatrixVals {
h, s, v := mathFunc(matrix, sinValue, cosValue, i, timeScaled)
val.R, val.G, val.B, val.A = HSVToRGB(h, s, v)
}
time++
}
19 changes: 19 additions & 0 deletions rgbanimations/vialrgbDualBeacon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package rgbanimations

import keyboard "github.com/percyjw-2/tinygo-keyboard"

func GetDualBeaconAnim() keyboard.RgbAnimation {
return keyboard.RgbAnimation{
AnimationFunc: vialRGBDualBeacon,
AnimationType: keyboard.VIALRGB_EFFECT_DUAL_BEACON,
}
}

func dualBeaconMath(matrix *keyboard.RGBMatrix, sin int8, cos int8, i int, _ uint16) (uint8, uint8, uint8) {
h := matrix.CurrentHue + uint8(int8(matrix.LedMatrixMapping[i].PhysicalY-matrix.CenterYPhysical)*cos+int8(matrix.LedMatrixMapping[i].PhysicalX-matrix.CenterXPhysical)*sin)/128
return h, matrix.CurrentSaturation, matrix.CurrentValue
}

func vialRGBDualBeacon(matrix *keyboard.RGBMatrix) {
effectRunnerSinCosI(matrix, dualBeaconMath)
}
19 changes: 19 additions & 0 deletions rgbanimations/vialrgbRainbowBeacon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package rgbanimations

import keyboard "github.com/percyjw-2/tinygo-keyboard"

func GetRainbowBeaconAnim() keyboard.RgbAnimation {
return keyboard.RgbAnimation{
AnimationFunc: vialRGBRainbowBeacon,
AnimationType: keyboard.VIALRGB_EFFECT_RAINBOW_BEACON,
}
}

func rainbowBeaconMath(matrix *keyboard.RGBMatrix, sin int8, cos int8, i int, _ uint16) (uint8, uint8, uint8) {
h := matrix.CurrentHue + uint8(int8(matrix.LedMatrixMapping[i].PhysicalY-matrix.CenterYPhysical)*2*cos+int8(matrix.LedMatrixMapping[i].PhysicalX-matrix.CenterXPhysical)*2*sin)/128
return h, matrix.CurrentSaturation, matrix.CurrentValue
}

func vialRGBRainbowBeacon(matrix *keyboard.RGBMatrix) {
effectRunnerSinCosI(matrix, rainbowBeaconMath)
}

0 comments on commit 39bb188

Please sign in to comment.