Raxol.Effects.Halo (Raxol v2.9.2)

View Source

A sharp glyph set in a drifting field of dithered characters.

The treatment the raxol.io hero wears, as a function: a mark is drawn at full strength, a texture drifts around it, and a keep-out ring between them stops the texture crowding the mark. The browser version rasterizes a font glyph onto a canvas (Hooks.HaloField in the site's app.js); a terminal needs no rasterizer, because the mark is already characters there.

Two tones that never mix. The glyph is whatever the caller passes, at full weight; the field is drawn from :ramp alone. Nothing in the field is ever drawn over the glyph, and no glyph character is ever picked from the ramp, so the mark stays legible no matter how dense the texture gets.

Frames

field/2 is pure in :frame, so a caller animates by passing its own tick and nothing is held between calls. The texture drifts diagonally: x shifts every second frame and y every third, which is slow enough to read as motion rather than as static that never settles.

Halo.field(["≡··≡"], size: {20, 5}, frame: t)

Fade

The field thins toward the middle, so it reads as a frame around the mark rather than as a rectangle of noise with a hole in it. :floor is the coverage a cell needs before it is drawn at all, which is what makes the texture break up at the centre instead of ending on a hard edge.

Summary

Functions

field/2 with lines set beside it, as renderable rows.

Render glyph centred in a field of drifting texture.

The ramp field/2 draws its texture from, lightest first.

Types

glyph()

@type glyph() :: [String.t()]

Functions

caption(glyph, lines, opts \\ [])

@spec caption(glyph(), [String.t()], keyword()) :: [map()]

field/2 with lines set beside it, as renderable rows.

The reason this exists rather than leaving the caller to zip: a field is only ever wanted next to something, and doing that by hand means zipping, padding every row to the field's width, and joining -- which is three chances to render a ragged left edge on the captioned side. Rows past the end of lines keep their texture and get no caption, so the field is never truncated to the caption's length.

Returns text/2 elements rather than strings, styled :fg, so a caller drops the result straight into a column.

Takes field/2's options, plus:

  • :gap -- columns between the field and the caption, default 2.
  • :fg -- colour for the rows, default :cyan.

field(glyph, opts \\ [])

@spec field(glyph(), keyword()) :: [String.t()]

Render glyph centred in a field of drifting texture.

Returns one string per row, each exactly as wide as :size asks, so the result drops straight into a column of text/2 calls without any row needing to be padded or measured.

Options:

  • :size -- {width, height} in character cells, default {20, 5}.
  • :frame -- the caller's tick. The field drifts with it; the glyph does not move.
  • :keep_out -- {x, y} cells of clear space held around the glyph, default {1, 1}. Counted in cells rather than in even visual distance, so a caller whose mark nearly fills the field can drop it to one and still get texture on both sides.
  • :floor -- texture below this weight is left blank, default 0.18. Raising it thins the field.
  • :ramp -- the characters to draw the texture from, lightest first.

A glyph taller or wider than the field is not an error: it is centred and clipped, which keeps a caller that shrinks its pane from crashing.

ramp()

@spec ramp() :: [String.t()]

The ramp field/2 draws its texture from, lightest first.

Exposed so a caller can render something in the same tones, or hold the treatment against the site's own in a test.