A text field that burns away when you send it

I wanted to know if a live text field inside a canvas could be sent and burnt off in place: the letters you typed lift away as embers while the field underneath is already empty and ready for the next line. Type something and press Send, or watch the demo lines go.

After Vanish Input by Rauno Freiberg (in Elsewhere).

Outbox2 sent
  1. Running ten minutes late
  2. Got the tickets

Enter sends. The letters burn off the field.

 

Show the code the markup, the copy, the embers, the send, the card size
  1. The markup. A <form> with a text field, a submit button and a list of sent chips, as the one drawable child of a 2D canvas.
  2. Styles. The field has one flat colour inside its border, so its text box holds only background and glyphs.
  3. The copy. The text box is copied once with drawImage() into a plain canvas, and only that copy is read.
  4. The embers. Each dark texel becomes an ember, let go from left to right, lifted and pushed by a wavering wind, in fixed steps from a seeded generator.
  5. The send. In the paint after a submit: copy, spawn, paint the field colour over the old text for that frame, clear the live field and add a chip.
  6. The card size. The form gets the canvas size in pixels from script, so its hit boxes match where it is drawn.

How it works

The form is an ordinary <form> with a text field, a Send button and a list of sent messages. It's the one drawable child of a 2D canvas, drawn at the canvas size with drawElementImage(form, 0, 0, width, height) in every paint. So the field takes focus, typing, selection and Enter like any other field, and Send is a real submit button.

One copy. On submit the page asks for a paint. In that paint, after the form is drawn, the text box of the field (inside its border) is copied out of the canvas twice with drawImage(): once at device scale into a small canvas that keeps the letters, and once at twice CSS scale into a plain canvas made with willReadFrequently. That plain canvas is the only thing read with getImageData(), once per send. The drawable canvas is never read and never made with willReadFrequently.

Embers. Every texel of the copy darker than 120 is a glyph texel. Up to 2,600 of them become embers. A cut runs across the text from left to right in 0.55 seconds: to its right the kept letters are drawn as they were, and to its left each ember is let go, flashes white, cools through orange and red, rises and drifts on a wavering wind. The simulation runs in fixed steps of 1/60 s from a generator seeded by the text, so the same line gives the same plume.

A clean field. In the same paint the field's colour is painted over its old text, the live field's value is set to an empty string and a chip with the text is added to the list. The next paint draws the form with the empty field, so the letters are only ever in the embers.

Before you type. The page sends its first line on the first paint, drawn 0.9 seconds in, and then fills and sends a demo line every few seconds until you touch the form or untick the box. With reduced motion on, each plume is drawn once, 1.3 seconds in, as a still frame, and the demo lines wait.

Live checks

These run on their own copies of the form, on small canvases in the corner of the window. They don't touch the demo above.

Findings