A drawing app built for agent/human collaboration
Rust
paint --shadow: shadows take a colour's hue and keep their values
Indicode BV822bc092de8a
diff --git a/README.md b/README.mdindex b2d1ad1..570b108 100644--- a/README.md+++ b/README.md@@ -41,7 +41,7 @@ There are no downloads yet; build it from source (about ten minutes the first ti1. Install Rust with [rustup](https://rustup.rs) and [`just`](https://github.com/casey/just) (`brew install just`, or `cargo install just`). On Linux also `pkg-config`, `libfreetype-dev` and `libfontconfig1-dev`.2. `git clone https://github.com/klad-app/klad && cd klad`, then `just build` makes the `klad` binary in `target/release/` (on Linux in `target/linux/release/`).3. On a Mac, `target/release/klad open` starts the editor on its start window: make a drawing and start painting.-4. `just samples` builds the sample drawings in `samples/` (a lantern, a walking creature, painted solids, a bouncing ball, ink examples); open one with `target/release/klad open samples/lantern/lantern.draw`.+4. `just samples` builds the sample drawings in `samples/` (a lantern, a walking creature, painted solids, a bowl of lemons, a bouncing ball, ink examples); open one with `target/release/klad open samples/lantern/lantern.draw`.## Drawing with an agentdiff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rsindex 9353386..f837a3a 100644--- a/crates/cli/src/main.rs+++ b/crates/cli/src/main.rs@@ -978,6 +978,17 @@ enum Command {help = "How much darker the core just past the terminator is")]core: f32,+ #[arg(+ long,+ help = "The shadow side takes this colour's hue and chroma and keeps its own values (a colour or a palette name)"+ )]+ shadow: Option<String>,+ #[arg(+ long,+ default_value_t = 0.7,+ help = "How far the shadow side goes towards --shadow, 0 to 1"+ )]+ shadow_mix: f32,#[arg(long,default_value_t = 30.0,@@ -2261,6 +2272,8 @@ fn run() -> Result<()> {bounce,bounce_strength,core,+ shadow,+ shadow_mix,angle,weight,decisive,@@ -2297,6 +2310,8 @@ fn run() -> Result<()> {bounce,bounce_strength,core,+ shadow,+ shadow_mix,angle,weight,decisive,diff --git a/crates/cli/src/shapes.rs b/crates/cli/src/shapes.rsindex 1774ee6..37faf8b 100644--- a/crates/cli/src/shapes.rs+++ b/crates/cli/src/shapes.rs@@ -3,7 +3,7 @@ use klad_core::bundle::Bundle;use klad_core::color;use klad_core::doc::Document;use klad_core::ops::{FillSpec, HatchSpec, InkSpec, LightSpec, Op, PaintSpec, ScatterSpec, StrokeSpec, apply_all};-use klad_render::form::{self, Form, FormRules, Lighting};+use klad_render::form::{self, Form, FormRules, Lighting, Shadow};use klad_render::shapes::{self, HatchRules, InkRules, Outline, P, Run, ScatterRules};use serde_json::json;@@ -221,8 +221,8 @@ fn hatch(doc: &Document, spec: &HatchSpec) -> Result<Vec<Op>> {.collect()}-fn linear(hex: &str) -> Result<[f32; 3]> {- Ok(color::to_linear(color::parse_hex(hex)?))+fn linear(doc: &Document, text: &str) -> Result<[f32; 3]> {+ Ok(color::to_linear(color::parse_hex(&doc.resolve_color(text)?)?))}fn form_rules(doc: &Document, spec: &PaintSpec) -> Result<FormRules> {@@ -238,12 +238,19 @@ fn form_rules(doc: &Document, spec: &PaintSpec) -> Result<FormRules> {toward: [spec.light[0], spec.light[1], spec.elevation],},};- let scaled = |hex: &str, k: f32| -> Result<[f32; 3]> { Ok(linear(hex)?.map(|c| c * k)) };+ let scaled = |text: &str, k: f32| -> Result<[f32; 3]> { Ok(linear(doc, text)?.map(|c| c * k)) };+ let shadow = match &spec.shadow {+ Some(text) => Some(Shadow::of(+ color::parse_hex(&doc.resolve_color(text)?)?,+ spec.shadow_mix,+ )),+ None => None,+ };Ok(FormRules {form,light,- colour: linear(&spec.color)?,- key: linear(&spec.key)?,+ colour: linear(doc, &spec.color)?,+ key: linear(doc, &spec.key)?,fill: scaled(&spec.fill, spec.fill_strength)?,bounce: scaled(&spec.bounce, spec.bounce_strength)?,core: spec.core,@@ -253,6 +260,7 @@ fn form_rules(doc: &Document, spec: &PaintSpec) -> Result<FormRules> {vary: spec.vary,seed: spec.seed,spill: doc.layer(&spec.layer).is_some_and(|l| l.clip || l.lock_alpha),+ shadow,})}@@ -324,6 +332,7 @@ fn shapes_change(op: &Op) -> bool {| Op::Remove { .. }| Op::Move { .. }| Op::Path { .. }+ | Op::Palette(_))}@@ -410,6 +419,61 @@ mod tests {std::fs::remove_dir_all(&dir).unwrap();}+ #[test]+ fn paint_takes_palette_names_from_the_same_batch_and_a_shadow_colour_changes_only_the_shadow_side() {+ let (dir, b) = bundle("shadow");+ let painted = |extra: &str| -> Vec<(f32, String)> {+ let ops = parse_lines(&format!(+ r##"{{"op":"palette","add":"#c0603c","name":"clay"}}+{{"op":"palette","add":"#a898d0","name":"lavender"}}+{{"op":"add","node":{{"id":"bowl","type":"ellipse","cx":200,"cy":150,"rx":90,"ry":70}},"in":"l4","frame":0}}+{{"op":"paint","layer":"l1","in":["bowl"],"color":"clay","light":[-1,0]{extra}}}"##+ ))+ .unwrap();+ expand(&b, ops)+ .unwrap()+ .into_iter()+ .filter_map(|o| match o {+ Op::Stroke(s) => {+ let points = s.points.unwrap_or_default();+ let x = points.iter().map(|q| q[0]).sum::<f32>() / points.len().max(1) as f32;+ Some((x, s.color))+ }+ _ => None,+ })+ .collect()+ };+ let plain = painted("");+ let tinted = painted(r#","shadow":"lavender","shadowMix":0.8"#);+ assert_eq!(plain.len(), tinted.len());+ let lit = |strokes: &[(f32, String)]| -> Vec<String> {+ strokes+ .iter()+ .filter(|(x, _)| *x < 150.0)+ .map(|(_, c)| c.clone())+ .collect()+ };+ assert_eq!(lit(&plain), lit(&tinted));+ let blue = |strokes: &[(f32, String)]| {+ let far: Vec<f32> = strokes+ .iter()+ .filter(|(x, _)| *x > 260.0)+ .map(|(_, c)| {+ let [r, _, b, _] = color::parse_hex(c).unwrap();+ b - r+ })+ .collect();+ far.iter().sum::<f32>() / far.len().max(1) as f32+ };+ assert!(+ blue(&tinted) > blue(&plain) + 0.05,+ "{} {}",+ blue(&tinted),+ blue(&plain)+ );+ std::fs::remove_dir_all(&dir).unwrap();+ }+#[test]fn a_lamp_shades_each_shape_on_the_side_away_from_it() {let (dir, b) = bundle("lamp");diff --git a/crates/core/src/ops.rs b/crates/core/src/ops.rsindex a415d23..01aad93 100644--- a/crates/core/src/ops.rs+++ b/crates/core/src/ops.rs@@ -474,6 +474,10 @@ pub struct PaintSpec {pub bounce_strength: f32,#[serde(default = "paint_core")]pub core: f32,+ #[serde(default)]+ pub shadow: Option<String>,+ #[serde(default = "paint_shadow_mix")]+ pub shadow_mix: f32,#[serde(default = "hatch_angle")]pub angle: f32,#[serde(default = "paint_weight")]@@ -642,6 +646,10 @@ fn paint_bounce_strength() -> f32 {0.1}+fn paint_shadow_mix() -> f32 {+ 0.7+}+fn paint_core() -> f32 {0.35}diff --git a/crates/render/src/form.rs b/crates/render/src/form.rsindex d93d8ad..a07be67 100644--- a/crates/render/src/form.rs+++ b/crates/render/src/form.rs@@ -1,4 +1,5 @@use crate::shapes::{P, Run, area};+use klad_core::color;use klad_core::cut::inside_polygon;use klad_core::rng::Rng;@@ -15,6 +16,45 @@ pub enum Lighting {Lamp { at: [f32; 3] },}+#[derive(Clone, Copy, Debug, PartialEq)]+pub struct Shadow {+ pub lab: [f32; 3],+ pub mix: f32,+}++impl Shadow {+ pub fn of(rgba: color::Rgba, mix: f32) -> Self {+ Self {+ lab: color::to_oklab(rgba),+ mix: mix.clamp(0.0, 1.0),+ }+ }++ fn tint(&self, rgb: [f32; 3], lit: f32) -> [f32; 3] {+ let k = self.mix * (1.0 - smooth(-0.1, 0.3, lit));+ if k <= 0.0 {+ return rgb;+ }+ let [l, a, b] = color::to_oklab(color::from_linear(rgb, 1.0));+ let fit = libm::sqrtf((l / self.lab[0].max(1e-3)).min(1.0));+ let (ta, tb) = (self.lab[1] * fit, self.lab[2] * fit);+ let (ma, mb) = (a + (ta - a) * k, b + (tb - b) * k);+ let from = libm::sqrtf(a * a + b * b);+ let to = libm::sqrtf(ta * ta + tb * tb);+ let mixed = libm::sqrtf(ma * ma + mb * mb);+ let keep = match mixed > 1e-4 {+ true => (from + (to - from) * k) / mixed,+ false => 1.0,+ };+ color::to_linear(color::from_oklab([l, ma * keep, mb * keep], 1.0))+ }+}++fn smooth(from: f32, to: f32, x: f32) -> f32 {+ let t = ((x - from) / (to - from)).clamp(0.0, 1.0);+ t * t * (3.0 - 2.0 * t)+}+#[derive(Clone, Copy, Debug)]pub struct FormRules {pub form: Form,@@ -30,6 +70,7 @@ pub struct FormRules {pub vary: f32,pub seed: u32,pub spill: bool,+ pub shadow: Option<Shadow>,}#[derive(Clone, Debug, PartialEq)]@@ -270,7 +311,8 @@ impl<'a> Shape<'a> {};let rgb = [0, 1, 2].map(|c| rules.colour[c] * (rules.key[c] * key + (rules.fill[c] * sky + rules.bounce[c] * ground) * core));- (rgb, facing * falloff)+ let lit = facing * falloff;+ (rules.shadow.map_or(rgb, |s| s.tint(rgb, lit)), lit)}fn band(&self, rules: &FormRules, p: P) -> f32 {@@ -591,6 +633,7 @@ mod tests {vary: 0.03,seed: 4,spill: false,+ shadow: None,}}@@ -691,6 +734,49 @@ mod tests {assert!(hi / lo < 1.25);}+ #[test]+ fn a_shadow_colour_turns_the_shadow_side_towards_its_hue_and_keeps_the_values() {+ let shape = disc(100.0, 100.0, 60.0);+ let plain = FormRules {+ colour: color::to_linear(color::parse_hex("#c0603c").unwrap()),+ ..rules(Lighting::Direction {+ toward: [-1.0, 0.0, 0.5],+ })+ };+ let lavender = color::parse_hex("#a898d0").unwrap();+ let tinted = FormRules {+ shadow: Some(Shadow::of(lavender, 0.8)),+ ..plain+ };+ let at = |r: &FormRules, x: f32| shade_at(std::slice::from_ref(&shape), r, [x, 100.0]).unwrap();+ let lab = |rgb: [f32; 3]| color::to_oklab(color::from_linear(rgb, 1.0));+ let hue = |l: [f32; 3]| libm::atan2f(l[2], l[1]);+ let (lit, facing) = at(&plain, 55.0);+ assert!(facing > 0.3);+ assert_eq!(at(&tinted, 55.0).0, lit);+ let (dark, facing) = at(&plain, 150.0);+ assert!(facing < -0.1);+ let (before, after, target) = (lab(dark), lab(at(&tinted, 150.0).0), color::to_oklab(lavender));+ assert!((before[0] - after[0]).abs() < 0.02, "{before:?} {after:?}");+ let off = |l: [f32; 3]| (hue(l) - hue(target)).abs();+ assert!(off(after) < off(before) * 0.4, "{before:?} {after:?} {target:?}");+ let chroma = |l: [f32; 3]| libm::sqrtf(l[1] * l[1] + l[2] * l[2]);+ assert!(chroma(after) > 0.6 * chroma(before).min(chroma(target)));+ let jump = |r: &FormRules| {+ let steps: Vec<[f32; 3]> = (0..=50).map(|i| lab(at(r, 50.0 + 2.0 * i as f32).0)).collect();+ steps+ .windows(2)+ .map(|w| libm::sqrtf((0..3).map(|c| (w[1][c] - w[0][c]).powi(2)).sum()))+ .fold(0.0f32, f32::max)+ };+ assert!(+ jump(&tinted) < jump(&plain) * 1.5,+ "largest step {} against {}",+ jump(&tinted),+ jump(&plain)+ );+ }+#[test]fn a_cylinder_is_painted_along_its_axis() {let tube = vec![[0.0, 0.0], [40.0, 0.0], [40.0, 160.0], [0.0, 160.0]];diff --git a/docs/DESIGN.md b/docs/DESIGN.mdindex 81c8bce..e071980 100644--- a/docs/DESIGN.md+++ b/docs/DESIGN.md@@ -1,4 +1,4 @@-_Last updated: 2026-11-04 19:35_+_Last updated: 2026-11-04 19:51_# klad: design@@ -375,7 +375,7 @@ An error is one line on stderr (`error: reading a.draw/doc.json: No such file or| `klad ink <bundle> <layer> --from <node>,... \| --path "M..." [--weight 6] [--light x,y] [--break 60] [--gap] [--wobble 0.6] [--taper in,out] [--brush] [--color] [--hand 1]` | ink the outlines of shapes as tapered strokes with weight rules, each drawn like a hand || `klad light <bundle> --from <node>,... [--light x,y] [--shade <layer>] [--rim <layer>] [--depth 14] [--soft 3] [--rim-width 4] [--lamp x,y,h]` | shade and rim fills from one light direction, or per shape away from a lamp || `klad hatch <bundle> <layer> --in <node>,... [--angle 30 \| --along] [--spacing 6] [--length 12-30] [--jitter] [--weight] [--hand 1]` | short tapered strokes inside closed shapes, each drawn like a hand |-| `klad paint <bundle> <layer> --in <node>,... [--color] [--form round\|flat\|cylinder] [--axis 90] [--facing x,y,z] [--light x,y] [--elevation 0.6] [--lamp x,y,h] [--key] [--fill] [--bounce] [--core 0.35] [--weight 14] [--brush oil] [--bold oil-load] [--decisive 1] [--hand 1]` | paints each shape as a form: a height field from its outline (round), a plane or a cylinder, lit by a key light or lamp with fill, bounce and a core; strokes follow bands of equal light, take their colour from the model and stop where the light changes; big to small, then decisive strokes in the lights |+| `klad paint <bundle> <layer> --in <node>,... [--color] [--form round\|flat\|cylinder] [--axis 90] [--facing x,y,z] [--light x,y] [--elevation 0.6] [--lamp x,y,h] [--key] [--fill] [--bounce] [--core 0.35] [--shadow c] [--shadow-mix 0.7] [--weight 14] [--brush oil] [--bold oil-load] [--decisive 1] [--hand 1]` | paints each shape as a form: a height field from its outline (round), a plane or a cylinder, lit by a key light or lamp with fill, bounce and a core; strokes follow bands of equal light, take their colour from the model and stop where the light changes; big to small, then decisive strokes in the lights || `klad prepare <bundle> [--from] [--to]` | replay the painted drawings of a span of frames into the cache || `klad scatter <bundle> <layer> --in <node>,... [--mark "M..."] [--count n \| --spacing 14] [--size 0.7-1.2] [--turn -15,15] [--avoid <node>,...] [--hand 1]` | copies of a small mark inside closed shapes || `klad fill <bundle> <layer> --shape <node> [--expand 2]` | fill exactly a shape's area |diff --git a/docs/skill/SKILL.md b/docs/skill/SKILL.mdindex 0cfc767..5833e5d 100644--- a/docs/skill/SKILL.md+++ b/docs/skill/SKILL.md@@ -193,7 +193,7 @@ klad paint art.draw paint --in pillar --form cylinder --axis 90 --lamp 200,600,1klad prepare art.draw # buffer every drawing before the user opens it```-- Painting a form: after the flats, `klad paint` paints each shape as a form. `--form round` (default) bulges any closed shape like a pillow, its height growing with the distance to the outline; `flat` is a plane facing `--facing x,y,z` (z toward the viewer, y down); `cylinder` is round across `--axis` degrees. The light model is a key light from `--light x,y` at `--elevation` (or `--lamp x,y,height` in canvas px: the shape nearest the lamp gets the full key light, farther ones less by inverse square, so paint a cluster in one op), cool fill from above (`--fill`, `--fill-strength`), warm bounce from below (`--bounce`, `--bounce-strength`) and a darker core just past the terminator (`--core`); `--color` is the local colour in full light, so the lit side comes out at that colour and the shadow side about four value steps under it. Strokes follow the form (along bands of equal light on round forms, along the axis on cylinders, at `--angle` on planes), take their colour from the model where they lie and stop where the light changes, so none carries the lit colour into the shadow. Passes go from twice `--weight` down to half of it (the small ones only where the form turns), then a decisive pass with `--bold` (`oil-load`) in the lights and a few quiet strokes in the shadows (`--decisive 0` skips both); `--vary` lets each stroke stray in value and temperature. Paint on a layer clipped to the flats, or lock the flats layer and paint into it: strokes then run past the outline and short strokes along it cut the edge in; on a plain layer they stay inside it and the flats show at the rim.+- Painting a form: after the flats, `klad paint` paints each shape as a form. `--form round` (default) bulges any closed shape like a pillow, its height growing with the distance to the outline; `flat` is a plane facing `--facing x,y,z` (z toward the viewer, y down); `cylinder` is round across `--axis` degrees. The light model is a key light from `--light x,y` at `--elevation` (or `--lamp x,y,height` in canvas px: the shape nearest the lamp gets the full key light, farther ones less by inverse square, so paint a cluster in one op), cool fill from above (`--fill`, `--fill-strength`), warm bounce from below (`--bounce`, `--bounce-strength`) and a darker core just past the terminator (`--core`); `--color` is the local colour in full light, so the lit side comes out at that colour and the shadow side about four value steps under it. The lights multiply the local colour, so a warm colour goes darker and browner in shadow; `--shadow <colour>` (`"shadow"` in `apply`) turns the side out of the key light towards that colour's hue and chroma while keeping the values the model gives it, by `--shadow-mix` (default 0.7) and less in the halftones, with the chroma lowered in the darkest parts. A cool lavender or blue grey keeps shadows from going brown or grey; raise `--fill-strength` (0.3 or so) for lighter shadow sides. Every colour option of `paint` takes palette names. Strokes follow the form (along bands of equal light on round forms, along the axis on cylinders, at `--angle` on planes), take their colour from the model where they lie and stop where the light changes, so none carries the lit colour into the shadow. Passes go from twice `--weight` down to half of it (the small ones only where the form turns), then a decisive pass with `--bold` (`oil-load`) in the lights and a few quiet strokes in the shadows (`--decisive 0` skips both); `--vary` lets each stroke stray in value and temperature. Paint on a layer clipped to the flats, or lock the flats layer and paint into it: strokes then run past the outline and short strokes along it cut the edge in; on a plain layer they stay inside it and the flats show at the rim.- Every stroke the shape ops make is drawn like a hand (`--hand 1`, the default; `0` gives the old even strokes): its own pressure curve (a press-in, a peak, a longer lift-off), tapers that are a share of its length, a width that varies from stroke to stroke, and a slight bow on hatching and flat planes. Brushes for it: `oil` (soft edge, size and opacity from pressure) for building forms, `oil-load` (harder edge, more grain) for strokes that should stay visible.- `klad light` takes `--lamp x,y,height` too: each shape is shaded away from the lamp instead of one direction for all.- `klad prepare art.draw [--from 0 --to 23]` replays every painted drawing of those frames into the cache after a big CLI change, so the editor opens and plays it without replaying strokes. The editor still makes its frame pictures itself, quickly, from the cached drawings.diff --git a/justfile b/justfileindex 9734fe3..5f5c95b 100644--- a/justfile+++ b/justfile@@ -19,7 +19,7 @@ lint:cargo clippy --workspace --all-targets -- -D warningssamples: build- for s in lantern ink-shapes bounce creature solids; do FORCE=1 bash samples/$s/build.sh >/dev/null && echo "samples/$s/$s.draw"; done+ for s in lantern ink-shapes bounce creature solids lemons; do FORCE=1 bash samples/$s/build.sh >/dev/null && echo "samples/$s/$s.draw"; donenotices:bash licenses/notices.shdiff --git a/samples/README.md b/samples/README.mdindex 32da3db..64fd024 100644--- a/samples/README.md+++ b/samples/README.md@@ -8,6 +8,7 @@ Drawings made from scratch with the `klad` CLI, each from a generator that print| `ink-shapes` | The ink options side by side: weight from the light, breaks, gaps, wobble, tapers || `bounce` | Frame-by-frame timing: keys, holds, a clip and the exports || `creature` | A walk and an idle from keys with named parts, in-betweened, coloured from the first drawing, with arcs checked |+| `lemons` | Painting by form with `klad paint` on locked flats, and a shadow colour: lavender shadows instead of brown ones (`PLAIN=1`: without it) || `solids` | Painting stroke by stroke: a sphere, a cube and a cylinder built in 3D with `docs/skill/drawkit.py`, lit, painted with natural strokes |The generated `.draw` bundles and pictures stay out of git.diff --git a/samples/lemons/build.sh b/samples/lemons/build.shnew file mode 100755index 0000000..93fe217--- /dev/null+++ b/samples/lemons/build.sh@@ -0,0 +1,21 @@+#!/usr/bin/env bash+set -euo pipefail+here="$(cd "$(dirname "$0")" && pwd)"+root="$(cd "$here/../.." && pwd)"+case "$(uname -s)" in+ Darwin) built=target ;;+ Linux) built=target/linux ;;+ *) built=target/windows ;;+esac+klad="${KLAD:-$root/${KLAD_TARGET_DIR:-$built}/release/klad}"+out="${1:-$here/lemons.draw}"+if [ -e "$out" ] && [ "${FORCE:-0}" != 1 ]; then+ echo "$out exists and may hold edits made in the editor; give another path, or FORCE=1 to rebuild it from generate.py" >&2+ exit 1+fi+rm -rf "$out"+"$klad" new "$out" --width 1200 --height 900 --layers 0 >/dev/null+python3 "$here/generate.py" ${PLAIN:+--plain} | "$klad" apply "$out" >/dev/null+"$klad" render "$out" -o "${out%.draw}.png"+"$klad" export "$out" --scale 2 -o "${out%.draw}@2x.png"+"$klad" hash "$out" --no-cachediff --git a/samples/lemons/generate.py b/samples/lemons/generate.pynew file mode 100644index 0000000..862ba60--- /dev/null+++ b/samples/lemons/generate.py@@ -0,0 +1,71 @@+import json+import math+import sys++PLAIN = "--plain" in sys.argv+LIGHT = [-0.7, -0.7]+KEY = "#fff1dc"+SHADOW = "#9d8fc4"+COLOURS = {"wall": "#ece3cf", "table": "#b8a78b", "clay": "#b9603d", "clay inside": "#8f4630", "lemon": "#e6bf34",+ "cast": "#b4a6c4", "contact": "#8d7fa6"}+++def lemon(cx, cy, rx, ry, turn):+ a = math.radians(turn)+ points = []+ for i in range(96):+ t = 2 * math.pi * i / 96+ tip = max(math.exp(-((t % math.pi) ** 2) / 0.06), math.exp(-((t % math.pi - math.pi) ** 2) / 0.06))+ x, y = rx * math.cos(t) * (1 + 0.1 * tip), ry * math.sin(t) * (1 - 0.2 * tip)+ points.append((cx + x * math.cos(a) - y * math.sin(a), cy + x * math.sin(a) + y * math.cos(a)))+ return "M" + " L".join(f"{x:.1f} {y:.1f}" for x, y in points) + " Z"+++SHAPES = {+ "table": {"type": "rect", "x": 0, "y": 560, "w": 1200, "h": 340},+ "inside": {"type": "ellipse", "cx": 560, "cy": 470, "rx": 260, "ry": 70},+ "lemon-a": {"type": "path", "d": lemon(468, 482, 106, 72, -14)},+ "lemon-b": {"type": "path", "d": lemon(652, 474, 100, 70, 18)},+ "bowl": {"type": "path", "d": "M300 470 C 300 604 420 694 560 694 C 700 694 820 604 820 470 "+ "C 820 509 704 540 560 540 C 416 540 300 509 300 470 Z"},+ "lemon-c": {"type": "path", "d": lemon(905, 706, 102, 70, -8)},+}+PAINT = {+ "table": dict(color="table", form="flat", facing=[0, -1, 0.9], angle=2, weight=20, decisive=0.6),+ "inside": dict(color="clay inside", form="flat", facing=[0.35, 0.5, 1], angle=0, weight=12),+ "lemon-a": dict(color="lemon", weight=9),+ "lemon-b": dict(color="lemon", weight=9),+ "bowl": dict(color="clay", weight=14),+ "lemon-c": dict(color="lemon", weight=9),+}+++def layer(name, kind, **extra):+ return {"op": "add", "layer": {"id": f"{name}-layer", "kind": kind, "name": name, **extra}}+++def ops():+ out = [{"op": "palette", "add": c, "name": n} for n, c in COLOURS.items()]+ out += [layer("wall", "vector"), layer("table", "paint"), layer("cast", "vector", blend="multiply")]+ out += [layer(id, "paint") for id in ("inside", "lemon-a", "lemon-b", "bowl")]+ out += [layer("cast-front", "vector", blend="multiply"), layer("lemon-c", "paint"), layer("sketch", "vector", visible=False)]+ wall = {"linear": {"from": [0, 0], "to": [900, 560], "stops": [[0, "#f6efdf"], [1, COLOURS["wall"]]]}}+ out.append({"op": "add", "node": {"type": "rect", "x": 0, "y": 0, "w": 1200, "h": 560, "fill": wall}, "in": "wall-layer"})+ out += [{"op": "add", "node": {"id": id, **shape}, "in": "sketch-layer"} for id, shape in SHAPES.items()]+ for id, settings in PAINT.items():+ out.append({"op": "fill", "layer": f"{id}-layer", "shape": id, "color": settings["color"]})+ out.append({"op": "set", "id": f"{id}-layer", "lockAlpha": True})+ paint = {"op": "paint", "layer": f"{id}-layer", "in": [id], "light": LIGHT, "key": KEY, "fillStrength": 0.32,+ "bounceStrength": 0.16, "seed": len(out), **settings}+ if not PLAIN:+ paint.update(shadow=SHADOW, shadowMix=0.7)+ out.append(paint)+ out.append({"op": "set", "id": f"{id}-layer", "lockAlpha": False})+ shadows = [("cast", 650, 704, 285, 40, COLOURS["cast"], 16), ("cast", 610, 694, 200, 16, COLOURS["contact"], 6),+ ("cast-front", 948, 768, 110, 20, COLOURS["cast"], 10), ("cast-front", 925, 768, 70, 8, COLOURS["contact"], 4)]+ out += [{"op": "add", "node": {"type": "ellipse", "cx": x, "cy": y, "rx": rx, "ry": ry, "fill": c, "blur": b}, "in": f"{l}-layer"}+ for l, x, y, rx, ry, c, b in shadows]+ return out+++print("\n".join(json.dumps(o) for o in ops()))