Files
8bitMyGoUI/fx/palettecycle.go
T
ZacharyZhang-NY 8be66c09f2 Add fx components 291-320 and the home scene; Kit.Shot, Kit.Toward
Palette cycling, sky, sun and moon, clouds, starfield, rain, snow,
petals, leaves, fireflies, waterfall, ocean, campfire, lava, aurora,
lightning, mountains and a season scene; scanlines, vignette, screen
shake, flash, dither fades, iris wipes, dissolves, mosaics, glitches,
sparkles, explosions and confetti. Home opens on a live scene in the
palette's season and a strip of all eight palettes.

pixel adds Canvas.Cycled, Sprite.At, SpriteOf, Kit.Toward and
Kit.Shot, which spends a cue under Reduce Motion so it never replays;
display exports Reduce. Gallery grids and the sidebar are one Tab
stop each.
2026-10-12 04:05:25 -04:00

32 lines
827 B
Go

package fx
import (
"fmt"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type PaletteCycleOptions struct {
// FPS is steps a second; zero means 8.
FPS int
// Slot inks the sprite's # dots.
Slot pixel.Slot
Scale int
Label string
}
// PaletteCycle draws sp, rotating band's slots one place a step.
func PaletteCycle(c *ui.Context, sp *pixel.Sprite, band []pixel.Slot, o PaletteCycleOptions) *ui.Element {
k := pixel.K(c)
fps, sc := pixel.Or("PaletteCycle FPS", o.FPS, 8), scale("PaletteCycle", o.Scale, 1)
if len(band) < 2 {
panic(fmt.Sprintf("fx: PaletteCycle band %v needs two slots", band))
}
return box(c, k, o.Label, sp.W*sc, sp.H*sc).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
g.Cycled(band, g.Step(fps)).Sprite(0, 0, sp, 0, o.Slot, sc)
})
}