textual

Textual - A minimal live-coding language for displaying text

Local server

To start a local server, run:

npx serve --cors

Using Textual in Estuary

!exolang "textual" "http://localhost:3000/exolang.js"
!exolang "textual" "https://textual.savamala.top/exolang.js"

Tell Estuary that you are using Textual by starting your code with this line:

##textual

Performance

Textual renders on a full-screen 2D canvas. Performance varies significantly between browsers; it is much better in Chrome/Chromium than in Firefox.

Displaying text

Display text in the center of the screen with the default settings:

text("Hello, world!").out();

text supports multi-line text:

text("Hello,\nTextual!").out();
text(`Hello,
Textual!`).out();

Size:

text("Hello, Textual!").size(200).out();

Emojis:

text(":moon :sun :water :fire :heart :mercury").size(100).out()

Font family:

By default, Textual uses the platform’s sans-serif font. You can choose a specific font with .font():

text('Textual').font('wingdings').out();

When no font is specified, zalgo text uses Helvetica (with Arial and sans-serif as fallbacks). If you set a font explicitly, zalgo will use it even if the marks do not render well.

Stroke:

By default, text is filled. Use .stroke() to render it as an outline:

text('textual').stroke(3).size(200).color('blue').out()
text('textual').size(200).color('pink').out()

Shadow:

Adds a shadow to the text. The arguments follow Canvas’s setShadow order: shadow(x, y, blur, color):

text("textual").shadow().out()                    // 2, 2, 4, gray
text("textual").shadow(4, 4).out()                // 4, 4, 4, gray
text("textual").shadow(4, 4, 8, "purple").out()

Shadows are expensive on the 2D canvas, especially with large fonts. Use them sparingly in live performances.

Zalgo:

Adds combining diacritical marks to the text for a glitchy or chaotic look. The optional arguments are the average number of marks per character (default 5) and the random seed:

text("textual").zalgo().out()                // seed 0, always the same result
text("textual").zalgo(5, 1).out()            // another variant
text("textual").zalgo(20).out()              // more marks

Hack:

Substitutes characters with similar alternatives. The optional arguments are the probability of each character being changed (default 0.3) and the random seed:

text('textual').hack().out();               // seed 0, always the same result
text('textual').hack(.6, time*2).out();     // changes two times per second (seed is integer)
text('textual').hack().zalgo().out();       // can be combined with other effects

Based on text-hacker by GEIKHA (Apache License).

Letter-spacing:

Changes the space between letters. sp and spacing are synonyms.

text('textual').sp(50).out()
text('textual').sp(remap(osc(.12), 0, 30)).out()

Argument is in pixels and the default value is 4.

Word-spacing:

Change the space between words. wsp and wordspacing are synonyms.

text('tex tual').wsp(80).out()
text('tex tual').wsp(seq(100,0).smooth()).out()

Argument is in pixels and the default value is 8.

Stretch:

Expands or condences the font.

text('textual').stretch(.5).out();
text('textual').stretch(osc(.15)).out();
text('textual').stretch('expanded').out();

The optional argument can be a number between -1 and 1 or one of these options: “ultra-condensed”, “extra-condensed”, “condensed”, “semi-condensed”, “normal”, “semi-expanded”, “expanded”, “extra-expanded”, “ultra-expanded”. Default value is -0.5.

Caps:

Activates small caps.

text('Textual').caps().out()
text('Textual').caps(sqr(.2)).out()

Direction:

Change the direction of the text or parts of it.

Arguments: dir(l=0, p=1, s=0)

text('textual').dir().out()           // all text inverted: lautxet
text('textual').dir(0,.5).out()       // invert a group of 7 (length) characters. Each character has 50% to be the first. 
text('textual').dir(2).out()          // invert groups of 2 characters: ettxaul
text('textual').dir(-1).out()         // invert all characters except one
text('textual').dir(-5).out()         // invert groups of 2 characters (length 7-5=2), from the right: txeutla
text('textual').dir(2,.2).out()       // 20% of probability for each inversion
text('textual').dir(2, .5, time).out() // 50%, change random seed with time
text('textual').dir(2, osc(), time).out() // Change probability and seed over time. When osc() is negative, the text is stable
text('textual').dir(2, unipolar(osc()), 6).out() // Custom seed, gradual change.
text('textual').dir(remap(osc(.1), -6, 6)).out() // Change length of inverted groups and direction over time

