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.
43 lines
1007 B
Go
43 lines
1007 B
Go
package fx
|
|
|
|
import (
|
|
"math"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type IrisWipeOptions struct {
|
|
// Slot fills outside the iris; zero means the darkest slot.
|
|
Slot pixel.Slot
|
|
}
|
|
|
|
// IrisWipe closes a circle on content's middle, or opens it.
|
|
func IrisWipe(c *ui.Context, closed bool, o IrisWipeOptions, content func()) *ui.Element {
|
|
k := pixel.K(c)
|
|
s := slotOr(o.Slot, dark(k))
|
|
e := ui.Column(c)
|
|
step := k.Toward(c, e, closed, 12, 8)
|
|
return cover(k, e, func(g pixel.Canvas) { iris(g, s, step) }, content)
|
|
}
|
|
|
|
// iris fills outside a circle, gone by step 8.
|
|
func iris(g pixel.Canvas, s pixel.Slot, step int) {
|
|
if step == 0 {
|
|
return
|
|
}
|
|
cx, cy := g.W/2, g.H/2
|
|
r := int(math.Ceil(math.Hypot(float64(g.W)/2, float64(g.H)/2))) * (8 - step) / 8
|
|
for y := range g.H {
|
|
dy := y - cy
|
|
if dy*dy >= r*r {
|
|
g.HLine(0, y, g.W, s)
|
|
continue
|
|
}
|
|
dx := int(math.Sqrt(float64(r*r - dy*dy)))
|
|
g.HLine(0, y, cx-dx, s)
|
|
g.HLine(cx+dx, y, g.W-cx-dx, s)
|
|
}
|
|
}
|