Skip to content

Claude paints with code: a Claude Code skill for procedural illustration in 83 styles, from ink wash (水墨), watercolour and ukiyo-e to stained glass, Roman mosaic, Art Deco, shadow puppets, pastel UI, sketchbook doodles, spot illustrations, grainy picture books, dreamy hills, sunlit greenery. No image model: numpy + Pillow on a CPU, draw-on GIFs.

Replace watercolour/collage examples with non-zen subjects

cloveric8ff78f6c34cd
diff --git a/README.md b/README.md
index bb8a923..0fe572c 100644
--- a/README.md
+++ b/README.md
@@ -7,15 +7,15 @@
| Ink wash · 水墨 | Watercolour · 水彩 | Paper collage · 剪纸拼贴 |
|---|---|---|
-| ![ink](examples/drawing_bawansiqian.gif) | ![watercolour](examples/drawing_watercolor_lotus.gif) | ![collage](examples/drawing_papercut_moon.gif) |
+| ![ink](examples/drawing_bawansiqian.gif) | ![watercolour](examples/drawing_watercolor_autumn.gif) | ![collage](examples/drawing_papercut_balloons.gif) |
| 八万四千法门 · *Many paths, one summit* | 月印万川 · *One moon in ten thousand rivers* |
|---|---|
| ![bawansiqian](examples/bawansiqian.jpg) | ![moon_river](examples/moon_river.jpg) |
-| **一花一世界** · *A world in a flower* | **小沙弥看月亮** · *The little monk and the moon* |
-| ![lotus](examples/watercolor_lotus.jpg) | ![papercut](examples/papercut_moon.jpg) |
+| **秋日湖畔** · *Autumn Lake* | **热气球小镇** · *Balloon Day* |
+| ![autumn](examples/watercolor_autumn.jpg) | ![balloons](examples/papercut_balloons.jpg) |
-Every mark above is computed: paper fibres, ink washes and mist, dry-brush strokes, pigment granulation and blooms, torn-paper edges, crayon wax and newsprint. No diffusion model, no API, no stock art. It is just Python with **numpy + Pillow** on a CPU: 2–4 s for an ink painting and about 20 s for watercolour or collage, at 1920×1080.
+Every mark above is computed: paper fibres, ink washes and mist, dry-brush strokes, pigment granulation and blooms, torn-paper edges, crayon wax and newsprint. No diffusion model, no API, no stock art. It is just Python with **numpy + Pillow** on a CPU: 2–4 s for an ink painting and 15–30 s for watercolour or collage, at 1920×1080.
---
@@ -136,8 +136,8 @@ pip install -r ~/.claude/skills/claude-drawing/requirements.txt # numpy、Pill
```bash
python3 examples/bawansiqian.py out.png --stages stages/ # 水墨:八万四千法门
python3 examples/moon_river.py out.png # 水墨:月印万川
-python3 examples/watercolor_lotus.py out.png # 水彩:一花一世界
-python3 examples/papercut_moon.py out.png # 剪纸:小沙弥看月亮
+python3 examples/watercolor_autumn.py out.png # 水彩:秋日湖畔
+python3 examples/papercut_balloons.py out.png # 剪纸:热气球小镇
```
### 作画要点(Claude 交图前逐条自查)
diff --git a/SKILL.md b/SKILL.md
index 3de3ef4..f69e0a5 100644
--- a/SKILL.md
+++ b/SKILL.md
@@ -15,8 +15,8 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型
| 画风 | 库 | 范例 | 耗时 |
|---|---|---|---|
| 水墨 | `lib/inkpaint.py` · `Painting` | `examples/bawansiqian.py` 八万四千法门、`examples/moon_river.py` 月印万川 | 2–4 秒 |
-| 水彩 | `lib/watercolor.py` · `Watercolor` | `examples/watercolor_lotus.py` 一花一世界(清晨荷塘) | 约 17 秒 |
-| 剪纸拼贴 | `lib/papercut.py` · `Collage` | `examples/papercut_moon.py` 小沙弥看月亮 | 约 20 秒 |
+| 水彩 | `lib/watercolor.py` · `Watercolor` | `examples/watercolor_autumn.py` 秋日湖畔(秋树罩染、湖面倒影、红色小舟) | 约 15 秒 |
+| 剪纸拼贴 | `lib/papercut.py` · `Collage` | `examples/papercut_balloons.py` 热气球小镇(条纹热气球、笑脸太阳、纸云、小房子) | 约 30 秒 |
三种画风共用 `lib/core.py` 里的底层工具:噪声、模糊、样条曲线、多边形遮罩、有机轮廓 `blob_pts`、毛笔 `bristle_stroke`、中文字体查找。
@@ -59,6 +59,7 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask
- `glaze(mask, 颜色, strength, edge, gran, bloom, variation)`:透明罩染,叠加会像真颜料一样变深、混色
- `gradient_wash(y0, y1, top, bottom)`:湿画渐变天空
- 笔触:`stroke()` 彩色干笔、`line()` 细线勾勒、`lift(mask)` 提白、`splatter()` 甩点
+- `soften(mask)` 任意遮罩水彩化边缘;`blobs([(cx, cy, rx, ry)])` 一组团块合成一片(树冠、灌木、云);`mirror(mask, 水线y)` 水面倒影(带波纹断续)
- `Watercolor.petal_pts(x, y, 角度, 长, 宽)`:花瓣或叶片轮廓;`hexc('#rrggbb')` 转颜色
**剪纸 `Collage`**:
@@ -94,6 +95,8 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask
| 叶子中间一圈深色像靶心 | 第二层深色用湿画(soft 约 16)偏向一侧积色,不要同心 |
| 叶梗画到了叶面上 | 先画梗,用 `*(1 - 叶遮罩)` 限制只在叶外 |
| 颜色发脏 | 同一处罩染不超过三层;亮部留白或用 `lift` 提白 |
+| 深色团块漂到树冠外,成了孤立的圆点 | 后几层罩染乘以第一层树冠遮罩(稍微扩一点),深色只积在冠内 |
+| 树枝乱成一团 | 只画 3–5 根,从树干向上向外伸进树冠,长度按树冠大小算 |
**剪纸拼贴**
@@ -104,6 +107,8 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask
| 画面顶边或左边多出一条阴影 | 阴影偏移不能用会首尾相接的循环平移,要用补零平移(已修) |
| 月亮画了光芒,像太阳 | 月亮用蜡笔光圈加几颗闪光,不要放射线 |
| 脸的五官太粗太凶 | 线宽约 r×0.035,腮红用 `glow` |
+| 小鸟画成了一团 | 小鸟用两道细弧线(线宽约 2.6),不要用很短的粗笔 |
+| 纸片被画面边缘切掉 | 云、气球这类主体要完整留在画面内,留出边距 |
## 四、做成动画
diff --git a/examples/drawing_papercut_balloons.gif b/examples/drawing_papercut_balloons.gif
new file mode 100644
index 0000000..a6cbf4c
Binary files /dev/null and b/examples/drawing_papercut_balloons.gif differ
diff --git a/examples/drawing_papercut_moon.gif b/examples/drawing_papercut_moon.gif
deleted file mode 100644
index 36a2610..0000000
Binary files a/examples/drawing_papercut_moon.gif and /dev/null differ
diff --git a/examples/drawing_watercolor_autumn.gif b/examples/drawing_watercolor_autumn.gif
new file mode 100644
index 0000000..904d7f8
Binary files /dev/null and b/examples/drawing_watercolor_autumn.gif differ
diff --git a/examples/drawing_watercolor_lotus.gif b/examples/drawing_watercolor_lotus.gif
deleted file mode 100644
index 5cd80d5..0000000
Binary files a/examples/drawing_watercolor_lotus.gif and /dev/null differ
diff --git a/examples/papercut_balloons.jpg b/examples/papercut_balloons.jpg
new file mode 100644
index 0000000..a80e916
Binary files /dev/null and b/examples/papercut_balloons.jpg differ
diff --git a/examples/papercut_balloons.py b/examples/papercut_balloons.py
new file mode 100644
index 0000000..5e60694
--- /dev/null
+++ b/examples/papercut_balloons.py
@@ -0,0 +1,116 @@
+"""Example (paper collage): Balloon Day / 热气球小镇 — torn-paper hills with white rims, striped
+hot-air balloons, a notebook-paper cloud and a newsprint cloud, a smiling crayon sun, little houses,
+a waving kid, a paper plane. Pure code, no image model.
+python3 papercut_balloons.py [out.png] [--stages DIR]
+"""
+import os, sys
+sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'lib'))
+import numpy as np
+from papercut import Collage
+from core import spline, fbm1d, polygon_mask
+
+out = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith('--') else 'papercut_balloons.png'
+stages = sys.argv[sys.argv.index('--stages') + 1] if '--stages' in sys.argv else None
+
+c = Collage(1920, 1080, seed=42)
+rng = c.rng
+W, H = c.W, c.H
+
+# ---- sky, sun with crayon rays, clouds of different papers
+c.background('#8cc6e7', texture='paper')
+SX, SY, SR = 250, 200, 92
+for a in np.linspace(0, 2 * np.pi, 12, endpoint=False):
+ c.crayon([(SX + np.cos(a) * (SR + 22), SY + np.sin(a) * (SR + 22)), (SX + np.cos(a) * (SR + 70), SY + np.sin(a) * (SR + 70))], 7, '#f39c34', 0.9)
+c.piece(mask=c.circle_mask(SX, SY, SR), colour='#f7c948', texture='crayon', torn=0.4, rim=0.8, shadow=0.3, angle=0.8)
+c.face(SX, SY + 6, SR * 0.85, mood='smile')
+c.piece(mask=c.cloud_mask(700, 190, 320, 130, puffs=4, seed=5), colour='#fbf8ef', texture='notebook', torn=0.7, rim=0.8, shadow=0.35)
+c.piece(mask=c.cloud_mask(1560, 190, 330, 130, puffs=5, seed=6), colour='#e9e3d6', texture='newsprint', torn=0.7, rim=0.9, shadow=0.35)
+c.piece(mask=c.cloud_mask(1090, 330, 200, 80, puffs=3, seed=7), colour='#fbfbf6', texture='paper', torn=0.6, rim=0.6, shadow=0.3)
+c.stage('sky')
+
+# ---- hills and a little town
+xs = np.linspace(-20, W + 20, 60)
+far = [(x, 700 - 60 * np.sin(x / 300 + 1.0) - 20 * fbm1d(60, 12, 3, 1)[i]) for i, x in enumerate(xs)]
+c.piece(far + [(W + 20, H + 20), (-20, H + 20)], '#a6d47f', texture='paper', torn=0.8, rim=0.9, shadow=0.35)
+mid = [(x, 800 - 80 * np.sin(x / 360 + 2.6) - 20 * fbm1d(60, 12, 3, 2)[i]) for i, x in enumerate(xs)]
+c.piece(mid + [(W + 20, H + 20), (-20, H + 20)], '#6fb56b', texture='paper', torn=0.8, rim=0.9, shadow=0.4)
+
+def house(x, base_y, w, h, body, roof, seed):
+ r = np.random.default_rng(seed)
+ c.piece([(x - w / 2, base_y), (x + w / 2, base_y), (x + w / 2, base_y - h), (x - w / 2, base_y - h)], body, torn=0.2, rim=0.4, shadow=0.35)
+ c.piece([(x - w / 2 - 10, base_y - h + 4), (x + w / 2 + 10, base_y - h + 4), (x, base_y - h - w * 0.55)], roof, torn=0.25, rim=0.5, shadow=0.35)
+ c.piece([(x - 9, base_y), (x + 9, base_y), (x + 9, base_y - 28), (x - 9, base_y - 28)], '#6b4a3a', torn=0.1, rim=0.2, shadow=0.2)
+ for wx in (-w * 0.28, w * 0.28):
+ c.piece([(x + wx - 9, base_y - h * 0.62), (x + wx + 9, base_y - h * 0.62), (x + wx + 9, base_y - h * 0.62 - 18), (x + wx - 9, base_y - h * 0.62 - 18)], '#ffe08a', torn=0.05, rim=0.1, shadow=0.15)
+
+def lolly_tree(x, base_y, r_):
+ c.piece([(x - 6, base_y), (x + 6, base_y), (x + 5, base_y - r_ * 1.5), (x - 5, base_y - r_ * 1.5)], '#7a5236', torn=0.1, rim=0.2, shadow=0.25)
+ c.piece(mask=c.circle_mask(x, base_y - r_ * 1.6, r_), colour='#3f8f55', texture='crayon', torn=0.5, rim=0.7, shadow=0.35, angle=1.2)
+
+mid_y = lambda x: 800 - 80 * np.sin(x / 360 + 2.6)
+for (x, w, h, body, roof) in [(560, 90, 70, '#f6e7c8', '#d9534f'), (680, 70, 58, '#f4b6c2', '#8e5a44'), (1500, 96, 74, '#bfe0f2', '#e07a3c'),
+ (1620, 76, 60, '#f6e7c8', '#b8452f'), (1750, 84, 66, '#ffd9a8', '#5b7fb5')]:
+ house(x, mid_y(x) + 30, w, h, body, roof, int(x))
+for (x, r_) in [(440, 34), (800, 28), (1390, 32), (1860, 30)]:
+ lolly_tree(x, mid_y(x) + 32, r_)
+near = [(x, 930 - 70 * np.exp(-((x - 1300) / 600) ** 2) - 15 * fbm1d(60, 10, 3, 3)[i]) for i, x in enumerate(xs)]
+c.piece(near + [(W + 20, H + 20), (-20, H + 20)], '#3f8f55', texture='paper', torn=0.7, rim=0.9, shadow=0.45)
+for _ in range(50):
+ x = rng.uniform(30, W - 30); y = 930 - 70 * np.exp(-((x - 1300) / 600) ** 2) + rng.uniform(25, 140)
+ for k in range(3):
+ c.crayon([(x + k * 7, y), (x + k * 7 + rng.normal(0, 4), y - rng.uniform(14, 26))], 3.2, '#2c6b3e', 0.9)
+for (x, y) in [(260, 1000), (330, 1020), (1100, 1010), (1640, 1030)]: # a few crayon flowers
+ for a in np.linspace(0, 2 * np.pi, 5, endpoint=False):
+ c.dot(x + np.cos(a) * 9, y + np.sin(a) * 9, 7, '#f7f1e4')
+ c.dot(x, y, 6, '#f7c948')
+c.stage('town')
+
+# ---- hot-air balloons: striped envelope, ropes, kraft basket
+def balloon(cx, cy, r, cols, n_stripes=6, kid=False):
+ neck_y, neck_w = cy + r * 1.35, r * 0.42
+ top = [(cx + r * np.cos(t), cy + r * np.sin(t)) for t in np.linspace(np.pi, 2 * np.pi, 40)]
+ right = spline([(cx + r, cy), (cx + r * 0.86, cy + r * 0.62), (cx + neck_w / 2, neck_y)], 14).tolist()
+ left = spline([(cx - neck_w / 2, neck_y), (cx - r * 0.86, cy + r * 0.62), (cx - r, cy)], 14).tolist()
+ env = polygon_mask(H, W, top + right + left, ss=2)
+ c.piece(mask=env, colour=cols[0], texture='paper', torn=0.25, rim=0.6, shadow=0.4)
+ # stripes follow the envelope's width row by row (like gores on a real balloon)
+ on = env > 0.5
+ left_x = np.where(on.any(1), on.argmax(1), 0).astype(np.float32)
+ right_x = np.where(on.any(1), W - 1 - on[:, ::-1].argmax(1), 0).astype(np.float32)
+ ctr = (left_x + right_x) / 2; hw = np.maximum((right_x - left_x) / 2, 1)
+ u = (c.XX - ctr[:, None]) / hw[:, None]
+ k = np.floor((u + 1) / 2 * n_stripes)
+ stripe = ((k % 2) == 1).astype(np.float32) * env
+ c.piece(mask=stripe, colour=cols[1], texture='paper', torn=0.0, rim=0.0, shadow=0.0)
+ by = neck_y + r * 0.45; bw = r * 0.5
+ for (x0, x1) in [(cx - neck_w / 2, cx - bw / 2), (cx + neck_w / 2, cx + bw / 2)]:
+ c.crayon([(x0, neck_y), (x1, by)], 3, '#5b4636', 0.9)
+ if kid:
+ hx, hy, hr = cx - bw * 0.1, by - r * 0.16, r * 0.17
+ c.crayon([(hx + hr * 0.9, hy + hr * 0.6), (hx + hr * 2.1, hy - hr * 0.9)], 6, '#f3cda6', 1.0) # waving arm
+ c.dot(hx + hr * 2.2, hy - hr * 1.05, hr * 0.32, '#f3cda6')
+ c.piece(mask=c.circle_mask(hx, hy, hr), colour='#f3cda6', torn=0.15, rim=0.4, shadow=0.3)
+ c.piece([(hx - hr, hy - hr * 0.35), (hx + hr, hy - hr * 0.35), (hx + hr * 0.7, hy - hr * 1.15), (hx - hr * 0.7, hy - hr * 1.15)], '#3a2f5c', torn=0.2, rim=0.3, shadow=0.2) # little cap
+ c.face(hx, hy + hr * 0.1, hr * 0.95, mood='dots')
+ c.piece([(cx - bw / 2, by), (cx + bw / 2, by), (cx + bw * 0.42, by + r * 0.34), (cx - bw * 0.42, by + r * 0.34)], '#c8955c', texture='kraft', torn=0.3, rim=0.6, shadow=0.4)
+ for j in range(1, 4):
+ c.crayon([(cx - bw * 0.46, by + r * 0.085 * j), (cx + bw * 0.46, by + r * 0.085 * j)], 2.2, '#8a5d34', 0.8)
+
+balloon(1700, 330, 72, ('#35a7a0', '#f6e7c8'), 6)
+balloon(830, 470, 58, ('#f28aa0', '#fbf8ef'), 6)
+balloon(1250, 360, 165, ('#e4572e', '#f3c13a'), 8, kid=True)
+c.stage('balloons')
+
+# ---- a paper plane with a crayon trail, and birds
+PX, PY = 470, 420
+trail = spline([(90, 560), (200, 500), (300, 520), (400, 450)], 12)
+for i in range(0, len(trail) - 1, 2):
+ c.crayon([tuple(trail[i]), tuple(trail[i + 1])], 3.2, '#ffffff', 0.9)
+c.piece([(PX - 60, PY + 26), (PX + 70, PY - 30), (PX - 20, PY + 4)], '#fbfbf6', torn=0.0, rim=0.0, shadow=0.35)
+c.piece([(PX - 20, PY + 4), (PX + 70, PY - 30), (PX - 30, PY + 40)], '#e6e2d6', torn=0.0, rim=0.0, shadow=0.3)
+for (bx, by, s) in [(975, 150, 1.0), (1045, 182, 0.8), (925, 196, 0.7)]: # crayon birds: two thin arcs
+ c.crayon(spline([(bx - 34 * s, by + 4 * s), (bx - 16 * s, by - 14 * s), (bx, by)], 8), 2.6, '#2f3e5c', 0.95)
+ c.crayon(spline([(bx, by), (bx + 16 * s, by - 14 * s), (bx + 34 * s, by + 4 * s)], 8), 2.6, '#2f3e5c', 0.95)
+
+c.save(out, stages_dir=stages)
+print('saved', out)
diff --git a/examples/papercut_moon.jpg b/examples/papercut_moon.jpg
deleted file mode 100644
index 01d3d0c..0000000
Binary files a/examples/papercut_moon.jpg and /dev/null differ
diff --git a/examples/papercut_moon.py b/examples/papercut_moon.py
deleted file mode 100644
index 0bcc8be..0000000
--- a/examples/papercut_moon.py
+++ /dev/null
@@ -1,87 +0,0 @@
-"""范例(剪纸拼贴):「小沙弥看月亮」— 撕纸毛边、纸片阴影、蜡笔质感、报纸云、笔记本纸条、可爱小人。
-python3 papercut_moon.py [out.png] [--stages DIR]
-"""
-import os, sys
-sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'lib'))
-import numpy as np
-from papercut import Collage
-from core import blob_pts, spline, fbm1d
-
-out = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith('--') else 'papercut_moon.png'
-stages = sys.argv[sys.argv.index('--stages') + 1] if '--stages' in sys.argv else None
-
-c = Collage(1920, 1080, seed=15)
-rng = c.rng
-W, H = c.W, c.H
-
-# ---- night sky in navy crayon, stars
-c.background('#232d66', texture='kraft')
-for _ in range(40):
- c.dot(rng.uniform(30, W - 30), rng.uniform(20, 560), rng.uniform(1.5, 3.2), '#f6e7a8')
-for (x, y, r) in [(260, 150, 22), (880, 110, 16), (1040, 360, 14), (1750, 140, 20), (150, 430, 14), (1650, 480, 12)]:
- c.piece(Collage.star_pts(x, y, r), '#f4cf5e', texture='crayon', torn=0.15, rim=0.3, shadow=0.25)
-c.stage('夜空')
-
-# ---- the moon: soft glow, torn paper disc with a sleepy smile, crayon rays
-MX, MY, MR = 1360, 300, 150
-c.glow(MX, MY, 260, '#f7d98a', 0.18)
-c.piece(mask=c.circle_mask(MX, MY, MR), colour='#f6d77a', texture='crayon', torn=0.5, rim=0.9, shadow=0.35, angle=0.9)
-c.face(MX, MY + 10, MR * 0.85, mood='sleep')
-halo = [(MX + np.cos(a) * (MR + 38 + 6 * np.sin(5 * a)), MY + np.sin(a) * (MR + 38 + 6 * np.sin(5 * a))) for a in np.linspace(-2.2, 2.6, 40)]
-c.crayon(spline(halo, 4), 5, '#f2c94c', 0.75) # a hand-drawn crayon halo, not sun rays
-for a in (-2.6, -0.3, 0.6, 2.9):
- x, y = MX + np.cos(a) * (MR + 90), MY + np.sin(a) * (MR + 90)
- c.crayon([(x - 12, y), (x + 12, y)], 4, '#f6e7a8'); c.crayon([(x, y - 12), (x, y + 12)], 4, '#f6e7a8') # twinkles
-c.stage('月亮')
-
-# ---- a newspaper cloud drifting across
-c.piece(mask=c.cloud_mask(560, 250, 380, 170, puffs=5, seed=3), colour='#e9e3d6', texture='newsprint', torn=0.7, rim=0.9, shadow=0.35)
-c.stage('报纸云')
-
-# ---- torn-paper hills, far to near
-xs = np.linspace(-20, W + 20, 60)
-far = [(x, 640 - 70 * np.sin(x / 260 + 0.5) - 30 * fbm1d(60, 12, 3, 1)[i]) for i, x in enumerate(xs)]
-c.piece(far + [(W + 20, H + 20), (-20, H + 20)], '#3b3f86', texture='paper', torn=0.8, rim=0.9, shadow=0.4)
-mid = [(x, 760 - 90 * np.sin(x / 330 + 2.2) - 25 * fbm1d(60, 12, 3, 2)[i]) for i, x in enumerate(xs)]
-c.piece(mid + [(W + 20, H + 20), (-20, H + 20)], '#2e6275', texture='paper', torn=0.8, rim=0.9, shadow=0.4)
-# a little pagoda with a lit window on the middle hill
-PX, PY = 1560, 700
-for k, (wid, hgt) in enumerate([(120, 26), (96, 24), (72, 22)]):
- y = PY - k * 58
- c.piece([(PX - 30 + k * 4, y), (PX + 30 - k * 4, y), (PX + 30 - k * 4, y - 34), (PX - 30 + k * 4, y - 34)], '#6b3b36', torn=0.2, rim=0.3, shadow=0.3)
- c.piece([(PX - wid / 2, y - 30), (PX + wid / 2, y - 30), (PX + wid * 0.28, y - 30 - hgt), (PX - wid * 0.28, y - 30 - hgt)], '#3a2433', torn=0.25, rim=0.4, shadow=0.3)
-c.dot(PX, PY - 16, 9, '#ffd66b'); c.glow(PX, PY - 16, 28, '#ffd66b', 0.35)
-c.crayon([(PX, PY - 180), (PX, PY - 206)], 5, '#3a2433')
-near = [(x, 880 - 120 * np.exp(-((x - 620) / 520) ** 2) - 20 * fbm1d(60, 10, 3, 3)[i]) for i, x in enumerate(xs)]
-c.piece(near + [(W + 20, H + 20), (-20, H + 20)], '#4f8a4f', texture='paper', torn=0.7, rim=0.9, shadow=0.45)
-for _ in range(60): # crayon grass tufts
- x = rng.uniform(40, W - 40); y = 880 - 120 * np.exp(-((x - 620) / 520) ** 2) + rng.uniform(20, 170)
- for k in range(3):
- c.crayon([(x + k * 7, y), (x + k * 7 + rng.normal(0, 4), y - rng.uniform(14, 28))], 3.2, '#2f6a3a', 0.9)
-c.stage('山丘')
-
-# ---- a small monk sitting on the hill, looking up at the moon
-BX, BY = 640, 770
-robe = spline([(BX - 95, BY + 70), (BX - 80, BY - 10), (BX - 40, BY - 55), (BX + 40, BY - 55), (BX + 80, BY - 10), (BX + 95, BY + 70)], 10)
-c.piece(np.vstack([robe, [(BX + 95, BY + 78), (BX - 95, BY + 78)]]), '#e0873b', texture='paper', torn=0.35, rim=0.6, shadow=0.45)
-c.piece([(BX - 45, BY - 50), (BX - 10, BY - 50), (BX + 70, BY + 60), (BX + 35, BY + 66)], '#b8512e', texture='paper', torn=0.3, rim=0.5, shadow=0.3)
-c.piece(mask=c.circle_mask(BX + 30, BY + 20, 20), colour='#f3cda6', torn=0.2, rim=0.4, shadow=0.3) # hands in lap
-c.piece(mask=c.circle_mask(BX, BY - 110, 62), colour='#f3cda6', texture='paper', torn=0.3, rim=0.7, shadow=0.4)
-for sx in (-1, 1):
- c.piece(mask=c.circle_mask(BX + sx * 60, BY - 106, 13), colour='#eebf95', torn=0.15, rim=0.3, shadow=0.2)
-c.face(BX + 6, BY - 118, 56, mood='smile')
-for (dx, dy) in [(-20, -150), (0, -156), (20, -150)]: # three dots on the shaved head
- c.dot(BX + dx, BY + dy, 3.5, '#c98e6d')
-c.stage('小沙弥')
-
-# ---- a torn notebook scrap with a note, and fireflies
-note = [(1440, 820), (1780, 800), (1790, 960), (1452, 985)]
-c.piece(note, '#fbf8ef', texture='notebook', torn=0.6, rim=0.5, shadow=0.45)
-c.text('心中有月', 1490, 850, 64, '#3a5fa8')
-c.crayon(spline([(1500, 940), (1600, 952), (1720, 930)], 8), 4, '#d9534f', 0.85)
-for _ in range(14):
- x, y = rng.uniform(200, 1400), rng.uniform(640, 1000)
- c.glow(x, y, 16, '#fff0a0', 0.45); c.dot(x, y, 3, '#fff6c0')
-
-c.save(out, stages_dir=stages)
-print('saved', out)
diff --git a/examples/watercolor_autumn.jpg b/examples/watercolor_autumn.jpg
new file mode 100644
index 0000000..0f88049
Binary files /dev/null and b/examples/watercolor_autumn.jpg differ
diff --git a/examples/watercolor_autumn.py b/examples/watercolor_autumn.py
new file mode 100644
index 0000000..9701c2c
--- /dev/null
+++ b/examples/watercolor_autumn.py
@@ -0,0 +1,102 @@
+"""Example (watercolour): Autumn Lake / 秋日湖畔 — wet-in-wet sky, glazed foliage with blooms,
+mirrored reflections, lifted ripples, a red canoe. Pure code, no image model.
+python3 watercolor_autumn.py [out.png] [--stages DIR]
+"""
+import os, sys
+sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'lib'))
+import numpy as np
+from watercolor import Watercolor, hexc
+from core import blob_pts, spline, curve
+
+out = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith('--') else 'watercolor_autumn.png'
+stages = sys.argv[sys.argv.index('--stages') + 1] if '--stages' in sys.argv else None
+
+p = Watercolor(1920, 1080, seed=1017)
+p.paper()
+p.stage('paper')
+rng = p.rng
+Y0 = 640 # waterline
+
+# ---- sky and distant hills (wet-in-wet)
+p.gradient_wash(0, Y0, top=hexc('#94b6d6'), bottom=hexc('#f6e2c2'), strength=0.5, soft_bottom=30)
+hills = [(0, Y0 + 5)] + [(x, 560 - 55 * np.sin(x / 240 + 0.8) - 30 * np.sin(x / 95) - rng.uniform(0, 12)) for x in np.linspace(0, 1920, 44)] + [(1920, Y0 + 5)]
+p.glaze(p.shape(hills, soft=12, ragged=0.35), hexc('#8d95b6'), 0.42, edge=0.25, gran=0.45)
+far_trees = p.blobs([(x, Y0 - rng.uniform(12, 30), rng.uniform(26, 48), rng.uniform(18, 34)) for x in np.linspace(560, 1360, 22)], rough=0.3, soft=5)
+p.glaze(far_trees * (p.YY < Y0 + 2) * np.clip((Y0 + 2 - p.YY) / 40, 0.45, 1), hexc('#b39a58'), 0.38, edge=0.35, gran=0.45)
+p.stage('sky')
+
+# ---- the lake: sky colour near the horizon deepening toward us
+water = np.clip((p.YY - Y0) / 3, 0, 1)
+p.glaze(water * np.clip(0.35 + (p.YY - Y0) / 520, 0, 1), hexc('#6e9db0'), 0.6, edge=0.05, gran=0.35, variation=0.3)
+p.glaze(p.mirror(p.shape(hills, soft=12, ragged=0.35), Y0, soft=6, breakup=0.3), hexc('#8d95b6'), 0.25, edge=0.1)
+p.stage('lake')
+
+# ---- trees: trunks, then three glazes (yellow -> orange -> red), each with blooms
+def tree(tx, ty, root_y, spread, colours, seed):
+ r = np.random.default_rng(seed)
+ sx, sy = spread
+ trunk_w = max(7, sx * 0.07)
+ p.stroke(curve((tx + r.normal(0, 6), root_y), (tx, ty + sy * 0.15), r.normal(0, sx * 0.08), 20, wig=4, seed=seed), trunk_w, hexc('#6b4a32'), 0.85, dry=0.3, taper=(0.02, 0.55))
+ for k in range(4): # a few branches reaching up and out into the crown
+ side = -1 if k % 2 == 0 else 1
+ by = ty + sy * r.uniform(0.2, 0.6)
+ ex, ey = tx + side * sx * r.uniform(0.35, 0.65), by - sy * r.uniform(0.35, 0.7)
+ p.stroke(curve((tx, by), (ex, ey), side * sx * 0.06, 12), trunk_w * 0.4, hexc('#6b4a32'), 0.7, dry=0.35, taper=(0.05, 0.7))
+ masks = []; base = None
+ for i, (col, frac, strength) in enumerate(colours):
+ items = []
+ for _ in range(int(22 * frac) + 6):
+ ang = r.uniform(0, 2 * np.pi); rad = r.uniform(0, 1) ** 0.7
+ ox, oy = np.cos(ang) * sx * rad, np.sin(ang) * sy * rad
+ if i > 0: ox += sx * 0.12 * i; oy += sy * 0.15 * i # later glazes pool lower-right (shadow side)
+ items.append((tx + ox, ty + oy, sx * r.uniform(0.2, 0.34) * (1 - 0.2 * i), sy * r.uniform(0.2, 0.34) * (1 - 0.2 * i)))
+ m = p.blobs(items, rough=0.35, soft=4, ragged=0.45)
+ if base is None: base = m
+ else: m = m * np.clip(base * 1.3, 0, 1) # darker glazes stay inside the crown
+ p.glaze(m, hexc(col), strength, edge=0.5, gran=0.45, bloom=2 if i == 0 else 1)
+ masks.append((m, col))
+ return masks
+
+refl = []
+refl += tree(360, 330, Y0 + 20, (230, 170), [('#f1c34a', 1.0, 0.75), ('#e48a38', 0.6, 0.6), ('#c64a31', 0.3, 0.5)], 1)
+refl += tree(1590, 360, Y0 + 20, (210, 160), [('#f0a93f', 1.0, 0.75), ('#d9642f', 0.7, 0.6), ('#a83a2c', 0.35, 0.55)], 2)
+refl += tree(1230, 500, Y0 + 12, (110, 80), [('#eecb5a', 1.0, 0.7), ('#e0943c', 0.5, 0.55)], 3)
+refl += tree(820, 540, Y0 + 8, (70, 55), [('#d9b25a', 1.0, 0.6), ('#b7773a', 0.5, 0.5)], 4)
+p.stage('trees')
+
+# ---- reflections of the foliage, then lifted ripple lines
+for (m, col) in refl:
+ p.glaze(p.mirror(m * (p.YY < Y0), Y0, soft=9, breakup=0.55), hexc(col), 0.35, edge=0.1, gran=0.3)
+rip = np.zeros((p.H, p.W), np.float32)
+for _ in range(34):
+ y = rng.uniform(Y0 + 15, 1060); x = rng.uniform(-50, 1800); ln = rng.uniform(120, 420)
+ rip = np.maximum(rip, p.band([(x, y), (x + ln, y + rng.normal(0, 1.5))], rng.uniform(2, 4), soft=1.2))
+p.lift(rip, 0.5)
+p.stage('reflections')
+
+# ---- a red canoe with a paddler, and its reflection
+CX, CY = 1010, 770
+hull = spline([(CX - 130, CY - 14), (CX - 70, CY + 14), (CX + 70, CY + 14), (CX + 135, CY - 16), (CX + 60, CY - 6), (CX - 60, CY - 6), (CX - 130, CY - 14)], 10)
+hm = p.shape(hull, soft=1.2, ragged=0.1)
+p.glaze(hm, hexc('#b8382c'), 0.95, edge=0.5, gran=0.2)
+p.stroke(spline([(CX - 8, CY - 6), (CX - 4, CY - 38)], 6), 16, hexc('#2f4a6b'), 0.9, dry=0.2, taper=(0.1, 0.2)) # paddler
+p.glaze(p.shape(blob_pts(CX - 3, CY - 48, 11, 12, rough=0.05, seed=9), soft=1), hexc('#e8b48f'), 0.9, edge=0.3)
+p.stroke(spline([(CX - 34, CY - 52), (CX + 14, CY - 20), (CX + 52, CY + 16)], 8), 3.2, hexc('#6b4a32'), 0.85, dry=0.2) # paddle
+p.glaze(p.mirror(hm, CY + 10, soft=5, breakup=0.5), hexc('#b8382c'), 0.35, edge=0.1)
+p.stage('canoe')
+
+# ---- foreground bank with dry-brush grass, falling leaves
+bank = [(0, 1080), (0, 930), (220, 905), (520, 950), (760, 1020), (820, 1080)]
+p.glaze(p.shape(bank, soft=4, ragged=0.35), hexc('#8e8a45'), 0.7, edge=0.5, gran=0.5, bloom=1)
+for _ in range(70):
+ x = rng.uniform(0, 780); y = rng.uniform(930, 1075)
+ if y < 905 + (x / 780) * 120: continue
+ p.stroke([(x, y), (x + rng.normal(4, 8), y - rng.uniform(25, 60))], rng.uniform(2, 3.5), hexc('#5d6a32'), 0.7, dry=0.5, taper=(0.05, 0.8))
+for _ in range(18):
+ x, y = rng.uniform(250, 1750), rng.uniform(120, 620)
+ lm = p.shape(Watercolor.petal_pts(x, y, rng.uniform(0, 6.28), rng.uniform(16, 26), rng.uniform(6, 9)), soft=1, ragged=0.1)
+ p.glaze(lm, hexc(rng.choice(['#e48a38', '#c64a31', '#f1c34a'])), 0.8, edge=0.5)
+p.splatter(hexc('#d9642f'), 26, box=(120, 150, 1800, 700), size=(1.5, 4), strength=0.55)
+
+p.save(out, stages_dir=stages)
+print('saved', out)
diff --git a/examples/watercolor_lotus.jpg b/examples/watercolor_lotus.jpg
deleted file mode 100644
index ab2dffd..0000000
Binary files a/examples/watercolor_lotus.jpg and /dev/null differ
diff --git a/examples/watercolor_lotus.py b/examples/watercolor_lotus.py
deleted file mode 100644
index 475c8f9..0000000
--- a/examples/watercolor_lotus.py
+++ /dev/null
@@ -1,98 +0,0 @@
-"""范例(水彩):「一花一世界」— 清晨荷塘。纯代码水彩:湿画天空、罩染荷叶、水痕边、颗粒、水渍花、提白叶脉。
-python3 watercolor_lotus.py [out.png] [--stages DIR]
-"""
-import os, sys
-sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'lib'))
-import numpy as np
-from watercolor import Watercolor, hexc
-from core import blob_pts, spline, curve
-
-out = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith('--') else 'watercolor_lotus.png'
-stages = sys.argv[sys.argv.index('--stages') + 1] if '--stages' in sys.argv else None
-
-p = Watercolor(1920, 1080, seed=108)
-p.paper()
-p.stage('纸')
-rng = p.rng
-
-# ---- sky: wet-in-wet from cool blue to dawn peach
-p.gradient_wash(0, 520, top=hexc('#8fb0cf'), bottom=hexc('#f2cfae'), strength=0.55)
-# ---- far bank: soft blue-grey trees melting into the sky
-far = [(0, 560)] + [(x, 520 - 40 * np.sin(x / 190) - 25 * np.sin(x / 67 + 1) - rng.uniform(0, 18)) for x in np.linspace(0, 1920, 40)] + [(1920, 560)]
-p.glaze(p.shape(far, soft=14, ragged=0.35), hexc('#7d93a8'), 0.5, edge=0.25, gran=0.4)
-p.stage('天空')
-
-# ---- water: pale teal, darker toward the viewer, with horizontal dry-brush streaks
-water = [(0, 545), (1920, 545), (1920, 1080), (0, 1080)]
-wm = p.shape(water, soft=6, ragged=0.1) * np.clip((p.YY - 545) / 500, 0.35, 1)
-p.glaze(wm, hexc('#9cc3bf'), 0.55, edge=0.1, gran=0.45, variation=0.35)
-for _ in range(26):
- y = rng.uniform(580, 1060); x = rng.uniform(-100, 1700); ln = rng.uniform(200, 520)
- p.stroke(spline([(x, y), (x + ln / 2, y + rng.normal(0, 2)), (x + ln, y)], 10), rng.uniform(3, 7), hexc('#5f8f93'), 0.35, dry=0.7)
-p.stage('水面')
-
-# ---- lotus leaves (back to front): base glaze, darker second glaze, bloom, lifted veins, stem
-def leaf(cx, cy, rx, ry, rot, dark=0.55, hue='#a9c46b'):
- pts = blob_pts(cx, cy, rx, ry, rough=0.11, n=140, seed=int(cx), rot=rot)
- m = p.shape(pts, soft=2.5, ragged=0.22)
- # stem first, visible only below the leaf
- vx0, vy0 = cx + rx * 0.08, cy - ry * 0.05
- p.glaze(p.band([(vx0, cy + ry * 0.6), (vx0 - 6, cy + ry + 60)], 7, soft=2) * (1 - m), hexc('#6f8a4a'), 0.4, edge=0.2)
- p.glaze(m, hexc(hue), 0.75, edge=0.55, gran=0.35)
- # shadow glaze pooled on one side (wet-in-wet, soft), not a centred ring
- side = p.shape(blob_pts(cx - rx * 0.28, cy + ry * 0.18, rx * 0.72, ry * 0.7, rough=0.2, n=100, seed=int(cy), rot=rot), soft=16, ragged=0.45)
- p.glaze(side * m, hexc('#4a7a45'), dark, edge=0.25, gran=0.45, bloom=1)
- vx, vy = cx + rx * 0.08, cy - ry * 0.05
- veins = np.zeros((p.H, p.W), np.float32)
- for a in np.linspace(0, 2 * np.pi, 13, endpoint=False):
- ex, ey = vx + np.cos(a + rot) * rx * 0.9, vy + np.sin(a + rot) * ry * 0.9
- veins = np.maximum(veins, p.band(spline([(vx, vy), ((vx + ex) / 2 + rng.normal(0, 5), (vy + ey) / 2), (ex, ey)], 8), 3, soft=1.2))
- p.lift(veins * m, 0.32)
-
-for (cx, cy, rx, ry, rot, dk, hue) in [(300, 640, 170, 55, -0.05, 0.45, '#b3c877'), (1560, 620, 150, 48, 0.08, 0.45, '#a3c27a'),
- (980, 700, 200, 70, 0.04, 0.5, '#9fc06a'), (1750, 820, 230, 90, -0.1, 0.55, '#8fb873'),
- (160, 900, 260, 110, 0.12, 0.6, '#a9c46b'), (620, 960, 240, 95, -0.06, 0.6, '#98bd6e')]:
- leaf(cx, cy, rx, ry, rot, dk, hue)
-p.stage('荷叶')
-
-# ---- lotus flowers: stems, petals (pink with deeper tips), seed pod
-def flower(bx, by, scale=1.0, open_=True):
- p.glaze(p.band(spline([(bx, by + 20), (bx + 8, by + 180), (bx + 2, by + 330)], 10), 9 * scale, soft=2), hexc('#7a9650'), 0.7, edge=0.4)
- angles = np.linspace(-150, -30, 7) if open_ else np.linspace(-110, -70, 3)
- for k, a in enumerate(angles):
- ang = np.radians(a + rng.normal(0, 4))
- L = (150 if open_ else 175) * scale * (0.85 + 0.3 * np.sin(np.pi * k / max(1, len(angles) - 1)))
- Wd = (46 if open_ else 42) * scale
- pts = Watercolor.petal_pts(bx, by, ang, L, Wd, curl=rng.normal(0, 0.05))
- m = p.shape(pts, soft=2, ragged=0.15)
- p.glaze(m, hexc('#f0a3b3'), 0.55, edge=0.6, gran=0.25)
- tip = Watercolor.petal_pts(bx + np.cos(ang) * L * 0.45, by + np.sin(ang) * L * 0.45, ang, L * 0.55, Wd * 0.75)
- p.glaze(p.shape(tip, soft=7, ragged=0.3) * m, hexc('#c94f73'), 0.55, edge=0.3)
- p.line(spline([(bx, by), (bx + np.cos(ang) * L * 0.9, by + np.sin(ang) * L * 0.9)], 6), 1.0, hexc('#b0506a'), 0.25)
- if open_:
- pod = p.shape(blob_pts(bx, by - 30 * scale, 34 * scale, 18 * scale, rough=0.05, seed=int(bx)), soft=2)
- p.glaze(pod, hexc('#e3bf4d'), 0.8, edge=0.6, gran=0.3)
- for _ in range(7):
- p.splatter(hexc('#9a7a2a'), 1, box=(bx - 22 * scale, by - 40 * scale, bx + 22 * scale, by - 24 * scale), size=(2, 3.5), strength=0.8)
- # soft reflection in the water
- ref = p.shape([(bx - 40 * scale, by + 340), (bx + 40 * scale, by + 340), (bx + 20, by + 470), (bx - 20, by + 470)], soft=20, ragged=0.4)
- p.glaze(ref * (p.YY > 545), hexc('#e7a3b2'), 0.25, edge=0.1)
-
-flower(1150, 430, 1.05, True)
-flower(560, 470, 0.85, False)
-p.stage('荷花')
-
-# ---- a dragonfly and a few flicked droplets
-dx, dy = 1450, 300
-p.line(spline([(dx - 70, dy + 10), (dx, dy), (dx + 30, dy - 4)], 8), 3.2, hexc('#4b3b36'), 0.8)
-for (a, L) in [(-100, 95), (-70, 88), (100, 90), (70, 84)]:
- ang = np.radians(a)
- wp = Watercolor.petal_pts(dx - 8, dy, ang, L, 16)
- p.glaze(p.shape(wp, soft=1.5, ragged=0.1), hexc('#b9d4e6'), 0.35, edge=0.7, gran=0.1)
-p.splatter(hexc('#6f9a5b'), 30, box=(0, 560, 1920, 1080), size=(1.5, 4.5), strength=0.5)
-p.splatter(hexc('#e38fa6'), 14, box=(900, 250, 1400, 700), size=(1.2, 3.5), strength=0.45)
-
-p.title_vertical('一花一世界', 150, 140, 80)
-p.seal('清净', 250, 160, 34)
-p.save(out, stages_dir=stages)
-print('saved', out)
diff --git a/lib/watercolor.py b/lib/watercolor.py
index b7b71fa..01f4924 100644
--- a/lib/watercolor.py
+++ b/lib/watercolor.py
@@ -55,12 +55,31 @@ class Watercolor:
# ------------------------------------------------------------ masks
def shape(self, pts, soft=2.0, ragged=0.18, seed=None):
"""closed outline -> soft, slightly ragged mask (0..1). soft ~1-4 crisp wet edge; 15-40 wet-in-wet feather"""
- m = polygon_mask(self.H, self.W, pts, ss=2)
- if soft > 0:
- m = blur(m, soft)
- n = self.noise(max(6, soft * 3), 3, seed)
- m = smoothstep(0.5 - 0.25, 0.5 + 0.25, m + (n - 0.5) * ragged)
- return m
+ return self.soften(polygon_mask(self.H, self.W, pts, ss=2), soft, ragged, seed)
+
+ def soften(self, m, soft=2.0, ragged=0.18, seed=None):
+ """give any hard mask a watercolour edge"""
+ if soft <= 0: return m
+ m = blur(m, soft)
+ n = self.noise(max(6, soft * 3), 3, seed)
+ return smoothstep(0.5 - 0.25, 0.5 + 0.25, m + (n - 0.5) * ragged)
+
+ def blobs(self, items, rough=0.22, soft=3.0, ragged=0.3):
+ """union of organic blobs [(cx, cy, rx, ry), ...] -> one soft mask (foliage clusters, clouds, bushes)"""
+ m = np.zeros((self.H, self.W), np.float32)
+ for (cx, cy, rx, ry) in items:
+ m = np.maximum(m, polygon_mask(self.H, self.W, blob_pts(cx, cy, rx, ry, rough=rough, n=70, seed=self._seed())))
+ return self.soften(m, soft, ragged)
+
+ def mirror(self, m, y0, soft=8, squash=1.0, breakup=0.5):
+ """water reflection of mask `m` about the waterline y0 (softened, broken by horizontal ripples)"""
+ ys = np.arange(self.H)
+ src = np.clip((2 * y0 - ys) if squash == 1.0 else (y0 - (ys - y0) / squash), 0, self.H - 1).astype(int)
+ r = m[src, :] * (ys[:, None] > y0)
+ r = blur(r, soft)
+ rip = noise2d(self.H, self.W, 4, 2, self._seed())
+ rip = np.asarray(Image.fromarray(rip, mode='F').resize((self.W // 40, self.H), Image.BILINEAR).resize((self.W, self.H), Image.BILINEAR))
+ return r * (1 - breakup + breakup * smoothstep(0.3, 0.7, rip))
def band(self, pts, width, soft=2.0):
"""a thick soft stroke (stems, reeds, rivers) as a mask"""