dir and direction are synonyms.

Mono:

Converts emojis into their respective text characters, whenever they exist.

text(':heart').mono().out()
text(':heart').mono(osc()).out()
text(':heart').mono().color("cyan").out()

Transformations

These transformations can be applied to any element.

Position:

text("Textual").move(-.4, .5).out()
text("Textual").move(-.4, .5*osc(.2)).out()
text('Textual').move(.1).out() // Move both x and y by 0.1
text('Textual').movex(.3).out()
text('Textual').movey(seq(.2,-.5,.8,0).slow(4).smooth()).out()

Color:

RGB values from 0 to 1:

text('Textual').color(.5, 0, .5).out()
text('textual').color([.7,.3,.4]).out()

RGBA:

text('Textual').color(.5, 0, .5, .4).out()
text('textual').color([.7,.3,.4,.5]).out()

Color names:

text('textual').color('cyan').out()
text('textual').color(seq('cyan','orange')).out()

Rotation:

text("textual").spin(.2).move(.2,.2).out()
text("textual").spin(time/4%2).out()

In spin(), 1 equals PI radians.

Note that spin always rotates the node around its center.

Orbit:

Rotates a node following an orbit around its position.

text(':heart').move(.5,0).orbit(.2,saw(.5)).out()
const sun = text(':sun-face').size(100);

const earthMoon = group(
    text(':earth').size(50),
    text(':moon-face').size(20).orbit(0.12, saw(.2))
).orbit(0.5, saw(.04));

group(sun, earthMoon).fit().move(remap(osc([.02,.03]),-.5,.5)).out();

Zoom:

text('textual').zoom(3,8).out()
text('textual').zoom(seq(1,10).smooth(),1).out()
text('textual').zoom(.5).out()  // scale both axes
text('textual').zoomx(5).out()
text('textual').zoomy(-4).out()

text('textual').stroke(.2),
{
  zoomx: range(2,10),
  zoomy: range(2,10)
}).out();

Arbitrary transformations:

Apply any transformation you like by directly accessing the canvas context and calling its native methods:

text('textual').stroke(1).size(100).transform(ctx=>{
  ctx.rotate((time/3)%2*Math.PI);
  ctx.translate(seq(0,300).slow(12.31).smooth(),4);
  ctx.rotate((time/4)%2*Math.PI);
}).out()
text(':fire_emoji').
transform(ctx => {
ctx.rotate(Math.PI*saw(.2));
ctx.translate(200,0);
ctx.rotate(-1*Math.PI*saw(.2));
}).out()
fb(.92)

Or use matrix to provide a custom transformation matrix:

text('textual').matrix(8,3,3,5,0,0).out()

matrix has six optional parameters (a=1, b=0, c=0, d=1, e=0, and f=0) that define the affine transformation to be applied:

| a  c  e |
| b  d  f |
| 0  0  1 |

Examples:

const a = Math.PI / 4; // const a = time;
text("textual").matrix(Math.cos(a), Math.sin(a), -Math.sin(a), Math.cos(a)).out();

Oscillators

All oscillators take a frequency in Hz. To synchronize with the tempo, pass cps:

osc(1)              // 1 Hz, free-running
osc(cps)            // one cycle per beat
saw(cps * 2)        // sawtooth, two cycles per beat
tri(cps)            // triangle
sqr(cps / 2)        // square

Oscillator phase is anchored to the current tempo reference, so changing the tempo (e.g. with tap tempo) resets the phase.

text('textual').move(0,osc(cps)).out()
text(":moon").spin(saw(0.5)).size(500).out()
text(":moon").spin(saw(-0.5)).size(500).out()
fb(.9)

Reescaling values

text('textual').color(unipolar(saw(.2)), 0, 0).out()
text('textual').color(unipolar(saw([.06, .13, .19]))).out()

text('textual').move(bipolar(Math.random())).out();

text('textual').spin(remap(osc(-.19), -.1, .1)).
  move(remap(osc(.19), -.5, .5)).out()
text('textual').zalgo(remap(tri(.018),1,50)).out()

Feedback

