Skip to content

Commit 7162ae7

Browse files
committed
fxes
1 parent c11a2f6 commit 7162ae7

File tree

1 file changed

+20
-65
lines changed

1 file changed

+20
-65
lines changed

pkg/sensehat/sensehat.go

Lines changed: 20 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -712,66 +712,52 @@ func (s *SenseHat) FlashLED(x, y int, r, g, b uint8, duration time.Duration) err
712712
return s.SetPixel(x, y, 0, 0, 0)
713713
}
714714

715-
// PlaneAnimation animates "SKYSPY" text scrolling followed by a plane flying across the LED matrix.
715+
// PlaneAnimation animates a plane flying across the LED matrix with nav lights.
716716
func (s *SenseHat) PlaneAnimation(frameDelay time.Duration) error {
717-
// 5x5 font for SKYSPY (each letter is 5 columns wide)
718-
letters := map[rune][][2]int{
719-
'S': {{0, 1}, {0, 2}, {0, 3}, {0, 4}, {1, 0}, {1, 4}, {2, 0}, {2, 2}, {2, 4}, {3, 0}, {3, 4}, {4, 0}, {4, 1}, {4, 2}, {4, 4}},
720-
'K': {{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {1, 2}, {2, 1}, {2, 3}, {3, 0}, {3, 4}},
721-
'Y': {{0, 0}, {0, 1}, {1, 2}, {2, 2}, {2, 3}, {2, 4}, {3, 2}, {4, 0}, {4, 1}},
722-
'P': {{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {1, 0}, {1, 2}, {2, 0}, {2, 2}, {3, 0}, {3, 1}, {3, 2}},
723-
}
724-
725-
// Build "SKYSPY" as a bitmap with 1 column spacing between letters
726-
text := "SKYSPY"
727-
letterWidth := 5
728-
spacing := 1
729-
var textPixels [][2]int
730-
xOffset := 0
731-
for _, ch := range text {
732-
if pixels, ok := letters[ch]; ok {
733-
for _, p := range pixels {
734-
textPixels = append(textPixels, [2]int{p[0] + xOffset, p[1]})
735-
}
736-
}
737-
xOffset += letterWidth + spacing
717+
// Plane shape (relative pixels from nose position)
718+
// Shape: >=>
719+
// =
720+
plane := [][2]int{
721+
{0, 0}, // nose
722+
{-1, 0}, // body
723+
{-2, 0}, // tail
724+
{-1, -1}, // top wing
725+
{-1, 1}, // bottom wing
738726
}
739-
textWidth := xOffset - spacing
740727

741-
// Scroll text from right to left with airplane nav lights
728+
// Animate plane flying from left (-2) to right (9) to fully exit
742729
strobeCounter := 0
743-
for scroll := 0; scroll <= textWidth+8; scroll++ {
730+
for x := -2; x <= 9; x++ {
744731
if err := s.ClearLEDs(); err != nil {
745732
return err
746733
}
747734

748-
// Draw scrolling text
749-
for _, p := range textPixels {
750-
px := 7 - scroll + p[0]
751-
py := 1 + p[1] // Center vertically
735+
// Draw plane at current position (y=3 for center)
736+
for _, p := range plane {
737+
px := x + p[0]
738+
py := 3 + p[1]
752739
if px >= 0 && px <= 7 && py >= 0 && py <= 7 {
753-
if err := s.SetPixel(px, py, 0, 200, 255); err != nil {
740+
if err := s.SetPixel(px, py, 255, 255, 255); err != nil {
754741
return err
755742
}
756743
}
757744
}
758745

759746
// Navigation lights: green on right (starboard), red on left (port)
760-
// Bottom row: positions 0 and 7
761747
if err := s.SetPixel(0, 7, 255, 0, 0); err != nil { // Red - port (left)
762748
return err
763749
}
764750
if err := s.SetPixel(7, 7, 0, 255, 0); err != nil { // Green - starboard (right)
765751
return err
766752
}
767753

768-
// Strobe lights: white flashing every 4 frames (slower flash)
754+
// Strobe lights: white flashing every 4 frames, opposite corners
769755
strobeOn := (strobeCounter % 4) < 2
770756
if strobeOn {
771-
if err := s.SetPixel(1, 7, 255, 255, 255); err != nil { // White strobe near red
757+
if err := s.SetPixel(7, 0, 255, 255, 255); err != nil { // White strobe top-right
772758
return err
773759
}
774-
if err := s.SetPixel(6, 7, 255, 255, 255); err != nil { // White strobe near green
760+
if err := s.SetPixel(0, 0, 255, 255, 255); err != nil { // White strobe top-left
775761
return err
776762
}
777763
}
@@ -780,37 +766,6 @@ func (s *SenseHat) PlaneAnimation(frameDelay time.Duration) error {
780766
time.Sleep(frameDelay)
781767
}
782768

783-
// Plane shape (relative pixels from nose position)
784-
// Shape: >=>
785-
// =
786-
plane := [][2]int{
787-
{0, 0}, // nose
788-
{-1, 0}, // body
789-
{-2, 0}, // tail
790-
{-1, -1}, // top wing
791-
{-1, 1}, // bottom wing
792-
}
793-
794-
// Animate plane flying from left (-2) to right (9) to fully exit
795-
for x := -2; x <= 9; x++ {
796-
if err := s.ClearLEDs(); err != nil {
797-
return err
798-
}
799-
800-
// Draw plane at current position (y=3 for center)
801-
for _, p := range plane {
802-
px := x + p[0]
803-
py := 3 + p[1]
804-
if px >= 0 && px <= 7 && py >= 0 && py <= 7 {
805-
if err := s.SetPixel(px, py, 255, 255, 255); err != nil {
806-
return err
807-
}
808-
}
809-
}
810-
811-
time.Sleep(frameDelay)
812-
}
813-
814769
// Clear after animation
815770
return s.ClearLEDs()
816771
}

0 commit comments

Comments
 (0)