SelfscribeDownloadOpen the app

Custom diagram shapes

Draw a shape once, then use it like a built-in one.

Document · Advanced · uses diagram, animation

Edit it in the playgroundRead the file

What it shows

Draw your own shapes for a diagram and make them move while they work.

What you learn

A type line with a drawing, a sign instead of a drawing, size and colour, motion, states that change a node, steps that switch between states.

Try this

  • Step on to 14:00 under the first diagram, and the fan turns while the water stops.
  • Change motion=spin on the fan's type to motion=float, and the fan bobs instead of turning.
examples/own-shapes.self · 162 lines
~~~ selfscribe
# Lesson: Draw your own shapes for a diagram and make them move while they work.
# You learn: a `type` line with a drawing, a sign instead of a drawing, size and colour, motion, states that change a node, steps that switch between states.
# Try this: step on to 14:00 under the first diagram, and the fan turns while the water stops.
# Try this: change `motion=spin` on the fan's type to `motion=float`, and the fan bobs instead of turning.
# summary: Draw a shape once, then use it like a built-in one.
# category: diagrams
# tags: document, advanced, ideas
# uses: diagram, animation
use markdown
set title Custom diagram shapes
set style sans wide
set heading-font Bitter

# ---- Colours, each with its shade for dark pages ----------------------------------------
palette
  leaf    #3f6212  dark #bef264
  tint    color-mix(in srgb, var(--leaf) 11%, transparent)

# ---- "> a line": the line under the title, in the document's own voice -------------------
line  > _       -> p.lede    { margin: -0.3em 0 0.9em; font-size: 1.15em; line-height: 1.5; opacity: 0.82 }  as lede

# ---- "kit a | b | c": what the greenhouse has, as tags in a row ---------------------------
line  kit _     -> p.kit     split "|" span.part  { display: flex; flex-wrap: wrap; gap: 0.4em; margin: 0 0 1.4em }  as kit
class part  { padding: 0.2em 0.75em; border-radius: 999px; background: var(--tint); color: var(--leaf); font: 600 0.82em/1.6 var(--doc-font-ui) }

# ---- ```flow ... ```: a diagram, drawn by the flow plugin -------------------------------
# Everything inside the block (types, nodes, links, states, steps) is the plugin's own text.
block  ``` flow ... ```  -> flow  verbatim
~~~
# The greenhouse on plot 14

> How the water and the air look after themselves while we are at work.

```flow
set direction=LR
type butt draw="M18 6 C18 2 82 2 82 6 L90 50 L82 94 C82 98 18 98 18 94 L10 50 Z M14 30 L86 30 M14 70 L86 70" size 56x70 color=teal
type valve draw="M4 30 L50 62 L4 94 Z M96 30 L50 62 L96 94 Z M50 62 L50 14 M30 14 L70 14" size 44x40 color=teal
type pump draw="M50 4 C75 4 96 25 96 50 C96 75 75 96 50 96 C25 96 4 75 4 50 C4 25 25 4 50 4 Z M36 26 L76 50 L36 74 Z" size 46x46 color=accent
type drip draw="M50 4 C50 4 86 48 86 68 C86 86 70 96 50 96 C30 96 14 86 14 68 C14 48 50 4 50 4 Z" size 30x40 color=teal
type fan draw="M50 50 C30 30 30 4 50 4 C62 4 62 30 50 50 Z M50 50 C70 30 96 30 96 50 C96 62 70 62 50 50 Z M50 50 C70 70 70 96 50 96 C38 96 38 70 50 50 Z M50 50 C30 70 4 70 4 50 C4 38 30 38 50 50 Z" size 54x54 color=grey motion=spin
type panel draw="M14 18 L86 18 L98 82 L2 82 Z M38 18 L34 82 M62 18 L66 82 M8 50 L92 50" size 64x44 color=yellow
type tomato icon="🍅" size 46x46
type chilli icon="🌶️" size 46x46
type lettuce icon="🥬" size 46x46
type bell icon="🔔" size 40x40

node sun "Solar panel, 20 W" :panel at 130,-130
node butt "Water butt, 200 L" :butt at 0,0
node valve "Timer valve" :valve at 150,15
node pump "12 V pump" :pump at 280,12
node drip "Drip line" :drip at 420,15
node tomato "Tomatoes" :tomato at 560,-90
node chilli "Chillies" :chilli at 560,12
node lettuce "Lettuces" :lettuce at 560,114
node fan "Roof fan" :fan at 100,233
node thermo "Thermostat: 18 °C" color=green at 280,238
node bell "Frost alert" :bell color=grey at 570,240

butt -> valve -> pump -> drip moving
drip -> tomato moving
drip -> chilli moving
drip -> lettuce moving
sun -> pump dash=dashed color=yellow
thermo -> fan "above 26 °C"
thermo -> bell "below 2 °C"

state watering "Watering" {
  valve color=green
  pump motion=pulse
  fan motion=none
}
state hot "A hot afternoon" {
  thermo "Thermostat: 31 °C" color=red
  valve color=red
  butt -> valve -> pump -> drip still
  drip -> tomato still
  drip -> chilli still
  drip -> lettuce still
}
state frost "A frosty night" {
  thermo "Thermostat: 1 °C" color=teal
  valve color=grey
  fan motion=none
  sun color=grey
  sun -> pump color=grey
  butt -> valve -> pump -> drip still
  drip -> tomato still
  drip -> chilli still
  drip -> lettuce still
  bell motion=pulse color=red
}
step "06:00 · The timer opens the valve, and the beds drink for 12 minutes" state=watering
step "14:00 · 31 °C under the glass: the fan turns and the water stays off" state=hot
step "02:00 · 1 °C: the alarm rings on both our phones" state=frost
```

