Writing a line decoration

Sparkles, glows and bursts that follow a line, written like a Script Tone.

For your AI agentThis whole guide as one plain-text file: line-decorations.txt. Hand it over as it is.

For: artists writing their own path decorations, and the AI agents helping them. Hand this file to your agent together with Writing a Script Tone: a decoration is written the same way as a Script Tone, and that guide covers the header (§3), the pen g (§5), randomness (§6), shape helpers (§7) and errors (§9). This guide covers only what is different.

The sample in §5 was run, and its output was visually checked.

1. What a decoration is

A path can wear one decoration: sparkles, a glow, burst lines, dots — anything drawn along its line, on both sides, not cut by the path. The path stays the object: you select, edit, move and delete the path, and the decoration follows. It is never selected on its own.

In the app

  1. Select a path or a compound (Selection tool, or the Path tools). A compound's decoration follows its final outline, including the inner edge of a ring. Decorations on its member paths remain stored, but are not drawn while those paths are inside the compound. An oval or rectangle made with a Shape tool needs Convert to Path before you can decorate it.
  2. In the inspector's Adornment section, the popup shows what the path wears: None, or a preset — Sparkles, Glow, Burst, Stipple glow, Uneasy lines, Soap bubbles, Hearts, Lightning, Flower garland, Lace, Scallops or Hair shine. Choose a preset to add or replace the decoration; None removes it. Each change is one undo step. Custom… opens the script editor with the path's current custom script, or with a starter that draws dots along the line. Edit it or paste in a script; Done applies it. The popup then shows the script's // @name.
  3. Once set: Seed / Roll, Invert (flips black and white in everything the decoration draws — white sparkles over a dark tone; it survives choosing another preset), the script's sliders, Edit Script…, and Generate (draws it again and re-measures its reach, §4). Sliders apply when you let go — there is no Live mode for decorations, so per-tick speed doesn't matter; the time and size limits are Script Tone guide §10.
  4. While you drag the path's anchors the decoration hides; it redraws once you let go. Moving the whole path doesn't run the script again.

2. The shape of a script

Exactly as for a Script Tone (Script Tone guide §2–3, including the @jscg version rules): a // @jscg 1 header, // @param sliders, and one function generate(p, g).

3. The inputs — p

InputWhat it is
p.width, p.heightthe bounding box of the whole path, in points (a straight horizontal path has height 0)
p.seed0…4294967295 — the Roll. All randomness comes from it (Script Tone guide §6)
p.linesone entry per line of the path (a path can hold several — e.g. after a Join or a boolean), each { points, anchors, closed }
p.lines[i].pointsthe line, flattened: [x0, y0, x1, y1, …]. For a closed line, the last point does NOT repeat the first. A line can be a single point (a one-anchor subpath) with no segments
p.lines[i].anchorsthe path's anchors: [x, y, kind, x, y, kind, …] — kind 0 smooth, 1 sharp corner, 2 open end
p.lines[i].closedtrue for a closed line
p.path, p.anchors, p.closedshorthand for the first line
p.<name>each slider from the header

Coordinates: points, origin at the top-left of the whole path's box, y growing down. All entries in p.lines use this same origin. Unlike a Script Tone, draw outside the box freely — a decoration straddles its line, so half of it is usually outside. Nothing is cut by the path.

There is no p.outline and no p.reach: how far the ink goes is measured from what you draw (§4).

4. Reach — how far the ink goes

Each time you add or change the decoration — Add, a slider, Roll, Edit Script, Generate — the app prepares the drawing (running your script, or reusing a drawing it already made for exactly these settings; Generate always runs it again), and measures how far the ink reaches past the whole path's bounding box. That distance is saved with the path. It decides what area the app redraws and exports, and visible ink is limited to it: the decoration is cut off at the path's box grown by the saved reach, so the screen and the export always agree.