Feedback allows keeping the image obtained in the previous frame in the current frame.

fb(keep) where keep is a number from 0 (keep nothing) to 1 (keep all).

fb(0.98);
text("Textual").move(-.4, .5*Math.sin(time)).color(.5,0,.3).out()

Sequences

seq(1, 2, 3) cycles through the given values, one full pass per cycle, synchronized with Estuary’s tempo.

text("textual").move(seq(-0.5, 0, 0.5), 0).out()

Modifiers can be chained:

seq(1, 2, 3).fast(2)          // two passes per cycle
seq(1, 2, 3).slow(2)          // half a pass per cycle
seq(1, 2, 3).offset(1)        // start from the second value
seq(1, 2, 3).smooth()         // interpolate instead of stepping
seq(1, 2, 3).fast(2).smooth() // combined

The array form seq([1, 2, 3]) is also accepted and is useful when the values come from a variable:

text(":heart").size(seq([50, 100, 200]).smooth()).out()      // Array form
text(":heart").size(seq(50, 100, 200).smooth()).out()        // Equivalent without array
text('textual').color(seq([1,0,0],[0,1,0]).smooth()).out()   // Smooth works with arrays too

Ranges

range(5) -> [0, 1, 2, 3, 4]
range(30, 0, -10) -> [30, 20, 10]
range(0, 2, 0.2) -> [0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6, 1.8]
range(2, 0, -0.5) -> [2, 1.5, 1, 0.5]
swarm(text(":heart"), { size: range(200, 50, -20) }).out();
text('textual').size(seq(range(100,500,100))).out();

swarm(text(":sun"), {
    orbit: range(0.1, 0.9, 0.05).map(r => [r, r*beat])
}).fit().out();

swarm(rect(), {
    spin: range(.1, 1, .1)
}).fit().out()

Text expansion

xt(':name') returns the raw expansion of a shortcode. For simple shortcodes it behaves the same as text(':name'). Its real use is when the entry is a cycle: xt(':moon-cycle') returns the array of values, which you can then use with seq, index, or manipulate.

text(xt(':moon_cycle')).out()             // 🌑🌒🌓🌔🌕🌖🌗🌘
text(seq(xt(':moon_cycle'))).out()        // cycle through all emojis
text(seq(xt(':sun :moon-cycle :sun'))).out()
text(xt(':moon_cycle')[2]).out()          // 🌓
text(seq(xt(':planets-cycle').reverse())).out()

Bézier curves

Curve:

A simple curve with origin (0,0). The first two arguments are the end point, and the third is the bend.

curve(1, 0).out()                       // straight line
curve(1, 0, 0.3).out()                  // an arc
curve(1, 0, osc(0.5) + 0.5).out()       // oscillating arc
curve(osc(.3), osc(.23), 0.2).out()     // moving end point
curve(1, 1, 0.3).stroke(6).out()        // diagonal, wide stroke
curve(1, 1, 0.3).move(-0.5, -0.5).out() // moved
curve(1, 0, osc(0.3)).fill().out()      // filled

Bézier curves have two colors: one for the fill and one for the stroke:

curve(1, 0, osc(.2)).fill().fillColor("navy").stroke(4).strokeColor("cyan").out()
curve(1, 0, osc(.2)).fill().fillColor("red").stroke(0).out()
curve(1, 0, osc(.2)).fill().color("red").stroke(12).out() // both are red

S-shaped curve:

An S-shaped curve with origin (0,0). The first two arguments are the end point, and the third is the bend.

scurve(1, 0).out()
scurve(1, 0.5, 0.3).out()
scurve(1, 0, 0.5).color("cyan").stroke(4).out()
scurve(1, 0, osc(0.5) + 0.5).out()
scurve(1, 0, seq(0.2, 0.5, 1).smooth()).out()
scurve(1, 0, 0.5).spin(time).out()

scurve and sCurve are synonyms. Default values are 1, 0 and 0.

Bézier:

A quadratic or cubic Bézier curve.

// Quadratic (3 points: start, control, end)
bezier([0,0], [0.5, 0.5], [1, 0]).out()
bezier([0,0, 0.5,0.5, 1,0]).out()       // flat array
bezier(0, 0, 0.5, 0.5, 1, 0).out()      // flat args

