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.
41 lines
974 B
Go
41 lines
974 B
Go
package fx
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type VignetteOptions struct {
|
|
// Slot darkens the edges; zero means the darkest slot.
|
|
Slot pixel.Slot
|
|
}
|
|
|
|
// Vignette dithers a slot inward from edges; corners go solid.
|
|
func Vignette(c *ui.Context, o VignetteOptions, content func()) *ui.Element {
|
|
k := pixel.K(c)
|
|
s := slotOr(o.Slot, dark(k))
|
|
return cover(k, ui.Column(c), func(g pixel.Canvas) { vignette(g, s) }, content)
|
|
}
|
|
|
|
// vignette's level grows with the elliptic distance out.
|
|
func vignette(g pixel.Canvas, s pixel.Slot) {
|
|
level := func(x, y int) int {
|
|
ex := float64(2*x+1-g.W) / float64(g.W)
|
|
ey := float64(2*y+1-g.H) / float64(g.H)
|
|
return min(16, max(0, int((ex*ex+ey*ey-0.6)*16/1.2)))
|
|
}
|
|
for y := range g.H {
|
|
for x := 0; x < g.W; {
|
|
l, end := level(x, y), x+1
|
|
for end < g.W && level(end, y) == l {
|
|
end++
|
|
}
|
|
if l > 0 {
|
|
g.Veil(x, y, end-x, 1, s, l)
|
|
}
|
|
x = end
|
|
}
|
|
}
|
|
}
|