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.

Add overlay sheets style (60 total): tracing-paper separations on a light box

cloveric31fa1aa55c53
diff --git a/README.md b/README.md
index 1f44e98..6abacc1 100644
--- a/README.md
+++ b/README.md
@@ -1,54 +1,54 @@
# Claude Drawing · Claude 绘图
-**Claude paints with code — no image model.** Fifty-nine styles, from ink wash and impasto oil to clay, cyanotype, stained glass, a Roman mosaic, Delft tiles, a cyberpunk street, a ray-traced ball pit, low-poly 3D, a thermal camera, an X-ray, a VHS tape and a synthwave sunset.
-**不用生图模型,Claude 用代码一笔一笔作画。** 五十九种画风,从水墨、油画到黏土、蓝晒、彩色玻璃花窗、罗马马赛克、代尔夫特蓝瓷砖、赛博朋克、光线追踪的小球海、低多边形 3D、热成像、X 光片、VHS 录像带和 Synthwave 落日。
+**Claude paints with code — no image model.** Sixty styles, from ink wash and impasto oil to clay, cyanotype, stained glass, a Roman mosaic, Delft tiles, a cyberpunk street, a ray-traced ball pit, low-poly 3D, a thermal camera, an X-ray, a VHS tape and a synthwave sunset.
+**不用生图模型,Claude 用代码一笔一笔作画。** 六十种画风,从水墨、油画到黏土、蓝晒、彩色玻璃花窗、罗马马赛克、代尔夫特蓝瓷砖、赛博朋克、光线追踪的小球海、低多边形 3D、热成像、X 光片、VHS 录像带和 Synthwave 落日。
[English](#english) · [中文](#中文)
<p align="center"><img src="examples/drawing_bawansiqian.gif" width="100%"><br><sub><b>Ink wash · 水墨</b> — every style below is drawn stage by stage like this (the storybook one is a real character animation) · 下面每种画风都是这样一步步画出来的(绘本角色动画是一段真正的角色动画)</sub></p>
-| Ink wash · 水墨(月印万川) | Watercolour · 水彩 | Watercolour washes · 水彩底纹 |
+| Ink wash · 水墨(月印万川) | Watercolour · 水彩 | Paper collage · 剪纸拼贴 |
|---|---|---|
-| ![moonriver](examples/drawing_moon_river.gif) | ![watercolour](examples/drawing_watercolor_autumn.gif) | ![washes](examples/drawing_watercolor_washes.gif) |
-| **Paper collage · 剪纸拼贴** | **Coloured pencil · 韩国彩铅** | **Anime · 日本动漫** |
-| ![collage](examples/drawing_papercut_balloons.gif) | ![pencil](examples/drawing_colorpencil_dessert.gif) | ![anime](examples/drawing_anime_summer.gif) |
-| **Editorial · 编辑风手绘** | **Impasto oil · 油画厚涂** | **Ukiyo-e · 浮世绘木版画** |
-| ![editorial](examples/drawing_editorial_ideas.gif) | ![oil](examples/drawing_oil_wheatfield.gif) | ![ukiyoe](examples/drawing_ukiyoe_fuji.gif) |
-| **Pixel art · 像素风** | **Stop-motion clay · 黏土定格** | **Cyanotype · 蓝晒** |
-| ![pixel](examples/drawing_pixel_rainy_cafe.gif) | ![clay](examples/drawing_clay_lighthouse.gif) | ![cyanotype](examples/drawing_cyanotype_botanicals.gif) |
-| **Cross-stitch · 十字绣** | **Retro panel · 复古仪器面板** | **Sticker collage × receipt · 贴纸拼贴 · 小票** |
-| ![stitch](examples/drawing_stitch_sampler.gif) | ![panel](examples/drawing_panel_radio.gif) | ![sticker](examples/drawing_sticker_market.gif) |
-| **Lab notebook × stickers · 实验笔记本 · 贴纸** | **Chalkboard · 黑板板书** | **Cyberpunk · 赛博朋克** |
-| ![notebook](examples/drawing_notebook_brewing.gif) | ![chalk](examples/drawing_chalk_lesson.gif) | ![cyberpunk](examples/drawing_cyberpunk_neon_street.gif) |
-| **Hand-drawn cartoon · 卡通手绘** | **Continuous line art · 单线画** | **Soft 3D · 柔光 3D** |
-| ![cartoon](examples/drawing_cartoon_toaster.gif) | ![lineart](examples/drawing_lineart_paper_plane.gif) | ![soft3d](examples/drawing_soft3d_rise.gif) |
-| **Shape morph · 形变动画** | **Newspaper collage · 报刊拼贴** | **Aurora glass · 弥散玻璃** |
-| ![morph](examples/drawing_morph_water_cycle.gif) | ![newscollage](examples/drawing_newscollage_curiosity.gif) | ![aurora](examples/drawing_aurora_morning.gif) |
-| **Bauhaus geometric · 包豪斯几何** | **Retro synthwave · 复古 Synthwave** | **Isometric 2.5D · 等轴 2.5D** |
-| ![bauhaus](examples/drawing_bauhaus_form_colour.gif) | ![synthwave](examples/drawing_synthwave_coastline.gif) | ![isometric](examples/drawing_isometric_weather_island.gif) |
-| **Perler beads · 拼豆** | **Petroglyph · 岩画** | **Egyptian tomb painting · 古埃及墓室壁画** |
-| ![perler](examples/drawing_perler_strawberry_coaster.gif) | ![petroglyph](examples/drawing_petroglyph_migration.gif) | ![tomb](examples/drawing_tomb_harvest.gif) |
-| **Roman mosaic · 罗马马赛克** | **Stained glass · 彩色玻璃花窗** | **Illuminated manuscript · 泥金手抄本** |
-| ![mosaic](examples/drawing_mosaic_harbor.gif) | ![stainedglass](examples/drawing_stainedglass_seasons.gif) | ![illuminated](examples/drawing_illuminated_starchart.gif) |
-| **Leonardo codex · 达·芬奇手稿** | **Silhouette · 剪影** | **Letterpress poster · 凸版印刷海报** |
-| ![codex](examples/drawing_codex_ornithopter.gif) | ![silhouette](examples/drawing_silhouette_family.gif) | ![letterpress](examples/drawing_letterpress_circus.gif) |
-| **Soviet constructivism · 苏联构成主义** | **Art Deco · 装饰艺术** | **Golden-age comic · 黄金时代漫画** |
-| ![constructivism](examples/drawing_constructivism_radio.gif) | ![artdeco](examples/drawing_artdeco_express.gif) | ![comic](examples/drawing_comic_rocket.gif) |
-| **Pop silkscreen · 波普丝网** | **ASCII art (line printer) · ASCII 字符画** | **Low poly · 低多边形** |
-| ![popart](examples/drawing_popart_cat_moods.gif) | ![lineprinter](examples/drawing_lineprinter_launch.gif) | ![lowpoly](examples/drawing_lowpoly_canyon.gif) |
-| **Stencil graffiti · 喷漆模板涂鸦** | **Embroidered patches · 刺绣徽章** | **Blueprint · 蓝图工程图** |
-| ![stencil](examples/drawing_stencil_kite.gif) | ![patch](examples/drawing_patch_camping.gif) | ![blueprint](examples/drawing_blueprint_lighthouse.gif) |
-| **Children's crayon · 儿童蜡笔画** | **Green-screen CRT · 绿屏终端** | **Thermal camera · 热成像** |
-| ![crayon](examples/drawing_crayon_picnic.gif) | ![crt](examples/drawing_crt_weather.gif) | ![thermal](examples/drawing_thermal_kitchen.gif) |
-| **Delft tiles · 代尔夫特蓝瓷砖** | **Cave painting · 洞穴壁画** | **1-bit paint program · 1-bit 早期画图软件** |
-| ![delft](examples/drawing_delft_canal.gif) | ![cave](examples/drawing_cave_hunt.gif) | ![macpaint](examples/drawing_macpaint_garden.gif) |
-| **Greek black-figure vase · 古希腊黑绘陶瓶** | **Graphite pencil · 铅笔素描** | **X-ray · X 光片** |
-| ![blackfigure](examples/drawing_blackfigure_games.gif) | ![graphite](examples/drawing_graphite_bicycle.gif) | ![xray](examples/drawing_xray_luggage.gif) |
-| **1930s rubber hose · 1930 年代黑白橡皮管动画** | **Linocut · 黑白麻胶版画** | **VHS home video · VHS 家庭录像** |
-| ![rubberhose](examples/drawing_rubberhose_morning.gif) | ![linocut](examples/drawing_linocut_snowy_village.gif) | ![vhs](examples/drawing_vhs_birthday.gif) |
-| **Flat vector · 扁平矢量** | **Storybook animation · 绘本角色动画** | **Ballpoint doodle · 圆珠笔涂鸦** |
-| ![flatvector](examples/drawing_flatvector_night_camp.gif) | ![storybook](examples/drawing_storybook_acorn.gif) | ![ballpoint](examples/drawing_ballpoint_board_game.gif) |
+| ![moonriver](examples/drawing_moon_river.gif) | ![watercolour](examples/drawing_watercolor_autumn.gif) | ![collage](examples/drawing_papercut_balloons.gif) |
+| **Coloured pencil · 韩国彩铅** | **Anime · 日本动漫** | **Editorial · 编辑风手绘** |
+| ![pencil](examples/drawing_colorpencil_dessert.gif) | ![anime](examples/drawing_anime_summer.gif) | ![editorial](examples/drawing_editorial_ideas.gif) |
+| **Impasto oil · 油画厚涂** | **Ukiyo-e · 浮世绘木版画** | **Pixel art · 像素风** |
+| ![oil](examples/drawing_oil_wheatfield.gif) | ![ukiyoe](examples/drawing_ukiyoe_fuji.gif) | ![pixel](examples/drawing_pixel_rainy_cafe.gif) |
+| **Stop-motion clay · 黏土定格** | **Cyanotype · 蓝晒** | **Cross-stitch · 十字绣** |
+| ![clay](examples/drawing_clay_lighthouse.gif) | ![cyanotype](examples/drawing_cyanotype_botanicals.gif) | ![stitch](examples/drawing_stitch_sampler.gif) |
+| **Retro panel · 复古仪器面板** | **Sticker collage × receipt · 贴纸拼贴 · 小票** | **Lab notebook × stickers · 实验笔记本 · 贴纸** |
+| ![panel](examples/drawing_panel_radio.gif) | ![sticker](examples/drawing_sticker_market.gif) | ![notebook](examples/drawing_notebook_brewing.gif) |
+| **Chalkboard · 黑板板书** | **Cyberpunk · 赛博朋克** | **Hand-drawn cartoon · 卡通手绘** |
+| ![chalk](examples/drawing_chalk_lesson.gif) | ![cyberpunk](examples/drawing_cyberpunk_neon_street.gif) | ![cartoon](examples/drawing_cartoon_toaster.gif) |
+| **Continuous line art · 单线画** | **Soft 3D · 柔光 3D** | **Shape morph · 形变动画** |
+| ![lineart](examples/drawing_lineart_paper_plane.gif) | ![soft3d](examples/drawing_soft3d_rise.gif) | ![morph](examples/drawing_morph_water_cycle.gif) |
+| **Newspaper collage · 报刊拼贴** | **Aurora glass · 弥散玻璃** | **Bauhaus geometric · 包豪斯几何** |
+| ![newscollage](examples/drawing_newscollage_curiosity.gif) | ![aurora](examples/drawing_aurora_morning.gif) | ![bauhaus](examples/drawing_bauhaus_form_colour.gif) |
+| **Retro synthwave · 复古 Synthwave** | **Isometric 2.5D · 等轴 2.5D** | **Perler beads · 拼豆** |
+| ![synthwave](examples/drawing_synthwave_coastline.gif) | ![isometric](examples/drawing_isometric_weather_island.gif) | ![perler](examples/drawing_perler_strawberry_coaster.gif) |
+| **Petroglyph · 岩画** | **Egyptian tomb painting · 古埃及墓室壁画** | **Roman mosaic · 罗马马赛克** |
+| ![petroglyph](examples/drawing_petroglyph_migration.gif) | ![tomb](examples/drawing_tomb_harvest.gif) | ![mosaic](examples/drawing_mosaic_harbor.gif) |
+| **Stained glass · 彩色玻璃花窗** | **Illuminated manuscript · 泥金手抄本** | **Leonardo codex · 达·芬奇手稿** |
+| ![stainedglass](examples/drawing_stainedglass_seasons.gif) | ![illuminated](examples/drawing_illuminated_starchart.gif) | ![codex](examples/drawing_codex_ornithopter.gif) |
+| **Silhouette · 剪影** | **Letterpress poster · 凸版印刷海报** | **Soviet constructivism · 苏联构成主义** |
+| ![silhouette](examples/drawing_silhouette_family.gif) | ![letterpress](examples/drawing_letterpress_circus.gif) | ![constructivism](examples/drawing_constructivism_radio.gif) |
+| **Art Deco · 装饰艺术** | **Golden-age comic · 黄金时代漫画** | **Pop silkscreen · 波普丝网** |
+| ![artdeco](examples/drawing_artdeco_express.gif) | ![comic](examples/drawing_comic_rocket.gif) | ![popart](examples/drawing_popart_cat_moods.gif) |
+| **ASCII art (line printer) · ASCII 字符画** | **Low poly · 低多边形** | **Stencil graffiti · 喷漆模板涂鸦** |
+| ![lineprinter](examples/drawing_lineprinter_launch.gif) | ![lowpoly](examples/drawing_lowpoly_canyon.gif) | ![stencil](examples/drawing_stencil_kite.gif) |
+| **Embroidered patches · 刺绣徽章** | **Blueprint · 蓝图工程图** | **Children's crayon · 儿童蜡笔画** |
+| ![patch](examples/drawing_patch_camping.gif) | ![blueprint](examples/drawing_blueprint_lighthouse.gif) | ![crayon](examples/drawing_crayon_picnic.gif) |
+| **Green-screen CRT · 绿屏终端** | **Thermal camera · 热成像** | **Delft tiles · 代尔夫特蓝瓷砖** |
+| ![crt](examples/drawing_crt_weather.gif) | ![thermal](examples/drawing_thermal_kitchen.gif) | ![delft](examples/drawing_delft_canal.gif) |
+| **Cave painting · 洞穴壁画** | **1-bit paint program · 1-bit 早期画图软件** | **Greek black-figure vase · 古希腊黑绘陶瓶** |
+| ![cave](examples/drawing_cave_hunt.gif) | ![macpaint](examples/drawing_macpaint_garden.gif) | ![blackfigure](examples/drawing_blackfigure_games.gif) |
+| **Graphite pencil · 铅笔素描** | **X-ray · X 光片** | **1930s rubber hose · 1930 年代黑白橡皮管动画** |
+| ![graphite](examples/drawing_graphite_bicycle.gif) | ![xray](examples/drawing_xray_luggage.gif) | ![rubberhose](examples/drawing_rubberhose_morning.gif) |
+| **Linocut · 黑白麻胶版画** | **VHS home video · VHS 家庭录像** | **Flat vector · 扁平矢量** |
+| ![linocut](examples/drawing_linocut_snowy_village.gif) | ![vhs](examples/drawing_vhs_birthday.gif) | ![flatvector](examples/drawing_flatvector_night_camp.gif) |
+| **Storybook animation · 绘本角色动画** | **Ballpoint doodle · 圆珠笔涂鸦** | **Overlay sheets · 描图纸叠层** |
+| ![storybook](examples/drawing_storybook_acorn.gif) | ![ballpoint](examples/drawing_ballpoint_board_game.gif) | ![overlay](examples/drawing_overlay_city_map.gif) |
### Gallery · 画廊
@@ -56,66 +56,68 @@
|---|---|
| **八万四千法门** · *Many Paths, One Summit*<br><sub>Ink wash · 水墨</sub> | **月印万川** · *One Moon in Ten Thousand Rivers*<br><sub>Ink wash · 水墨</sub> |
| <img src="examples/bawansiqian.jpg" width="100%"> | <img src="examples/moon_river.jpg" width="100%"> |
-| **秋日湖畔** · *Autumn Lake*<br><sub>Watercolour · 水彩</sub> | **热气球小镇** · *Balloon Day*<br><sub>Paper collage · 剪纸拼贴</sub> |
-| <img src="examples/watercolor_autumn.jpg" width="100%"> | <img src="examples/papercut_balloons.jpg" width="100%"> |
-| **午后甜点** · *Afternoon Dessert*<br><sub>Coloured pencil · 韩国彩铅</sub> | **夏空** · *Summer Sky*<br><sub>Anime · 日本动漫</sub> |
-| <img src="examples/colorpencil_dessert.jpg" width="100%"> | <img src="examples/anime_summer.jpg" width="100%"> |
-| **灵感生长** · *Growing Ideas*<br><sub>Editorial · 编辑风手绘</sub> | **麦田星空** · *Swirling Sky over the Wheat Field*<br><sub>Impasto oil · 油画厚涂</sub> |
-| <img src="examples/editorial_ideas.jpg" width="100%"> | <img src="examples/oil_wheatfield.jpg" width="100%"> |
-| **富士曙** · *Fuji at Dawn*<br><sub>Ukiyo-e · 浮世绘</sub> | **雨夜咖啡店** · *Rainy Night Cafe*<br><sub>Pixel art · 像素风</sub> |
-| <img src="examples/ukiyoe_fuji.jpg" width="100%"> | <img src="examples/pixel_rainy_cafe.png" width="100%"> |
-| **灯塔岛** · *Lighthouse Island*<br><sub>Stop-motion clay · 黏土定格</sub> | **蓝晒植物** · *Sun-Print Botanicals*<br><sub>Cyanotype · 蓝晒</sub> |
-| <img src="examples/clay_lighthouse.jpg" width="100%"> | <img src="examples/cyanotype_botanicals.jpg" width="100%"> |
-| **家** · *Home Sampler*<br><sub>Cross-stitch · 十字绣</sub> | **Aurora 64 收音机** · *Aurora 64 Radio*<br><sub>Vintage instrument panel · 复古仪器面板</sub> |
-| <img src="examples/stitch_sampler.jpg" width="100%"> | <img src="examples/panel_radio.jpg" width="100%"> |
-| **周末市集** · *Weekend Market*<br><sub>Sticker collage × receipt · 贴纸拼贴 · 小票</sub> | **咖啡萃取实验** · *Coffee Brewing Experiment*<br><sub>Lab notebook × stickers · 实验笔记本 · 贴纸</sub> |
-| <img src="examples/sticker_market.jpg" width="100%"> | <img src="examples/notebook_brewing.jpg" width="100%"> |
-| **为什么天空是蓝的** · *Why Is the Sky Blue?*<br><sub>Chalkboard · 黑板板书</sub> | **霓虹不夜城** · *Neon District*<br><sub>Cyberpunk · 赛博朋克</sub> |
-| <img src="examples/chalk_lesson.jpg" width="100%"> | <img src="examples/cyberpunk_neon_street.jpg" width="100%"> |
-| **早安吐司** · *Good Morning, Toast*<br><sub>Hand-drawn cartoon · 卡通手绘</sub> | **岛上的气象站** · *Island Weather Station*<br><sub>Isometric 2.5D · 等轴 2.5D</sub> |
-| <img src="examples/cartoon_toaster.jpg" width="100%"> | <img src="examples/isometric_weather_island.jpg" width="100%"> |
-| **从这扇窗到那扇窗** · *From Window to Window*<br><sub>Continuous line art · 单线画</sub> | **浮出** · *Rise*<br><sub>Soft 3D · 柔光 3D</sub> |
-| <img src="examples/lineart_paper_plane.jpg" width="100%"> | <img src="examples/soft3d_rise.jpg" width="100%"> |
-| **一滴水的旅程** · *A Drop's Round Trip*<br><sub>Shape morph · 形变动画</sub> | **好奇心周刊 · 拆开看看** · *Curiosity Weekly · Take It Apart*<br><sub>Newspaper collage · 报刊拼贴</sub> |
-| <img src="examples/morph_water_cycle.jpg" width="100%"> | <img src="examples/newscollage_curiosity.jpg" width="100%"> |
-| **晨间计划** · *Morning Plan*<br><sub>Aurora glassmorphism · 弥散玻璃</sub> | **形与色** · *Form & Colour*<br><sub>Bauhaus geometric · 包豪斯几何</sub> |
-| <img src="examples/aurora_morning.jpg" width="100%"> | <img src="examples/bauhaus_form_colour.jpg" width="100%"> |
-| **海岸线 1987** · *Coastline 1987*<br><sub>Retro synthwave · 复古 Synthwave</sub> | **草莓杯垫** · *Strawberry Coaster*<br><sub>Perler beads · 拼豆</sub> |
-| <img src="examples/synthwave_coastline.jpg" width="100%"> | <img src="examples/perler_strawberry_coaster.jpg" width="100%"> |
-| **迁徙季** · *Migration Season*<br><sub>Petroglyph · 岩画</sub> | **尼罗河丰收** · *Harvest on the Nile*<br><sub>Egyptian tomb painting · 古埃及墓室壁画</sub> |
-| <img src="examples/petroglyph_migration.jpg" width="100%"> | <img src="examples/tomb_harvest.jpg" width="100%"> |
-| **港口渔获** · *The Day's Catch*<br><sub>Roman mosaic · 罗马马赛克</sub> | **四季之窗** · *Window of the Seasons*<br><sub>Stained glass · 彩色玻璃花窗</sub> |
-| <img src="examples/mosaic_harbor.jpg" width="100%"> | <img src="examples/stainedglass_seasons.jpg" width="100%"> |
-| **星辰之书** · *Liber Stellarum*<br><sub>Illuminated manuscript · 泥金手抄本</sub> | **扑翼机** · *The Ornithopter*<br><sub>Leonardo codex · 达·芬奇手稿</sub> |
-| <img src="examples/illuminated_starchart.jpg" width="100%"> | <img src="examples/codex_ornithopter.jpg" width="100%"> |
-| **剪影小像** · *Shades of the Wren Household*<br><sub>Silhouette · 剪影</sub> | **马戏团来了** · *The Circus Is Coming*<br><sub>Letterpress poster · 凸版印刷海报</sub> |
-| <img src="examples/silhouette_family.jpg" width="100%"> | <img src="examples/letterpress_circus.jpg" width="100%"> |
-| **无线电** · *Radio*<br><sub>Soviet constructivism · 苏联构成主义</sub> | **夜行快车** · *Night Express*<br><sub>Art Deco · 装饰艺术</sub> |
-| <img src="examples/constructivism_radio.jpg" width="100%"> | <img src="examples/artdeco_express.jpg" width="100%"> |
-| **火箭小队** · *Rocket Squad*<br><sub>Golden-age comic · 黄金时代漫画</sub> | **猫的六种心情** · *Six Moods of a Cat*<br><sub>Pop silkscreen · 波普丝网</sub> |
-| <img src="examples/comic_rocket.jpg" width="100%"> | <img src="examples/popart_cat_moods.jpg" width="100%"> |
-| **发射记录** · *Liftoff Trace*<br><sub>ASCII art (line printer) · ASCII 字符画(行式打印机)</sub> | **峡谷飞行** · *Canyon Run*<br><sub>Low poly · 低多边形</sub> |
-| <img src="examples/lineprinter_launch.jpg" width="100%"> | <img src="examples/lowpoly_canyon.jpg" width="100%"> |
-| **放风筝** · *Hold On*<br><sub>Stencil graffiti · 喷漆模板涂鸦</sub> | **三晚露营** · *Three Nights Out*<br><sub>Embroidered patches · 刺绣徽章</sub> |
-| <img src="examples/stencil_kite.jpg" width="100%"> | <img src="examples/patch_camping.jpg" width="100%"> |
-| **灯塔剖面** · *Halvard Rock Light*<br><sub>Blueprint · 蓝图工程图</sub> | **我的周末** · *My Weekend*<br><sub>Children's crayon · 儿童蜡笔画</sub> |
-| <img src="examples/blueprint_lighthouse.jpg" width="100%"> | <img src="examples/crayon_picnic.jpg" width="100%"> |
-| **今天带伞吗** · *Bring an Umbrella?*<br><sub>Green-screen CRT terminal · 绿屏终端(荧光字符画)</sub> | **厨房里的温度** · *Kitchen Heat Map*<br><sub>Thermal camera · 热成像</sub> |
-| <img src="examples/crt_weather.jpg" width="100%"> | <img src="examples/thermal_kitchen.jpg" width="100%"> |
-| **一阵风** · *The Gust*<br><sub>Delft tiles · 代尔夫特蓝瓷砖</sub> | **篝火旁的岩洞** · *The Hunt by the Fire*<br><sub>Cave painting · 洞穴壁画</sub> |
-| <img src="examples/delft_canal.jpg" width="100%"> | <img src="examples/cave_hunt.jpg" width="100%"> |
-| **窗台花园** · *Windowsill Garden*<br><sub>1-bit paint program · 1-bit 早期画图软件</sub> | **赛跑与赛车** · *Games on a Vase*<br><sub>Greek black-figure vase · 古希腊黑绘陶瓶</sub> |
-| <img src="examples/macpaint_garden.jpg" width="100%"> | <img src="examples/blackfigure_games.jpg" width="100%"> |
-| **老街角的自行车** · *The Bread Run*<br><sub>Graphite pencil · 铅笔素描</sub> | **行李安检** · *Security Check*<br><sub>X-ray · X 光片</sub> |
-| <img src="examples/graphite_bicycle.jpg" width="100%"> | <img src="examples/xray_luggage.jpg" width="100%"> |
-| **早晨的闹钟** · *Seven O'Clock*<br><sub>1930s rubber hose · 1930 年代黑白橡皮管动画</sub> | **雪夜归途** · *Homeward, First Snow*<br><sub>Linocut · 黑白麻胶版画</sub> |
-| <img src="examples/rubberhose_morning.jpg" width="100%"> | <img src="examples/linocut_snowy_village.jpg" width="100%"> |
-| **吹蜡烛** · *Blow Out the Candles*<br><sub>VHS home video · VHS 家庭录像</sub> | **山间夜营** · *Night Camp*<br><sub>Flat vector · 扁平矢量</sub> |
-| <img src="examples/vhs_birthday.jpg" width="100%"> | <img src="examples/flatvector_night_camp.jpg" width="100%"> |
-| **小橡果的秋天** · *An Acorn's Autumn*<br><sub>Storybook animation · 绘本角色动画</sub> | **蛇梯棋大冒险** · *Snakes & Ladders, Round 7*<br><sub>Ballpoint doodle · 圆珠笔涂鸦</sub> |
-| <img src="examples/storybook_acorn.jpg" width="100%"> | <img src="examples/ballpoint_board_game.jpg" width="100%"> |
-
-Every mark above is computed: paper fibres, ink washes and mist, dry-brush strokes, pigment granulation and blooms, torn-paper edges, pencil wax on paper tooth, cel-shaded clouds, risograph grain and halftones, lit impasto relief, woodblock grain and bokashi, dithered pixels, plasticine lit like a film set, sunlight through leaves on Prussian blue, twisted thread on Aida cloth, machined knobs behind a backlit dial, die-cut vinyl with a laminate gloss, streaky thermal print, graphite catching the tooth of graph paper, highlighter pooling at the start of a swipe, chalk dust settling under half-erased lessons, rain-lit neon glass mirrored in a wet street, a blue-pencil rough under boiling brush ink, an island ray-traced under one soft sun, a single unbroken gold line, candy balls with softbox glints, one outline morphing through six shapes, halftone photos cut out with scissors, frosted glass blurring the real pixels behind it, screen-printed primaries out of register, a slit sun sinking behind a neon grid played off tape, hollow fuse beads on a pegboard melting together under an iron, pits knocked through desert varnish, a red grid showing through flaking plaster, stones laid row by row along an outline, daylight through leaded glass, burnished gold that mirrors the room, left-handed hatching in iron-gall ink, black paper cut with scissors, wood type printed a hair out of register, red and black plates slipping apart, airbrush fades inside knife-cut friskets, Ben-Day dots on yellowed newsprint, one photo key pulled across hand-painted colour, characters struck through a fading ribbon, flat-shaded triangles dithered to 15 bits, spray drifting past cut card, satin stitches catching the light by their angle, ink lines printed white on Prussian blue, wax scribbles skipping the paper's pits, phosphor glowing behind curved glass, heat leaking out of a kitchen, cobalt fired into tin glaze tile by tile, ochre blown onto rock lit by a fire, 1-bit patterns in an old paint program, slip silhouettes incised to the clay, graphite that never quite reaches black, X-rays adding up through a suitcase, grey cels shot on scratched film, gouge marks in a rolled-up block, a birthday smeared onto tape, seven flat colours lifting off each other, an acorn squashing and stretching through a world drawn as it goes, ballpoint ink blobbing at every corner of a hand-drawn game. No diffusion model, no API, no stock art. It is just Python with **numpy + Pillow** on a CPU: from 0.1 s (pixel art) to about 45 s (the soft 3D ray tracer) per 1920×1080 image.
+| **秋日湖畔** · *Autumn Lake*<br><sub>Watercolour · 水彩</sub> | **水彩底纹** · *Watercolour Washes*<br><sub>Watercolour · 水彩 — a background for explainer videos · 讲解视频的背景</sub> |
+| <img src="examples/watercolor_autumn.jpg" width="100%"> | <img src="examples/watercolor_washes.jpg" width="100%"> |
+| **热气球小镇** · *Balloon Day*<br><sub>Paper collage · 剪纸拼贴</sub> | **午后甜点** · *Afternoon Dessert*<br><sub>Coloured pencil · 韩国彩铅</sub> |
+| <img src="examples/papercut_balloons.jpg" width="100%"> | <img src="examples/colorpencil_dessert.jpg" width="100%"> |
+| **夏空** · *Summer Sky*<br><sub>Anime · 日本动漫</sub> | **灵感生长** · *Growing Ideas*<br><sub>Editorial · 编辑风手绘</sub> |
+| <img src="examples/anime_summer.jpg" width="100%"> | <img src="examples/editorial_ideas.jpg" width="100%"> |
+| **麦田星空** · *Swirling Sky over the Wheat Field*<br><sub>Impasto oil · 油画厚涂</sub> | **富士曙** · *Fuji at Dawn*<br><sub>Ukiyo-e · 浮世绘</sub> |
+| <img src="examples/oil_wheatfield.jpg" width="100%"> | <img src="examples/ukiyoe_fuji.jpg" width="100%"> |
+| **雨夜咖啡店** · *Rainy Night Cafe*<br><sub>Pixel art · 像素风</sub> | **灯塔岛** · *Lighthouse Island*<br><sub>Stop-motion clay · 黏土定格</sub> |
+| <img src="examples/pixel_rainy_cafe.png" width="100%"> | <img src="examples/clay_lighthouse.jpg" width="100%"> |
+| **蓝晒植物** · *Sun-Print Botanicals*<br><sub>Cyanotype · 蓝晒</sub> | **家** · *Home Sampler*<br><sub>Cross-stitch · 十字绣</sub> |
+| <img src="examples/cyanotype_botanicals.jpg" width="100%"> | <img src="examples/stitch_sampler.jpg" width="100%"> |
+| **Aurora 64 收音机** · *Aurora 64 Radio*<br><sub>Vintage instrument panel · 复古仪器面板</sub> | **周末市集** · *Weekend Market*<br><sub>Sticker collage × receipt · 贴纸拼贴 · 小票</sub> |
+| <img src="examples/panel_radio.jpg" width="100%"> | <img src="examples/sticker_market.jpg" width="100%"> |
+| **咖啡萃取实验** · *Coffee Brewing Experiment*<br><sub>Lab notebook × stickers · 实验笔记本 · 贴纸</sub> | **为什么天空是蓝的** · *Why Is the Sky Blue?*<br><sub>Chalkboard · 黑板板书</sub> |
+| <img src="examples/notebook_brewing.jpg" width="100%"> | <img src="examples/chalk_lesson.jpg" width="100%"> |
+| **霓虹不夜城** · *Neon District*<br><sub>Cyberpunk · 赛博朋克</sub> | **早安吐司** · *Good Morning, Toast*<br><sub>Hand-drawn cartoon · 卡通手绘</sub> |
+| <img src="examples/cyberpunk_neon_street.jpg" width="100%"> | <img src="examples/cartoon_toaster.jpg" width="100%"> |
+| **岛上的气象站** · *Island Weather Station*<br><sub>Isometric 2.5D · 等轴 2.5D</sub> | **从这扇窗到那扇窗** · *From Window to Window*<br><sub>Continuous line art · 单线画</sub> |
+| <img src="examples/isometric_weather_island.jpg" width="100%"> | <img src="examples/lineart_paper_plane.jpg" width="100%"> |
+| **浮出** · *Rise*<br><sub>Soft 3D · 柔光 3D</sub> | **一滴水的旅程** · *A Drop's Round Trip*<br><sub>Shape morph · 形变动画</sub> |
+| <img src="examples/soft3d_rise.jpg" width="100%"> | <img src="examples/morph_water_cycle.jpg" width="100%"> |
+| **好奇心周刊 · 拆开看看** · *Curiosity Weekly · Take It Apart*<br><sub>Newspaper collage · 报刊拼贴</sub> | **晨间计划** · *Morning Plan*<br><sub>Aurora glassmorphism · 弥散玻璃</sub> |
+| <img src="examples/newscollage_curiosity.jpg" width="100%"> | <img src="examples/aurora_morning.jpg" width="100%"> |
+| **形与色** · *Form & Colour*<br><sub>Bauhaus geometric · 包豪斯几何</sub> | **海岸线 1987** · *Coastline 1987*<br><sub>Retro synthwave · 复古 Synthwave</sub> |
+| <img src="examples/bauhaus_form_colour.jpg" width="100%"> | <img src="examples/synthwave_coastline.jpg" width="100%"> |
+| **草莓杯垫** · *Strawberry Coaster*<br><sub>Perler beads · 拼豆</sub> | **迁徙季** · *Migration Season*<br><sub>Petroglyph · 岩画</sub> |
+| <img src="examples/perler_strawberry_coaster.jpg" width="100%"> | <img src="examples/petroglyph_migration.jpg" width="100%"> |
+| **尼罗河丰收** · *Harvest on the Nile*<br><sub>Egyptian tomb painting · 古埃及墓室壁画</sub> | **港口渔获** · *The Day's Catch*<br><sub>Roman mosaic · 罗马马赛克</sub> |
+| <img src="examples/tomb_harvest.jpg" width="100%"> | <img src="examples/mosaic_harbor.jpg" width="100%"> |
+| **四季之窗** · *Window of the Seasons*<br><sub>Stained glass · 彩色玻璃花窗</sub> | **星辰之书** · *Liber Stellarum*<br><sub>Illuminated manuscript · 泥金手抄本</sub> |
+| <img src="examples/stainedglass_seasons.jpg" width="100%"> | <img src="examples/illuminated_starchart.jpg" width="100%"> |
+| **扑翼机** · *The Ornithopter*<br><sub>Leonardo codex · 达·芬奇手稿</sub> | **剪影小像** · *Shades of the Wren Household*<br><sub>Silhouette · 剪影</sub> |
+| <img src="examples/codex_ornithopter.jpg" width="100%"> | <img src="examples/silhouette_family.jpg" width="100%"> |
+| **马戏团来了** · *The Circus Is Coming*<br><sub>Letterpress poster · 凸版印刷海报</sub> | **无线电** · *Radio*<br><sub>Soviet constructivism · 苏联构成主义</sub> |
+| <img src="examples/letterpress_circus.jpg" width="100%"> | <img src="examples/constructivism_radio.jpg" width="100%"> |
+| **夜行快车** · *Night Express*<br><sub>Art Deco · 装饰艺术</sub> | **火箭小队** · *Rocket Squad*<br><sub>Golden-age comic · 黄金时代漫画</sub> |
+| <img src="examples/artdeco_express.jpg" width="100%"> | <img src="examples/comic_rocket.jpg" width="100%"> |
+| **猫的六种心情** · *Six Moods of a Cat*<br><sub>Pop silkscreen · 波普丝网</sub> | **发射记录** · *Liftoff Trace*<br><sub>ASCII art (line printer) · ASCII 字符画(行式打印机)</sub> |
+| <img src="examples/popart_cat_moods.jpg" width="100%"> | <img src="examples/lineprinter_launch.jpg" width="100%"> |
+| **峡谷飞行** · *Canyon Run*<br><sub>Low poly · 低多边形</sub> | **放风筝** · *Hold On*<br><sub>Stencil graffiti · 喷漆模板涂鸦</sub> |
+| <img src="examples/lowpoly_canyon.jpg" width="100%"> | <img src="examples/stencil_kite.jpg" width="100%"> |
+| **三晚露营** · *Three Nights Out*<br><sub>Embroidered patches · 刺绣徽章</sub> | **灯塔剖面** · *Halvard Rock Light*<br><sub>Blueprint · 蓝图工程图</sub> |
+| <img src="examples/patch_camping.jpg" width="100%"> | <img src="examples/blueprint_lighthouse.jpg" width="100%"> |
+| **我的周末** · *My Weekend*<br><sub>Children's crayon · 儿童蜡笔画</sub> | **今天带伞吗** · *Bring an Umbrella?*<br><sub>Green-screen CRT terminal · 绿屏终端(荧光字符画)</sub> |
+| <img src="examples/crayon_picnic.jpg" width="100%"> | <img src="examples/crt_weather.jpg" width="100%"> |
+| **厨房里的温度** · *Kitchen Heat Map*<br><sub>Thermal camera · 热成像</sub> | **一阵风** · *The Gust*<br><sub>Delft tiles · 代尔夫特蓝瓷砖</sub> |
+| <img src="examples/thermal_kitchen.jpg" width="100%"> | <img src="examples/delft_canal.jpg" width="100%"> |
+| **篝火旁的岩洞** · *The Hunt by the Fire*<br><sub>Cave painting · 洞穴壁画</sub> | **窗台花园** · *Windowsill Garden*<br><sub>1-bit paint program · 1-bit 早期画图软件</sub> |
+| <img src="examples/cave_hunt.jpg" width="100%"> | <img src="examples/macpaint_garden.jpg" width="100%"> |
+| **赛跑与赛车** · *Games on a Vase*<br><sub>Greek black-figure vase · 古希腊黑绘陶瓶</sub> | **老街角的自行车** · *The Bread Run*<br><sub>Graphite pencil · 铅笔素描</sub> |
+| <img src="examples/blackfigure_games.jpg" width="100%"> | <img src="examples/graphite_bicycle.jpg" width="100%"> |
+| **行李安检** · *Security Check*<br><sub>X-ray · X 光片</sub> | **早晨的闹钟** · *Seven O'Clock*<br><sub>1930s rubber hose · 1930 年代黑白橡皮管动画</sub> |
+| <img src="examples/xray_luggage.jpg" width="100%"> | <img src="examples/rubberhose_morning.jpg" width="100%"> |
+| **雪夜归途** · *Homeward, First Snow*<br><sub>Linocut · 黑白麻胶版画</sub> | **吹蜡烛** · *Blow Out the Candles*<br><sub>VHS home video · VHS 家庭录像</sub> |
+| <img src="examples/linocut_snowy_village.jpg" width="100%"> | <img src="examples/vhs_birthday.jpg" width="100%"> |
+| **山间夜营** · *Night Camp*<br><sub>Flat vector · 扁平矢量</sub> | **小橡果的秋天** · *An Acorn's Autumn*<br><sub>Storybook animation · 绘本角色动画</sub> |
+| <img src="examples/flatvector_night_camp.jpg" width="100%"> | <img src="examples/storybook_acorn.jpg" width="100%"> |
+| **蛇梯棋大冒险** · *Snakes & Ladders, Round 7*<br><sub>Ballpoint doodle · 圆珠笔涂鸦</sub> | **海港步行图** · *Larkhaven on Foot*<br><sub>Overlay sheets · 描图纸叠层</sub> |
+| <img src="examples/ballpoint_board_game.jpg" width="100%"> | <img src="examples/overlay_city_map.jpg" width="100%"> |
+
+Every mark above is computed: paper fibres, ink washes and mist, dry-brush strokes, pigment granulation and blooms, torn-paper edges, pencil wax on paper tooth, cel-shaded clouds, risograph grain and halftones, lit impasto relief, woodblock grain and bokashi, dithered pixels, plasticine lit like a film set, sunlight through leaves on Prussian blue, twisted thread on Aida cloth, machined knobs behind a backlit dial, die-cut vinyl with a laminate gloss, streaky thermal print, graphite catching the tooth of graph paper, highlighter pooling at the start of a swipe, chalk dust settling under half-erased lessons, rain-lit neon glass mirrored in a wet street, a blue-pencil rough under boiling brush ink, an island ray-traced under one soft sun, a single unbroken gold line, candy balls with softbox glints, one outline morphing through six shapes, halftone photos cut out with scissors, frosted glass blurring the real pixels behind it, screen-printed primaries out of register, a slit sun sinking behind a neon grid played off tape, hollow fuse beads on a pegboard melting together under an iron, pits knocked through desert varnish, a red grid showing through flaking plaster, stones laid row by row along an outline, daylight through leaded glass, burnished gold that mirrors the room, left-handed hatching in iron-gall ink, black paper cut with scissors, wood type printed a hair out of register, red and black plates slipping apart, airbrush fades inside knife-cut friskets, Ben-Day dots on yellowed newsprint, one photo key pulled across hand-painted colour, characters struck through a fading ribbon, flat-shaded triangles dithered to 15 bits, spray drifting past cut card, satin stitches catching the light by their angle, ink lines printed white on Prussian blue, wax scribbles skipping the paper's pits, phosphor glowing behind curved glass, heat leaking out of a kitchen, cobalt fired into tin glaze tile by tile, ochre blown onto rock lit by a fire, 1-bit patterns in an old paint program, slip silhouettes incised to the clay, graphite that never quite reaches black, X-rays adding up through a suitcase, grey cels shot on scratched film, gouge marks in a rolled-up block, a birthday smeared onto tape, seven flat colours lifting off each other, an acorn squashing and stretching through a world drawn as it goes, ballpoint ink blobbing at every corner of a hand-drawn game, inks multiplying through tracing paper on a light box. No diffusion model, no API, no stock art. It is just Python with **numpy + Pillow** on a CPU: from 0.1 s (pixel art) to about 45 s (the soft 3D ray tracer) per 1920×1080 image.
---
@@ -123,7 +125,7 @@ Every mark above is computed: paper fibres, ink washes and mist, dry-brush strok
### What it is
-A [Claude Code](https://claude.com/claude-code) skill and a small painting library with fifty-nine styles:
+A [Claude Code](https://claude.com/claude-code) skill and a small painting library with sixty styles:
| Style | Module | What makes it read as the real medium |
|---|---|---|
@@ -186,6 +188,7 @@ A [Claude Code](https://claude.com/claude-code) skill and a small painting libra
| **Flat vector** | `lib/flatvector.py` · `FlatVector` | an artboard of crisp anti-aliased geometric shapes (analytic circles, filleted polygons, tapered capsules, spline land profiles) combined with boolean ops, with no outlines anywhere; seven flat hues, every other colour a tone or mix of them; one light for the whole board, so every object splits into a lit face and a shade face (faceted ridge lines on the mountains, pines split down the middle, a cloud's belly cut from the cloud itself); the vector-paper depth cue: each lifted layer first drops a short, soft, night-blue shadow on what is already there, so every overlap shows a thin seam; glow as stacked flat translucent rings; a faint per-layer fibre and a fine, fixed print grain |
| **Storybook animation** | `lib/storybook.py` · `Storybook` | a real animation, not a draw-on: every piece of scenery is pre-painted once with a reveal map (the moment the pen or brush reaches each pixel), so ink lines draw along their length, washes spread with a darker wet front and props pop in with an overshoot — and the hills, flowers and banks are drawn exactly as the character passes (`follow`). The character is rendered every frame from implicit shapes in its own frame, squashed and stretched with a volume-preserving affine along its motion, rested exactly on the ground, lit by one fixed light so the highlight stays put while it rolls; poses come from eased, sprung and ballistic choreography plus impact lines, dust puffs, speed lines and ripples. The closing line writes itself in stroke order (skeleton walk), and the same scene renders a journey poster with the key poses multiply-exposed on a pencil motion arc |
| **Ballpoint doodle** | `lib/ballpoint.py` · `Ballpoint` | ballpoint ink is an oil paste a rolling ball lays down, kept as optical density, so a line drawn twice, a crossing or a blob goes darker and more saturated (blue deepens to blue-violet, never flat black); every stroke starts dry and thin, drifts in pressure and width, skips a few pixels now and then, drops gloops where the pen stops and at sharp turns, and flicks off in a little hook; outlines are gone over twice, slightly off; every stroke presses a groove into the copy paper that catches the raking light, and the sheet carries the blind indentations of a shopping list written on the page above; coloured pencil is wax on the paper tooth, hatched in quick slanted patches that run past the lines, light on big areas and pressed hard on small ones; the handwriting is the skeleton of a thin hand font re-drawn as pen strokes, each letter resized, tilted and lifted off a wandering baseline, with a word scribbled out and written again |
+| **Overlay sheets (tracing paper on a light box)** | `lib/overlay.py` · `Overlay` | the picture is a product of transmittances: a warm light box glows through a base sheet printed in black line and grey tints, then through translucent sheets that each carry ONE ink, laid down on registration crosses; an ink's coverage is a screen tint (or a double hit above 100 %), and inks on different sheets multiply, so blue over yellow turns green, magenta over yellow red and magenta over blue violet; every sheet has its own paper tint, the cloudy fibre formation you only see against the light, stray fibres, a cut edge that reads as a thin dark line, punched holes that drop onto a steel peg bar; a lifted sheet is a little larger, throws a wide soft shadow you can see through it and blurs everything under it like the diffuser it is, then lands crisp with a thin contact shadow; curled corners, crepe drafting tape with torn ends, a clear film with a gloss sheen; the town under it is cut by recursive street splits into blocks with a ring of buildings and party walls, water-lined round the coast |
Ask Claude to *"draw it yourself"*, *"paint this with code"*, or *"claude绘图"*, and name a style if you like. Claude then:
@@ -298,6 +301,7 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages
- **Flat vector**: win with a few big shapes and empty space, not with detail: three or four land layers, one moon, a generous sky, and one small story told with one or two warm accents. Seven colours; every other shade is a tone of one of them. One light for the whole board, with the shade faces always on the far side. With no outlines, choose each object's colour against what sits behind it (an orange tent goes on the sand, not in front of the orange hills). Lift layers a few pixels for a soft seam of shadow, and keep texture around 1% so flat fields still read as flat. Put translucent shapes over a single background colour only. People, if any, are tiny silhouettes.
- **Storybook animation**: the story is the acting, so choreograph first — anticipation before every big move (squash and lean away), stretch along the velocity, squash on every landing with impact lines and dust, a spring settle afterwards — and let the world be drawn by the character (`follow=` with a lead of 150–350 px, `pre=` for what is left of the start). Give `soft` in pixels, not as a fraction of a 2000-px layer, or the paint front turns into fog. Keep the camera still: only what moves is re-encoded, so 151 frames stay near 0.6 MB. On the poster, pick poses that sit apart along the path, draw the end state itself instead of a ghost on top of it, and hide the props' final positions.
- **Ballpoint doodle**: draw what sits in front first (the pieces), then let every later line stop at it with `clip` — the snakes, the ladders, the grid and the pencil all go round the pieces, the way a pen lifts at something already drawn. Keep big pencil areas light (pressure ~0.4) and small ones saturated (0.7–0.9), and let the hatching run a few px past the lines. Use red only for "this move" (hops, ring, arrow, the conclusion) and blue/black for everything else. Put every label inside an empty square or the margin — text split by a grid line or crowded by a sweat drop reads as a mistake. Keep the fold and the blind indentations faint; they should be found, not seen.
+- **Overlay sheets**: think in light, not paint — every sheet only takes light away, so tints are coverage and overlaps come out of the multiply on their own. Draw every separation in the same laid-down canvas coordinates and print the same registration crosses on each, so they register by construction. Keep tracing paper clear (transmittance ~0.98, formation ~2 %), or three sheets turn the town grey. Reversed-out numbers show whatever is underneath, so keep stop markers off dark landmarks, and give a tram and a walking route their own side of the same road. Put tape and curled corners where there is nothing printed. Lift a sheet only a little (σ ~3 px of blur, a 20–35 px offset): it should read as hovering, not as a second picture.
### Roadmap
@@ -309,7 +313,7 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages
### 这是什么
-一个 [Claude Code](https://claude.com/claude-code) skill,加上一个小巧的绘图库,内置五十九种画风:
+一个 [Claude Code](https://claude.com/claude-code) skill,加上一个小巧的绘图库,内置六十种画风:
| 画风 | 模块 | 为什么看起来像真的 |
|---|---|---|
@@ -372,6 +376,7 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages
| **扁平矢量** | `lib/flatvector.py` · `FlatVector` | 矢量软件的画板:边缘干净、抗锯齿的几何形(解析圆、圆角多边形、锥形胶囊、样条地块),可以并、交、减,全画没有一根描边;七种平涂色,其余颜色都是它们的深浅或相互调和;整幅只有一个光源,每样东西都分成亮面和暗面(山的折线山脊,松树从中间劈开,云的暗面是云减去挪动后的自己);「矢量纸片」的层次:每抬起一层,先往已有画面投一道短而柔的夜蓝色阴影,所以每处重叠都有一道细缝;光是一圈圈叠起来的平涂半透明光环;每层极淡的纤维纹,加固定的细颗粒 |
| **绘本角色动画** | `lib/storybook.py` · `Storybook` | 是真动画,不是阶段叠化:每样风景都预画一次,并记一张「揭示图」(笔或刷子在第几时刻碰到每个像素),所以墨线沿着笔路画出来、水彩带着一道略深的湿边晕开、小物件回弹着冒出来;山坡、小花、河岸正好在角色经过时画上(`follow`)。角色每帧用隐式曲面现画,沿运动方向做保体积的挤压拉伸,最低点正好贴地,光照固定在世界里(滚动时高光不跟着转);动作由缓动、弹簧和抛物线编排,配冲击线、白色尘团、速度线和水波。结尾一行字按笔顺一笔笔写出来(走骨架),同一个场景还能出一张旅程总图:关键姿态多次曝光在铅笔运动弧上 |
| **圆珠笔涂鸦** | `lib/ballpoint.py` · `Ballpoint` | 圆珠笔墨是滚珠压上去的油性墨膏,按光密度叠加:描两遍、交叉、墨团都会更深更饱和(蓝色叠成深蓝紫,不会是死黑);每一笔起笔干而细,压力和线宽一路漂移,偶尔断墨几像素,停笔和急转弯处掉墨团,抬笔甩出小钩;轮廓描两遍、略微错开;每一笔都在复印纸上压出凹槽,侧光下看得见,纸上还留着上一页购物单的无墨压痕;彩铅是挂在纸纹上的蜡,一块块斜向快速排线、出界,大面积轻、小面积重;手写字是细手写字体的骨架重新用笔描出来,每个字母各自缩放、倾斜、上下浮动,还有一个词划掉重写 |
+| **描图纸叠层** | `lib/overlay.py` · `Overlay` | 画面就是一路透过率相乘:暖白灯箱从下面照上来,先透过一张黑线灰调的底图,再透过一张张只印一种油墨的半透明叠片,叠片对着套准十字放下;油墨按网点覆盖率算(超过 100% 是叠印加深),不同叠片的油墨正片叠底,蓝叠黄成绿、品红叠黄成红、品红叠蓝成紫;每张纸有自己的纸色、只有背光才看得见的云状纤维和零星纤维丝、一道细暗的裁切边、落在钢定位钉上的打孔;抬起的纸略放大、投一片透过纸也看得见的宽软阴影,并像漫射片一样把下面的东西都模糊掉,放下后才清晰,只剩一道贴边细影;卷角、撕口的皱纹绘图胶带、带光泽的透明胶片;底图里的小城用递归切分的街道切出街区,沿街一圈房屋和分户墙,海岸外一圈圈水线 |
对 Claude 说「claude绘图」「你自己画」「用代码画」,也可以指定画风。它会:
1. **先定构图**:层次、焦点、留白,而且画面要图解内容本身;
@@ -460,6 +465,7 @@ python3 examples/vhs_birthday.py out.png # VHS 家庭
python3 examples/flatvector_night_camp.py out.png # 扁平矢量:山间夜营
python3 examples/storybook_acorn.py out.jpg --gif out.gif # 绘本角色动画:小橡果的秋天
python3 examples/ballpoint_board_game.py out.png # 圆珠笔涂鸦:蛇梯棋大冒险
+python3 examples/overlay_city_map.py out.jpg --stages stages/ # 描图纸叠层:海港步行图
```
### 作画要点(Claude 交图前逐条自查)
@@ -521,6 +527,7 @@ python3 examples/ballpoint_board_game.py out.png # 圆珠笔
- **扁平矢量**:靠几个大形状和留白取胜,不靠细节:三四层地形、一个月亮、大片天空,用一两处暖色讲一件小事。只用 7 色,其余都是它们的深浅。整幅一个光源,暗面永远在背光那边。没有描边,所以每样东西的颜色要对着它身后的颜色来定(橙色帐篷放在黄沙上,别放在橙色山丘前)。每层抬起几像素,留一道柔和的阴影缝;纹理控制在 1% 左右,平涂看上去还得是平的。半透明形状只放在单一底色上。要画人,只画很小的剪影。
- **绘本角色动画**:故事靠表演,先编排动作——每个大动作前都要有预备(压扁、往反方向后仰),沿速度方向拉伸,每次落地压扁并配冲击线和尘团,之后用弹簧回稳——再让世界跟着角色画出来(`follow=` 提前量 150–350 px,起点左边那段用 `pre=`)。柔边按像素给,别写成 2000 px 宽层的比例,否则湿边变成一团雾。镜头别动:只有动的地方重新编码,151 帧才能压在 0.6 MB 左右。总图里选沿路分得开的姿态,终点画最后一帧本身,别再叠残影,道具终点位置也藏掉。
- **圆珠笔涂鸦**:先画在前面的东西(棋子),后画的线都用 `clip` 在它前面停住——蛇、梯子、格线、彩铅都绕开棋子,就像笔走到已经画好的东西前会抬起来。大面积彩铅轻压(约 0.4),小面积压重(0.7–0.9),排线出界几像素。红笔只留给「这一步」(跳格、圈、箭头、结论),其余用蓝、黑。每个标注都放进空格子或页边:被格线劈开、被汗滴挤住的字看起来像画错了。折痕和无墨压痕要淡,是「找得到」而不是「一眼看见」。
+- **描图纸叠层**:按「光」想,不按「颜料」想——每张纸只会挡光,所以浅色是网点覆盖率,叠色交给正片叠底自己算。所有分色片都用纸放下时的同一套画布坐标画,每张都印同一组套准十字,天然对得上。描图纸要透(透过率约 0.98、云纹约 2%),否则三张叠下来整座城发灰。反白数字露出的是下面那一层,所以站点别压在深色地标上;电车和步行路线在同一条路上要各走一边。胶带和卷角放在没印东西的地方。纸只抬一点(模糊 σ 约 3 px、偏 20–35 px),看上去是「悬着」,不是又一张画。
### 计划
diff --git a/SKILL.md b/SKILL.md
index d19eb1b..931f399 100644
--- a/SKILL.md
+++ b/SKILL.md
@@ -1,6 +1,6 @@
---
name: claude绘图
-description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型,由 Claude 用代码一笔一笔「画」出图片(程序化绘画)。内置五十九种画风:中国水墨、水彩、剪纸拼贴、韩国彩铅、日本动漫、编辑风手绘(Riso)、油画厚涂(梵高式流向笔触+颜料浮雕打光)、浮世绘木版画(晕色、木纹、墨线主版、青海波)、像素风(低分辨率+Bayer 抖动+像素字体)、黏土定格(高度图捏出的彩泥+影棚打光)、蓝晒(普鲁士蓝日光晒图,植物剪影透光)、十字绣(Aida 布十字绣+回针绣+缎面绣+法式结)、复古仪器面板(60 年代收音机/仪器正面:柚木、拉丝铝、旋钮、刻度窗、指示灯)、贴纸拼贴·小票(模切乙烯贴纸、热敏小票、和纸胶带、吊牌、橡皮章)、实验笔记本·贴纸(线圈方格本、铅笔图表、荧光笔、红笔圈、便利贴)、黑板板书(墨绿石板、粉笔颗粒、板擦残影、示意图与公式)、赛博朋克(雨夜霓虹街道、玻璃管霓虹招牌、全息广告、湿路面倒影)、卡通手绘(蓝铅笔稿、毛笔线、错位平涂、赛璐璐阴影、逐帧抖线)、等轴 2.5D(正等轴微缩模型、一个太阳照出三面明暗、悬浮数据卡)、单线画(一根不断开的线一笔画完、唯一点睛色)、柔光 3D(光线追踪的糖果色小球海和鼓鼓的软字、景深)、形变动画(一条轮廓依次变形、洋葱皮残影、缓动曲线)、报刊拼贴(牛皮纸、手撕旧报纸、网点老照片、勒索信拼贴字)、弥散玻璃(弥散渐变、磨砂玻璃卡片界面)、包豪斯几何(三原色几何、丝网印刷海报)、复古 Synthwave(切口落日、霓虹网格、镀铬字、录像带质感)、拼豆(钉板上的熔珠小管、熨烫熔合)、岩画(沙漠漆上凿出的凹坑图形、新旧凿痕、剥落)、古埃及墓室壁画(灰泥墙、红格起稿、分栏叙事、象形文字、剥落)、罗马马赛克(石子与玻璃沿轮廓一排排铺、灰缝、燕尾铭牌)、彩色玻璃花窗(哥特尖拱窗、通体着色玻璃、grisaille 彩绘与银染、铅条、透光)、泥金手抄本(羊皮纸、鹅毛笔哥特体、朱红标题、打磨金箔首字母)、达·芬奇手稿(铁胆墨水、左手排线、红粉笔、镜像手写、机械分解图)、剪影(黑纸剪出的侧影小像、薄金粉、椭圆金框)、凸版印刷海报(木活字、红黑双色错版、木刻插图)、苏联构成主义(红黑两版、斜条与楔形、西里尔大字、网点照片拼贴)、装饰艺术 Art Deco(1930 年代喷枪流线型海报、交替射线、阶梯高楼、金色 Deco 字)、黄金时代漫画(毛笔墨线、Ben-Day 网点、四色错版、新闻纸)、波普丝网(多格撞色平涂 + 错位的照相黑版)、ASCII 字符画(行式打印机、绿条连续纸、叠打)、低多边形(1999 年代 3D:平面着色、仿射贴图、逐顶点雾、15 位色抖动)、喷漆模板涂鸦(混凝土墙上多层卡纸模板喷绘、雾化与滴痕)、刺绣徽章(牛仔布上的机绣徽章:填充绣、缎面绣、锁边)、蓝图工程图(描图墨线晒成蓝底白线)、儿童蜡笔画(小孩在糙纸上的蜡笔涂抹)、绿屏终端 CRT(荧光字符画、扫描线、余辉)、热成像(先画温度场再上伪彩色)、代尔夫特蓝瓷砖(锡釉砖上的钴蓝手绘)、洞穴壁画(火光下的赭石、吹喷手印)、1-bit 早期画图软件(黑白整屏、8×8 图案填充)、古希腊黑绘陶瓶(黑釉剪影、刻线、饰带展开图)、铅笔素描(石墨排线、擦笔、边缘只剩线稿)、X 光片(安检透视、轮廓发亮、伪彩)、1930 年代黑白橡皮管动画(白手套、饼切眼、老胶片)、黑白麻胶版画(刻刀减法、手拓发花、套色错版)、VHS 家庭录像(钨丝灯偏色、色度渗色、REC)、扁平矢量(分层几何色块、七色、层间投影)、绘本角色动画(小角色挤压拉伸的真动画)、圆珠笔涂鸦(蓝红圆珠笔线稿、墨团、彩铅、页边涂鸦)。用户说「claude绘图」「用代码画」「你自己画」「不用生图模型画」「程序化绘画」,或点名以上任一画风(含黏土、彩泥、定格动画、蓝晒、晒图、十字绣、刺绣、复古面板、老式收音机、贴纸、小票、收据、手帐拼贴、实验笔记本、方格本、荧光笔、便利贴、黑板、板书、粉笔、赛博朋克、霓虹、雨夜街道、卡通、手绘卡通、逐帧手绘、抖线、等轴、2.5D、微缩模型、单线画、一笔画、线条动画、柔光 3D、3D 渲染、C4D 风、软糖字、小球海、形变、变形动画、报刊拼贴、剪报、达达、勒索信字、网点印刷、弥散渐变、玻璃拟态、毛玻璃、包豪斯、几何构成、丝网印刷、Synthwave、蒸汽波、合成器浪潮、80 年代复古、拼豆、拼拼豆、熔珠、熨豆、豆豆画、钉板、烫豆、岩画、岩刻、凿刻、石刻、沙漠漆、史前壁刻、大角羊、古埃及、埃及壁画、墓室壁画、法老时代、象形文字、尼罗河、底比斯、罗马马赛克、马赛克镶嵌、镶嵌画、石子拼画、地砖画、古罗马地板、彩色玻璃、彩绘玻璃、花窗、玻璃花窗、教堂花窗、哥特花窗、铅条玻璃、泥金手抄本、手抄本、彩饰手抄本、中世纪手稿、羊皮纸、哥特体、花体首字母、泥金、贴金、星盘、达芬奇、达·芬奇、达芬奇手稿、手稿风、文艺复兴手稿、发明手稿、镜像字、镜像书写、扑翼机、红粉笔、钢笔排线、机械草图、分解图、剪影、剪影肖像、侧影、侧面像、黑纸剪影、剪影小像、椭圆金框、乔治时代肖像、摄政时期肖像、凸版印刷、活版印刷、木活字、铅字海报、马戏团海报、复古海报、老海报、19 世纪海报、双色套印、错版、套色错位、木刻插图、构成主义、苏联海报、苏联构成主义、俄国先锋派、罗德琴科风、红黑海报、照片蒙太奇、照片拼贴海报、西里尔字、装饰艺术、装饰风、流线型、流线型海报、1930 年代海报、旅行海报、铁路海报、火车海报、喷枪画、喷笔画、阶梯高楼、射线背景、盖茨比风、黄金时代漫画、老漫画、复古漫画、美漫封面、漫画封面、Ben-Day 网点、本戴点、网点上色、四色印刷、四色错版、新闻纸、对白框、拟声字、1940 年代漫画、波普、波普艺术、波普丝网、沃霍尔风、丝网版画头像、撞色头像、多格重复头像、六宫格撞色头像、ASCII、字符画、字符艺术、文字画、行式打印机、绿条纸、连续打印纸、针孔打印纸、老电脑打印、叠打、低多边形、低面数、低模、多边形风、千禧年 3D、90 年代 3D、复古 3D 游戏、老游戏截图、PS1 风、N64 风、平面着色、线框、游戏 HUD、飞行游戏、穿环、喷漆、模板涂鸦、镂空模板、喷漆模板、模板喷绘、街头涂鸦、街头艺术、墙绘、滴漆、班克西风格、刺绣徽章、徽章、布章、臂章、刺绣贴、绣标、锁边、牛仔外套徽章、户外徽章、营地徽章、弧形条章、蓝图、工程图、施工图、蜡笔画、儿童画、绿屏终端、CRT、显像管、热成像、热像仪、温度图、代尔夫特、荷兰蓝瓷砖、洞穴壁画、史前壁画、赭石、1-bit、黑白画图软件、MacPaint 风、黑绘、古希腊陶瓶、希腊瓶画、铅笔素描、素描、铅笔画、X 光、X 光片、安检图像、橡皮管动画、黑白卡通、老动画、麻胶版画、黑白版画、藏书票、VHS、家庭录像、录像带、扁平插画、扁平风、矢量插画、绘本动画、角色动画、挤压拉伸、圆珠笔、圆珠笔涂鸦、原子笔、页边涂鸦、课本涂鸦、手画棋盘),或 "draw it yourself", "paint with code", "procedural painting", "watercolor / collage / colored pencil / anime / editorial / impasto oil / ukiyo-e / pixel art / clay / claymation / cyanotype / sun print / cross-stitch / embroidery / retro instrument panel / vintage radio / sticker collage / receipt / lab notebook / graph paper / chalkboard / blackboard / cyberpunk / neon city / cartoon / hand-drawn animation / isometric / 2.5D / continuous line / one-line drawing / soft 3D / 3D render / puffy letters / ball pit / shape morph / morphing / newspaper collage / Dada / ransom note / halftone / glassmorphism / aurora gradient / Bauhaus / geometric poster / screen print / synthwave / retrowave / outrun / perler beads / hama beads / artkal / fuse beads / melty beads / pegboard beads / petroglyph / rock art / rock carving / desert varnish / Egyptian tomb painting / ancient Egypt / hieroglyphs / Theban tomb / Roman mosaic / floor mosaic / tesserae / opus vermiculatum / Pompeii mosaic / stained glass / leaded glass / church window / Gothic window / grisaille / illuminated manuscript / medieval manuscript / book of hours / gold leaf / illuminated initial / blackletter / vellum / astrolabe / da Vinci notebook / Leonardo codex / Renaissance sketchbook / mirror writing / iron-gall ink / red chalk / sanguine / ornithopter / exploded view / inventor's sketch / silhouette / silhouette portrait / cut-paper profile / shade portrait / Georgian portrait / Regency portrait / oval gilt frame / letterpress / wood type / playbill / circus poster / Victorian poster / two-colour misregistration / woodcut poster / constructivism / constructivist poster / Soviet avant-garde / Russian avant-garde / Rodchenko style / photomontage poster / art deco / streamline moderne / 1930s travel poster / railway poster / airbrush poster / sunburst rays / Gatsby style / golden age comic / vintage comic book / comic cover / Ben-Day dots / four-color printing / newsprint / speech balloon / pulp cover / pop art / Warhol-style / pop silkscreen / silkscreen portrait / repeated pop portrait grid / ASCII art / text art / typewriter art / line printer / greenbar / fanfold paper / tractor feed / overstrike / printer plot / low poly / low-poly / retro 3D / 90s 3D game / PS1 style / N64 style / software rasterizer / flat shading / affine texture mapping / vertex fog / game HUD / stencil / stencil graffiti / spray paint stencil / street art / drips and overspray / Banksy-style stencil / embroidered patch / embroidery patch / iron-on patch / sew-on patch / merit badge / camp badge / merrow border / rocker patch / denim jacket patches / blueprint / technical drawing / crayon / kid's drawing / CRT terminal / green screen / thermal camera / thermal imaging / Delft tiles / Delft blue / cave painting / ochre / Lascaux-style / 1-bit / MacPaint-style / black-figure / Greek vase / pencil drawing / graphite / X-ray / baggage scanner / rubber hose / 1930s cartoon / linocut / lino print / VHS / home video / flat vector / flat illustration / storybook animation / squash and stretch / ballpoint / biro / ballpoint doodle / margin doodles / hand-drawn board game without an image model" 时使用;也用于需要逐步画出(draw-on)动画的插画。单独说「剪纸」指剪纸拼贴、「刺绣」指十字绣、「丝网印刷 / screen print」指包豪斯几何;「打马赛克」是打码,不是马赛克画风;单说「蓝图」指蓝图工程图,「蓝晒 / 晒图」仍指蓝晒;「铅笔 / 素描」指铅笔素描,「彩铅」指韩国彩铅;「像素」仍指像素风,「1-bit / 黑白画图软件」指 1-bit 早期画图软件;「霓虹」仍指赛博朋克;「喷漆 / 街头涂鸦」仍指喷漆模板涂鸦,「圆珠笔 / 随手涂鸦 / 页边涂鸦」指圆珠笔涂鸦。
+description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型,由 Claude 用代码一笔一笔「画」出图片(程序化绘画)。内置六十种画风:中国水墨、水彩、剪纸拼贴、韩国彩铅、日本动漫、编辑风手绘(Riso)、油画厚涂(梵高式流向笔触+颜料浮雕打光)、浮世绘木版画(晕色、木纹、墨线主版、青海波)、像素风(低分辨率+Bayer 抖动+像素字体)、黏土定格(高度图捏出的彩泥+影棚打光)、蓝晒(普鲁士蓝日光晒图,植物剪影透光)、十字绣(Aida 布十字绣+回针绣+缎面绣+法式结)、复古仪器面板(60 年代收音机/仪器正面:柚木、拉丝铝、旋钮、刻度窗、指示灯)、贴纸拼贴·小票(模切乙烯贴纸、热敏小票、和纸胶带、吊牌、橡皮章)、实验笔记本·贴纸(线圈方格本、铅笔图表、荧光笔、红笔圈、便利贴)、黑板板书(墨绿石板、粉笔颗粒、板擦残影、示意图与公式)、赛博朋克(雨夜霓虹街道、玻璃管霓虹招牌、全息广告、湿路面倒影)、卡通手绘(蓝铅笔稿、毛笔线、错位平涂、赛璐璐阴影、逐帧抖线)、等轴 2.5D(正等轴微缩模型、一个太阳照出三面明暗、悬浮数据卡)、单线画(一根不断开的线一笔画完、唯一点睛色)、柔光 3D(光线追踪的糖果色小球海和鼓鼓的软字、景深)、形变动画(一条轮廓依次变形、洋葱皮残影、缓动曲线)、报刊拼贴(牛皮纸、手撕旧报纸、网点老照片、勒索信拼贴字)、弥散玻璃(弥散渐变、磨砂玻璃卡片界面)、包豪斯几何(三原色几何、丝网印刷海报)、复古 Synthwave(切口落日、霓虹网格、镀铬字、录像带质感)、拼豆(钉板上的熔珠小管、熨烫熔合)、岩画(沙漠漆上凿出的凹坑图形、新旧凿痕、剥落)、古埃及墓室壁画(灰泥墙、红格起稿、分栏叙事、象形文字、剥落)、罗马马赛克(石子与玻璃沿轮廓一排排铺、灰缝、燕尾铭牌)、彩色玻璃花窗(哥特尖拱窗、通体着色玻璃、grisaille 彩绘与银染、铅条、透光)、泥金手抄本(羊皮纸、鹅毛笔哥特体、朱红标题、打磨金箔首字母)、达·芬奇手稿(铁胆墨水、左手排线、红粉笔、镜像手写、机械分解图)、剪影(黑纸剪出的侧影小像、薄金粉、椭圆金框)、凸版印刷海报(木活字、红黑双色错版、木刻插图)、苏联构成主义(红黑两版、斜条与楔形、西里尔大字、网点照片拼贴)、装饰艺术 Art Deco(1930 年代喷枪流线型海报、交替射线、阶梯高楼、金色 Deco 字)、黄金时代漫画(毛笔墨线、Ben-Day 网点、四色错版、新闻纸)、波普丝网(多格撞色平涂 + 错位的照相黑版)、ASCII 字符画(行式打印机、绿条连续纸、叠打)、低多边形(1999 年代 3D:平面着色、仿射贴图、逐顶点雾、15 位色抖动)、喷漆模板涂鸦(混凝土墙上多层卡纸模板喷绘、雾化与滴痕)、刺绣徽章(牛仔布上的机绣徽章:填充绣、缎面绣、锁边)、蓝图工程图(描图墨线晒成蓝底白线)、儿童蜡笔画(小孩在糙纸上的蜡笔涂抹)、绿屏终端 CRT(荧光字符画、扫描线、余辉)、热成像(先画温度场再上伪彩色)、代尔夫特蓝瓷砖(锡釉砖上的钴蓝手绘)、洞穴壁画(火光下的赭石、吹喷手印)、1-bit 早期画图软件(黑白整屏、8×8 图案填充)、古希腊黑绘陶瓶(黑釉剪影、刻线、饰带展开图)、铅笔素描(石墨排线、擦笔、边缘只剩线稿)、X 光片(安检透视、轮廓发亮、伪彩)、1930 年代黑白橡皮管动画(白手套、饼切眼、老胶片)、黑白麻胶版画(刻刀减法、手拓发花、套色错版)、VHS 家庭录像(钨丝灯偏色、色度渗色、REC)、扁平矢量(分层几何色块、七色、层间投影)、绘本角色动画(小角色挤压拉伸的真动画)、圆珠笔涂鸦(蓝红圆珠笔线稿、墨团、彩铅、页边涂鸦)、描图纸叠层(灯箱上的黑线底图 + 一张张单色描图纸叠片:正片叠底、套准十字、定位钉、绘图胶带)。用户说「claude绘图」「用代码画」「你自己画」「不用生图模型画」「程序化绘画」,或点名以上任一画风(含黏土、彩泥、定格动画、蓝晒、晒图、十字绣、刺绣、复古面板、老式收音机、贴纸、小票、收据、手帐拼贴、实验笔记本、方格本、荧光笔、便利贴、黑板、板书、粉笔、赛博朋克、霓虹、雨夜街道、卡通、手绘卡通、逐帧手绘、抖线、等轴、2.5D、微缩模型、单线画、一笔画、线条动画、柔光 3D、3D 渲染、C4D 风、软糖字、小球海、形变、变形动画、报刊拼贴、剪报、达达、勒索信字、网点印刷、弥散渐变、玻璃拟态、毛玻璃、包豪斯、几何构成、丝网印刷、Synthwave、蒸汽波、合成器浪潮、80 年代复古、拼豆、拼拼豆、熔珠、熨豆、豆豆画、钉板、烫豆、岩画、岩刻、凿刻、石刻、沙漠漆、史前壁刻、大角羊、古埃及、埃及壁画、墓室壁画、法老时代、象形文字、尼罗河、底比斯、罗马马赛克、马赛克镶嵌、镶嵌画、石子拼画、地砖画、古罗马地板、彩色玻璃、彩绘玻璃、花窗、玻璃花窗、教堂花窗、哥特花窗、铅条玻璃、泥金手抄本、手抄本、彩饰手抄本、中世纪手稿、羊皮纸、哥特体、花体首字母、泥金、贴金、星盘、达芬奇、达·芬奇、达芬奇手稿、手稿风、文艺复兴手稿、发明手稿、镜像字、镜像书写、扑翼机、红粉笔、钢笔排线、机械草图、分解图、剪影、剪影肖像、侧影、侧面像、黑纸剪影、剪影小像、椭圆金框、乔治时代肖像、摄政时期肖像、凸版印刷、活版印刷、木活字、铅字海报、马戏团海报、复古海报、老海报、19 世纪海报、双色套印、错版、套色错位、木刻插图、构成主义、苏联海报、苏联构成主义、俄国先锋派、罗德琴科风、红黑海报、照片蒙太奇、照片拼贴海报、西里尔字、装饰艺术、装饰风、流线型、流线型海报、1930 年代海报、旅行海报、铁路海报、火车海报、喷枪画、喷笔画、阶梯高楼、射线背景、盖茨比风、黄金时代漫画、老漫画、复古漫画、美漫封面、漫画封面、Ben-Day 网点、本戴点、网点上色、四色印刷、四色错版、新闻纸、对白框、拟声字、1940 年代漫画、波普、波普艺术、波普丝网、沃霍尔风、丝网版画头像、撞色头像、多格重复头像、六宫格撞色头像、ASCII、字符画、字符艺术、文字画、行式打印机、绿条纸、连续打印纸、针孔打印纸、老电脑打印、叠打、低多边形、低面数、低模、多边形风、千禧年 3D、90 年代 3D、复古 3D 游戏、老游戏截图、PS1 风、N64 风、平面着色、线框、游戏 HUD、飞行游戏、穿环、喷漆、模板涂鸦、镂空模板、喷漆模板、模板喷绘、街头涂鸦、街头艺术、墙绘、滴漆、班克西风格、刺绣徽章、徽章、布章、臂章、刺绣贴、绣标、锁边、牛仔外套徽章、户外徽章、营地徽章、弧形条章、蓝图、工程图、施工图、蜡笔画、儿童画、绿屏终端、CRT、显像管、热成像、热像仪、温度图、代尔夫特、荷兰蓝瓷砖、洞穴壁画、史前壁画、赭石、1-bit、黑白画图软件、MacPaint 风、黑绘、古希腊陶瓶、希腊瓶画、铅笔素描、素描、铅笔画、X 光、X 光片、安检图像、橡皮管动画、黑白卡通、老动画、麻胶版画、黑白版画、藏书票、VHS、家庭录像、录像带、扁平插画、扁平风、矢量插画、绘本动画、角色动画、挤压拉伸、圆珠笔、圆珠笔涂鸦、原子笔、页边涂鸦、课本涂鸦、手画棋盘、描图纸、硫酸纸、叠片、叠层、分色片、灯箱、拷贝台、透光台、套准、定位钉),或 "draw it yourself", "paint with code", "procedural painting", "watercolor / collage / colored pencil / anime / editorial / impasto oil / ukiyo-e / pixel art / clay / claymation / cyanotype / sun print / cross-stitch / embroidery / retro instrument panel / vintage radio / sticker collage / receipt / lab notebook / graph paper / chalkboard / blackboard / cyberpunk / neon city / cartoon / hand-drawn animation / isometric / 2.5D / continuous line / one-line drawing / soft 3D / 3D render / puffy letters / ball pit / shape morph / morphing / newspaper collage / Dada / ransom note / halftone / glassmorphism / aurora gradient / Bauhaus / geometric poster / screen print / synthwave / retrowave / outrun / perler beads / hama beads / artkal / fuse beads / melty beads / pegboard beads / petroglyph / rock art / rock carving / desert varnish / Egyptian tomb painting / ancient Egypt / hieroglyphs / Theban tomb / Roman mosaic / floor mosaic / tesserae / opus vermiculatum / Pompeii mosaic / stained glass / leaded glass / church window / Gothic window / grisaille / illuminated manuscript / medieval manuscript / book of hours / gold leaf / illuminated initial / blackletter / vellum / astrolabe / da Vinci notebook / Leonardo codex / Renaissance sketchbook / mirror writing / iron-gall ink / red chalk / sanguine / ornithopter / exploded view / inventor's sketch / silhouette / silhouette portrait / cut-paper profile / shade portrait / Georgian portrait / Regency portrait / oval gilt frame / letterpress / wood type / playbill / circus poster / Victorian poster / two-colour misregistration / woodcut poster / constructivism / constructivist poster / Soviet avant-garde / Russian avant-garde / Rodchenko style / photomontage poster / art deco / streamline moderne / 1930s travel poster / railway poster / airbrush poster / sunburst rays / Gatsby style / golden age comic / vintage comic book / comic cover / Ben-Day dots / four-color printing / newsprint / speech balloon / pulp cover / pop art / Warhol-style / pop silkscreen / silkscreen portrait / repeated pop portrait grid / ASCII art / text art / typewriter art / line printer / greenbar / fanfold paper / tractor feed / overstrike / printer plot / low poly / low-poly / retro 3D / 90s 3D game / PS1 style / N64 style / software rasterizer / flat shading / affine texture mapping / vertex fog / game HUD / stencil / stencil graffiti / spray paint stencil / street art / drips and overspray / Banksy-style stencil / embroidered patch / embroidery patch / iron-on patch / sew-on patch / merit badge / camp badge / merrow border / rocker patch / denim jacket patches / blueprint / technical drawing / crayon / kid's drawing / CRT terminal / green screen / thermal camera / thermal imaging / Delft tiles / Delft blue / cave painting / ochre / Lascaux-style / 1-bit / MacPaint-style / black-figure / Greek vase / pencil drawing / graphite / X-ray / baggage scanner / rubber hose / 1930s cartoon / linocut / lino print / VHS / home video / flat vector / flat illustration / storybook animation / squash and stretch / ballpoint / biro / ballpoint doodle / margin doodles / hand-drawn board game / overlay sheets / tracing-paper overlays / light box / colour separations / registration marks / acetate overlay without an image model" 时使用;也用于需要逐步画出(draw-on)动画的插画。单独说「剪纸」指剪纸拼贴、「刺绣」指十字绣、「丝网印刷 / screen print」指包豪斯几何;「打马赛克」是打码,不是马赛克画风;单说「蓝图」指蓝图工程图,「蓝晒 / 晒图」仍指蓝晒;「铅笔 / 素描」指铅笔素描,「彩铅」指韩国彩铅;「像素」仍指像素风,「1-bit / 黑白画图软件」指 1-bit 早期画图软件;「霓虹」仍指赛博朋克;「喷漆 / 街头涂鸦」仍指喷漆模板涂鸦,「圆珠笔 / 随手涂鸦 / 页边涂鸦」指圆珠笔涂鸦;「描图纸 / 硫酸纸 / 叠片 / 灯箱」指描图纸叠层(蓝图工程图那张描图布是晒成蓝图的,不是叠片)。
---
# Claude 绘图
@@ -73,6 +73,7 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型
| 扁平矢量 | `lib/flatvector.py` · `FlatVector` | `examples/flatvector_night_camp.py` 山间夜营(七色限定色板,无描边的大块几何形一层层叠起来,层与层之间一道柔和投影,加极细颗粒;夜蓝天空里一轮带橙色光芒的月亮,紫色雪山分出亮面和折线暗面,品红、橙色两种山丘带,黄沙地;下午插在山顶的小旗下,一条虚线小路走之字形下山、穿过山丘,尽头是戴头灯走最后一段路的小小背包客;营地已经亮了:橙色 A 字帐篷门口透出光,篝火的光在沙地上铺成一圈圈平涂光环;几何松树、圆冠树、两朵平底云、一颗流星) | 约 1 秒 |
| 绘本角色动画 | `lib/storybook.py` · `Storybook` | `examples/storybook_acorn.py` 小橡果的秋天(真动画 + 旅程总图:米色纸上,枝头打盹的小橡果被晃醒、拉长掉下、落地压扁再弹起,追着一片红橡叶滚下山坡,山坡、小花、远山随它经过一笔笔画出来;跳上漂在小河上的橡叶,撞岸后空翻上岸,钻进土里发芽长成一棵还戴着橡果帽的小橡树;最后「hello, little oak」按笔顺写出来,彩纸屑飞起。总图把六个关键姿态多次曝光在铅笔运动弧上;加 `--gif out.gif` 出 15 fps 的真动画) | 约 1 秒(总图)/ 约 3 秒(151 帧动图) |
| 圆珠笔涂鸦 | `lib/ballpoint.py` · `Ballpoint` | `examples/ballpoint_board_game.py` 蛇梯棋大冒险 · Snakes & Ladders, Round 7(午休时在复印纸上用蓝、红、黑三支圆珠笔画的 8×8 蛇梯棋,彩铅一行行涂成彩虹色格子;一局正在进行:骰子刚从页边弹过来、掷出 4,蜗牛从 10 跳四格到 14(红笔虚线弧标出 1-2-3-4),正顺着长梯子爬到 38(红圈、虚线箭头、+24!),小云从 47 被绿蛇滑下去,晕乎乎地喊 nooo~,骰子怪在 51 捂着脸;页边是彩旗、太阳、井字棋、纸飞机、星星串、山坡小房子、花盆,吐槽小纸条「who drew this snake so LONG?!」、记分卡、把 three 划掉改成 four、红笔结论 slow snail, fast ladder!;右下角还有上一页购物单压过来的无墨压痕) | 约 4 秒 |
+| 描图纸叠层 | `lib/overlay.py` · `Overlay` | `examples/overlay_city_map.py` 海港步行图 · Larkhaven on Foot(暖白灯箱上,定位钉挂着一张黑线灰调的海边小城底图:递归切出的街区、沿街一圈房屋和分户墙、深色地标、海岸与防波堤、铁路、城堡山和岬角的等高线;三张单色叠片对着套准十字落下——蓝片(沿岸一圈圈水线、河、港湾、渡轮航线、2 路电车)、黄片(公园、集市广场、海滩)、品红片(六站步行路线,坐渡轮去灯塔);不同叠片的油墨正片叠底:植物园的池塘叠成绿、路线压过公园成红、压过海面成紫;描图纸背光下的纤维云纹、卷角、打孔、绘图胶带,旁边一张透明胶片上的图例卡) | 约 7 秒 |
各画风共用 `lib/core.py` 里的底层工具:噪声、模糊、样条曲线、多边形遮罩、有机轮廓 `blob_pts`、毛笔 `bristle_stroke`、中文字体查找;新四种还用到补零平移 `shift`、文字遮罩 `text_mask`、西文字体查找 `latin_font`/`load_font`,以及高度图打光 `height_normals`、`height_shadow`(沿光线步进的投影)、`ambient_occlusion`。
@@ -135,7 +136,8 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型
- 家庭回忆、怀旧、「当年的那一天」(生日、过年、毕业、第一次……)、童年和老房子、found footage 式的悬念开场、讲解片里的「回到 80 年代 / 那时候的家 / 老录像里的证据」页 → VHS 家庭录像(要霓虹落日的 80 年代复古未来用复古 Synthwave;要老照片和剪报用报刊拼贴;要屏幕上的字符用 ASCII 字符画);
- 风景、户外、旅行与露营、MG 动画式的场景背景和转场、讲解片的「场景 / 旅程 / 夜晚」页、要干净现代又有层次的插画 → 扁平矢量(要撕纸边和蜡笔的手作感用剪纸拼贴;要正等轴的微缩模型用等轴 2.5D;要 80 年代霓虹用复古 Synthwave);
- 要「真的动起来」的小故事、一个可爱小角色的旅程或成长(从 A 到 B、出发—遇到—到达)、讲解片的片头片尾和转场、品牌吉祥物小动画、「一路走一路画出来」的过程感 → 绘本角色动画(`Storybook.gif()` 出真动画,`journey()` 出一张旅程总图;只要一条轮廓的变形用形变动画;要逐帧抖线的静态卡通插画用卡通手绘);
-- 上课 / 午休走神的随手涂鸦、纸上正在进行的游戏或计划(手画棋盘、寻宝图、清单、路线、比分)、学生和办公室日常的轻松小故事、讲解片里「在草稿纸上推演一步」的页 → 圆珠笔涂鸦(要铅笔图表、荧光笔和贴纸的实验记录用实验笔记本;要没有线稿、柔和的彩铅小物用韩国彩铅;要小孩的蜡笔画用儿童蜡笔画;要黑白石墨写生用铅笔素描)。
+- 上课 / 午休走神的随手涂鸦、纸上正在进行的游戏或计划(手画棋盘、寻宝图、清单、路线、比分)、学生和办公室日常的轻松小故事、讲解片里「在草稿纸上推演一步」的页 → 圆珠笔涂鸦(要铅笔图表、荧光笔和贴纸的实验记录用实验笔记本;要没有线稿、柔和的彩铅小物用韩国彩铅;要小孩的蜡笔画用儿童蜡笔画;要黑白石墨写生用铅笔素描);
+- 地图、路线与导览、城市 / 园区 / 校园平面图,「一层一层把信息加上去」的图解(底图 → 水系 → 绿地 → 路线),设计稿或方案的分层、叠加与对照,讲解片里「把几层信息叠起来看」的页 → 描图纸叠层(要正等轴的微缩模型用等轴 2.5D;要剖面、尺寸和施工说明用蓝图工程图;要三原色丝网海报用包豪斯几何)。
每种画风一幅范例作为质量基准(范例都不用禅意主题);水墨另加一幅「月印万川」(留白托月、水面倒影)。
@@ -953,6 +955,15 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask
- 遮罩和点:`poly(pts)`、`ellipse(cx, cy, rx, ry, rot)`、`band(pts, width)`、`tube(pts, w0, w1)` 由粗到细的身体(蛇、尾巴),`Ballpoint.tube_sides(pts, w0, w1)` 它的左右两条边(一笔描下去绕过尾尖再描回来);`circle_pts`、`star_pts`、`cloud_pts(cx, cy, w, h, bumps, seed, flat)`、`spiral_pts(cx, cy, r, turns, a0)`、`heart_pts`、`Ballpoint.resample(pts, step)`
- `stage(name)`、`save(path, stages_dir)`;`save('x.jpg')` 默认 quality 88、4:4:4;常量 `PENS PENCILS PAPER`;字体可用 `INKPAINT_FONT_BALLPOINT` / `INKPAINT_FONT_BALLPOINT_CJK` 指定(默认 macOS Noteworthy Light / 黑体-简 细体,Linux Kalam / Caveat / Noto Sans CJK,Windows Segoe Print / 微软雅黑)
+**描图纸叠层 `Overlay`**:
+- 思路:透光台上的分色叠片。灯箱从下面打暖白光,画面就是一路透过率相乘:底图(胶版纸)印黑线和灰调,上面每张描图纸 / 胶片只印一种油墨。油墨按网点覆盖率 c 算透过率(c ≤ 1 是平网 1 − c(1 − ink),c > 1 是叠印加深 ink^(c−1));不同叠片之间正片叠底,蓝叠黄成绿、品红叠黄成红、蓝叠品红成紫;同一块版自己不叠加(取最大覆盖率)。每张纸有自己的纸色、只有背光下才看得见的云状纤维(formation)、零星纤维丝、裁切边的一道细暗线和打孔;描图纸平放时也让下面的暗部略微发灰(frost)。抬起的纸略放大、往右下投一片宽而软的暖色阴影(透过纸也看得见),而且它是离开画面的漫射片,会把下面的一切模糊掉;放下后清晰,阴影收成一条贴边细线,套准十字落在底图的十字上
+- 构造:`Overlay(W, H, seed, keep_stages=True)`;`desk(colour)`、`lightbox(x0, y0, x1, y1, radius, bezel)`、`lamp(level)`(0 关灯:灰色乳白亚克力;1 开灯:暖白,中间偏左最亮;中间值又暗又偏暖);`peg_bar(x0, x1, y0, y1, pegs=[('round', x, y, r), ('slot', x, y, w, h)])` 定位钉条(不透明的钢条,画在所有纸下面,纸上的孔里露出钉子和一圈透光缝)
+- 纸:`sheet(x, y, w, h, kind='base'|'tracing'|'drafting'|'film', ink, tint, fibre, curl=('br', 70), edge)` 返回 `Sheet`。坐标一律是**纸放下时的画布坐标**,所以几张叠片用同一组点画,自动套准。`place(sheet, lift, dx, dy, rot)` 显示、抬起(lift 0–1,偏 dx / dy 像素、转 rot 度)或放下(全 0);第一次 `place` 决定叠放顺序;`remove(sheet)`;`tape(cx, cy, w, h, rot)` 撕口的皱纹绘图胶带,压在最上面、半透光
+- 在纸上印:`fill(遮罩或多边形, cover, ink)`;`line(pts, width, cover, ink, closed, smooth, dash=(实, 虚))`、`lines(paths, …)` 一批线一次栅格化;`dots`、`circle(cx, cy, r, width=None)`、`hatch(mask, spacing, angle)`、`stipple(mask, n, r)`;`text(s, x, y, size, font_kind, cover, ink, anchor, spacing, rot, halo, knock)`:halo 先清掉字周围的墨,knock 把字从墨里反白掏出(实心圆里的站点编号);`knock(mask)`、`cross(x, y)` 套准十字、`arrow(tip, direction, size)`、`punch(x, y, r)` / `punch_slot(x, y, w, h)` 打孔
+- 遮罩(画布大小):`poly(pts, smooth)`、`circle`、`ellipse`、`rrect`、`band(pts, width)`;`edge(mask, width)` 轮廓线、`offset(mask, d)` 外扩 / 内缩、`contour(mask, d, width)` 离边 d 像素的一圈线(海岸水线)、`Overlay.inset(凸多边形, d)` 街区从街道往里缩、`circle_pts`
+- 字体 `font(kind, size)`:map / map_bold / map_heavy / map_italic / map_light(Gill Sans 一族)、title(Avenir Next Heavy)、label、cjk / cjk_light(黑体),也认 core 的样式名;可用 `INKPAINT_FONT_OVERLAY_<KIND>` 指定
+- 常量 `INKS`(black blue yellow magenta cyan orange green red)、`PAPERS`;`stage(name)`、`save(path, stages_dir)`;`save('x.jpg')` 默认 quality 88、4:4:4 色度
+
**顺序**:都是先远后近、先大后小,文字最后叠加。水墨的雾要画在它该吞没的东西之后;水彩的叶梗要先画,并且只画在叶子外面。
## 三、毛病清单(都真实出现过)
@@ -1876,6 +1887,22 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask
| 墨线旁边的压痕亮边太抢、像浮雕 | 压痕打光增益 0.16 → 0.13,上限 ±0.1 |
| 动图里蛇和格子的彩铅颜色被量化成土褐色 | 两段调色板:150 色从「有色像素 ×5」的样本里中值切分,另外 104 色只从有色像素(饱和度 > 0.12)里切;49 帧约 0.6 MB |
+**描图纸叠层**
+
+| 问题 | 改法 |
+|---|---|
+| 三张描图纸叠在一起,整张图发灰发脏,背光纤维像大理石纹 | 描图纸透过率 0.955 → 0.98,云纹幅度 5% → 2%、尺度改细(6 / 22 px);底图纸的云纹只留 1% |
+| 抬起的纸下面糊成一片、整块发暗 | 漫射模糊 σ 5.5 → 2.8 px(描图纸),阴影不透明度 0.30 → 0.22,落在纸下面的那部分阴影再减半(室内光还能透过纸照下来) |
+| 胶带像一块灰色塑料片 | 胶带是皱纹纸:一半透光、一半反射室内光(I·T·0.58 + T·0.36),颜色用暖奶油 `#f7ebcf`,皱纹和纤维只压暗 3–4% |
+| 胶带贴在黄色公园上,成了一块橄榄色斑 | 胶带别贴在色块上:挪到纸边经过街区的地方,或者换个角 |
+| 卷角成了一条灰色斜带,像脏印子 | 阴影带收窄(0.11R、只暗 7%),加一道折痕高光;卷角只放在空白页边,蓝片那个落在叠层最密处的卷角干脆不要 |
+| 站点圆里的反白数字看不清 | 反白就是「露出下面一层」:站点压在深色地标(车站、集市楼、城堡、灯塔)上,数字就变成深灰。把站点挪到浅色街道、公园或水面上 |
+| 步行路线和电车线在同一条路上叠成一条紫黑线 | 同一条路上分道走:电车偏左 4 px,步行偏右 6 px |
+| 电车线从路名「STATION ROAD」上穿过去 | 把路名放到别的路上,或者删掉 |
+| 公园和马路之间剩下 8–15 px 的细条街区,像一串虚线 | 递归切分的叶子块,按短轴厚度(3.46 × 短轴标准差)小于 12 px 就丢掉,留成空地 |
+| 动图 5.1 MB:每落下一张纸,整片带纹理的区域都重新编码 | 见第四节:只重发明显变化的像素,开灯的叠化帧不加抖动;1.9 MB |
+| 跳过小变化以后,灯箱渐变和海面上出现一圈圈等高线似的色斑 | 差值拆成平滑分量(模糊 2 px)和细节残差分开判断;停 900 毫秒的关键帧把平滑分量追到 3 级以内;开灯那几帧逐像素精确发送 |
+
## 四、做成动画
- 各画风都有 `stage(name)` 和 `save(path, stages_dir)`,按阶段依次淡入叠化,就是「一幅画被逐步画出来」。README 里的动图就是这样做的。
@@ -1895,6 +1922,7 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask
- 这一批十五种(蓝图工程图到绘本角色动画)又多了几条:
- 满屏几乎一种色调(X 光片的蓝胶片)时,补几个色位不够:按「主色调像素 / 其余彩色像素」两段分别中值切分(186 + 69 色);OSD 里必须精确的纯白、纯黑、REC 红这类颜色直接强制占色位(热成像、VHS 家庭录像),否则白字被量化成淡黄。
- 大块色层整片交接的叠化(扁平矢量的夜蓝 → 橙 → 沙):调色板样本里加上 1/3、2/3 两张叠化帧,Bayer 只叠在两张关键帧不同的地方(整帧都叠更大;Floyd–Steinberg 更大,还会抖出透明占位色)。只有黑白两值的画风(1-bit 早期画图软件)缩小用 BOX、配固定灰阶调色板,不做中值切分。
+- 描图纸叠层的动图(脚本在 `claude_drawing/overlay_work/make_gif_overlay.py`):阶段是 关灯 → 灯变暖 → 开灯 → 底图 → 每张叠片「抬起、偏着」→「放下」→ 胶片图例卡 → 贴胶带。一张纸落下,会让一大片带纹理的区域整体变几级、线条由糊变清,逐帧精确差分要 3–5 MB。做法:目标和屏上已显示颜色的差值拆成平滑分量(模糊 2 px)和细节残差,平滑分量超过阈值(叠化帧 12 级、关键帧 3 级)或单点超过阈值(30 / 16 级)才重发,只有单点超阈值的孤立像素(纸纹在阈值上下翻动)不发;开灯那几帧逐像素精确发送,其中的叠化帧不加抖动(加了每帧每个像素都变);最后一帧收紧阈值追平。73 帧约 1.9 MB,按解码结果逐帧自检。
- 绘本角色动画的动图是真动画,不是阶段叠化:`Storybook.gif()` 按时间逐帧渲染,720×405、15 fps(GIF 延时只能写厘秒,按累计取整写成 7、7、6 厘秒交替),共用一张加权调色板 + 固定 4×4 Bayer,没变的像素记成品红透明,151 帧(动作 9.95 秒 + 末帧停 1.4 秒)约 0.56 MB;范例加 `--gif out.gif` 出这张,`--stages` 的关键帧仍可喂给上面的阶段动图工具。
- 形变动画可以直接出真动画:`Morph.at(keys, T)` 给出全局时间 T 的轮廓,逐帧渲染即可。
- 更细的逐笔动画:把一组笔画单独画到透明层上导出,再用 Motion Canvas 遮罩按顺序显现。这个还没做成现成接口。
@@ -1962,6 +1990,7 @@ lib/vhs.py VHS 家庭录像(70 年代客厅:反照率 × 灯光
lib/flatvector.py 扁平矢量(分层几何色块、七色限定色板、层间柔和投影、细颗粒)
lib/storybook.py 绘本角色动画(按时间取帧:带揭示图的场景层、follow 边走边画、隐式曲面角色挤压拉伸、动作编排、特效、按骨架笔顺手写、旅程总图)
lib/ballpoint.py 圆珠笔涂鸦(复印纸纹、纤维与折痕;圆珠笔:干起笔、压力线宽、断墨、墨团、收笔小钩、描两遍、压痕;彩铅斜向排线出界;圆珠笔之字排线;字体骨架重描的手写、划掉重写、无墨压痕字)
+lib/overlay.py 描图纸叠层(灯箱发光、黑线灰调底图与单色叠片、透过率相乘的油墨、背光纤维云纹、抬起时的漫射模糊与投影、卷角、打孔与定位钉、套准十字、绘图胶带、透明胶片)
examples/*.py 范例脚本;*.jpg 成品;drawing_*.gif 逐步画出的动图
中文字体:自动找 Kaiti/Songti(macOS)、Noto CJK(Linux)、KaiTi/SimSun(Windows),或设 INKPAINT_FONT
西文字体(后来新增的画风用):core.latin_font(style) 按 sans / sans_bold / rounded / script / hand / typewriter 等找系统字体,可用 INKPAINT_FONT_<STYLE> 指定;字体文件不要放进仓库
diff --git a/examples/drawing_overlay_city_map.gif b/examples/drawing_overlay_city_map.gif
new file mode 100644
index 0000000..5628edc
Binary files /dev/null and b/examples/drawing_overlay_city_map.gif differ
diff --git a/examples/overlay_city_map.jpg b/examples/overlay_city_map.jpg
new file mode 100644
index 0000000..58591dd
Binary files /dev/null and b/examples/overlay_city_map.jpg differ
diff --git a/examples/overlay_city_map.py b/examples/overlay_city_map.py
new file mode 100644
index 0000000..e52f862
--- /dev/null
+++ b/examples/overlay_city_map.py
@@ -0,0 +1,441 @@
+"""Example (overlay sheets): Larkhaven on Foot / 海港步行图 — a coastal town plan built as separations on a light
+box. The base sheet hangs on a peg bar: the town in black linework with grey flat tones (blocks cut out by
+recursive street splits, buildings round each block with party walls, landmarks in a darker tone, the coast,
+breakwaters, a railway, contours on Castle Hill and the headland). Three translucent sheets, one ink each, come
+down on their registration crosses: blue (the sea water-lined round the coast, the river, the harbour, the ferry
+across the bay and tram line 2), yellow (the parks, the market squares, the beach) and magenta (a walking route
+with six numbered stops that takes the ferry to the lighthouse). The inks multiply where they cross: the pond in
+the botanic garden turns green, the route goes red across the parks and violet across the water. A legend card on
+clear film sits beside the map. No image model.
+python3 overlay_city_map.py [out.jpg] [--stages DIR]
+"""
+import os, sys, time
+sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'lib'))
+import numpy as np
+from overlay import Overlay
+from core import spline, blur, blob_pts
+
+out = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith('--') else 'overlay_city_map.jpg'
+stages = sys.argv[sys.argv.index('--stages') + 1] if '--stages' in sys.argv else None
+T0 = time.time()
+tick = lambda name: print(f'{name:16s} {time.time() - T0:5.1f}s') if os.environ.get('OVERLAY_TIMING') else None
+
+W, H = 1920, 1080
+o = Overlay(W, H, seed=11, keep_stages=bool(stages))
+rng = np.random.default_rng(5)
+o.desk()
+o.lightbox(34, 24, 1886, 1056)
+
+# ===================================================================== layout
+SX0, SY0, SW, SH = 86, 86, 1180, 905 # base sheet (laid down)
+FX0, FY0, FX1, FY1 = 136, 140, 1216, 922 # map frame
+PEG_Y = 98
+PEGS = [('round', 476, PEG_Y, 8), ('slot', 676, PEG_Y, 60, 14), ('round', 876, PEG_Y, 8)]
+CROSS = dict(L1=(111, 250), L2=(111, 800), R1=(1241, 250), R2=(1241, 800), B1=(330, 958), B2=(1020, 958))
+o.peg_bar(436, 916, 56, 86, PEGS)
+frame = o.rrect(FX0, FY0, FX1, FY1)
+
+
+def S(pts, per=10):
+ return spline(np.asarray(pts, np.float32), per)
+
+
+def tube(pts, w0, w1, per=12):
+ """a mask of varying width along a spline (the river)"""
+ P = S(pts, per)
+ seg = np.linalg.norm(np.diff(P, axis=0), axis=1); s = np.concatenate([[0], np.cumsum(seg)])
+ t = np.arange(0, s[-1], 1.5)
+ x, y = np.interp(t, s, P[:, 0]), np.interp(t, s, P[:, 1])
+ r = (w0 + (w1 - w0) * t / s[-1]) / 2
+ m = np.zeros((H, W), np.float32)
+ for xi, yi, ri in zip(x, y, r):
+ x0, x1, y0, y1 = int(xi - ri - 2), int(xi + ri + 3), int(yi - ri - 2), int(yi + ri + 3)
+ Y, X = np.mgrid[y0:y1, x0:x1]
+ np.maximum(m[y0:y1, x0:x1], np.clip(ri - np.hypot(X - xi, Y - yi) + 0.5, 0, 1), out=m[y0:y1, x0:x1])
+ return m, P
+
+
+# ===================================================================== geography
+COAST = [(FX0 - 4, 762), (190, 774), (262, 790), (330, 786), (392, 764), (436, 740), (468, 706), (482, 660), (500, 634),
+ (548, 626), (612, 624), (668, 630), (704, 648), (716, 690), (742, 736), (800, 752), (880, 744), (948, 724),
+ (996, 706), (1008, 752), (1026, 816), (1056, 862), (1094, 864), (1118, 826), (1128, 760), (1152, 708),
+ (1186, 680), (FX1 + 4, 668)]
+coast = S(COAST, 8)
+land = o.poly(np.vstack([[(FX0 - 4, FY0 - 4), (FX1 + 4, FY0 - 4)], coast[::-1]]))
+breakw = np.maximum(o.band(S([(450, 724), (480, 768), (528, 798), (588, 810)]), 13),
+ o.band(S([(744, 738), (724, 782), (686, 806), (640, 812)]), 13))
+jetty = o.band([(1006, 792), (968, 812)], 9)
+land = np.maximum(land, np.maximum(breakw, jetty)) * frame
+river, RIV = tube([(566, FY0 - 6), (586, 206), (566, 264), (534, 322), (526, 382), (552, 442), (594, 500), (590, 560),
+ (562, 604), (552, 640)], 15, 30)
+river *= frame
+land = np.clip(land - river, 0, 1)
+sea = np.clip(frame - land - river, 0, 1)
+water = np.clip(sea + river, 0, 1)
+tick('geography')
+
+# ---- main roads (white bands carved out of the blocks), parks and squares
+ROADS = dict(
+ station_rd=([(772, 214), (770, 300), (766, 380), (762, 428), (742, 500), (712, 566), (700, 612)], 16),
+ high_st=([(526, 384), (612, 394), (700, 412), (770, 428), (858, 414), (960, 394), (1060, 386), (FX1 + 6, 378)], 16),
+ west_rd=([(526, 384), (468, 404), (410, 448), (330, 494), (240, 516), (FX0 - 6, 528)], 15),
+ mill_rd=([(FX0 - 6, 262), (260, 266), (400, 252), (520, 236), (586, 232), (680, 236), (770, 236)], 14),
+ quay_rd=([(478, 612), (560, 610), (640, 612), (716, 618)], 14),
+ west_quay=([(478, 612), (470, 650), (458, 690), (446, 724)], 11),
+ east_quay=([(716, 618), (722, 668), (738, 714), (750, 734)], 11),
+ promenade=([(748, 728), (820, 730), (900, 716), (960, 700), (1000, 688), (1040, 640), (1092, 560), (1150, 512), (FX1 + 6, 486)], 14),
+ north_rd=([(860, 414), (880, 330), (930, 250), (1000, 196), (1060, FY0 - 6)], 13),
+ east_rd=([(1060, 386), (1080, 470), (1100, 552)], 12),
+ castle_rd=([(410, 448), (430, 360), (470, 300), (520, 236)], 11),
+ lane_lh=([(1004, 694), (1022, 760), (1046, 820), (1060, 848)], 8),
+)
+road = np.zeros((H, W), np.float32)
+for pts, w in ROADS.values():
+ road = np.maximum(road, o.band(S(pts), w))
+RAIL = S([(836, 186), (930, 176), (1040, 164), (1140, 152), (FX1 + 6, 146)])
+rail = o.band(RAIL, 13)
+CASTLE_HILL = blob_pts(300, 392, 116, 84, rough=0.07, seed=3)
+park_castle = o.poly(CASTLE_HILL, smooth=True)
+park_botanic = o.poly([(170, 160), (420, 158), (436, 186), (430, 236), (300, 244), (172, 240)], smooth=True)
+park_river = o.poly([(604, 452), (628, 470), (636, 520), (622, 556), (600, 548), (604, 506), (588, 470)], smooth=True)
+park_head = o.poly([(1006, 712), (1046, 700), (1104, 694), (1124, 760), (1100, 840), (1062, 850), (1030, 800)], smooth=True) * land
+sq_market = o.poly([(732, 446), (812, 440), (820, 498), (740, 508)])
+sq_church = o.poly([(880, 432), (928, 428), (934, 470), (884, 474)])
+beach = np.clip(o.offset(sea, 20) - sea, 0, 1) * land * (o.poly([(744, 700), (1000, 680), (1000, 800), (744, 800)]))
+open_space = np.clip(park_castle + park_botanic + park_river + park_head + sq_market + sq_church + beach, 0, 1)
+tick('roads/parks')
+
+# ---- blocks: recursive street splits inside each district
+def subdivide(m, oy, ox, gaps, max_area, jitter, depth, blocks, splits):
+ area = float(m.sum())
+ if area < 160: return
+ ys, xs = np.nonzero(m > 0.5)
+ if len(xs) < 20: return
+ cx, cy = xs.mean(), ys.mean()
+ ev, V = np.linalg.eigh(np.cov(np.stack([xs, ys])))
+ if 3.46 * np.sqrt(max(ev[0], 0)) < 12: return # a sliver between a street and a park: leave it open
+ if area < max_area * rng.uniform(0.6, 1.4) or depth > 10:
+ blocks.append((m, oy, ox)); return
+ ax = V[:, 1]
+ a = np.arctan2(ax[1], ax[0]) + rng.normal(0, jitter)
+ ax = np.array([np.cos(a), np.sin(a)])
+ proj = (xs - cx) * ax[0] + (ys - cy) * ax[1]
+ t = np.quantile(proj, rng.uniform(0.38, 0.62))
+ px, py = cx + ax[0] * t, cy + ax[1] * t
+ Y, X = np.mgrid[0:m.shape[0], 0:m.shape[1]].astype(np.float32)
+ sd = (X - px) * ax[0] + (Y - py) * ax[1]
+ g = gaps[min(depth, len(gaps) - 1)]
+ splits.append((ox + px, oy + py, -ax[1], ax[0], g, m.shape, oy, ox))
+ for part in (m * np.clip(sd - g / 2 + 0.5, 0, 1), m * np.clip(-sd - g / 2 + 0.5, 0, 1)):
+ yy, xx = np.nonzero(part > 0.02)
+ if not len(xx): continue
+ y0, y1, x0, x1 = yy.min(), yy.max() + 1, xx.min(), xx.max() + 1
+ subdivide(part[y0:y1, x0:x1], oy + y0, ox + x0, gaps, max_area, jitter, depth + 1, blocks, splits)
+
+
+buildable = land * (1 - np.clip(road + rail + open_space + o.offset(river, 7) - river, 0, 1))
+buildable = np.clip(buildable - np.clip(o.offset(water, 9) - water, 0, 1), 0, 1) # a quay / embankment strip along the water
+DISTRICTS = [ # polygon, street gaps by depth, max block area, angle jitter
+ ([(586, 236), (770, 236), (860, 414), (1060, 386), (1100, 552), (1000, 688), (716, 618), (560, 610), (600, 500), (560, 400)], (11, 9, 7, 6), 3600, 0.20),
+ ([(FX0, 262), (526, 236), (526, 384), (468, 404), (330, 494), (FX0, 528)], (10, 8, 6), 4200, 0.12),
+ ([(FX0, 528), (330, 494), (468, 404), (526, 384), (560, 400), (560, 610), (446, 724), (FX0, 770)], (10, 8, 7, 6), 3600, 0.18),
+ ([(586, 236), (770, 236), (770, FY0), (586, FY0)], (10, 8), 5200, 0.1),
+ ([(770, 236), (860, 414), (1060, 386), (FX1, 378), (FX1, FY0), (770, FY0)], (11, 9, 7), 5600, 0.10),
+ ([(1100, 552), (1060, 386), (FX1, 378), (FX1, 486), (1150, 512)], (9, 7), 4200, 0.12),
+ ([(1040, 640), (1092, 560), (1150, 512), (FX1, 486), (FX1, 668), (1152, 708), (1128, 712), (1104, 690), (1050, 700)], (9, 7), 3000, 0.15),
+]
+blocks, splits = [], []
+for poly, gaps, amax, jit in DISTRICTS:
+ dm = buildable * o.poly(poly)
+ yy, xx = np.nonzero(dm > 0.02)
+ if not len(xx): continue
+ y0, y1, x0, x1 = yy.min(), yy.max() + 1, xx.min(), xx.max() + 1
+ subdivide(dm[y0:y1, x0:x1], y0, x0, gaps, amax, jit, 0, blocks, splits)
+B = np.zeros((H, W), np.float32)
+for m, oy, ox in blocks:
+ np.maximum(B[oy:oy + m.shape[0], ox:ox + m.shape[1]], m, out=B[oy:oy + m.shape[0], ox:ox + m.shape[1]])
+inner = o.offset(B, -13)
+band_b = np.clip(B - inner, 0, 1)
+tick('blocks')
+
+# party walls: short ticks across the building band, square to every street edge
+ticks = []
+for (x, y, dx, dy, g, shp, oy, ox) in splits:
+ nx, ny = dy, -dx
+ L = np.hypot(*shp) / 2 + 4
+ s = -L
+ while s < L:
+ s += rng.uniform(10, 22)
+ bx, by = x + dx * s, y + dy * s
+ for sg in (1, -1):
+ a = (bx + nx * sg * (g / 2 - 1), by + ny * sg * (g / 2 - 1))
+ b = (bx + nx * sg * (g / 2 + 15), by + ny * sg * (g / 2 + 15))
+ ticks.append([a, b])
+for pts, w in list(ROADS.values()):
+ P = S(pts)
+ seg = np.linalg.norm(np.diff(P, axis=0), axis=1); cs = np.concatenate([[0], np.cumsum(seg)])
+ s = 0.0
+ while s < cs[-1]:
+ s += rng.uniform(10, 22)
+ i = min(np.searchsorted(cs, s), len(P) - 1)
+ d = P[i] - P[max(i - 1, 0)]; d = d / (np.linalg.norm(d) + 1e-6); n = np.array([-d[1], d[0]])
+ bx, by = np.interp(s, cs, P[:, 0]), np.interp(s, cs, P[:, 1])
+ for sg in (1, -1):
+ ticks.append([(bx + n[0] * sg * (w / 2 - 1), by + n[1] * sg * (w / 2 - 1)), (bx + n[0] * sg * (w / 2 + 15), by + n[1] * sg * (w / 2 + 15))])
+tick('party walls')
+
+# landmarks (darker tone)
+LANDMARKS = dict(
+ station=[(728, 160), (842, 160), (842, 204), (728, 204)],
+ market_hall=[(762, 464), (792, 462), (794, 490), (764, 492)],
+ church=[(892, 476), (930, 472), (931, 486), (950, 485), (951, 498), (932, 499), (934, 520), (897, 523), (895, 502), (878, 503), (877, 490), (894, 489)],
+ fish_market=[(480, 650), (498, 650), (494, 716), (472, 714)],
+ customs=[(626, 590), (676, 590), (676, 604), (626, 604)],
+)
+castle = blob_pts(300, 384, 30, 24, rough=0.02, n=10, seed=1)
+castle = np.array([(300 + (x - 300) * (1.0 if i % 2 == 0 else 0.62), 384 + (y - 384) * (1.0 if i % 2 == 0 else 0.62)) for i, (x, y) in enumerate(castle)])
+LANDMARKS['castle'] = castle.tolist()
+
+# ===================================================================== the base sheet (K): black linework, grey tones
+base = o.sheet(SX0, SY0, SW, SH, 'base', ink='black')
+base.punch(476, PEG_Y, 10.5); base.punch_slot(676, PEG_Y, 70, 20); base.punch(876, PEG_Y, 10.5)
+base.fill(band_b, 0.20)
+base.fill(inner * B, 0.06)
+base.lines(ticks, 0.8, 0.5)
+base.knock(np.clip(1 - band_b * 1.2, 0, 1) * (1 - B)) # ticks only inside the building band
+base.fill(o.edge(B, 1.1), 1.0)
+base.fill(o.edge(inner * B, 0.7) * B, 0.45)
+for k, pts in LANDMARKS.items():
+ m = o.poly(pts)
+ base.fill(m, 0.62); base.fill(o.edge(m, 1.2), 1.0)
+# coast, quays, breakwaters, river banks stay white: their lines are on the blue sheet; the land edge is printed here
+base.fill(o.edge(np.clip(land + river, 0, 1), 1.8), 1.0)
+for pm in (park_castle, park_botanic, park_river, sq_market, sq_church):
+ base.fill(o.edge(pm, 1.0), 0.8)
+# parks: tree symbols and paths
+for pm, n, seed in ((park_castle, 34, 1), (park_botanic, 26, 2), (park_head, 16, 3), (park_river, 6, 4)):
+ ys, xs = np.nonzero(o.offset(pm, -9) > 0.9)
+ if not len(xs): continue
+ r2 = np.random.default_rng(seed)
+ pick = r2.choice(len(xs), size=min(n, len(xs)), replace=False)
+ for i in pick:
+ rr = r2.uniform(4, 6.5)
+ base.line(o.circle_pts(xs[i], ys[i], rr), 1.0, 0.75, closed=True)
+base.line(S([(196, 236), (240, 206), (300, 214), (360, 186), (414, 200)]), 1.2, 0.8, dash=(5, 4))
+base.line(S([(214, 448), (260, 430), (300, 412)]), 1.2, 0.8, dash=(5, 4))
+base.line(S([(392, 446), (350, 420), (318, 406)]), 1.2, 0.8, dash=(5, 4))
+# contours: Castle Hill and the headland
+for k, f in enumerate([1.05, 0.86, 0.68, 0.5]):
+ base.line(blob_pts(298, 390, 116 * f, 84 * f, rough=0.06, seed=10 + k), 0.9, 0.42, closed=True, smooth=False)
+for k, f in enumerate([0.9, 0.62, 0.36]):
+ base.line(blob_pts(1074, 778, 54 * f, 70 * f, rough=0.08, seed=20 + k, rot=0.3), 0.9, 0.42, closed=True)
+base.text('38', 334, 432, 13, 'map_italic', 0.8)
+base.text('21', 1092, 742, 13, 'map_italic', 0.8)
+# railway: line with cross ticks; platforms
+base.line(RAIL, 3.0, 1.0)
+P = RAIL; seg = np.linalg.norm(np.diff(P, axis=0), axis=1); cs = np.concatenate([[0], np.cumsum(seg)])
+rt = []
+for s in np.arange(6, cs[-1], 12):
+ x, y = np.interp(s, cs, P[:, 0]), np.interp(s, cs, P[:, 1])
+ i = min(np.searchsorted(cs, s), len(P) - 1); d = P[i] - P[i - 1]; d /= np.linalg.norm(d); n = (-d[1], d[0])
+ rt.append([(x - n[0] * 5, y - n[1] * 5), (x + n[0] * 5, y + n[1] * 5)])
+base.lines(rt, 1.2, 1.0)
+base.lines([[(842, 172), (840, 172)], [(728, 212), (842, 212)]], 1.0, 0.8)
+# bridges over the river: parapets
+for (bx, by, ang, ln) in [(526, 384, 8, 30), (586, 233, -4, 28), (560, 611, 0, 36)]:
+ a = np.deg2rad(ang); d = np.array([np.cos(a), np.sin(a)]); n = np.array([-d[1], d[0]])
+ for sg in (1, -1):
+ c = np.array([bx, by]) + n * sg * 8
+ base.line([c - d * ln / 2, c + d * ln / 2], 1.6, 1.0)
+# moored boats in the harbour
+for (bx, by, a) in [(500, 690, 80), (504, 742, 76), (700, 680, 100), (698, 724, 104), (560, 660, 0), (604, 662, 0)]:
+ base.line(o.circle_pts(0, 0, 9, 3.4) @ np.array([[np.cos(np.deg2rad(a)), np.sin(np.deg2rad(a))], [-np.sin(np.deg2rad(a)), np.cos(np.deg2rad(a))]]) + (bx, by), 1.0, 0.85, closed=True)
+# lighthouse
+base.circle(1062, 852, 6.5); base.line(o.circle_pts(1062, 852, 11), 1.1, 1.0, closed=True)
+for a in range(0, 360, 45):
+ t = np.deg2rad(a); base.line([(1062 + np.cos(t) * 14, 852 + np.sin(t) * 14), (1062 + np.cos(t) * 20, 852 + np.sin(t) * 20)], 1.0, 0.9)
+# beach stipple
+base.stipple(beach, 170, 0.8, 0.6, seed=4)
+tick('base drawing')
+
+# labels
+LAB = dict(halo=3.5)
+base.text('OLD TOWN', 880, 560, 21, 'map_bold', 0.62, spacing=7, **LAB)
+base.text('WEST BANK', 250, 640, 21, 'map_bold', 0.62, spacing=7, **LAB)
+base.text('NORTH QUARTER', 1010, 300, 19, 'map_bold', 0.62, spacing=6, **LAB)
+base.text('Castle Hill', 300, 452, 16, 'map_italic', 0.95, **LAB)
+base.text('Botanic Garden', 236, 186, 16, 'map_italic', 0.95, **LAB)
+base.text('Station', 785, 150, 15, 'map_italic', 0.95, anchor='mb', **LAB)
+base.text('Market', 776, 520, 14, 'map_italic', 0.95, **LAB)
+base.text("St Bride's", 958, 530, 14, 'map_italic', 0.95, **LAB)
+base.text('Fish Market', 454, 690, 13, 'map_italic', 0.95, rot=86, **LAB)
+base.text('Lighthouse', 1062, 886, 14, 'map_italic', 0.95, **LAB)
+base.text('HIGH STREET', 980, 391, 12, 'map', 0.95, spacing=2.5, rot=6, **LAB)
+base.text('MILL ROAD', 330, 260, 12, 'map', 0.95, spacing=2.5, rot=2, **LAB)
+base.text('WEST ROAD', 230, 517, 12, 'map', 0.95, spacing=2.5, rot=7, **LAB)
+base.text('QUAY STREET', 600, 611, 11, 'map', 0.95, spacing=2.2, **LAB)
+# frame, margins, plate marks
+base.line([(FX0, FY0), (FX1, FY0), (FX1, FY1), (FX0, FY1)], 2.2, 1.0, closed=True, cap=False)
+base.line([(FX0 - 7, FY0 - 7), (FX1 + 7, FY0 - 7), (FX1 + 7, FY1 + 7), (FX0 - 7, FY1 + 7)], 0.9, 1.0, closed=True, cap=False)
+base.text('LARKHAVEN · TOWN PLAN · 1 : 5 000', FX0 - 7, 118, 14, 'map_bold', 0.9, anchor='lm', spacing=2.6)
+base.text('PLATE K — BASE', FX1 + 7, 118, 14, 'map_bold', 0.9, anchor='rm', spacing=2.6)
+base.text('K', 352, 958, 15, 'map_bold', 0.9, anchor='lm')
+for c in CROSS.values():
+ base.cross(*c, size=17, r=9.5)
+tick('base done')
+
+# ===================================================================== blue sheet (C): water, ferry, tram -- on the pegs
+blue = o.sheet(90, SY0, 1172, 890, 'tracing', ink='blue')
+blue.punch(476, PEG_Y, 10.5); blue.punch_slot(676, PEG_Y, 70, 20); blue.punch(876, PEG_Y, 10.5)
+near = np.clip(blur(1 - sea, 13) * 1.6, 0, 1) * sea
+blue.fill(sea * (0.16 + 0.22 * near))
+harbour = o.poly([(466, 616), (724, 616), (750, 742), (644, 818), (584, 816), (446, 728)])
+for k, d in enumerate([5, 10, 16, 23, 31, 41]):
+ keep = sea * frame * (1 - harbour * (k >= 2))
+ blue.fill(o.contour(np.clip(1 - sea, 0, 1), d, 1.05 - 0.06 * k) * keep, 0.95 - 0.1 * k)
+blue.fill(river, 0.40)
+blue.fill(o.edge(river, 1.3) * frame * (1 - sea), 1.0)
+for (bx, by, ang, ln) in [(526, 384, 8, 30), (586, 233, -4, 28), (560, 611, 0, 36)]: # bridge decks cover the water
+ a = np.deg2rad(ang); d = np.array([np.cos(a), np.sin(a)]); n = np.array([-d[1], d[0]])
+ c = np.array([bx, by])
+ blue.knock(o.poly([c - d * ln / 2 - n * 8, c + d * ln / 2 - n * 8, c + d * ln / 2 + n * 8, c - d * ln / 2 + n * 8]))
+pond = o.ellipse(332, 204, 30, 12, rot=-6)
+blue.fill(pond, 0.42); blue.fill(o.edge(pond, 1.2), 1.0)
+# ferry across the bay, with the boat on its way
+FERRY = S([(512, 700), (560, 760), (612, 806), (700, 846), (820, 862), (930, 840), (972, 812)])
+blue.line(FERRY, 2.4, 1.0, dash=(11, 7))
+fx, fy, fa = 790, 860, np.deg2rad(6)
+hull = np.array([(-17, -5), (12, -5), (19, 0), (12, 5), (-17, 5)], np.float32)
+R = np.array([[np.cos(fa), np.sin(fa)], [-np.sin(fa), np.cos(fa)]], np.float32)
+blue.fill(hull @ R + (fx, fy), 1.0)
+blue.fill(np.array([(-8, -3), (4, -3), (4, 3), (-8, 3)], np.float32) @ R + (fx, fy - 7), 1.0)
+blue.text('FERRY · EVERY 20 MIN', 846, 892, 13, 'map_bold', 1.0, spacing=2.4, rot=-2, halo=3)
+# tram line 2
+TRAM = S([(768, 222), (766, 300), (762, 380), (758, 428), (738, 500), (708, 566), (702, 604), (718, 640), (736, 700), (760, 728),
+ (840, 728), (920, 711), (990, 690), (1036, 644), (1090, 562), (1150, 514), (FX1, 488)])
+blue.line(TRAM, 4.2, 1.0)
+for (sx, sy) in [(768, 226), (760, 424), (704, 600), (880, 720), (1064, 604)]: # stops: station, market, harbour, beach, headland
+ blue.circle(sx, sy, 8.5)
+ blue.knock(o.circle(sx, sy, 4.6))
+blue.text('TRAM 2', 1132, 506, 13, 'map_bold', 1.0, spacing=2.4, rot=39, halo=3)
+# water names
+blue.text('S A L T S O U N D', 300, 868, 30, 'map_italic', 1.0, spacing=2, halo=5)
+blue.text('THE HARBOUR', 604, 724, 14, 'map_bold', 1.0, spacing=3.2, halo=4)
+blue.text('Lark River', 616, 296, 19, 'map_italic', 1.0, rot=-66, halo=3)
+for c in CROSS.values():
+ blue.cross(*c, size=17, r=9.5)
+blue.text('C', 1042, 958, 15, 'map_bold', 1.0, anchor='lm')
+tick('blue')
+
+# ===================================================================== yellow sheet (Y): parks, squares, the beach
+yel = o.sheet(96, 140, 914, 840, 'drafting', ink='yellow', curl=('br', 66))
+yel.punch(108, 470, 7.5); yel.punch(108, 530, 7.5)
+for pm in (park_castle, park_botanic, park_river):
+ yel.fill(pm, 0.52)
+ yel.fill(o.edge(pm, 2.6), 1.5)
+for sq in (sq_market, sq_church):
+ yel.fill(sq, 1.0)
+ yel.fill(o.edge(sq, 2.0), 1.8)
+yel.fill(beach, 0.42)
+yel.stipple(beach, 110, 1.0, 1.6, seed=9)
+for (sx, sy, r) in [(214, 372, 13), (402, 216, 11), (650, 522, 10)]: # the sunniest benches
+ yel.circle(sx, sy, r * 0.45, cover=1.8)
+ for a in range(0, 360, 45):
+ t = np.deg2rad(a)
+ yel.line([(sx + np.cos(t) * r * 0.7, sy + np.sin(t) * r * 0.7), (sx + np.cos(t) * r, sy + np.sin(t) * r)], 1.6, 1.8)
+for c in ('L1', 'L2', 'B1'):
+ yel.cross(*CROSS[c], size=17, r=9.5)
+yel.text('Y', 111, 828, 15, 'map_bold', 1.6, anchor='mm')
+tick('yellow')
+
+# ===================================================================== magenta sheet (M): the walk, six stops
+mag = o.sheet(200, 196, 1058, 784, 'tracing', ink='magenta', curl=('bl', 70))
+mag.punch(1246, 480, 7.5); mag.punch(1246, 540, 7.5)
+STOPS = [(806, 226), (808, 450), (526, 384), (352, 404), (486, 622), (1056, 812)]
+WALK = [
+ S([(792, 238), (778, 258), (776, 330), (771, 400), (772, 426), (790, 440)]),
+ S([(792, 438), (770, 428), (700, 412), (612, 394), (542, 386)]),
+ S([(510, 388), (468, 404), (430, 430), (394, 442), (370, 418)]),
+ S([(348, 422), (338, 466), (334, 494), (380, 520), (420, 560), (450, 598), (470, 616)]),
+]
+for seg in WALK:
+ mag.line(seg, 5.0, 1.0, dash=(15, 8))
+ P = seg; cs = np.concatenate([[0], np.cumsum(np.linalg.norm(np.diff(P, axis=0), axis=1))])
+ sm = cs[-1] * 0.55; i = np.searchsorted(cs, sm)
+ mag.arrow((np.interp(sm, cs, P[:, 0]), np.interp(sm, cs, P[:, 1])), P[min(i + 1, len(P) - 1)] - P[max(i - 1, 0)], 15)
+ferry_walk = FERRY
+cs = np.concatenate([[0], np.cumsum(np.linalg.norm(np.diff(ferry_walk, axis=0), axis=1))])
+dots = [(np.interp(s, cs, ferry_walk[:, 0]), np.interp(s, cs, ferry_walk[:, 1])) for s in np.arange(10, cs[-1] - 6, 13)]
+mag.dots(dots, 3.2)
+mag.line(S([(486, 640), (496, 664), (510, 690)]), 5.0, 1.0, dash=(10, 7))
+mag.line(S([(976, 808), (1006, 796), (1036, 806)]), 5.0, 1.0, dash=(15, 8))
+for k, (sx, sy) in enumerate(STOPS):
+ mag.circle(sx, sy, 16.5)
+ mag.text(str(k + 1), sx, sy + 1, 21, 'map_bold', knock=True)
+mag.text('start', 830, 226, 16, 'map_italic', 1.0, anchor='lm', halo=3)
+mag.text('best view', 386, 380, 15, 'map_italic', 1.0, anchor='lm', halo=3)
+mag.text('lunch', 462, 604, 15, 'map_italic', 1.0, anchor='rm', halo=3)
+mag.text('take the ferry', 700, 826, 15, 'map_italic', 1.0, anchor='mm', rot=-10, halo=3)
+mag.text('finish', 1080, 806, 16, 'map_italic', 1.0, anchor='lm', halo=3)
+for c in ('R1', 'R2', 'B2', 'B1'):
+ mag.cross(*CROSS[c], size=17, r=9.5)
+mag.text('M', 1241, 828, 15, 'map_bold', 1.0, anchor='mm')
+tick('magenta')
+
+# ===================================================================== legend card on clear film
+LX0, LY0, LX1, LY1 = 1312, 112, 1832, 952
+film = o.sheet(LX0, LY0, LX1 - LX0, LY1 - LY0, 'film', ink='black', curl=('br', 60))
+x = LX0 + 46
+film.text('A HARBOUR WALK · FOUR SHEETS', x, 168, 15, 'map_bold', 0.75, anchor='lm', spacing=3)
+film.text('Larkhaven', x - 4, 236, 86, 'title', 1.0, anchor='lm')
+film.text('海港小城 · 步行地图', x, 318, 40, 'cjk', 1.0, anchor='lm')
+film.text('six stops, one ferry, about two hours', x, 366, 22, 'map_italic', 0.85, anchor='lm')
+film.line([(x, 400), (LX1 - 46, 400)], 2.0, 1.0, cap=False)
+rows = [('black', 0.9, 'Base', 'streets, blocks, coast', '底图'), ('blue', 1.0, 'Water', 'sea, river, ferry, tram', '水系'),
+ ('yellow', 1.0, 'Parks', 'gardens, squares, beach', '公园'), ('magenta', 1.0, 'Route', 'the walk, six stops', '路线')]
+for i, (ink, cv, a, b, zh) in enumerate(rows):
+ y = 444 + i * 50
+ film.fill(o.rrect(x, y - 13, x + 26, y + 13, 2), cv, ink=ink)
+ film.text(a, x + 44, y, 23, 'map_bold', 1.0, anchor='lm')
+ film.text(b, x + 122, y, 20, 'map', 0.8, anchor='lm')
+ film.text(zh, LX1 - 46, y, 20, 'cjk', 0.75, anchor='rm')
+ film.line([(x, y + 25), (LX1 - 46, y + 25)], 1.0, 0.25, cap=False)
+names = [('Station', '车站'), ('Market Square', '集市广场'), ('Old Bridge', '老桥'), ('Castle Hill', '城堡山'), ('Fish Market', '鱼市'), ('Lighthouse', '灯塔')]
+for i, (en, zh) in enumerate(names):
+ y = 672 + i * 34
+ film.circle(x + 13, y, 12.5, ink='magenta')
+ film.text(str(i + 1), x + 13, y + 1, 16, 'map_bold', knock=True, halo_inks=['magenta'])
+ film.text(en, x + 40, y, 21, 'map', 1.0, anchor='lm')
+ film.text(zh, LX1 - 46, y, 19, 'cjk', 0.7, anchor='rm')
+# scale bar and north arrow
+sy = 898
+for k in range(4):
+ m = o.rrect(x + k * 50, sy - 4, x + (k + 1) * 50, sy + 4)
+ film.fill(m, 1.0 if k % 2 == 0 else 0.0)
+film.line([(x, sy - 4), (x + 200, sy - 4), (x + 200, sy + 4), (x, sy + 4)], 1.0, 1.0, closed=True, cap=False)
+for k, lab in enumerate(['0', '100', '200', '300', '400 m']):
+ film.text(lab, x + k * 50, sy - 18, 14, 'map', 0.9, anchor='mm')
+nx, ny = LX1 - 72, 886
+film.fill([(nx, ny - 30), (nx + 11, ny + 10), (nx, ny + 3)], 1.0)
+film.line([(nx, ny - 30), (nx - 11, ny + 10), (nx, ny + 3)], 1.2, 1.0, closed=True)
+film.text('N', nx, ny + 26, 16, 'map_bold', 1.0)
+tick('film')
+
+# ===================================================================== on the light box, stage by stage
+o.lamp(0.0); o.stage('lamp_off')
+o.lamp(0.5); o.stage('lamp_warm')
+o.lamp(1.0); o.stage('lamp_on')
+o.place(base); o.stage('base')
+o.place(blue, lift=1.0, dx=8, dy=-22, rot=0.7); o.stage('blue_lifted')
+o.place(blue); o.stage('blue_down')
+o.place(yel, lift=1.0, dx=-34, dy=-26, rot=-1.5); o.stage('yellow_lifted')
+o.place(yel); o.stage('yellow_down')
+o.place(mag, lift=1.0, dx=34, dy=-30, rot=1.4); o.stage('magenta_lifted')
+o.place(mag); o.stage('magenta_down')
+o.place(film, lift=1.0, dx=-16, dy=-30, rot=2.2); o.stage('film_lifted')
+o.place(film); o.stage('film_down')
+for (cx, cy, rot) in [(94, 972, 40), (1258, 972, -40), (1008, 144, 40), (660, 198, 4), (1254, 200, 40), (1316, 116, -38), (1828, 116, 38)]:
+ o.tape(cx, cy, rot=rot)
+img = o.save(out, stages_dir=stages)
+tick('saved')
+print('saved', out)
diff --git a/lib/overlay.py b/lib/overlay.py
new file mode 100644
index 0000000..90222c6
--- /dev/null
+++ b/lib/overlay.py
@@ -0,0 +1,842 @@
+"""overlay — 描图纸叠层 / Overlay Sheets: separations on a light box (numpy + Pillow only).
+
+A soft light box glows warm white from below. On it lies a base sheet printed in black linework with grey flat
+tones; on top of that, translucent tracing-paper or film sheets, each printed in ONE ink, are laid down on their
+registration crosses. The light comes through everything, so the picture is a product of transmittances:
+
+ light box a dark bevelled case on a desk with a recessed opal panel. `lamp(level)` runs from off (a dull grey
+ acrylic lit only by the room) through a warm, dim glow to full: warm white, brightest a little left
+ of centre, falling off to a creamy edge, with a warm spill onto the inside of the bezel.
+ sheets every sheet keeps its own buffers in its own frame: paper (tint, backlit *formation* -- the cloudy
+ flocs you only see against the light -- and stray fibres), a coverage map per ink, punched holes
+ and a cut edge that reads as a thin darker line. Kinds: 'base' (bond paper, almost no texture),
+ 'tracing' (cloudy, fibrous, frosts what is under it a little even when flat), 'drafting' (matte
+ film: a faint even tooth, less frost), 'film' (clear acetate: almost no loss and a gloss sheen).
+ inks coverage c is a printed tint: 0..1 is the share of the area under ink (a screen), so its
+ transmittance is 1 - c (1 - ink); above 1 the ink is printed again (a double hit) and deepens as
+ ink^(c-1). Overlapping inks on different sheets multiply, exactly like the real thing: blue over
+ yellow makes green, magenta over yellow makes red, blue over magenta makes violet. One plate never
+ doubles itself: drawing on the same ink keeps the max coverage. Prints get a faint ink mottle.
+ lifting `place(sheet, lift, dx, dy, rot)`. A lifted sheet floats above the stack: it is a little larger
+ (closer to the eye), it casts a wide, soft, warm shadow that you also see through it, and -- being
+ a diffuser held off the drawing -- it blurs everything under it. Laid down (lift 0, no offset) it
+ is crisp, its shadow shrinks to a thin contact line and its crosses sit on the base crosses.
+ curl a corner that will not lie flat: a shading band across the corner, a soft shadow under it and a
+ little blur of what is beneath the lifted tip.
+ hardware `peg_bar` -- a steel bar with a round, a slot and a round peg (the animation-desk standard); the
+ base sheet's punched holes drop onto the pegs and the light shines through the gap around each
+ peg. `tape` -- crepe drafting tape with torn ends, semi-opaque on the light.
+
+Drawing happens in canvas coordinates of the *laid-down* position, on any sheet, so separations register by
+construction: draw the river on the base and on the blue sheet with the same points.
+
+ import sys; sys.path.insert(0, 'lib')
+ from overlay import Overlay
+ o = Overlay(1920, 1080, seed=3)
+ o.desk(); o.lightbox(34, 24, 1886, 1056)
+ o.lamp(1.0)
+ base = o.sheet(160, 120, 1200, 840, 'base', ink='black')
+ base.fill(o.circle(760, 540, 260), 0.2) # grey flat tone (20 % black)
+ base.line(o.circle_pts(760, 540, 260), 2.2, closed=True)
+ base.cross(200, 160); base.cross(1320, 920)
+ o.place(base)
+ blue = o.sheet(150, 110, 1220, 860, 'tracing', ink='blue', curl=('br', 80))
+ blue.fill(o.circle(900, 540, 200), 0.45); blue.cross(200, 160); blue.cross(1320, 920)
+ o.place(blue, lift=1, dx=-30, dy=-24, rot=-1.5); o.stage('blue_lifted')
+ o.place(blue) # lands crisp, crosses on crosses
+ o.tape(1360, 140, rot=40)
+ o.save('overlay.jpg')
+"""
+import glob
+import os
+import numpy as np
+from PIL import Image, ImageDraw, ImageFont, ImageFilter
+from core import blur, spline, noise2d, smoothstep, shift, load_font
+
+INKS = {
+ 'black': '#24211d',
+ 'blue': '#1d62cf',
+ 'yellow': '#f8c92c',
+ 'magenta': '#d8177d',
+ 'cyan': '#1d9fd8',
+ 'orange': '#f06a28',
+ 'green': '#279a57',
+ 'red': '#de3434',
+}
+PAPERS = { # tint (transmittance), formation amplitude, fibres, frost (veil when flat), edge darkness, under-blur when lifted
+ 'base': dict(tint=(0.966, 0.957, 0.934), formation=0.010, fibres=0.30, frost=0.00, edge=0.34, diffuse=2.2),
+ 'tracing': dict(tint=(0.982, 0.978, 0.966), formation=0.020, fibres=0.80, frost=0.040, edge=0.40, diffuse=2.8),
+ 'drafting': dict(tint=(0.986, 0.986, 0.980), formation=0.009, fibres=0.20, frost=0.022, edge=0.42, diffuse=2.4),
+ 'film': dict(tint=(0.984, 0.989, 0.989), formation=0.000, fibres=0.00, frost=0.000, edge=0.55, diffuse=1.2),
+}
+SHADOW = (0.29, 0.20, 0.12) # warm brown: the room light is warm, the shadow takes the light box's tint
+TAPE = '#f7ebcf'
+
+_FONT_TABLE = { # (glob, face index); first hit wins -- macOS, Linux, Windows. Override: $INKPAINT_FONT_OVERLAY_<KIND>
+ 'map': [('/System/Library/Fonts/Supplemental/GillSans.ttc', 0), ('/usr/share/fonts/**/DejaVuSans.ttf', 0),
+ ('C:/Windows/Fonts/GIL_____.TTF', 0), ('C:/Windows/Fonts/arial.ttf', 0)],
+ 'map_bold': [('/System/Library/Fonts/Supplemental/GillSans.ttc', 4), ('/usr/share/fonts/**/DejaVuSans-Bold.ttf', 0),
+ ('C:/Windows/Fonts/GILB____.TTF', 0), ('C:/Windows/Fonts/arialbd.ttf', 0)],
+ 'map_heavy': [('/System/Library/Fonts/Supplemental/GillSans.ttc', 6), ('/usr/share/fonts/**/DejaVuSans-Bold.ttf', 0),
+ ('C:/Windows/Fonts/GILSANUB.TTF', 0), ('C:/Windows/Fonts/arialbd.ttf', 0)],
+ 'map_italic': [('/System/Library/Fonts/Supplemental/GillSans.ttc', 2), ('/System/Library/Fonts/Supplemental/Georgia Italic.ttf', 0),
+ ('/usr/share/fonts/**/DejaVuSerif-Italic.ttf', 0), ('C:/Windows/Fonts/georgiai.ttf', 0)],
+ 'map_light': [('/System/Library/Fonts/Supplemental/GillSans.ttc', 7), ('/usr/share/fonts/**/DejaVuSans-ExtraLight.ttf', 0),
+ ('C:/Windows/Fonts/GIL_____.TTF', 0), ('C:/Windows/Fonts/arial.ttf', 0)],
+ 'title': [('/System/Library/Fonts/Avenir Next.ttc', 8), ('/System/Library/Fonts/HelveticaNeue.ttc', 1),
+ ('/usr/share/fonts/**/DejaVuSans-Bold.ttf', 0), ('C:/Windows/Fonts/arialbd.ttf', 0)],
+ 'label': [('/System/Library/Fonts/Avenir Next.ttc', 2), ('/System/Library/Fonts/HelveticaNeue.ttc', 10),
+ ('/usr/share/fonts/**/DejaVuSans-Bold.ttf', 0), ('C:/Windows/Fonts/arialbd.ttf', 0)],
+ 'cjk': [('/System/Library/Fonts/STHeiti Medium.ttc', 1), ('/System/Library/Fonts/Hiragino Sans GB.ttc', 2),
+ ('/usr/share/fonts/**/NotoSansCJK*Bold*.tt[cf]', 0), ('/usr/share/fonts/**/NotoSansCJK*.tt[cf]', 0),
+ ('C:/Windows/Fonts/msyhbd.ttc', 0), ('C:/Windows/Fonts/msyh.ttc', 0)],
+ 'cjk_light': [('/System/Library/Fonts/STHeiti Light.ttc', 1), ('/System/Library/Fonts/Hiragino Sans GB.ttc', 0),
+ ('/usr/share/fonts/**/NotoSansCJK*Regular*.tt[cf]', 0), ('C:/Windows/Fonts/msyh.ttc', 0)],
+}
+_FONTS = {}
+
+
+def hexc(h):
+ h = h.lstrip('#')
+ return np.array([int(h[i:i + 2], 16) for i in (0, 2, 4)], np.float32) / 255
+
+
+def _c(c):
+ if isinstance(c, str):
+ return hexc(INKS[c]) if c in INKS else hexc(c)
+ return np.asarray(c, np.float32)
+
+
+def font(kind, size):
+ """PIL font: overlay kinds (map, map_bold, map_heavy, map_italic, map_light, title, label, cjk, cjk_light) or
+ any core.load_font style (sans, sans_bold, serif, condensed, typewriter, ...)"""
+ key = (kind, int(size))
+ if key in _FONTS: return _FONTS[key]
+ f = None
+ env = os.environ.get('INKPAINT_FONT_OVERLAY_' + kind.upper())
+ cands = ([(env, 0)] if env and os.path.exists(env) else []) + _FONT_TABLE.get(kind, [])
+ for pat, idx in cands:
+ for p in glob.glob(pat, recursive=True):
+ try:
+ f = ImageFont.truetype(p, int(size), index=idx); break
+ except OSError:
+ continue
+ if f: break
+ if f is None:
+ f = load_font(kind if kind not in _FONT_TABLE else ('sans_bold' if 'bold' in kind or kind == 'title' else 'sans'), size)
+ _FONTS[key] = f
+ return f
+
+
+def _closed_spline(P, per=8):
+ P = np.asarray(P, np.float32)
+ Q = np.vstack([P[-1:], P, P[:2]])
+ out = []
+ for i in range(1, len(Q) - 2):
+ p0, p1, p2, p3 = Q[i - 1], Q[i], Q[i + 1], Q[i + 2]
+ for t in np.linspace(0, 1, per, endpoint=False):
+ t2, t3 = t * t, t * t * t
+ out.append(0.5 * ((2 * p1) + (-p0 + p2) * t + (2 * p0 - 5 * p1 + 4 * p2 - p3) * t2 + (-p0 + 3 * p1 - 3 * p2 + p3) * t3))
+ return np.array(out, np.float32)
+
+
+def _level(f, t, width):
+ """anti-aliased line of `width` px along the level set f == t (gradient-normalised, so constant width)"""
+ gy, gx = np.gradient(f)
+ g = np.sqrt(gx * gx + gy * gy) + 1e-5
+ return np.clip(width / 2 + 0.5 - np.abs(f - t) / g, 0, 1).astype(np.float32)
+
+
+class Sheet:
+ """One sheet on the light box. Create it with `Overlay.sheet()`; draw on it in canvas coordinates of its
+ laid-down position; show it with `Overlay.place()`."""
+
+ def __init__(self, ov, x, y, w, h, kind, ink, tint, fibre, curl, seed, edge):
+ self.ov = ov
+ self.x0, self.y0, self.w, self.h = int(round(x)), int(round(y)), int(round(w)), int(round(h))
+ self.kind = kind
+ self.P = dict(PAPERS[kind])
+ if tint is not None: self.P['tint'] = tuple(_c(tint))
+ if fibre is not None: self.P['fibres'] = fibre
+ if edge is not None: self.P['edge'] = edge
+ self.ink = ink
+ self.cov = {}
+ self.holes = np.zeros((self.h, self.w), np.float32)
+ self.curl = curl
+ self.rng = np.random.default_rng(seed)
+ self.tex_seed = int(seed) + 7919 # paper texture: fixed, so a rebuild looks the same
+ self.state = None # (lift, dx, dy, rot) once placed
+ self.sheen = kind == 'film'
+ self._cache = None
+
+ # ------------------------------------------------------------ geometry
+ def _local(self, sl_y, sl_x):
+ """intersection of a canvas box with this sheet -> (canvas slices, local slices) or None"""
+ y0, y1 = max(sl_y.start, self.y0), min(sl_y.stop, self.y0 + self.h)
+ x0, x1 = max(sl_x.start, self.x0), min(sl_x.stop, self.x0 + self.w)
+ if y1 <= y0 or x1 <= x0: return None
+ return ((slice(y0 - sl_y.start, y1 - sl_y.start), slice(x0 - sl_x.start, x1 - sl_x.start)),
+ (slice(y0 - self.y0, y1 - self.y0), slice(x0 - self.x0, x1 - self.x0)))
+
+ def _buf(self, ink):
+ ink = ink or self.ink
+ if ink not in self.cov:
+ self.cov[ink] = np.zeros((self.h, self.w), np.float32)
+ return self.cov[ink]
+
+ def _put(self, m, oy, ox, cover, ink):
+ """max-merge a mask crop m (canvas origin oy, ox) into the ink plate"""
+ self._cache = None
+ hit = self._local(slice(oy, oy + m.shape[0]), slice(ox, ox + m.shape[1]))
+ if hit is None: return
+ (my, mx), (ly, lx) = hit
+ b = self._buf(ink)
+ np.maximum(b[ly, lx], m[my, mx] * cover, out=b[ly, lx])
+
+ # ------------------------------------------------------------ printing
+ def fill(self, m, cover=1.0, ink=None, smooth=False):
+ """flat ink: `m` is a canvas mask or a polygon (list of points); cover < 1 is a tint, > 1 a double hit"""
+ if not isinstance(m, np.ndarray) or m.ndim != 2 or m.shape != (self.ov.H, self.ov.W):
+ m, oy, ox = self.ov._poly_crop([m], smooth)
+ else:
+ sl = (slice(self.y0, self.y0 + self.h), slice(self.x0, self.x0 + self.w))
+ m, oy, ox = m[sl], self.y0, self.x0
+ self._put(m, oy, ox, cover, ink)
+
+ def line(self, pts, width=2.0, cover=1.0, ink=None, closed=False, smooth=False, dash=None, cap=True):
+ """printed line along a polyline; dash=(on, off) in px; round caps"""
+ self.lines([pts], width, cover, ink, closed, smooth, dash, cap)
+
+ def lines(self, paths, width=2.0, cover=1.0, ink=None, closed=False, smooth=False, dash=None, cap=True):
+ """many lines in one raster pass (streets, party walls, ticks)"""
+ m, oy, ox = self.ov._lines_crop(paths, width, closed, smooth, dash, cap)
+ if m is not None: self._put(m, oy, ox, cover, ink)
+
+ def dots(self, pts, r=3.0, cover=1.0, ink=None):
+ m, oy, ox = self.ov._dots_crop(pts, r)
+ if m is not None: self._put(m, oy, ox, cover, ink)
+
+ def circle(self, cx, cy, r, width=None, cover=1.0, ink=None):
+ """filled disc (width None) or ring"""
+ if width is None:
+ self.dots([(cx, cy)], r, cover, ink)
+ else:
+ self.line(self.ov.circle_pts(cx, cy, r), width, cover, ink, closed=True)
+
+ def hatch(self, m, spacing=8.0, angle=45.0, width=1.2, cover=1.0, ink=None):
+ """parallel ruled lines clipped to a canvas mask (cross-hatched areas, slipways, sand)"""
+ ys, xs = np.nonzero(m > 0.02)
+ if not len(xs): return
+ x0, x1, y0, y1 = xs.min() - 2, xs.max() + 3, ys.min() - 2, ys.max() + 3
+ a = np.deg2rad(angle); d = np.array([np.cos(a), np.sin(a)]); nrm = np.array([-d[1], d[0]])
+ cx, cy = (x0 + x1) / 2, (y0 + y1) / 2; R = np.hypot(x1 - x0, y1 - y0) / 2 + 2
+ paths = []
+ for k in np.arange(-R, R, spacing):
+ c = np.array([cx, cy]) + nrm * k
+ paths.append([c - d * R, c + d * R])
+ lm, oy, ox = self.ov._lines_crop(paths, width, False, False, None, False, box=(x0, y0, x1, y1))
+ lm = lm * m[oy:oy + lm.shape[0], ox:ox + lm.shape[1]]
+ self._put(lm, oy, ox, cover, ink)
+
+ def stipple(self, m, n=400, r=1.6, cover=1.0, ink=None, seed=None):
+ """random dots inside a canvas mask (sand, shingle, scrub)"""
+ rng = np.random.default_rng(seed if seed is not None else int(self.rng.integers(1 << 30)))
+ ys, xs = np.nonzero(m > 0.5)
+ if not len(xs): return
+ i = rng.choice(len(xs), size=min(n, len(xs)), replace=False)
+ self.dots(np.stack([xs[i] + rng.uniform(0, 1, len(i)), ys[i] + rng.uniform(0, 1, len(i))], 1), r, cover, ink)
+
+ def text(self, s, x, y, size, font_kind='map', cover=1.0, ink=None, anchor='mm', spacing=0.0, rot=0.0,
+ halo=0.0, halo_inks=None, knock=False):
+ """printed type. halo > 0 first clears ink (on `halo_inks`, default every plate of this sheet) in a
+ band around the letters so a label reads over tone; knock=True clears the letters themselves out of the
+ ink (reversed-out numbers in a solid disc)"""
+ m, oy, ox = self.ov._text_crop(s, x, y, size, font_kind, anchor, spacing, rot, pad=int(halo) + 4)
+ if m is None: return None
+ if halo > 0:
+ hm = np.asarray(Image.fromarray((m * 255).astype(np.uint8)).filter(ImageFilter.MaxFilter(int(2 * round(halo) + 1))), np.float32) / 255
+ hm = blur(hm, 0.6)
+ for k in (halo_inks or list(self.cov.keys())):
+ self._clear(hm, oy, ox, k)
+ if knock:
+ for k in (halo_inks or [ink or self.ink]):
+ self._clear(m, oy, ox, k)
+ else:
+ self._put(m, oy, ox, cover, ink)
+ ys, xs = np.nonzero(m > 0.3)
+ return (ox + xs.min(), oy + ys.min(), ox + xs.max(), oy + ys.max()) if len(xs) else None
+
+ def _clear(self, m, oy, ox, ink):
+ self._cache = None
+ hit = self._local(slice(oy, oy + m.shape[0]), slice(ox, ox + m.shape[1]))
+ if hit is None or ink not in self.cov: return
+ (my, mx), (ly, lx) = hit
+ self.cov[ink][ly, lx] *= (1 - np.clip(m[my, mx], 0, 1))
+
+ def knock(self, m, ink=None):
+ """clear ink inside a canvas mask (every plate of this sheet when ink is None)"""
+ sl = (slice(self.y0, self.y0 + self.h), slice(self.x0, self.x0 + self.w))
+ for k in ([ink] if ink else list(self.cov.keys())):
+ self._clear(m[sl], self.y0, self.x0, k)
+
+ def cross(self, x, y, size=20.0, r=11.0, width=None, ink=None, cover=1.0):
+ """registration mark: a circle and a cross. Print the same point on every sheet -- laid down, they coincide"""
+ w = width or (1.3 if (ink or self.ink) == 'black' else 2.4)
+ self.lines([[(x - size, y), (x + size, y)], [(x, y - size), (x, y + size)]], w, cover, ink, cap=False)
+ self.line(self.ov.circle_pts(x, y, r), w, cover, ink, closed=True)
+
+ def arrow(self, tip, direction, size=14.0, cover=1.0, ink=None, spread=26.0):
+ """solid arrowhead at `tip` pointing along `direction`"""
+ d = np.asarray(direction, np.float32); d /= np.linalg.norm(d) + 1e-6
+ a = np.deg2rad(spread)
+ rot = lambda v, t: np.array([v[0] * np.cos(t) - v[1] * np.sin(t), v[0] * np.sin(t) + v[1] * np.cos(t)])
+ p = np.asarray(tip, np.float32)
+ self.fill([p, p - rot(d, a) * size, p - d * size * 0.72, p - rot(d, -a) * size], cover, ink)
+
+ # ------------------------------------------------------------ the paper itself
+ def punch(self, x, y, r=10.0):
+ """a punched round hole (canvas coordinates of the laid-down sheet)"""
+ self._cache = None
+ m, oy, ox = self.ov._dots_crop([(x, y)], r)
+ hit = self._local(slice(oy, oy + m.shape[0]), slice(ox, ox + m.shape[1]))
+ if hit is None: return
+ (my, mx), (ly, lx) = hit
+ np.maximum(self.holes[ly, lx], m[my, mx], out=self.holes[ly, lx])
+
+ def punch_slot(self, x, y, w=70.0, h=20.0):
+ """a punched slot (the middle hole of an animation peg pattern)"""
+ self._cache = None
+ m, oy, ox = self.ov._lines_crop([[(x - w / 2 + h / 2, y), (x + w / 2 - h / 2, y)]], h, False, False, None, True)
+ hit = self._local(slice(oy, oy + m.shape[0]), slice(ox, ox + m.shape[1]))
+ if hit is None: return
+ (my, mx), (ly, lx) = hit
+ np.maximum(self.holes[ly, lx], m[my, mx], out=self.holes[ly, lx])
+
+ def _build(self):
+ """local transmittance T (h, w, 3), footprint F (h, w), curl weights -- cached until drawn on again"""
+ if self._cache is not None: return self._cache
+ h, w, P = self.h, self.w, self.P
+ rng = np.random.default_rng(self.tex_seed)
+ s = int(rng.integers(1 << 30))
+ F = np.ones((h, w), np.float32)
+ F[:, :1] = F[:, -1:] = 0.5; F[:1, :] = F[-1:, :] = 0.5
+ F *= 1 - self.holes
+ # paper: backlit formation (cloudy flocs), stray fibres, cut edge
+ tint = np.asarray(P['tint'], np.float32)
+ T = np.ones((h, w, 3), np.float32) * tint
+ if P['formation'] > 0:
+ form = 0.55 * noise2d(h, w, 6, 3, s) + 0.45 * noise2d(h, w, 22, 3, s + 1)
+ form = (form - form.mean()) / (form.std() + 1e-6)
+ T *= (1 - P['formation'] * 0.5 * form)[..., None]
+ if P['fibres'] > 0:
+ n = int(w * h / 2600 * P['fibres'])
+ fib = Image.new('L', (w, h), 0); d = ImageDraw.Draw(fib)
+ for _ in range(n):
+ x, y = rng.uniform(0, w), rng.uniform(0, h)
+ a = rng.uniform(0, np.pi); L = rng.uniform(8, 34); bend = rng.normal(0, 0.35)
+ t = np.linspace(-0.5, 0.5, 6)
+ xs = x + np.cos(a + bend * t) * L * t; ys = y + np.sin(a + bend * t) * L * t
+ d.line(list(zip(xs.tolist(), ys.tolist())), fill=int(rng.uniform(30, 80)), width=1)
+ fib = np.asarray(fib, np.float32) / 255
+ T *= (1 - 0.11 * blur(fib, 0.5) * P['fibres'] ** 0.5)[..., None]
+ if self.kind == 'drafting': # matte film tooth: even and very fine
+ T *= (1 - 0.012 * (noise2d(h, w, 1.4, 2, s + 2) - 0.5))[..., None]
+ # inks
+ mottle = 0.94 + 0.12 * noise2d(h, w, 2.2, 2, s + 3) + 0.05 * (noise2d(h, w, 90, 2, s + 4) - 0.5)
+ for k, c in self.cov.items():
+ c = blur(c, 0.45) * mottle
+ ink = _c(k)
+ lin = np.clip(c, 0, 1)[..., None]
+ Tk = 1 - lin * (1 - ink)
+ extra = np.clip(c - 1, 0, None)[..., None]
+ if extra.max() > 0: Tk = Tk * ink ** extra
+ T *= Tk
+ # corner curl: a shading band across the corner, the tip a touch lighter (it tilts toward the room light)
+ cw = np.zeros((h, w), np.float32); csh = np.zeros((h, w), np.float32)
+ if self.curl:
+ corner, R = (self.curl, 70.0) if isinstance(self.curl, str) else self.curl
+ cx = 0 if 'l' in corner else w; cy = 0 if 't' in corner else h
+ sx = 1 if 'l' in corner else -1; sy = 1 if 't' in corner else -1
+ Y, X = np.mgrid[0:h, 0:w].astype(np.float32)
+ u = ((X - cx) * sx + (Y - cy) * sy) / np.sqrt(2) / R
+ band = np.exp(-((u - 0.52) / 0.11) ** 2) * (u < 1.2) # the roll, turned away from the room light
+ crease = np.exp(-((u - 0.66) / 0.035) ** 2) # its top edge catches the light
+ T *= (1 - 0.07 * band)[..., None]
+ T = T + (1 - T) * (0.10 * np.clip(1 - u / 0.42, 0, 1) ** 1.5 + 0.35 * crease)[..., None]
+ cw = (np.clip(1 - u, 0, 1) ** 2).astype(np.float32)
+ d2 = (X - cx - sx * 0.2 * R) ** 2 + (Y - cy - sy * 0.26 * R) ** 2
+ csh = (0.16 * np.exp(-d2 / (2 * (0.26 * R) ** 2))).astype(np.float32)
+ # the cut edge (and the rims of the holes) catch as a thin darker line
+ f = blur(F, 0.7)
+ edge = _level(f, 0.5, 1.3)
+ T *= 1 - P['edge'] * edge[..., None] * (1 - np.array([0.38, 0.30, 0.22], np.float32)) * 1.6
+ T = np.clip(T, 0, 1)
+ A = (1 - T) * F[..., None] # what the sheet takes away; 0 off the paper
+ sheen = None
+ if self.sheen:
+ Y, X = np.mgrid[0:h, 0:w].astype(np.float32)
+ dd = (X * 0.42 + Y) / max(h, w)
+ sheen = (0.07 * np.exp(-((dd - 0.36) / 0.09) ** 2) + 0.04 * np.exp(-((dd - 0.55) / 0.03) ** 2)).astype(np.float32)
+ self._cache = dict(A=A.astype(np.float32), F=F, cw=cw, csh=csh, sheen=sheen)
+ return self._cache
+
+
+class Overlay:
+ INKS = INKS
+ PAPERS = PAPERS
+
+ def __init__(self, W=1920, H=1080, seed=0, keep_stages=True):
+ self.W, self.H = W, H
+ self.rng = np.random.default_rng(seed)
+ self.seed = seed
+ self.keep_stages = keep_stages # False: stage() is free (no snapshot renders)
+ self.stages = []
+ self.items = [] # z-order: peg bars, sheets (once placed), tapes
+ self.level = 1.0
+ self.bg = np.ones((H, W, 3), np.float32) * hexc('#3a3530')
+ self.panel = None
+ self._E = {}
+ self._post = None
+
+ def _seed(self):
+ return int(self.rng.integers(1 << 30))
+
+ # ------------------------------------------------------------ masks (canvas size, anti-aliased)
+ def _blank(self, x0, y0, x1, y1, ss=2):
+ x0, y0 = int(np.floor(x0)), int(np.floor(y0))
+ x1, y1 = int(np.ceil(x1)) + 1, int(np.ceil(y1)) + 1
+ x0, y0, x1, y1 = max(0, x0), max(0, y0), min(self.W, x1), min(self.H, y1)
+ if x1 <= x0 or y1 <= y0: return None
+ im = Image.new('L', ((x1 - x0) * ss, (y1 - y0) * ss), 0)
+ return im, ImageDraw.Draw(im), x0, y0, x1, y1
+
+ @staticmethod
+ def _down(im, x0, y0, x1, y1):
+ return np.asarray(im.resize((x1 - x0, y1 - y0), Image.BOX), np.float32) / 255
+
+ def _poly_crop(self, polys, smooth=False):
+ polys = [np.asarray(_closed_spline(p) if smooth else p, np.float32) for p in polys]
+ allp = np.vstack(polys)
+ r = self._blank(allp[:, 0].min() - 2, allp[:, 1].min() - 2, allp[:, 0].max() + 2, allp[:, 1].max() + 2)
+ if r is None: return np.zeros((1, 1), np.float32), 0, 0
+ im, d, x0, y0, x1, y1 = r
+ for p in polys:
+ d.polygon([((x - x0) * 2, (y - y0) * 2) for x, y in p.tolist()], fill=255)
+ return self._down(im, x0, y0, x1, y1), y0, x0
+
+ def _expand(self, m, oy, ox):
+ out = np.zeros((self.H, self.W), np.float32)
+ out[oy:oy + m.shape[0], ox:ox + m.shape[1]] = m
+ return out
+
+ def poly(self, pts, smooth=False):
+ """filled polygon (or a list of polygons); smooth=True runs a closed Catmull-Rom spline through the points"""
+ polys = pts if (len(pts) and np.ndim(pts[0]) == 2) else [pts]
+ return self._expand(*self._poly_crop(polys, smooth))
+
+ def circle(self, cx, cy, r):
+ m, oy, ox = self._dots_crop([(cx, cy)], r)
+ return self._expand(m, oy, ox)
+
+ def ellipse(self, cx, cy, rx, ry, rot=0.0):
+ t = np.linspace(0, 2 * np.pi, 120, endpoint=False)
+ c, s = np.cos(np.deg2rad(rot)), np.sin(np.deg2rad(rot))
+ x, y = np.cos(t) * rx, np.sin(t) * ry
+ return self.poly(np.stack([cx + x * c - y * s, cy + x * s + y * c], 1))
+
+ def rrect(self, x0, y0, x1, y1, r=0.0):
+ rr = self._blank(x0 - 1, y0 - 1, x1 + 1, y1 + 1)
+ im, d, bx, by, bx1, by1 = rr
+ d.rounded_rectangle(((x0 - bx) * 2, (y0 - by) * 2, (x1 - bx) * 2, (y1 - by) * 2), r * 2, fill=255)
+ return self._expand(self._down(im, bx, by, bx1, by1), by, bx)
+
+ def band(self, pts, width, smooth=False):
+ """a thick stroke along a polyline as a mask (roads, rivers, piers)"""
+ m, oy, ox = self._lines_crop([pts], width, False, smooth, None, True)
+ return self._expand(m, oy, ox)
+
+ @staticmethod
+ def circle_pts(cx, cy, r, ry=None, n=None, a0=0.0, a1=360.0):
+ ry = r if ry is None else ry
+ n = n or max(24, int(2 * np.pi * max(r, ry) / 3))
+ t = np.deg2rad(np.linspace(a0, a1, n, endpoint=(a1 - a0) < 360))
+ return np.stack([cx + np.cos(t) * r, cy + np.sin(t) * ry], 1)
+
+ def edge(self, m, width=1.4):
+ """the outline of a mask as a line mask of `width` px"""
+ return _level(blur(m, 0.7), 0.5, width)
+
+ def offset(self, m, d):
+ """grow (d > 0) or shrink (d < 0) a mask by about d px, with rounded corners"""
+ if d == 0: return m.copy()
+ sig = abs(d) / 1.6
+ f = blur(m, sig)
+ t = 0.0548 if d > 0 else 1 - 0.0548
+ gy, gx = np.gradient(f)
+ g = np.sqrt(gx * gx + gy * gy) + 1e-5
+ return np.clip(0.5 + (f - t) / g, 0, 1).astype(np.float32)
+
+ def contour(self, m, d, width=1.2):
+ """a line about d px outside (d > 0) or inside (d < 0) a mask's edge -- water-lining round a coast"""
+ sig = max(0.7, abs(d) / 1.6)
+ t = 0.0548 if d > 0 else 1 - 0.0548
+ return _level(blur(m, sig), t, width)
+
+ @staticmethod
+ def inset(pts, d):
+ """inset a convex polygon by d px (or a list of per-edge distances): a block inside its streets"""
+ P = np.asarray(pts, np.float64); n = len(P)
+ dd = np.full(n, d, np.float64) if np.isscalar(d) else np.asarray(d, np.float64)
+ area = 0.5 * np.sum(P[:, 0] * np.roll(P[:, 1], -1) - np.roll(P[:, 0], -1) * P[:, 1])
+ sgn = 1 if area > 0 else -1
+ lines = []
+ for i in range(n):
+ a, b = P[i], P[(i + 1) % n]
+ t = b - a; t /= np.linalg.norm(t) + 1e-9
+ nrm = np.array([-t[1], t[0]]) * sgn # inward
+ lines.append((a + nrm * dd[i], t))
+ out = []
+ for i in range(n):
+ (p1, t1), (p2, t2) = lines[i - 1], lines[i]
+ den = t1[0] * t2[1] - t1[1] * t2[0]
+ if abs(den) < 1e-9: out.append(p2); continue
+ s = ((p2[0] - p1[0]) * t2[1] - (p2[1] - p1[1]) * t2[0]) / den
+ out.append(p1 + t1 * s)
+ return np.array(out, np.float32)
+
+ # ------------------------------------------------------------ raster helpers for sheets
+ def _lines_crop(self, paths, width, closed, smooth, dash, cap, box=None):
+ segs = []
+ for p in paths:
+ p = np.asarray(p, np.float32)
+ if smooth and len(p) > 2:
+ p = _closed_spline(p) if closed else spline(p, 8)
+ if closed: p = np.vstack([p, p[:1]])
+ if dash:
+ seg = np.linalg.norm(np.diff(p, axis=0), axis=1); s = np.concatenate([[0], np.cumsum(seg)])
+ on, off = dash; L = s[-1]; t = 0.0
+ while t < L:
+ tt = np.linspace(t, min(t + on, L), max(2, int(on / 2)))
+ segs.append(np.stack([np.interp(tt, s, p[:, 0]), np.interp(tt, s, p[:, 1])], 1))
+ t += on + off
+ else:
+ segs.append(p)
+ if not segs: return None, 0, 0
+ allp = np.vstack(segs); pad = width + 3
+ if box is None:
+ box = (allp[:, 0].min() - pad, allp[:, 1].min() - pad, allp[:, 0].max() + pad, allp[:, 1].max() + pad)
+ r = self._blank(*box)
+ if r is None: return None, 0, 0
+ im, d, x0, y0, x1, y1 = r
+ w2 = max(1, int(round(width * 2)))
+ for p in segs:
+ q = [((x - x0) * 2, (y - y0) * 2) for x, y in p.tolist()]
+ if len(q) >= 2: d.line(q, fill=255, width=w2, joint='curve')
+ if cap:
+ for (x, y) in (q[0], q[-1]):
+ d.ellipse((x - w2 / 2, y - w2 / 2, x + w2 / 2, y + w2 / 2), fill=255)
+ return self._down(im, x0, y0, x1, y1), y0, x0
+
+ def _dots_crop(self, pts, r):
+ pts = np.asarray(pts, np.float32).reshape(-1, 2)
+ rr = self._blank(pts[:, 0].min() - r - 2, pts[:, 1].min() - r - 2, pts[:, 0].max() + r + 2, pts[:, 1].max() + r + 2)
+ if rr is None: return None, 0, 0
+ im, d, x0, y0, x1, y1 = rr
+ for x, y in pts.tolist():
+ d.ellipse(((x - x0 - r) * 2, (y - y0 - r) * 2, (x - x0 + r) * 2, (y - y0 + r) * 2), fill=255)
+ return self._down(im, x0, y0, x1, y1), y0, x0
+
+ def _text_crop(self, s, x, y, size, font_kind, anchor, spacing, rot, pad=4):
+ f = font(font_kind, size)
+ adv = [f.getlength(ch) + spacing for ch in s]
+ total = sum(adv) - spacing if s else 0
+ R = int(total + size * 2 + pad * 2)
+ im = Image.new('L', (2 * R, 2 * R), 0); d = ImageDraw.Draw(im)
+ if spacing:
+ x0 = R - total * {'l': 0.0, 'm': 0.5, 'r': 1.0}[anchor[0]]
+ for ch, a in zip(s, adv):
+ d.text((x0, R), ch, font=f, fill=255, anchor='l' + anchor[1]); x0 += a
+ else:
+ d.text((R, R), s, font=f, fill=255, anchor=anchor)
+ if rot:
+ im = im.rotate(rot, resample=Image.BICUBIC, center=(R, R))
+ a = np.asarray(im, np.float32) / 255
+ ys, xs = np.nonzero(a > 0.002)
+ if not len(xs): return None, 0, 0
+ ya, yb, xa, xb = ys.min() - pad, ys.max() + pad + 1, xs.min() - pad, xs.max() + pad + 1
+ ox, oy = int(round(x)) - R + xa, int(round(y)) - R + ya
+ crop = a[max(ya, 0):yb, max(xa, 0):xb]
+ # clip to canvas
+ cy0, cx0 = max(0, -oy), max(0, -ox)
+ crop = crop[cy0:, cx0:]
+ oy, ox = oy + cy0, ox + cx0
+ crop = crop[:max(0, self.H - oy), :max(0, self.W - ox)]
+ return crop, oy, ox
+
+ # ------------------------------------------------------------ the set: desk, light box, pegs, tape
+ def desk(self, colour='#3a3530'):
+ """the dark desk the light box stands on (fine grain, faint horizontal streaks)"""
+ H, W = self.H, self.W
+ s = self._seed()
+ base = hexc(colour)
+ grain = 0.75 * noise2d(H, W, 3, 2, s) + 0.25 * noise2d(H, W, 60, 2, s + 1)
+ streak = np.interp(np.arange(H), np.linspace(0, H - 1, 140), self.rng.random(140))[:, None]
+ self.bg = base * (0.86 + 0.18 * grain + 0.06 * streak)[..., None]
+
+ def lightbox(self, x0, y0, x1, y1, radius=28, bezel=18, colour='#4b4743'):
+ """the case (bevelled, darker toward the bottom, a soft shadow on the desk) and its opal panel"""
+ H, W = self.H, self.W
+ case = self.rrect(x0, y0, x1, y1, radius)
+ sh = blur(shift(case, 0, 26), 30)
+ self.bg *= (1 - 0.55 * sh * (1 - case))[..., None]
+ Y = np.arange(H, dtype=np.float32)[:, None]
+ g = np.clip((Y - y0) / max(1, y1 - y0), 0, 1)
+ col = hexc(colour) * (1.12 - 0.42 * g)[..., None] * np.ones((1, W, 1), np.float32)
+ col *= (0.97 + 0.04 * noise2d(H, W, 2.0, 2, self._seed()))[..., None]
+ self.bg = self.bg * (1 - case[..., None]) + col * case[..., None]
+ top = _level(blur(case, 0.8), 0.5, 1.2) * (Y < y0 + radius)
+ self.bg += (top * 0.22)[..., None]
+ self.box = (x0 + bezel, y0 + bezel, x1 - bezel, y1 - bezel)
+ self.panel = self.rrect(*self.box, 12)
+ self._E = {}
+
+ def lamp(self, level=1.0):
+ """0 = off (grey opal acrylic in room light) .. 1 = on (warm white). In between it is dim and warmer"""
+ self.level = float(level)
+
+ def _emission(self):
+ key = round(self.level, 3)
+ if key in self._E: return self._E[key]
+ H, W = self.H, self.W
+ x0, y0, x1, y1 = self.box
+ Y, X = np.mgrid[0:H, 0:W].astype(np.float32)
+ r = np.hypot((X - (x0 + 0.42 * (x1 - x0))) / ((x1 - x0) * 0.70), (Y - (y0 + 0.46 * (y1 - y0))) / ((y1 - y0) * 0.80))
+ stops = [(0.0, '#ffffff'), (0.45, '#fffdf9'), (0.75, '#fcf7ee'), (1.0, '#f6ecdc'), (1.6, '#efe0c8')]
+ on = np.zeros((H, W, 3), np.float32)
+ for k in range(3):
+ on[..., k] = np.interp(r, [p for p, _ in stops], [hexc(c)[k] for _, c in stops])
+ on *= 0.985
+ off = hexc('#9c968c') * (1.0 - 0.10 * np.clip(r, 0, 1.4))[..., None]
+ lv = self.level
+ warm = np.array([1.0, 1 - 0.06 * (1 - lv), 1 - 0.20 * (1 - lv)], np.float32)
+ E = off * (1 - lv) + on * warm * lv ** 0.8
+ E *= (1 + 0.005 * (noise2d(H, W, 24, 2, self.seed + 17) - 0.5))[..., None]
+ # the panel sits in a recess: a dark line round it, and when lit a warm spill onto the bezel
+ pm = self.panel
+ lip = self.edge(pm, 2.0)
+ spill = np.clip(blur(pm, 9) - pm, 0, 1) * 0.55 * lv
+ img = self.bg * (1 - pm[..., None]) + E * pm[..., None]
+ img = img + (spill[..., None] * np.array([1.0, 0.86, 0.62], np.float32) * 0.45)
+ img *= (1 - 0.55 * lip)[..., None]
+ img *= (1 - 0.10 * np.clip(blur(1 - pm, 6) * pm * 2, 0, 1))[..., None]
+ self._E[key] = img.astype(np.float32)
+ return self._E[key]
+
+ def peg_bar(self, x0, x1, y0, y1, pegs=(), screws=True):
+ """a steel peg bar lying on the light box (opaque, lit by the room). pegs: ('round', x, y, r) and
+ ('slot', x, y, w, h); give the same points to `Sheet.punch` / `punch_slot` so sheets drop onto them"""
+ H, W = self.H, self.W
+ bar = self.rrect(x0, y0, x1, y1, 6)
+ Y = np.arange(H, dtype=np.float32)[:, None] * np.ones((1, W), np.float32)
+ X = np.ones((H, 1), np.float32) * np.arange(W, dtype=np.float32)[None, :]
+ g = np.clip((Y - y0) / max(1, y1 - y0), 0, 1)
+ steel = np.stack([np.interp(g, [0, 0.45, 1], [hexc(c)[k] for c in ('#f4f3f0', '#d3d0ca', '#a7a39c')]) for k in range(3)], -1)
+ col = steel * (1 + 0.02 * (noise2d(H, W, 1.2, 1, self._seed())[..., None] - 0.5))
+ alpha = bar.copy()
+ col = col * (1 - 0.45 * self.edge(bar, 1.0)[..., None])
+ col += (np.exp(-((Y - y0 - 2.5) / 0.8) ** 2) * bar * 0.12)[..., None]
+ for p in pegs:
+ if p[0] == 'round':
+ _, px, py, pr = p
+ m = self.circle(px, py, pr)
+ rr = np.clip(np.hypot(X - (px - pr * 0.25), Y - (py - pr * 0.3)) / (pr * 1.5), 0, 1)
+ c = hexc('#fbfaf8') * (1 - rr)[..., None] + hexc('#9d988f') * rr[..., None]
+ else:
+ _, px, py, pw, ph = p
+ m = self.rrect(px - pw / 2, py - ph / 2, px + pw / 2, py + ph / 2, ph / 2)
+ gg = np.clip((Y - (py - ph / 2)) / ph, 0, 1)
+ c = np.stack([np.interp(gg, [0, 0.35, 1], [hexc(cc)[k] for cc in ('#fbfaf8', '#d8d5cf', '#9d988f')]) for k in range(3)], -1)
+ c = c * (1 - 0.5 * self.edge(m, 1.0)[..., None])
+ col = col * (1 - m[..., None]) + np.clip(c, 0, 1) * m[..., None]
+ alpha = np.maximum(alpha, m)
+ if screws:
+ for sx in (x0 + 18, x1 - 18):
+ sy = (y0 + y1) / 2
+ m = self.circle(sx, sy, 5)
+ col = col * (1 - m[..., None]) + hexc('#bdb9b2') * m[..., None]
+ col = col * (1 - 0.6 * (self.edge(m, 0.9) + self.band([(sx - 3, sy), (sx + 3, sy)], 1.0) * m))[..., None]
+ shadow = blur(shift(alpha, 4, 6), 3.0) * 0.35
+ self.items.append(dict(kind='opaque', rgb=np.clip(col, 0, 1).astype(np.float32), alpha=alpha, shadow=shadow))
+
+ def tape(self, cx, cy, w=84.0, h=28.0, rot=0.0, colour=TAPE):
+ """a strip of crepe drafting tape with torn ends, pressed down on top of everything"""
+ n = 8
+ t = np.deg2rad(rot)
+ u = np.array([np.cos(t), np.sin(t)], np.float32); v = np.array([-np.sin(t), np.cos(t)], np.float32)
+ rng = self.rng
+ pts = []
+ for i in range(n + 1): # torn left end, top to bottom
+ jag = (rng.uniform(0.0, 0.06) if i % 2 else rng.uniform(0.0, 0.015)) * w
+ pts.append((-w / 2 + jag, -h / 2 + h * i / n))
+ for i in range(n, -1, -1): # torn right end, bottom to top
+ jag = (rng.uniform(0.0, 0.06) if i % 2 else rng.uniform(0.0, 0.015)) * w
+ pts.append((w / 2 - jag, -h / 2 + h * i / n))
+ P = [(cx + a * u[0] + b * v[0], cy + a * u[1] + b * v[1]) for a, b in pts]
+ m = self.poly(P)
+ x0, y0 = int(max(0, min(p[0] for p in P) - 4)), int(max(0, min(p[1] for p in P) - 4))
+ x1, y1 = int(min(self.W, max(p[0] for p in P) + 5)), int(min(self.H, max(p[1] for p in P) + 5))
+ sl = (slice(y0, y1), slice(x0, x1))
+ hh, ww = y1 - y0, x1 - x0
+ s = self._seed()
+ Y, X = np.mgrid[y0:y1, x0:x1].astype(np.float32)
+ along = (X - cx) * u[0] + (Y - cy) * u[1]; across = (Y - cy) * v[1] + (X - cx) * v[0]
+ crepe = np.sin(along * 0.9 + 2.0 * noise2d(hh, ww, 8, 2, s)) * 0.5 + 0.5
+ fib = noise2d(hh, ww, 2.0, 2, s + 1)
+ side = np.clip(np.abs(across) / (h / 2), 0, 1)
+ T = _c(colour) * (1.0 - 0.03 * crepe - 0.04 * (fib - 0.5))[..., None]
+ T = T * (1 - 0.08 * side ** 6)[..., None]
+ self.items.append(dict(kind='tape', sl=sl, m=m[sl], T=np.clip(T, 0, 1).astype(np.float32),
+ shadow=(blur(shift(m, 1, 2), 1.4) * 0.16)))
+
+ # ------------------------------------------------------------ sheets
+ def sheet(self, x, y, w, h, kind='tracing', ink='blue', tint=None, fibre=None, curl=None, seed=None, edge=None):
+ """a new sheet at its laid-down position (x, y, w, h). kind: base | tracing | drafting | film;
+ ink: the plate this sheet prints by default (a name from INKS or '#rrggbb'); curl: 'br' or ('br', 80)"""
+ return Sheet(self, x, y, w, h, kind, ink, tint, fibre, curl, seed if seed is not None else self._seed(), edge)
+
+ def place(self, sheet, lift=0.0, dx=0.0, dy=0.0, rot=0.0):
+ """show a sheet: laid down (all zero), or lifted `lift` (0..1) and held off by dx, dy px and rot degrees
+ (counter-clockwise). The first place() puts the sheet on top of everything placed so far"""
+ sheet.state = (float(lift), float(dx), float(dy), float(rot))
+ if not any(it is sheet for it in self.items):
+ k = len(self.items)
+ while k > 0 and isinstance(self.items[k - 1], dict) and self.items[k - 1]['kind'] == 'tape':
+ k -= 1
+ self.items.insert(k, sheet)
+
+ def remove(self, sheet):
+ self.items = [it for it in self.items if it is not sheet]
+
+ def _warp(self, sheet, arrs):
+ """sample local arrays at the sheet's current pose -> canvas box (sl, list of arrays)"""
+ lift, dx, dy, rot = sheet.state
+ s = 1 + 0.03 * lift
+ if lift == 0 and dx == 0 and dy == 0 and rot == 0:
+ sl = (slice(sheet.y0, sheet.y0 + sheet.h), slice(sheet.x0, sheet.x0 + sheet.w))
+ return sl, arrs
+ w, h = sheet.w, sheet.h
+ Cx, Cy = sheet.x0 + w / 2 + dx, sheet.y0 + h / 2 + dy
+ th = np.deg2rad(rot); c, si = np.cos(th), np.sin(th)
+ corners = np.array([[-w / 2, -h / 2], [w / 2, -h / 2], [w / 2, h / 2], [-w / 2, h / 2]]) * s
+ P = np.stack([Cx + corners[:, 0] * c + corners[:, 1] * si, Cy - corners[:, 0] * si + corners[:, 1] * c], 1)
+ bx0, by0 = int(max(0, np.floor(P[:, 0].min()) - 2)), int(max(0, np.floor(P[:, 1].min()) - 2))
+ bx1, by1 = int(min(self.W, np.ceil(P[:, 0].max()) + 2)), int(min(self.H, np.ceil(P[:, 1].max()) + 2))
+ # local = c_local + R^T (P - C) / s, R = [[c, si], [-si, c]]
+ a, b = c / s, -si / s
+ d_, e = si / s, c / s
+ cc = w / 2 + a * (bx0 - Cx) + b * (by0 - Cy)
+ f = h / 2 + d_ * (bx0 - Cx) + e * (by0 - Cy)
+ out = []
+ for arr in arrs:
+ if arr.ndim == 3:
+ out.append(np.stack([self._warp1(arr[..., k], (a, b, cc, d_, e, f), bx1 - bx0, by1 - by0) for k in range(arr.shape[2])], -1))
+ else:
+ out.append(self._warp1(arr, (a, b, cc, d_, e, f), bx1 - bx0, by1 - by0))
+ return (slice(by0, by1), slice(bx0, bx1)), out
+
+ @staticmethod
+ def _warp1(a, data, ww, hh):
+ return np.asarray(Image.fromarray(np.ascontiguousarray(a, np.float32), 'F').transform(
+ (ww, hh), Image.AFFINE, data, resample=Image.BILINEAR), np.float32)
+
+ # ------------------------------------------------------------ render
+ def render(self):
+ """the photograph of the light box as it is now (float H x W x 3)"""
+ if self.panel is None:
+ self.lightbox(34, 24, self.W - 34, self.H - 24)
+ I = self._emission().copy()
+ Eavg = 0.95 * self.level + 0.55 * (1 - self.level)
+ for it in self.items:
+ if isinstance(it, dict):
+ if it['kind'] == 'opaque':
+ I *= 1 - it['shadow'][..., None] * (1 - np.array(SHADOW, np.float32))
+ a = it['alpha'][..., None]
+ room = 0.55 + 0.45 * self.level # the room is lit a little by the box
+ I = I * (1 - a) + it['rgb'] * room * a
+ elif it['kind'] == 'tape':
+ I *= (1 - it['shadow'][..., None] * (1 - np.array(SHADOW, np.float32)))
+ sl, m = it['sl'], it['m'][..., None]
+ T = it['T']
+ lit = I[sl] * T * 0.58 + T * 0.36 * (0.55 + 0.45 * self.level) # crepe paper: half seen through, half lit by the room
+ I[sl] = I[sl] * (1 - m) + lit * m
+ continue
+ sheet = it
+ if sheet.state is None: continue
+ lift, dx, dy, rot = sheet.state
+ C = sheet._build()
+ arrs = [C['A'], C['F'], C['cw'], C['csh']] + ([C['sheen']] if C['sheen'] is not None else [])
+ sl, warped = self._warp(sheet, arrs)
+ A, F, cw, csh = warped[:4]
+ sheen = warped[4] if len(warped) > 4 else None
+ Fc = np.zeros((self.H, self.W), np.float32); Fc[sl] = F
+ sh_col = 1 - np.array(SHADOW, np.float32)
+ # 1. a lifted diffuser blurs what is under it (and a curled corner, a little, under its tip)
+ if lift > 0.01:
+ sub = I[sl]
+ r = sheet.P['diffuse'] * lift
+ sb = np.stack([blur(sub[..., k], r) for k in range(3)], -1)
+ I[sl] = sub + (sb - sub) * F[..., None]
+ if cw.max() > 0:
+ sub = I[sl]
+ sb = np.stack([blur(sub[..., k], 2.2) for k in range(3)], -1)
+ I[sl] = sub + (sb - sub) * (cw * F)[..., None]
+ # 2. shadows: wide and soft while lifted (seen through the sheet), a thin contact line once down
+ if lift > 0.01:
+ ox, oy = 3 + 16 * lift, 4 + 30 * lift
+ sh = blur(shift(Fc, ox, oy), 2.5 + 16 * lift) * 0.22 * lift
+ sh *= 1 - 0.55 * Fc # under the sheet the room light still gets through
+ I *= (1 - sh[..., None] * sh_col)
+ down = 1 - min(1.0, lift)
+ if down > 0:
+ sh = (blur(shift(Fc, 1, 1.5), 1.3) * 0.30 + blur(shift(Fc, 2, 3.5), 4.5) * 0.09) * (1 - Fc) * down
+ I *= (1 - sh[..., None] * sh_col)
+ if csh.max() > 0:
+ I[sl] *= (1 - (csh * F)[..., None] * sh_col)
+ # 3. the sheet: transmittance, plus the frost of tracing paper (scattered light lifts the darks)
+ sub = I[sl]
+ T = 1 - A
+ v = sheet.P['frost'] * (1 - 0.5 * min(1.0, lift))
+ out = sub * T
+ if v > 0:
+ out = out * (1 - v * F[..., None]) + (v * F)[..., None] * T * Eavg
+ if sheen is not None:
+ out = 1 - (1 - out) * (1 - (sheen * F)[..., None] * (0.4 + 0.6 * self.level))
+ I[sl] = out
+ return I
+
+ def composite(self):
+ I = self.render()
+ if self._post is None:
+ H, W = self.H, self.W
+ Y, X = np.mgrid[0:H, 0:W].astype(np.float32)
+ r = np.hypot((X - W / 2) / W, (Y - H / 2) / H)
+ vig = 1 - 0.07 * r ** 2 * 2.2
+ grain = 1 + 0.010 * (noise2d(H, W, 1.0, 1, self.seed + 99) - 0.5)
+ self._post = (vig * grain).astype(np.float32)
+ I = I * self._post[..., None]
+ return Image.fromarray((np.clip(I, 0, 1) * 255 + 0.5).astype(np.uint8))
+
+ def stage(self, name):
+ if self.keep_stages:
+ self.stages.append((name, self.composite()))
+
+ def save(self, path, stages_dir=None, quality=88):
+ img = self.composite()
+ if str(path).lower().endswith(('.jpg', '.jpeg')): img.save(path, quality=quality, subsampling=0)
+ else: img.save(path)
+ if stages_dir:
+ os.makedirs(stages_dir, exist_ok=True)
+ for i, (name, im) in enumerate(self.stages):
+ im.save(f'{stages_dir}/{i:02d}_{name}.png')
+ img.save(f'{stages_dir}/{len(self.stages):02d}_final.png')
+ return img