Files
8bitMyGoUI/fx/dissolve.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

40 lines
943 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package fx
import (
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type DissolveOptions struct {
// Slot replaces the dots; zero means the darkest slot.
Slot pixel.Slot
}
// Dissolve switches content's dots to a slot in shuffled order.
func Dissolve(c *ui.Context, covered bool, o DissolveOptions, content func()) *ui.Element {
k := pixel.K(c)
s := slotOr(o.Slot, dark(k))
e := ui.Column(c)
step := k.Toward(c, e, covered, 12, 8)
return cover(k, e, func(g pixel.Canvas) { dissolve(g, s, step) }, content)
}
// dissolve covers dots whose fixed rank, 0–7, is below step.
func dissolve(g pixel.Canvas, s pixel.Slot, step int) {
on := func(x, y int) bool { return rnd(x+y<<16, 150)%8 < step }
for y := range g.H {
for x := 0; x < g.W; x++ {
if !on(x, y) {
continue
}
end := x + 1
for end < g.W && on(end, y) {
end++
}
g.HLine(x, y, end-x, s)
x = end
}
}
}