Use decorations for edge effects. A script can draw inside the path too, but the path's own Fill is the better choice for filling its interior. Opaque shapes along the edge — petals, bubbles or lace — can cover the ink beneath them (and Invert turns their whites black). The Scallops preset draws only an outline.

5. Walking along the line

Most decorations place things at regular steps along the line, facing outward. This sample does exactly that — copy outward and walk into your own scripts:

// @jscg 1
// @name Dots along the path
// @param spacing 4..60 default 14 "Spacing"
// @param size 1..12 default 4 "Dot size"
// @param offset -30..30 default 0 "Offset from the line"

function circle(g, x, y, r) {
	var k = 0.5523 * r;
	g.moveTo(x + r, y);
	g.curveTo(x + r, y + k, x + k, y + r, x, y + r);
	g.curveTo(x - k, y + r, x - r, y + k, x - r, y);
	g.curveTo(x - r, y - k, x - k, y - r, x, y - r);
	g.curveTo(x + k, y - r, x + r, y - k, x + r, y);
	g.closePath();
}

// Which way is "out" for a closed line: +1 or -1 (screen y runs down). Open lines: +1.
function outward(line) {
	if (!line.closed) { return 1; }
	var pts = line.points, n = pts.length / 2, area = 0;
	for (var i = 0; i < n; i++) {
		var j = (i + 1) % n;
		area += pts[2 * i] * pts[2 * j + 1] - pts[2 * j] * pts[2 * i + 1];
	}
	return area > 0 ? 1 : -1;
}

// Calls visit(x, y, nx, ny) every `spacing` points along the line; (nx, ny) points outward.
function walk(line, spacing, visit) {
	var pts = line.points, n = pts.length / 2;
	if (n < 2 || !(spacing > 0)) { return; }
	var side = outward(line), next = 0;
	var segments = line.closed ? n : n - 1;
	// A closed line: stretch the spacing a little so the last item doesn't crowd the first.
	if (line.closed) {
		var total = 0;
		for (var k = 0; k < n; k++) {
			var k2 = (k + 1) % n;
			total += Math.hypot(pts[2 * k2] - pts[2 * k], pts[2 * k2 + 1] - pts[2 * k + 1]);
		}
		spacing = total / Math.max(1, Math.round(total / spacing));
	}
	for (var i = 0; i < segments; i++) {
		var j = (i + 1) % n;
		var x0 = pts[2 * i], y0 = pts[2 * i + 1];
		var dx = pts[2 * j] - x0, dy = pts[2 * j + 1] - y0;
		var len = Math.sqrt(dx * dx + dy * dy);
		if (len === 0) { continue; }
		while (next < len - (line.closed && i === segments - 1 ? spacing / 2 : 0)) {
			var t = next / len;
			visit(x0 + dx * t, y0 + dy * t, side * dy / len, -side * dx / len);
			next += spacing;
		}
		next -= len;
	}
}

function generate(p, g) {
	g.setFill(0, 0, 0, 1);
	for (var l = 0; l < p.lines.length; l++) {
		walk(p.lines[l], p.spacing, function (x, y, nx, ny) {
			circle(g, x + nx * p.offset, y + ny * p.offset, p.size);
		});
	}
	g.fill();
}

The built-in presets are complete examples; the first four are the clearest: Sparkles (corner handling), Glow (blur via a far-away shadow), Burst (tapered lines across the line), Stipple glow (dots thrown over the area and kept by distance to the line, the inside of a closed line left clean — the way to get even density around bumps and dents).

6. Sharing and storage

7. When something is wrong

Same as a Script Tone (Script Tone guide §9): the inspector shows ⚠️ and the reason, the path draws as a plain line, and Generate runs the script again. A script that ran too long is blocked until you press Generate.

Keep the Script Tone guide's rules: all randomness from p.seed (§6 — Math.random is seeded and Date frozen, so neither tells the time), loops with a fixed count, and the limits in §10.