Ascii.Pieces.Heartbeat (Ascii v0.3.0)

Copy Markdown View Source

An ecg trace sweeping over its last pass, with a bpm readout.

An ECG monitor. A PQRST trace sweeps left to right over a dotted grid and its last pass, erasing a few columns ahead, beside a rate readout.

Options

Give them to Ascii.new/2 as options:, and new ones while it plays with Ascii.put_options/2 (or a Phoenix player's options): the monitor starts afresh at the new rate.

  • bpm - the heart rate, beats a minute, 30 to 199: the trace's pace, and the readout in large digits. Default 72.

The frame is always 72 by 15.

Colours

It has no parts to colour one by one: in one ink, or a gradient, with :ink and :gradient (see Ascii.Ink). A green ink makes the monitor's own.

Keys and clicks

It takes none: it shows a rate, and Ascii.handle_event/2 ignores every event. A Phoenix player given interactive and notify still tells your LiveView where it was clicked.

Screen readers

Ascii.describe/1 reads the rate, as the readout shows it: "heartbeat: 72 bpm".

Example

monitor = Ascii.new!("heartbeat", options: %{bpm: 90}, ink: "#3fb950")

Ascii.describe(monitor)
#=> "heartbeat: 90 bpm"

{frame, _monitor} = Ascii.frame(monitor, 1.0)
{frame.cols, frame.rows, frame.palette}
#=> {72, 15, ["#3fb950"]}
<Ascii.Phoenix.live_player id="pulse" piece="heartbeat" options={%{bpm: @bpm}} ink="#3fb950" />

Ported from src/pieces/heartbeat.ts in bas3line/ascii (MIT).