kit 3 × 2 m greenhouse | 200 L water butt | 20 W solar panel | 12 minutes of water a day | frost alert to two phones

Step through a day with the bar under the drawing. The water runs at six in the morning, the fan turns when it gets hot, and the bell rings when a frost is on its way.

## The parts, drawn once

Each of these is one `type` line at the top of the diagram. Every node that uses it is drawn the same way, in the page's colours.

```flow
type butt draw="M18 6 C18 2 82 2 82 6 L90 50 L82 94 C82 98 18 98 18 94 L10 50 Z M14 30 L86 30 M14 70 L86 70" size 56x70 color=teal
type valve draw="M4 30 L50 62 L4 94 Z M96 30 L50 62 L96 94 Z M50 62 L50 14 M30 14 L70 14" size 44x40 color=teal
type pump draw="M50 4 C75 4 96 25 96 50 C96 75 75 96 50 96 C25 96 4 75 4 50 C4 25 25 4 50 4 Z M36 26 L76 50 L36 74 Z" size 46x46 color=accent
type drip draw="M50 4 C50 4 86 48 86 68 C86 86 70 96 50 96 C30 96 14 86 14 68 C14 48 50 4 50 4 Z" size 30x40 color=teal
type fan draw="M50 50 C30 30 30 4 50 4 C62 4 62 30 50 50 Z M50 50 C70 30 96 30 96 50 C96 62 70 62 50 50 Z M50 50 C70 70 70 96 50 96 C38 96 38 70 50 50 Z M50 50 C30 70 4 70 4 50 C4 38 30 38 50 50 Z" size 54x54 color=grey motion=spin
type panel draw="M14 18 L86 18 L98 82 L2 82 Z M38 18 L34 82 M62 18 L66 82 M8 50 L92 50" size 64x44 color=yellow
node a "Water butt" :butt
node b "Valve" :valve
node c "Pump" :pump
node d "Drip line" :drip
node e "Fan" :fan
node f "Solar panel" :panel
```

## Signs for boxes

For a quick picture, a sign is enough. This is how the frost alert reaches our phones:

```flow
set direction=LR
type sensor icon="🌡️" size 48x48
type hub icon="📡" size 48x48
type sky icon="☁️" size 56x48
type phone icon="📱" size 48x48
node s "Sensor by the tomatoes" :sensor
node h "Hub in the shed" :hub
node c "Weather service" :sky motion=float
node p "Our phones" :phone
s -> h "every 5 minutes" moving
h -> c moving
c -> p "below 2 °C" moving=slow
```

Nothing moves for a reader who has turned motion off, or on paper.

## How it's made

One line makes a shape of your own:

`type valve draw="M4 30 L50 62 L4 94 Z …" size 44x40 color=teal`

- `draw=` is the outline, in SVG path letters, inside a box 100 wide and 100 tall. The box is stretched to the node's size, so one drawing serves small and large.
- `icon=` is one sign instead of a drawing, as in `type tomato icon="🍅"`.
- `size 44x40` is how large its nodes are, and `color=` is their colour. The node's words sit under it.
- `motion=` is `spin`, `pulse`, `blink` or `float`. A state can change it: `fan motion=none` stills the fan in the `watering` state.

Then `node valve "Timer valve" :valve` uses it, as often as you like. The `step` lines at the end of the first diagram each show one state.

## Try it yourself

1. In the first diagram, change `motion=spin` on the fan's type to `motion=float`. The fan bobs instead of turning.
2. In the lettuce's type, change `icon="🥬"` to `icon="🥕"`, and its node's `"Lettuces"` to `"Carrots"`. The third bed grows carrots.
3. In the `frost` state, add the line `pump color=grey`. Step on to 02:00, and the pump greys out.
4. In the last picture, change `icon="📱"` to `icon="⌚"`. The alert goes to a watch.

**Next:** *Diagrams that move* makes links and switches move; *One diagram, many views* shows one diagram in several places.