Sparkles, glows and bursts that follow a line, written like a Script Tone.
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.
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
// @name.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).
width, height, seed, outline (the header refuses them), and also lines, path, anchors, closed (a decoration refuses them — they are its inputs).p| Input | What it is |
|---|---|
p.width, p.height | the bounding box of the whole path, in points (a straight horizontal path has height 0) |
p.seed | 0…4294967295 — the Roll. All randomness comes from it (Script Tone guide §6) |
p.lines | one 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].points | the 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].anchors | the path's anchors: [x, y, kind, x, y, kind, …] — kind 0 smooth, 1 sharp corner, 2 open end |
p.lines[i].closed | true for a closed line |
p.path, p.anchors, p.closed | shorthand 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).
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.
var r = p.width / 10). Even then, reshaping or rotating a path changes its box, which can change the reach. If the decoration looks cut off after reshaping or rotating, press Generate — it measures again.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.
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();
}
walk(line, spacing, visit) calls visit(x, y, nx, ny) every spacing points: (x, y) is on the line, (nx, ny) is a unit vector pointing outward — so x + nx * d, y + ny * d is d points outside the line (a negative d is inside).outward reads the line's turning direction. On an open line it is a fixed side of the drawing direction: heading right (left to right), outward is up; heading down, outward is to the right.line.anchors lists each anchor with its kind; mark sharp corners (kind 1), or keep items away from them — the Sparkles preset does both.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).
.mangapage all carry the script along. Share a script by copying its text (Edit Script… → copy), e.g. on Discord.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.