// Cubic (4 points: start, control1, control2, end)
bezier([0,0], [0.3,0.3], [0.8,0], [1,0]).out()
bezier([0,0, 0.3,0.3, 0.8,0, 1,0]).out()
bezier(0,0, 0.3,0.3, 0.8,0, 1,0).out()

Rectangles

Draw rectangles. Default values are 1 for width and height.

rect().out()    // Centered, stroke
rect(.5, .2).out()  // width: 0.5, height: 0.2

fb(1)
rect().move(osc(.11), osc(.13)).comp('difference').stroke(4).color(unipolar(osc([.14,.31,.24]))).out()

rect().spin(saw(.2)).out().fill()
rect(.5,.5).color('cyan').fill().strokeColor('black').out().spin(saw())

Circles and ellipses

Draw circles. Default values are 1 for radius, 0 for starting angle, and Math.PI*2 from ending angle.

circle().out()
circle(1, 0, 1.6).out()

swarm(circle().fill(), {zoom:saw([1,.8,.6,.4,.2]), color:[[1,1,1,0.3]]}).out();

Draw ellipses. Default values are 1 for both radius, 0 for starting angle, and Math.PI*2 from ending angle.

ellipse(.5,1,0,3.14).out()

Images and videos

Use img to load images:

const i = "https://thumb.wikimedia.org/wikipedia/commons/thumb/6/64/Rain_Quail_in_Bhigwan_August_2025_by_Tisha_Mukherjee_13.jpg/1280px-Rain_Quail_in_Bhigwan_August_2025_by_Tisha_Mukherjee_13.jpg";
img(i).out();

Images and videos can only be loaded from servers that allow access from any place (Access-Control-Allow-Origin: *).

Images and videos are always displaied at their natural size. Note that this is not the same behaviour than Punctual, where images are scaled to fill the canvas. Use zoom to reescale the image or video.

fit doesn’t change the image or video size, only its position.

const v = "https://upload.wikimedia.org/wikipedia/commons/f/f8/Bear_walking_at_Kaliningrad_Zoo.webm";
vid(v).out();

vid(v).rate(.2).out();
vid(v).range(0,5).out();     // Loops only the 5 first seconds
vid(v).loop(false).out();    // Reproduces the video once
vid(v).start(5).out();       // Start from 5 seconds

rate() sets the playback speed. Values are taken as absolute; negative values are treated as positive because the browser doesn’t support reverse playback. Use 0 to freeze the video.

Grouping and cloning nodes

Nodes can be grouped and transformations can be applied to the whole group:

group(
    text('textual').color('red'),
    sCurve(1,0,.6).move(-.5,0)
).spin(time/2).move(osc(.14)/2).out()

group(
    rect().stroke(10),
    text('textual')
).color('gray').out()

group(
  rect(),
  bezier(),
  text('textual')
).zalgo().out()    // zalgo is only applied to the text, where it makes sense

Nodes can also be cloned:

const t = text('textual').color('cyan').hack(1).move(.2,0).out();
t.clone().move(-.2,0).out();

Or equivalently:

text('textual').color('cyan').hack(1).move(.2,0).out().clone().move(-.2,0).out();

clone can receive the same arguments as the used primitive (ie. text or curve):

const base = text().color('magenta').spin(-time/2).size(80);

group(
    base.clone(":sun").move(remap(osc(.1),0,.4), 0),
    base.clone(":moon").move(remap(osc(.1),0,-.4), 0),
).spin(time/2).out()

You can also create a group of related nodes in a single line:

swarm(text('textual').stroke(), {size: [100, 200, 300]}).out();
swarm(rect(), {spin: [.25, .5, .75, 1], color: ['red', 'blue', 'purple']}).out();
swarm(text('textual').size(200).color(1,0,1,0.4), {zoom: osc([.1,.14,.15])}).out();

swarm(
    text(':fire').spin(saw(-.1)),
    {size: [50, 100, 150], move: [[-0.2, 0], [0, 0], [0.3, 0]]},
).spin(saw(.1)).out();

const t = swarm(
    text('textual').stroke().size(80),
    {direction:[1,0],move: [[-0.2, 0], [0.2, 0]]}
);
swarm(t, {move: [[0,.5],[0,0],[0,-.5]]}).out();

