Documentation
¶
Overview ¶
Package fx has cell effects: functions that transform a node's rendered cells, or the frame beneath a dialog, for a progress value.
The same Effect serves two purposes. Given to a transition, it is applied to the node's own cells, and t runs from 0, as the node starts to enter, to 1, when it is fully shown; at 1 a transition effect leaves the cells as they are. Given to a backdrop, it is applied to everything drawn beneath a layer, and t is the strength, following the layer's transition. Given to a box's border effects, it is applied to the box's frame; the effects made for borders, such as Chase, loop, and t is their phase.
See the documentation for guides and examples. It is also available for LLMs and agents as llms.txt.
Index ¶
- type Blinds
- type Braille
- type Burst
- type Chase
- type Comet
- type Decode
- type Delay
- type Desaturate
- type Dim
- type Direction
- type Dissolve
- type Drift
- type Drop
- type Drops
- type Ease
- type Effect
- type Fade
- type Fly
- type Func
- type Glitch
- type Iris
- type March
- type Pulse
- type Rain
- type Recolor
- type Reverse
- type Ripple
- type Roll
- type Scramble
- type Shade
- type Shake
- type Shimmer
- type Slide
- type Spotlight
- type Stagger
- type Typewriter
- type Unfold
- type Wave
- type Wipe
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Blinds ¶
type Blinds struct {
// From is the side or corner slats open from: Top and Bottom cut the node
// into rows, Left and Right into columns, and a corner into diagonal
// slats, Size columns across. The slats are counted from there. The zero
// value is Bottom.
From Direction
// Size is the number of rows or columns in a slat. Zero means 3.
Size int
}
Blinds reveals a node through slats, like opening window blinds: it is cut into slats of Size rows or columns, and every slat is revealed from its leading edge at the same time.
type Braille ¶
type Braille struct {
// Amount is how far the dots' grays move toward the terminal's
// background, from 0 to 1; zero is 0.65.
Amount float64
// Seed picks the order cells turn to dots in.
Seed uint32
}
Braille redraws everything as braille dots in grays, so what is beneath a dialog reads as a texture rather than as text. It suits backdrops, where t is the strength.
Each glyph becomes a pattern made from it, so the dots change as what is beneath them does. Lines and blocks keep their shape: box drawing becomes dotted lines that still meet, half blocks and quadrants fill the matching dots, and shades become dithers. Text keeps the outline of its words, with ascenders and descenders, and braille is kept as it is.
Backgrounds become the terminal's. A cell whose background stood out from it is filled with an even dither instead, denser the more it stood out, with its glyph, if any, cut out of the fill. Blank cells on the terminal's background stay blank, so the dots keep the shape of what was drawn.
The dots take the gray of their color, faded toward the gray of the terminal's background by Amount; follow Braille with Recolor to tint them. As t rises, colors fade to gray and cells turn to dots in a scattered order, all of them by the time t reaches 0.85.
type Burst ¶
type Burst struct {
// At is where the burst starts, in frame coordinates.
At image.Point
// Count is the number of particles; zero is 40.
Count int
// Seed varies the burst.
Seed uint32
}
Burst is a one-shot burst of confetti, such as for a success: particles fly out from a point, mostly upward, fall under gravity, twinkle, and fade. t is the burst's age, from 0 to 1; nothing is drawn at 1.
Particles are placed from Seed, their index, and t alone, so a burst keeps no state and is the same for the same Seed. They only change the glyph and foreground of the single-width cells they land on, so a burst works on a region of the frame, such as a layer's backdrop, or on a node's cells, as in bloom.Transition(age, base, fx.Burst{...}). Only the cells of the surface are drawn on, so a burst from a small node stays inside it.
type Chase ¶
type Chase struct {
// From and To are the colors of the gradient; a nil From is each cell's
// own color, and a nil To the terminal's foreground.
From, To color.Color
// Cycles is how many times the gradient repeats around the edge; zero
// is 1. More cycles make a ripple of narrower bands.
Cycles int
}
Chase colors the edge with a gradient from From to To and back, which travels clockwise around it as t goes from 0 to 1, such as a border with a rotating gradient.
type Comet ¶
type Comet struct {
// Color is the color of the head; nil is the terminal's foreground.
Color color.Color
// Length is how many cells the tail fades over, head included; zero
// is 8.
Length int
}
Comet sends a bright head with a fading tail once around the edge, clockwise from the top-left corner, as t goes from 0 to 1, such as a box that is busy.
type Decode ¶
type Decode struct {
// From is where the rain starts. The zero value is Top.
From Direction
Seed uint32
}
Decode reveals a node like digital rain settling into text: each lane, a column for rain from the top or bottom, a row from the left or right, or a diagonal from a corner, is revealed from From after a random delay. The leading cell of a lane shows a bright random glyph, the cells behind it their own content, and those ahead of it nothing. The delays are the same for the same Seed. Only single-width glyphs are replaced.
type Delay ¶
Delay runs Effect over part of t, from From to To: before From it sees 0, and after To it sees 1. A zero To means 1. Delays combined in a list of effects run in sequence.
type Desaturate ¶
type Desaturate struct {
Amount float64
}
Desaturate moves colors toward gray by Amount, from 0 to 1. Unset backgrounds are left unset.
type Dim ¶
type Dim struct {
Amount float64
}
Dim moves colors toward the terminal's background by Amount, from 0 to 1. Unset backgrounds are left unset, as they already show the terminal's.
type Direction ¶
type Direction uint8
Direction is a side or a corner of a node or of the screen, such as where an effect starts from. What a corner means is up to what it is given to, which each documents: a front that sweeps across a node from a corner runs diagonally, at 45 degrees as the terminal draws it, where a cell is twice as tall as it is wide.
The zero value is the default of whatever it is given to, which each documents.
const ( // Bottom is the bottom side. Bottom Direction // Top is the top side. Top // Left is the left side. Left // Right is the right side. Right // TopLeft is the top left corner. TopLeft // TopRight is the top right corner. TopRight // BottomLeft is the bottom left corner. BottomLeft // BottomRight is the bottom right corner. BottomRight )
type Dissolve ¶
type Dissolve struct {
Seed uint32
}
Dissolve reveals a node's cells in a random order, the same for the same Seed.
type Drift ¶
type Drift struct {
// Time is the clock the patches move on, such as anim.Ticker's Elapsed.
Time time.Duration
// Color is what the glyphs are drawn in, at their brightest; nil is the
// terminal's foreground.
Color color.Color
// Amount is how bright the glyphs are, from 0 to 1; zero is 0.16.
Amount float64
// Cover is how much of the surface the patches cover, from 0 to 1; zero
// is 0.3.
Cover float64
// Scale is how large the patches are, in columns; zero is 16.
Scale float64
// Speed is how fast the patches change, where 1 is about once every
// few seconds; zero is 1.
Speed float64
// Focus is where the patches gather, in frame coordinates, within
// Radius columns of it; a zero Radius leaves them alone.
Focus image.Point
Radius int
// Glyphs are the glyphs drawn, each a single cell wide; empty is
// letters and digits.
Glyphs string
Seed uint32
}
Drift fills the empty cells of its surface with faint patches of glyphs that drift, swell, and fade, each glyph scrambling as it fades in before it settles. With Radius, the patches also gather and brighten around Focus, such as where the pointer is.
See the comment at the top of this file for Time and t.
type Drop ¶
type Drop struct {
// At is where the drop falls, in frame coordinates, as mouse events
// report them.
At image.Point
// Time is when it fell, on the clock of the Ripple's Time.
Time time.Duration
// Size scales how far the ring travels, how long it lasts, and how
// bright it is; zero is 1. A drop of 0.3 suits one left by the pointer
// moving.
Size float64
}
Drop is a disturbance that sends a ring out across a Ripple, such as where the pointer was clicked.
type Drops ¶
type Drops struct {
// contains filtered or unexported fields
}
Drops keeps the 32 most recent drops for a Ripple, dropping the oldest as more are added. It is a value, so a Ripple holding it compares equal while nothing changes, and a frame need not be drawn again.
type Ease ¶
Ease runs Effect with t eased by Easing, such as one of the easings of package anim. A nil Easing leaves t as it is, and 0 and 1 are never eased, so an easing that overshoots, like anim.OutBack, still ends where the effect does.
A function is not comparable, so a frame that uses Ease is composited again on every frame, even if t has not changed.
type Effect ¶
Effect transforms the cells of a surface for progress t, from 0 to 1.
The layout engine skips compositing a frame identical to the previous one, which it decides by comparing effects with ==. Effects should be comparable values, as all of this package's are; effects that are not, and effects behind pointers, which can change in place, are assumed to change on every frame.
type Fade ¶
type Fade struct{}
Fade crossfades a node in over the frame beneath it. Backgrounds blend from the one beneath to the node's own; until t=0.5 each cell shows the glyph beneath, fading into that background, and after it the node's own, fading in. At t=0 the node looks exactly like what is beneath it. Cells over or holding wide glyphs keep the node's glyph throughout.
type Fly ¶
type Fly struct {
Seed uint32
}
Fly flies a moving node's cells over from where it was, canvas.Surface.From, to where it is, for a slot or layer that moves with effects, such as with bloom.SlotNode.MoveWith. The node starts out whole where it was, squeezed or stretched to the size it was there. Its columns, or its rows for a move mostly up or down, take off one after another, from the edge facing where they go, each cell a little apart from its neighbors, arc over, and land. A glyph in flight shows a bright random glyph in its own color, and blank cells wait where they were until they land, so the node is whole at both ends. Flights are the same for the same Seed. On a node that is not moving, it does nothing.
type Glitch ¶
type Glitch struct {
Seed uint32
}
Glitch shows a node as if the signal were breaking up: rows jitter sideways in short bursts, their colors split toward red and cyan, and some cells are hidden or garbled. The pattern changes in steps, so it flickers, and fades to nothing as t reaches 1. It is the same for the same Seed. Rows holding wide glyphs are not moved.
type Iris ¶
type Iris struct {
// At is the circle's center, in frame coordinates, such as the rectangle
// of a button from the previous frame. The zero point means the center of
// the node.
At image.Point
}
Iris reveals a node with a circle that grows from At until it covers the node, such as a dialog opening from the button that was pressed.
type March ¶
type March struct {
// Length is how many cells each run takes; zero is 2.
Length int
}
March draws the edge as marching ants: runs of its line glyphs alternate with dashed ones, and travel clockwise around it by one run of each as t goes from 0 to 1. Corners, and glyphs with no dashed form, such as double lines, are left as they are.
type Pulse ¶
type Pulse struct {
// Color is what the edge's colors move toward; nil is the terminal's
// foreground. They reach it at t=0.5.
Color color.Color
}
Pulse moves the edge's colors toward Color and back as t goes from 0 to 1, all of it at once, such as a border drawing attention to itself.
type Rain ¶
type Rain struct {
// Time is the clock the rain falls on, such as anim.Ticker's Elapsed.
Time time.Duration
// Color is what the trails are drawn in; nil is the terminal's
// foreground. Head is what the glyph leading each stream is; nil is
// Color.
Color, Head color.Color
// Amount is how bright the trails are, from 0 to 1; zero is 0.5.
Amount float64
// Density is how many of the columns have a stream falling at once,
// from 0 to 1; zero is 0.3.
Density float64
// Speed is how fast streams fall, in rows per second; zero is 12.
Speed float64
// Length is how many rows a trail fades over; zero is 14.
Length int
// Glyphs are the glyphs drawn, each a single cell wide; empty is
// letters and digits.
Glyphs string
Seed uint32
}
Rain sends streams of glyphs falling down the empty cells of its surface, each led by a bright glyph that scrambles as it falls and trailed by glyphs that settle and fade behind it.
See the comment at the top of this file for Time and t.
type Recolor ¶
Recolor moves every cell's colors toward Fg and Bg by Amount, keeping glyphs. A nil color is left as it is. With an Amount of zero, which is 1, every cell is drawn in the two colors, the way vex draws its dialog backdrop; less tints them, and the same color for both, such as Recolor{Fg: c, Bg: c, Amount: 0.3}, tints everything toward one color.
type Reverse ¶
type Reverse struct {
Effect Effect
}
Reverse runs Effect with 1-t, such as an effect for a node that is leaving while the progress passed to it rises, or a backdrop that weakens as t grows.
type Ripple ¶
type Ripple struct {
// Time is the clock the drops fell on, such as anim.Ticker's Elapsed.
Time time.Duration
// Drops are the drops whose rings are drawn, until each has faded: a
// drop of size 1 after Life, smaller ones sooner, and larger ones later.
Drops Drops
// Rain is how many drops fall on their own each second, at random
// places; zero is none.
Rain float64
// Color is what the glyphs are drawn in, at their brightest; nil is the
// terminal's foreground.
Color color.Color
// Speed is how fast rings travel, in columns per second; zero is 26.
Speed float64
// Life is how long a ring of a drop of size 1 lasts; zero is 1.8s.
Life time.Duration
// Glyphs are the glyphs drawn, each a single cell wide; empty is
// letters and digits.
Glyphs string
// Seed varies the glyphs, and where rain falls.
Seed uint32
}
Ripple sends rings of glyphs out across the empty cells of its surface from each of its drops, like a stone dropped in still water: a ring of glyphs that scramble as it travels, bright at its front, leaving a faint wake that fades behind it. Rings that cross add up. With Rain, drops also fall on their own, at random, so it moves while nothing happens.
Feed it drops from mouse events. See the comment at the top of this file for Time and t.
type Roll ¶
type Roll struct {
From string
}
Roll turns the digits of a number over like an odometer, for numbers that change, such as a counter. It is applied to a node showing the new number, with From the number it showed before, and each row of the node is treated as a number. Digits are matched from the right, skipping separators like commas, so 1,058 rolling from 1,021 turns its last two digits over, and the rest stay put. A digit rolls through the digits between its old and new ones the short way around, counting past 9 to 0 when that is shorter. The last digits start first, and rolling digits are dimmed slightly to read as motion.
At t=0 the node shows From's digits where they line up with the new number's, and at 1 its own. Digits with nothing to roll from, as when the number gains a place, appear as they are.
type Scramble ¶
type Scramble struct {
Seed uint32
}
Scramble shows random glyphs that settle into a node's own, in a random order, the same for the same Seed. Only single-width glyphs are scrambled.
type Shade ¶
type Shade struct {
Seed uint32
}
Shade reveals a node's cells through shades of the frame beneath: each cell steps from blank to ░, ▒, ▓ and then its own glyph, the cells starting at random times, the same for the same Seed. Shades are drawn in the cell's background color, or its foreground color if it has none, over the background beneath, so a node dithers in. Wide glyphs, and blanks without a background, appear in one step, at the end of their cell's turn.
type Shake ¶
type Shake struct {
// Amount is how far, in cells, the node moves at most; zero is 2.
Amount int
// Times is how many times the node swings each way; zero is 4.
Times int
}
Shake moves a node from side to side with a decaying wobble, such as an input that rejected what was typed. t is the shake's progress: the node is still at 0 and at 1.
type Shimmer ¶
type Shimmer struct {
// Color is what colors are mixed toward in the band; nil is the
// terminal's foreground.
Color color.Color
// Width is how wide the band is, in columns, a row counting as two; zero
// is 6.
Width int
// From is where the band starts. From a side, the band is parallel to
// it, and from a corner it is diagonal. The zero value is TopLeft.
From Direction
}
Shimmer sweeps a highlight band across a node, diagonally by default, for placeholders shown while content loads. t is the band's position: it starts just off the node and ends just off the other side, so a value that runs from 0 to 1 and then jumps back to 0 loops seamlessly.
type Slide ¶
type Slide struct {
// From is where the node comes from. The zero value is Bottom.
From Direction
}
Slide moves a node in from beyond a side or corner of its viewport, such as a dialog rising from the bottom of the screen.
type Spotlight ¶
type Spotlight struct {
// Rect is the area left lit, in frame coordinates, as returned by
// Frame.Rect. An empty Rect dims everything.
Rect image.Rectangle
// Amount is how far colors outside Rect move toward the terminal's
// background, from 0 to 1; zero is 0.7.
Amount float64
// Soft is how many cells around Rect the dimming takes to reach its full
// amount; zero is a hard edge. Horizontal distances count for half, as
// cells are twice as tall as they are wide, so the falloff looks round.
Soft int
}
Spotlight dims everything but a rectangle, for drawing attention to part of a screen, such as a step of a tour. It suits backdrops, where t is the strength.
type Stagger ¶
type Stagger struct {
Effect Effect
// From is where the first part is, and so which parts come first: Top
// and Bottom split the surface into rows, Left and Right into columns. A
// corner is taken as its top or bottom side, as parts are whole rows or
// columns. The zero value is Bottom.
From Direction
// Spread is how much of t is spent starting the parts, from 0 to 1: 0.5
// has the last part start as the first is halfway, and 1 has each part
// run in an instant. Zero means 0.5.
Spread float64
}
Stagger splits a surface into rows, or columns, that each run Effect on their own, one after another, such as a list whose items slide in one by one. Part i of n starts at Spread*i/(n-1) of t and runs over the 1-Spread that is left, so the last part ends as t reaches 1.
Offsets that Effect sets on a part, as Slide does, are applied by moving that part's cells within its own row or column, so a part never leaves its band: Stagger{Effect: Slide{From: Left}, From: Top} has each row of a node slide in from the left, clipped to the node's width. Parts see the node as their viewport, so a slide starts at the node's own edge rather than the screen's. A wide glyph cut by the edge of a column that is being moved is blanked while it moves.
type Unfold ¶
type Unfold struct{}
Unfold opens a node from its middle row outward, like a CRT turning on. A band of rows grows from the middle to the full height; its top row shows the node's first row and its bottom row the node's last, so a box's borders are drawn from the start, and the rows between show the node's middle.
type Wave ¶
type Wave struct {
// From is where the front starts. The zero value is Bottom.
From Direction
}
Wave reveals a node behind a front that sweeps in from a side or corner, wobbling like a wave. The cells just behind the front form a crest, mixed toward the terminal's foreground, which settles into their own colors.