Composition

Sets the type of compositing operation to apply when drawing the node.

Options are documented here: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation

fb(0.9);
text(":heart").size(200).composite("lighter").move(osc(0.3), 0).out()

text("textual").size(300).out()
  .clone().size(280).composite("multiply").color("#333").out()

text("textual").color("gray").size(300).out()
  .clone().size(280).composite("multiply").out()

text("textual").font('courier').sp(20).out()
  .clone().size(55).composite("destination-out").out()

fb(1)
group(
    text(":sun").move(osc(.13)/5, 0),
    text(":moon").move(osc(-.13)/5, 0),
).spin(saw(.1)).composite("difference").out()

composite, compose and comp are synonyms.

Valid options: “source-over”, “lighter”, “multiply”, “screen”, “difference”, “exclusion”, “overlay”, “xor”, “darken”, “lighten”, “color-dodge”, “color-burn”, “hard-light”, “soft-light”, “destination-out”, “destination-over”, “destination-in”, “destination-atop”, “source-in”, “source-out”, “source-atop”, “copy”, “hue”, “saturation”, “color”, “luminosity”.

Also accepts numbers as indexes from the valid options array:

text("textual").size(300).out()
  .clone().size(280).composite(5*saw()).color("#093").out();

swarm(rect(),
  {
    spin: saw([-.2,.2])
  }
).fill().grrad(0,1,1,'red','blue').composite(seq(range(10)).slow(8)).out();

Gradients

Apply any gradient to any node.

Linear gradient:

rect().fill().grlin().out()
rect().fill().grlin(-1,-1,1,1,'red','black').out()
rect().fill().grlin(0,1,0,-1,[0,.8,0],[1,0,0.8]).out()

group(
    rect().fill().spin(saw(.02)),
    rect().fill().move(osc(.03),.3)
).grlin(-.7,0,.7,0,'red','green','orange').composite('difference').out()

Creates a gradient along the line connecting two given coordinates (first 4 arguments). Any number of colors can be used.

Defaults: grlin(x1 = -1, y1 = 0, x2 = 1, y2 = 0, 'white', 'transparent')

Radial gradient:

rect().fill().grrad().out()
rect().fill().grrad(osc(.19),osc(.12),1.5,'purple','blue').out()

Creates a radiant gradient with given center and radius.

Defaults: grrad(x = 0, y = 0, r = 1, 'white', 'transparent')

Conic gradient:

rect().fill().grconic().out()
rect(2,2).fill().grconic(Math.PI*saw(.1), 0,0).out()
rect().fill().grconic(0, 0.5,0, 'red','green').out()

Creates a conic gradient with given initial angle and center.

Defaults: grconic(angle = 0, x = 0, y = 0, 'white', 'transparent')

Aspect ratio

You can change the aspect ratio used by any shape (all nodes, except for text).

aspect is the current aspect ratio of the canvas.

fit() can be used to change the local aspect ration for a node or group of nodes.

circle().fit().out()  // Corrects distorsion, perfectly round circle
circle().fit(1).out() // Same
circle().fit(aspect).out()  // Same as not specifying any fit. Circle fits the canvas
circle().fit(aspect/2).out()  // Circle fills half the width of the canvas

swarm(rect(2,2).fill().fit(aspect/2), {color: ['red', 'orange'], move: [[-1,0],[1,0]]}).out();
circle().fit(unipolar(osc())).out();

Interactivity

mousex and mousey can be used to get the mouse position at each frame. The position is normalized to the -1 to 1 range.

circle().move(mousex,mousey).fit().out()
rect().fill().color([unipolar(mousex),unipolar(mousey),0]).out()

Using Textual with Punctual

In Estuary, use two cells: one for Punctual and one for Textual.

Force the creation of the Punctual canvas first, because it is opaque:

hline 0 0.001 >> add;

Load Textual by using any sentence:

##textual
text('Hello, Punctual!').out()

Now, you can redirect your text into a stream:

text('Hello, Punctual!').out('my-stream')

The text is now invisible. Get it from Punctual:

v << vid "stream://my-stream";
v >> add;

Add any Punctual effects and enjoy!

This method uses a very hacky approach because Punctual does not support streams yet, and it depends on loading Textual before Punctual accesses any video.