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 shadow puppetry style (63 total): dyed leather puppets on a lamp-lit screen

cloveric3afdaa7d52e5
diff --git a/README.md b/README.md
index 6b1cbda..e68de5a 100644
--- a/README.md
+++ b/README.md
@@ -1,55 +1,55 @@
# Claude Drawing · Claude 绘图
-**Claude paints with code — no image model.** Sixty-two 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, a synthwave sunset, a pastel product-film UI and an answer sheet marked in red.
-**不用生图模型,Claude 用代码一笔一笔作画。** 六十二种画风,从水墨、油画到黏土、蓝晒、彩色玻璃花窗、罗马马赛克、代尔夫特蓝瓷砖、赛博朋克、光线追踪的小球海、低多边形 3D、热成像、X 光片、VHS 录像带、Synthwave 落日、产品发布片式的粉彩界面和红笔批改的答题卡。
+**Claude paints with code — no image model.** Sixty-three 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, a synthwave sunset, a pastel product-film UI, an answer sheet marked in red and a lamp-lit shadow-puppet play.
+**不用生图模型,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 · 水彩底纹 |
+| Watercolour · 水彩 | Watercolour washes · 水彩底纹 | 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) |
-| **Overlay sheets · 描图纸叠层** | **Pastel UI · 粉彩界面** | **Exam grading · 阅卷批改** |
-| ![overlay](examples/drawing_overlay_city_map.gif) | ![pastelui](examples/drawing_pastelui_packing.gif) | ![grading](examples/drawing_grading_math_quiz.gif) |
+| ![watercolour](examples/drawing_watercolor_autumn.gif) | ![washes](examples/drawing_watercolor_washes.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) |
+| **Pastel UI · 粉彩界面** | **Exam grading · 阅卷批改** | **Shadow puppetry · 皮影戏** |
+| ![pastelui](examples/drawing_pastelui_packing.gif) | ![grading](examples/drawing_grading_math_quiz.gif) | ![shadowpuppet](examples/drawing_shadowpuppet_cuju.gif) |
### Gallery · 画廊
@@ -57,70 +57,70 @@
|---|---|
| **八万四千法门** · *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> | **水彩底纹** · *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%"> |
-| **出发前,再查一遍行李** · *Pack Check*<br><sub>Pastel UI · 粉彩界面</sub> | **数学单元测验** · *Unit Test, Graded*<br><sub>Exam grading · 阅卷批改</sub> |
-| <img src="examples/pastelui_packing.jpg" width="100%"> | <img src="examples/grading_math_quiz.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, window cards floating on a pastel field over shadows tinted by it, a vermilion stamp running dry at one end and red ink pooling where the pen slowed down. 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> | **热气球小镇** · *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%"> |
+| **海港步行图** · *Larkhaven on Foot*<br><sub>Overlay sheets · 描图纸叠层</sub> | **出发前,再查一遍行李** · *Pack Check*<br><sub>Pastel UI · 粉彩界面</sub> |
+| <img src="examples/overlay_city_map.jpg" width="100%"> | <img src="examples/pastelui_packing.jpg" width="100%"> |
+| **数学单元测验** · *Unit Test, Graded*<br><sub>Exam grading · 阅卷批改</sub> | **蹴鞠** · *Cuju by Lamplight*<br><sub>Shadow puppetry · 皮影戏</sub> |
+| <img src="examples/grading_math_quiz.jpg" width="100%"> | <img src="examples/shadowpuppet_cuju.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, window cards floating on a pastel field over shadows tinted by it, a vermilion stamp running dry at one end, red ink pooling where the pen slowed down and dyed donkey hide glowing on a lamp-lit screen. 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.
---
@@ -128,7 +128,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 sixty-two styles:
+A [Claude Code](https://claude.com/claude-code) skill and a small painting library with sixty-three styles:
| Style | Module | What makes it read as the real medium |
|---|---|---|
@@ -194,6 +194,7 @@ A [Claude Code](https://claude.com/claude-code) skill and a small painting libra
| **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 |
| **Pastel UI (product-film interface)** | `lib/pastelui.py` · `PastelUI` | one frame of a modern product film: a flat pastel field (blue, pink, yellow, lilac, mint, peach) with one big pool of soft light and a few white bokeh discs; macOS window cards with a frosted rim, a white body, the red / yellow / green lights and split panes, side panels, a dot pill and a step strip, a heavy headline with a translucent marker under the key words, status chips, round check / cross badges, text highlights, an inline reference chip and a callout tag; every shape is a signed-distance field with analytic 1 px anti-aliasing, and shadows follow CSS box-shadow (offset, blur, spread; a wide one tinted with the field colour plus a tight neutral one), so cards float without a grey halo; everything is drawn into named layers with a pose (offset, scale, opacity, left-to-right reveal) and a depth, so the same drawing pops a window up, writes a line, pops a badge or lets a companion rise from behind a card; a magnifier that enlarges the real pixels under it; a circular colour wipe between sections; three flat companions peek over the card edges — a starburst in a cream circle, a violet cloud with a >_ prompt, an orange pixel critter |
| **Exam grading (an answer sheet marked in red)** | `lib/grading.py` · `Grading` | an answer sheet on a green felt desk, printed like the real form — timing marks down the edge, a heavy title, fields, a ticket number with its bubbles filled, a score / grader table, numbered sections, ruled answer lines and a hatched grading column — with an answer key held by a black binder clip beside it; every paper has its own frame and pose, so a sheet can come down onto the desk (a little larger with a wide soft shadow while lifted, a thin contact shadow once down); everything written after printing keeps a progress value and a time map, so a stage can show a stroke half drawn: the candidate's blue-black answers, vermilion rubber stamps (ragged edges, clustered pin-holes, one end pressed dry so the thin border breaks, ink pooled at the rims, a wet bleed, a slight tilt, the paper dented round the rubber) and the red pen — a wavy underline, a ring that overshoots its start, a bowed leader, a note set in a bold sans and inked like the pen (no handwriting font), crosses, ticks and a score written stroke by stroke and circled; ink is Beer–Lambert density, so the red deepens where the pen slowed down and where it crosses print; a red pen shaded as a cylinder whose shadow spreads from the tip, and a varnished wooden stamp that comes down, presses and lifts |
+| **Shadow puppetry (皮影戏)** | `lib/shadowpuppet.py` · `ShadowPuppet` | a shadow play seen from the audience, where everything on the screen is lamp light that came through it: a cloth screen lit by an oil lamp behind the middle (pale gold at the hot spot, deep amber toward the rim, thread slubs, a fold or two); puppets of scraped donkey hide kept as coverage plus an optical density per channel, so vermilion, teal, ochre and green glow, black dye is almost opaque and pieces darken where they overlap, in any order; pieces are cut, dyed in fields, inked along every cut edge and punched with the craft's hollow patterns (dots, rings, plum blossoms, coins, fish scales, ruyi cloud heads, lattice, ice cracks, stripes), and the hide's uneven thickness leaves no dye flat; a figure is a tree of jointed pieces with thread knots and an angle per joint (a hollow-carved or solid face in profile with one long eye and a long brow, a helmet with barred pheasant plumes or a crown with pompoms, cloud collar, breastplate mirror, scale armour, cuffs, thick-soled boots), with control rods tied to the collar and the hands; a puppet off the cloth grows, blurs and splits into two shadows (the lamp has two wicks), the soft double edge of a figure not quite pressed, and rods are sharp where they are tied and soft lower down; props come from the same leather (a pailou goal with a lattice net and a round eye, a stitched ball, a key-fret floor band, hanging name plaques); in front, a carved proscenium (key-fret lintel, a red lacquer plaque with raised gilt characters, an openwork valance and corner brackets the screen glows through) lit only by the light the screen spills onto its edges, and red paper lanterns lit from inside, with tassels and a warm halo |
Ask Claude to *"draw it yourself"*, *"paint this with code"*, or *"claude绘图"*, and name a style if you like. Claude then:
@@ -309,6 +310,7 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages
- **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.
- **Pastel UI**: one screen, one idea — a headline, one main window, one side panel and a status, with few words set large. Keep the field flat and the cards solid white; colour lives in the accents (the step strip, chips, badges, markers), and green is reserved for a pass, so use a blue field when there are checks and crosses. Put companions on a lower layer than the card they peek over, so the card itself hides the rest of them. Give a magnifier room: centre it on one thing with its labels outside the rim (a lens over a narrow column cuts its label and temperature in half). Draw each state of a thing as its own layer and switch them; for the draw-on GIF, give anything that moves a few in-between poses instead of a cross-fade.
- **Exam grading**: tell one grading story on one sheet — a few answers, one mistake, and every red mark pointing at it: a wave under it, a ring round it, a leader out to the grading column, and the note and the cross on the same row as the error (put that row first in the column so the leader stays short). Keep the words few and large and let the form itself (bubbles, timing marks, hatching) carry the texture. Give a ring room: it needs ~8 px of clear paper on each side, so leave the candidate a wider gap before the wrong figure. Stamps should be uneven but still legible (pressure ~0.64 at the light end). Red ink is Beer–Lambert density and only darkens a little above ~0.8, so light and dark passages come from the density range (about 0.4–1.2), not from the colour. In the GIF, give the pen and the stamps real in-between frames (`~` motion stages) instead of cross-fades.
+- **Shadow puppetry**: keep the screen dark at the rim and pale gold only round the lamp, so dyed leather glows instead of looking printed. Leave big fields of solid dye and put the hollow patterns in bands; a pattern cell under ~12 px on the canvas turns a robe into fishnet. In profile the shoulder sits right under the head, so a near arm raised past ~140° crosses the face: raise the far arm up and back and keep the near one forward (130–147°). The classic 亮相 is one arm high behind, one low in front and a knee up. Give each figure room for its plumes, and keep the shoulder guard on the near arm only. A puppet slightly off the cloth (d ≈ 0.05) should read as a sharp shadow with a soft double edge, not as out of focus. In the GIF, everything that moves gets real in-between frames (`~` motion stages): the lamp glow spreading, players sliding in from the wings blurred and doubled until they are pressed sharp, the kick, the 亮相 snap.
### Roadmap
@@ -320,7 +322,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,加上一个小巧的绘图库,内置六十三种画风:
| 画风 | 模块 | 为什么看起来像真的 |
|---|---|---|
@@ -386,6 +388,7 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages
| **描图纸叠层** | `lib/overlay.py` · `Overlay` | 画面就是一路透过率相乘:暖白灯箱从下面照上来,先透过一张黑线灰调的底图,再透过一张张只印一种油墨的半透明叠片,叠片对着套准十字放下;油墨按网点覆盖率算(超过 100% 是叠印加深),不同叠片的油墨正片叠底,蓝叠黄成绿、品红叠黄成红、品红叠蓝成紫;每张纸有自己的纸色、只有背光才看得见的云状纤维和零星纤维丝、一道细暗的裁切边、落在钢定位钉上的打孔;抬起的纸略放大、投一片透过纸也看得见的宽软阴影,并像漫射片一样把下面的东西都模糊掉,放下后才清晰,只剩一道贴边细影;卷角、撕口的皱纹绘图胶带、带光泽的透明胶片;底图里的小城用递归切分的街道切出街区,沿街一圈房屋和分户墙,海岸外一圈圈水线 |
| **粉彩界面** | `lib/pastelui.py` · `PastelUI` | 产品发布片里的一帧界面:整片纯色粉彩底(蓝 / 粉 / 黄 / 淡紫 / 薄荷 / 桃)加一大片柔光和几颗白色光斑;macOS 窗口卡片(磨砂外框、白色窗体、红黄绿三点、分栏)、侧面板、带圆点的小胶囊和步骤条、粗黑大标题压一条半透明色条、状态标签、圆形 ✓ / ✗ 徽章、文字高亮、嵌在正文里的引用标签和带尖角的小标签;所有形状都是有符号距离场、1 px 解析抗锯齿,阴影按 CSS box-shadow 算(偏移、模糊、扩展;一层染着底色的宽阴影加一层中性的近阴影),卡片浮起来却没有灰边;一切画进带姿态(位移、缩放、不透明度、从左往右揭开)和前后层次的图层,同一套画面既能弹出窗口、逐行写字、弹出徽章,也能让小图标从卡片后面探头;放大镜放大的是它下面真实的像素;节与节之间圆形擦除换底色;三个扁平小图标从卡片边探头——奶油色圆里的橙色星芒、紫色云朵里的 >_、橙色像素小怪 |
| **阅卷批改** | `lib/grading.py` · `Grading` | 绿毛毡桌上的一张答题卡,照真表格印:左边一排定位黑块、粗黑标题、姓名班级栏、考号格和涂好的圆泡、得分 / 阅卷人表格、分节、作答横线、斜纹阅卷栏;旁边是长尾夹夹住的标准答案卡。每张纸有自己的坐标和位姿,能从空中落到桌上(抬着时略大、投一片宽软的影,放下后只剩贴边细影);印刷之后写上去的东西都带「写到第几成」的进度和时间图,阶段快照能画出写到一半的笔画:考生的蓝黑作答、朱红橡皮章(毛边、成簇针孔、一头压得轻而细框断开飞白、边缘积墨、刚盖下的湿晕、轻微歪斜、纸面压出的凹痕),以及红笔的波浪线、越过起点的手画圈、弧形引线、用粗黑体按红墨处理的批注(不用手写字体)、叉、勾、一笔笔写出再圈起来的分数;墨按比尔定律算密度,笔走慢的拐弯处、压在印刷上都会更深;红笔按圆柱打光、投影从笔尖散开,上漆木章落下、压一下、再抬起 |
+| **皮影戏** | `lib/shadowpuppet.py` · `ShadowPuppet` | 观众这边看到的一场皮影,幕布上的一切都是透过来的灯光。幕布由一盏油灯从背后照亮:灯后面淡金,往外深琥珀,带纱线粗节和一两道折痕。人偶是刮薄的驴皮,按覆盖率加每个通道的光密度来算,所以朱红、青绿、赭黄、绿色透亮,黑色几乎不透,两块皮相叠处更深,和先后顺序无关;每块皮可以剪、分区染色、沿剪边描黑,打出皮影的各种镂空纹样(圆点、圆环、梅花、铜钱、鱼鳞、如意云头、方格、冰裂、条孔),皮厚不匀让染色不会死平。关节人偶是一棵带线结、每个关节一个角度的皮件树(阳刻空脸或阴刻脸的侧面像,一只长眼一道长眉;带黑横斑的雉翎盔或绒球三叉冠;云肩、护心镜、鱼鳞甲、袖口、厚底靴),操纵杆绑在领口和手上。离开幕布的人偶会变大、变虚,又因为灯有两个灯芯分成两个影,就是没贴紧时那种软的双边;操纵杆绑的地方清楚,往下越来越虚。同一套皮还做道具:牌楼式球门(窗棂网和风流眼)、缝线的鞠、回纹底带、挂在线上的小牌。幕前是雕花戏台(回纹横楣、红漆凸起金字牌匾、透空挂落和花牙子,幕布的光从镂空处透出来),只被幕布溢出的光照亮边缘;还有内有烛光的红纸灯笼,带穗子和一圈暖光 |
对 Claude 说「claude绘图」「你自己画」「用代码画」,也可以指定画风。它会:
1. **先定构图**:层次、焦点、留白,而且画面要图解内容本身;
@@ -477,6 +480,7 @@ python3 examples/ballpoint_board_game.py out.png # 圆珠笔
python3 examples/overlay_city_map.py out.jpg --stages stages/ # 描图纸叠层:海港步行图
python3 examples/pastelui_packing.py out.jpg --stages stages/ # 粉彩界面:出发前,再查一遍行李
python3 examples/grading_math_quiz.py out.jpg --stages stages/ # 阅卷批改:数学单元测验
+python3 examples/shadowpuppet_cuju.py out.jpg --stages stages/ # 皮影戏:蹴鞠
```
### 作画要点(Claude 交图前逐条自查)
@@ -541,6 +545,7 @@ python3 examples/grading_math_quiz.py out.jpg --stages stages/ # 阅卷批
- **描图纸叠层**:按「光」想,不按「颜料」想——每张纸只会挡光,所以浅色是网点覆盖率,叠色交给正片叠底自己算。所有分色片都用纸放下时的同一套画布坐标画,每张都印同一组套准十字,天然对得上。描图纸要透(透过率约 0.98、云纹约 2%),否则三张叠下来整座城发灰。反白数字露出的是下面那一层,所以站点别压在深色地标上;电车和步行路线在同一条路上要各走一边。胶带和卷角放在没印东西的地方。纸只抬一点(模糊 σ 约 3 px、偏 20–35 px),看上去是「悬着」,不是又一张画。
- **粉彩界面**:一屏只讲一件事——一个大标题、一个主窗口、一个侧面板、一个状态,字少而大。底色平、卡片实心白,颜色只放在强调处(步骤条、标签、徽章、色条);绿色只留给「通过」,所以有 ✓ / ✗ 的画面用蓝底。小图标放在它探头的那张卡片下一层,让卡片自己挡住其余部分。放大镜要有地方放:对准一样东西,标签放在镜框外(镜片压在窄窄一列上会把日期和温度切成两半)。同一样东西的不同状态各画一层再切换;做动图时,会动的东西给几个中间姿态,不要叠化。
- **阅卷批改**:一张卷子讲一件批改的事——几道作答、一处错,所有红笔都指向它:下面波浪线、外面一个圈、一道引线拉到阅卷栏,批注和叉跟出错那行同高(把批注行排在阅卷栏第一行,引线才短)。字少而大,纹理交给表格本身(涂卡圆泡、定位黑块、斜纹)。圈要有地方:两边各要约 8 px 空白,所以让考生在写错的那个数前多空一格。印章要不匀但认得出(轻的那头压力约 0.64)。红墨按比尔定律算密度,0.8 以上只是略微变深,浓淡要靠密度范围(约 0.4–1.2)拉开,而不是换颜色。做动图时,笔和章给真正的中间帧(`~` 运动阶段),不要叠化。
+- **皮影戏**:幕布边缘要暗,只在灯后面那一块发淡金,染色的皮才会「透亮」,而不是像印上去的。大面积留实色,镂空纹样只放在一段里:画布上一个纹样单元小于约 12 px,袍子就成了渔网。侧身时肩就在头的正下方,近侧手臂抬过约 140° 会从脸前过:要高举就举远侧那只往后上方,近侧手臂斜向前上(130–147°);亮相就是一手高(远侧向后上)、一手低(近侧向前下),再提膝。给翎子留地方;护肩花只放在近侧手臂上。离幕一点(d ≈ 0.05)的人应该是一个清楚的影加一条软的双边,不是失焦。做动图时,会动的都给真正的中间帧(`~` 运动阶段):光晕铺开,人从侧幕滑进来由虚变实,起脚,亮相定住。
### 计划
diff --git a/SKILL.md b/SKILL.md
index a91c8c6..69e37fd 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)、扁平矢量(分层几何色块、七色、层间投影)、绘本角色动画(小角色挤压拉伸的真动画)、圆珠笔涂鸦(蓝红圆珠笔线稿、墨团、彩铅、页边涂鸦)、描图纸叠层(灯箱上的黑线底图 + 一张张单色描图纸叠片:正片叠底、套准十字、定位钉、绘图胶带)、粉彩界面 · Pastel UI(产品发布片式的界面画面:纯色粉彩底与大光斑、macOS 窗口卡片、胶囊与粗黑标题色条、状态标签与 ✓ / ✗ 徽章、放大镜、从卡片边探头的扁平小图标)、阅卷批改 · Exam Grading(绿毛毡桌上被红笔批改的答题卡:定位黑块、考号涂卡、得分格与阅卷栏、长尾夹夹住的标准答案卡、油墨不均的朱红印章、立体红笔、波浪线 / 圈 / 引线 / 批注 / 叉 / 圈起来的分数)。用户说「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、家庭录像、录像带、扁平插画、扁平风、矢量插画、绘本动画、角色动画、挤压拉伸、圆珠笔、圆珠笔涂鸦、原子笔、页边涂鸦、课本涂鸦、手画棋盘、描图纸、硫酸纸、叠片、叠层、分色片、灯箱、拷贝台、透光台、套准、定位钉、粉彩界面、粉彩 UI、Dot 风、Dot 那种风格、产品发布会界面、发布会质感、窗口卡片、macOS 窗口、界面卡片、讲解片界面页、小图标探头、阅卷、阅卷批改、批改、判卷、改卷、改作业、答题卡、试卷、考卷、测验卷、红笔批改、红笔打分、打分数、盖章批改、朱红印章、标准答案卡、长尾夹、讲解片评测 / 打分页),或 "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 / pastel UI / Dot-style product film / launch-film interface / macOS window cards / exam grading / grading an answer sheet / red-pen marking / graded test paper / rubber-stamped answer sheet without an image model" 时使用;也用于需要逐步画出(draw-on)动画的插画。单独说「剪纸」指剪纸拼贴、「刺绣」指十字绣、「丝网印刷 / screen print」指包豪斯几何;「打马赛克」是打码,不是马赛克画风;单说「蓝图」指蓝图工程图,「蓝晒 / 晒图」仍指蓝晒;「铅笔 / 素描」指铅笔素描,「彩铅」指韩国彩铅;「像素」仍指像素风,「1-bit / 黑白画图软件」指 1-bit 早期画图软件;「霓虹」仍指赛博朋克;「喷漆 / 街头涂鸦」仍指喷漆模板涂鸦,「圆珠笔 / 随手涂鸦 / 页边涂鸦」指圆珠笔涂鸦;「描图纸 / 硫酸纸 / 叠片 / 灯箱」指描图纸叠层(蓝图工程图那张描图布是晒成蓝图的,不是叠片);「Dot 风 / 粉彩界面 / 窗口卡片 / 发布会界面」指粉彩界面(纯色底 + 白色实心窗口卡片),要磨砂玻璃和弥散渐变仍用弥散玻璃;「阅卷 / 批改 / 答题卡 / 判卷 / 红笔打分」指阅卷批改,实验记录里的红笔圈和便利贴仍用实验笔记本,带「已付」橡皮章的小票拼贴仍用贴纸拼贴 · 小票。
+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)、扁平矢量(分层几何色块、七色、层间投影)、绘本角色动画(小角色挤压拉伸的真动画)、圆珠笔涂鸦(蓝红圆珠笔线稿、墨团、彩铅、页边涂鸦)、描图纸叠层(灯箱上的黑线底图 + 一张张单色描图纸叠片:正片叠底、套准十字、定位钉、绘图胶带)、粉彩界面 · Pastel UI(产品发布片式的界面画面:纯色粉彩底与大光斑、macOS 窗口卡片、胶囊与粗黑标题色条、状态标签与 ✓ / ✗ 徽章、放大镜、从卡片边探头的扁平小图标)、阅卷批改 · Exam Grading(绿毛毡桌上被红笔批改的答题卡:定位黑块、考号涂卡、得分格与阅卷栏、长尾夹夹住的标准答案卡、油墨不均的朱红印章、立体红笔、波浪线 / 圈 / 引线 / 批注 / 叉 / 圈起来的分数)、皮影戏 · Shadow Puppetry(油灯照亮的幕布上,雕空、透明染色的驴皮关节人偶:镂空纹样、阳刻空脸、雉翎盔头、线结与操纵杆、离幕时虚化的双影;雕花戏台、红漆金字牌匾、红灯笼)。用户说「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、家庭录像、录像带、扁平插画、扁平风、矢量插画、绘本动画、角色动画、挤压拉伸、圆珠笔、圆珠笔涂鸦、原子笔、页边涂鸦、课本涂鸦、手画棋盘、描图纸、硫酸纸、叠片、叠层、分色片、灯箱、拷贝台、透光台、套准、定位钉、粉彩界面、粉彩 UI、Dot 风、Dot 那种风格、产品发布会界面、发布会质感、窗口卡片、macOS 窗口、界面卡片、讲解片界面页、小图标探头、阅卷、阅卷批改、批改、判卷、改卷、改作业、答题卡、试卷、考卷、测验卷、红笔批改、红笔打分、打分数、盖章批改、朱红印章、标准答案卡、长尾夹、讲解片评测 / 打分页、皮影、皮影戏、影子戏、驴皮影、灯影戏、皮影人偶、雕花戏台、戏台牌匾、亮相),或 "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 / pastel UI / Dot-style product film / launch-film interface / macOS window cards / exam grading / grading an answer sheet / red-pen marking / graded test paper / rubber-stamped answer sheet / shadow puppet / shadow puppetry / Chinese shadow play / leather shadow puppets / backlit puppet screen without an image model" 时使用;也用于需要逐步画出(draw-on)动画的插画。单独说「剪纸」指剪纸拼贴、「刺绣」指十字绣、「丝网印刷 / screen print」指包豪斯几何;「打马赛克」是打码,不是马赛克画风;单说「蓝图」指蓝图工程图,「蓝晒 / 晒图」仍指蓝晒;「铅笔 / 素描」指铅笔素描,「彩铅」指韩国彩铅;「像素」仍指像素风,「1-bit / 黑白画图软件」指 1-bit 早期画图软件;「霓虹」仍指赛博朋克;「喷漆 / 街头涂鸦」仍指喷漆模板涂鸦,「圆珠笔 / 随手涂鸦 / 页边涂鸦」指圆珠笔涂鸦;「描图纸 / 硫酸纸 / 叠片 / 灯箱」指描图纸叠层(蓝图工程图那张描图布是晒成蓝图的,不是叠片);「Dot 风 / 粉彩界面 / 窗口卡片 / 发布会界面」指粉彩界面(纯色底 + 白色实心窗口卡片),要磨砂玻璃和弥散渐变仍用弥散玻璃;「阅卷 / 批改 / 答题卡 / 判卷 / 红笔打分」指阅卷批改,实验记录里的红笔圈和便利贴仍用实验笔记本,带「已付」橡皮章的小票拼贴仍用贴纸拼贴 · 小票;「皮影 / 皮影戏 / 影子戏」指皮影戏(透光的彩色驴皮人偶),黑纸剪出的侧影小像仍用剪影,彩纸剪贴仍用剪纸拼贴。
---
# Claude 绘图
@@ -76,6 +76,7 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型
| 描图纸叠层 | `lib/overlay.py` · `Overlay` | `examples/overlay_city_map.py` 海港步行图 · Larkhaven on Foot(暖白灯箱上,定位钉挂着一张黑线灰调的海边小城底图:递归切出的街区、沿街一圈房屋和分户墙、深色地标、海岸与防波堤、铁路、城堡山和岬角的等高线;三张单色叠片对着套准十字落下——蓝片(沿岸一圈圈水线、河、港湾、渡轮航线、2 路电车)、黄片(公园、集市广场、海滩)、品红片(六站步行路线,坐渡轮去灯塔);不同叠片的油墨正片叠底:植物园的池塘叠成绿、路线压过公园成红、压过海面成紫;描图纸背光下的纤维云纹、卷角、打孔、绘图胶带,旁边一张透明胶片上的图例卡) | 约 7 秒 |
| 粉彩界面 · Pastel UI | `lib/pastelui.py` · `PastelUI` | `examples/pastelui_packing.py` 出发前,再查一遍行李 · Pack Check(产品发布片里的一帧:蓝色粉彩底、一大片柔光和几颗白色光斑;左上胶囊「旅行清单」和步骤条 证件 → 充电 → 雨具 → 出发,粗黑大标题「出发前,再查一遍行李」压一条浅蓝色条;macOS 窗口「打包清单 · 京都 4 天」:左栏目的地、三天天气预报(周一下雨)、已装好 11 / 12 进度条,右栏打包助手的话逐行写出——行首的引用标签「证件夹 ✓」、绿色色条压在已装好的东西下、粉色高亮「周一京都有小雨」配「伞还没装」小标签;右边「出门检查」面板三行:证件 ✓、充电 ✓、雨具 ✗,结论「还差一把伞」;放大镜停在周一的雨云上,镜里是真像素放大;紫色云朵 >_ 从窗口后面探头、奶油色圆里的橙色星芒从面板后面探头、橙色像素小怪站在面板上) | 约 0.5 秒(加 `--stages` 约 5 秒) |
| 阅卷批改 · Exam Grading | `lib/grading.py` · `Grading` | `examples/grading_math_quiz.py` 数学单元测验 · Unit Test, Graded(深绿毛毡桌上一张米色答题卡,下面还压着两张:左边一排定位黑块、角标、粗黑标题、姓名班级栏、考号格和涂好的涂卡圆泡、得分 / 阅卷人表格、填涂示例;一题三道计算,二题应用题(灰底题目框 + 浅方格横线作答区 + 斜纹阅卷栏);左边长尾夹夹着深蓝页眉的标准答案卡,下面一张评分小纸条。考生用蓝黑墨水逐行作答;两个朱红橡皮章盖进阅卷栏(书写工整 ✓、列式正确 ✓);红笔给三道计算打勾,在 128 ÷ 16 = 6(天)下画波浪线、圈出「6(天)」、引线拉到阅卷栏写「应为 8 天」再打叉,答句里的 6 划一道,标准答案卡上 ① 打勾、② 打叉,最后在得分格写 75 并圈起来,笔放在得分格旁;印章一头发干、边缘飞白、轻微歪斜,红墨有浓淡和晕染,纸纹和灯光不均;`--stages` 出 113 个阶段,含纸落下、章落下压一下抬起、红笔边走边写的中间帧) | 约 1 秒(成品)/ 约 35 秒(含阶段) |
+| 皮影戏 · Shadow Puppetry | `lib/shadowpuppet.py` · `ShadowPuppet` | `examples/shadowpuppet_cuju.py` 蹴鞠 · Cuju by Lamplight(油灯从背后照亮的琥珀色幕布,前面是雕花戏台:回纹浮雕横楣、红漆金字牌匾「蹴鞠」、透空回纹挂落、两角镂空花牙子、两盏红灯笼;幕上是雕空、透明染色的驴皮:牌楼式球门(瓦顶飞檐、鸱吻、窗棂网、红边风流眼)、底部回纹装饰带、四个关节人偶。红方球头刚起脚,一条腿踢得老高,同伴一手高一手低、提膝亮相;青方一个跳起扑球(离幕一点,边缘发软、成双影),一个指着球;鞠正卡在风流眼里;「球头」「骁色」两块小牌挂在线上。人偶是阳刻空脸或阴刻红脸、雉翎盔或三叉冠、云肩护心镜鱼鳞甲、厚底靴,皮叠在一起处更深,关节有线结,操纵杆从领口和手上垂下去;`--stages` 出 60 个阶段,全是真运动:点灯、横楣落下、灯笼晃着亮起、球门升起、人从侧幕滑进来由虚变实、传球、起脚、亮相、小牌落下) | 约 7 秒(成品)/ 约 27 秒(含阶段) |
各画风共用 `lib/core.py` 里的底层工具:噪声、模糊、样条曲线、多边形遮罩、有机轮廓 `blob_pts`、毛笔 `bristle_stroke`、中文字体查找;新四种还用到补零平移 `shift`、文字遮罩 `text_mask`、西文字体查找 `latin_font`/`load_font`,以及高度图打光 `height_normals`、`height_shadow`(沿光线步进的投影)、`ambient_occlusion`。
@@ -141,7 +142,8 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型
- 上课 / 午休走神的随手涂鸦、纸上正在进行的游戏或计划(手画棋盘、寻宝图、清单、路线、比分)、学生和办公室日常的轻松小故事、讲解片里「在草稿纸上推演一步」的页 → 圆珠笔涂鸦(要铅笔图表、荧光笔和贴纸的实验记录用实验笔记本;要没有线稿、柔和的彩铅小物用韩国彩铅;要小孩的蜡笔画用儿童蜡笔画;要黑白石墨写生用铅笔素描);
- 地图、路线与导览、城市 / 园区 / 校园平面图,「一层一层把信息加上去」的图解(底图 → 水系 → 绿地 → 路线),设计稿或方案的分层、叠加与对照,讲解片里「把几层信息叠起来看」的页 → 描图纸叠层(要正等轴的微缩模型用等轴 2.5D;要剖面、尺寸和施工说明用蓝图工程图;要三原色丝网海报用包豪斯几何);
- 产品发布片 / 科技讲解片的「界面 / 流程 / 检查结果」页,要明亮干净、像真产品截图的窗口卡片,一屏讲一件事(大标题 + 一个主窗口 + 一个侧面板 + 状态),一整部讲解片统一的主画面(每节换一种粉彩底、圆形擦除转场)→ 粉彩界面(要磨砂玻璃和弥散渐变用弥散玻璃;要等轴微缩模型用等轴 2.5D;要黑白早期界面用 1-bit 早期画图软件);
-- 考试、作业、批改与打分,「对照标准答案逐条检查」的过程(评测、验收、审核、评分规则、哪里错了、为什么扣分),讲解片里的「怎么判对错 / 评分标准 / 检查结果」页 → 阅卷批改(要草稿纸上的随手推演用圆珠笔涂鸦;要实验记录、红笔圈和便利贴用实验笔记本;要明亮的产品界面里打 ✓ / ✗ 用粉彩界面)。
+- 考试、作业、批改与打分,「对照标准答案逐条检查」的过程(评测、验收、审核、评分规则、哪里错了、为什么扣分),讲解片里的「怎么判对错 / 评分标准 / 检查结果」页 → 阅卷批改(要草稿纸上的随手推演用圆珠笔涂鸦;要实验记录、红笔圈和便利贴用实验笔记本;要明亮的产品界面里打 ✓ / ✗ 用粉彩界面);
+- 中国传统与民间艺术、节庆(元宵、庙会、过年)、戏曲和民间故事、古代体育与游戏(蹴鞠、赛龙舟、舞狮)、「一场好戏」式的小叙事(登场—交手—亮相),讲解片里的「历史 / 传统 / 一场比赛的高光时刻」页,要人物有动作又不能用真人 → 皮影戏(要黑纸剪的侧影小像用剪影;要彩纸剪贴的童趣用剪纸拼贴;要山水留白用水墨)。
每种画风一幅范例作为质量基准(范例都不用禅意主题);水墨另加一幅「月印万川」(留白托月、水面倒影)。
@@ -994,6 +996,16 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask
- 字体 `font(kind, size)`:heavy(兰亭黑 Heavy:标题、印章)、bold / medium / body / light(苹方)、latin / latin_heavy(Avenir Next)、digits(DIN)、mono(Menlo:考号);兰亭黑和苹方是 macOS 按需下载的字体,没有时退到冬青黑体、华文黑体,Linux 用 Noto Sans CJK,Windows 用微软雅黑;可用 `INKPAINT_FONT_GRADING_<KIND>` 指定
- 色板常量 `INK GRAY RULE ANSWER PEN STAMP NAVY FELT PAPERS SHADOW`;`render()`、`composite()`、`stage(name)`、`save(path, stages_dir)`;`save('x.jpg')` 默认 quality 88、4:4:4 色度
+**皮影戏 `ShadowPuppet`**:
+- 思路:幕布上看到的每一点都是透过来的灯光。幕布是一盏油灯从背后照亮的布:灯后面那一块最亮、最淡,往外越来越深的琥珀色,带纱线粗节、一两道折痕和暗角。人偶是刮薄上油的驴皮,半透明、染透明色:每块皮(`Leather`)存覆盖率和每个通道的光密度,到达眼睛的是 灯光 × exp(−密度),所以朱红、青绿、赭黄透亮,黑色几乎不透光,两块皮叠在一起密度相加、自然变深(关节、远侧手脚压在身上都这样),叠放顺序不影响结果。人偶贴在幕上(`d = 0`)清楚;`d` 越大影子越大越虚,又因为灯有两个灯芯,分成两个错开的影,就是「没贴紧」的那种软的双边。操纵杆在绑的地方清楚,越往下越离幕、越虚。最后整幅加一点辉光、一条柔肩的色调曲线、暗角和细颗粒;雕花戏台和灯笼在幕前,被幕布溢出的光照亮
+- 构造:`ShadowPuppet(W, H, seed, keep_stages=True, stages_dir=None)`(给了 `stages_dir`,`stage()` 当场写 PNG);`screen(colour, edge, hot, weave, folds)` 幕布(`hot` = 灯在幕后的位置);`lamp(level, radius, flicker)` 灯:亮度、光晕铺开到几成(0.1 = 刚点着的一小团)、闪一下(±);`proscenium(plaque='蹴鞠', top=150, valance=54, side=64, sill=80, bracket=170, plaque_w=420)` 戏台:回纹浮雕横楣 + 中间红漆金字牌匾、透空回纹挂落、两角镂空花牙子、立柱、台口,并把幕布开口设成框内;`frame(dy, alpha)` 横楣这一组的位姿(动图里从上面落下来,灯笼跟着动);`lantern(x, top, r, drop, tassel, lit, swing)` 红纸灯笼:竹骨、里面的烛光、黑漆金边帽、金结红穗、一圈暖光晕,`set(lit, swing, shown)`
+- 皮 `Leather(x0, y0, x1, y1, scale, ss=3, seed)`(坐标是设计单位,× scale 是像素,原点就是枢轴;`sp.leather(...)` 自动给种子):`fill(形状, 染料)` 剪出 / 贴上一块皮,`dye(形状, 染料)` 给已有的皮换色,`edge(宽)` 沿剪边描黑,`contour(区域, 宽)` 给一块区域描边,`punch(形状, rim)` 打孔(孔边一圈墨),`line(点, 宽)` 一条皮线,`carve(点, 宽)` 刻一道缝,`pattern(区域, 纹样, 大小, angle, margin, origin)` 在区域里镂空,四周留 margin 宽的实皮:`dots` 圆点、`rings` 圆环、`flower` 梅花、`coins` 铜钱、`scales` 鱼鳞甲、`cloud` 如意云头、`lattice` 方格(angle=45 是斜格)、`stripes` 条孔、`ice` 冰裂纹;圆点类(dots / rings / flower / coins)转 `angle=90` 时,窄条里只剩居中的一列(门柱就是这样);形状工具 `poly ellipse ring stroke ribbon(宽度渐变的带) text(竖排字) below / above / left_of / right_of inset grow`;`finish()` 把皮厚不匀(30 px 斑驳、90 px 色块、细纤维)算进去,变成「每个通道挡掉多少光」。形状可以给点列,也可以给同尺寸的遮罩
+- 人偶 `Puppet`:`add(名字, 皮, parent, joint)` 一棵关节树(子件的枢轴挂在父件的 joint 上,关节处一颗线结;先加父件);`pose(**角度)`:角度按「人朝右时逆时针」量,垂下的手脚 +90 是向前平伸,头 +10 是抬头,躯干 +6 是往后仰;`set(x, y, rot, d, flip, alpha)`;`state()` / `load(st)` / `Puppet.tween(a, b, t)` 存取和插值整套姿态(动图逐帧用);`rod(部件, 点, lean, width)` 操纵杆;`ground(地板 y, [部件])` 让最低的鞋底落在地上;`away[部件] = 距离` 让某一件单独离幕;`point(部件, 点)` 部件上一点的画布坐标
+- `figure(robe, trim, accent, trousers, face, skin, facedye, headdress, plume, pom, pattern, hands, scale)` 出一个标准人偶(朝右,`flip=True` 朝左):`pelvis` 短裙腰带为根,`torso` 云肩、护心镜、鱼鳞甲、腰带,`head` 侧脸(`face='hollow'` 阳刻空脸:脸挖空,只留侧脸线、一只长眼、一道长眉;`face='solid'` 阴刻:脸留着 `facedye` 染的皮,五官刻空),`arm_f / arm_b` 上臂(只有近侧带护肩花),`fore_f / fore_b` 小臂和袖口,`hand_f / hand_b`(`'open'` / `'fist'`),`thigh_f / thigh_b`,`shin_f / shin_b` 绑腿和厚底靴;头饰 `'plume'` 盔 + 两根带黑横斑的雉翎、`'crown'` 三叉冠 + 绒球 + 侧穗、`'bun'` 发髻飘带;scale 1 时鞋底到盔顶约 520 px
+- 道具(一块皮的 prop,可以像人偶一样移动、离幕):`gate(w, h, net_h, eye, eye_r, post, beam, roof, net, trim)` 牌楼式球门:立柱(一列铜钱孔)、额枋、瓦顶飞檐、鸱吻卷、宝珠,窗棂网和红边风流眼,枢轴在地面中点;`ball(r)` 鞠:六道缝线、红芯、每瓣一个梭形孔;`border(y0, y1, dye, trim)` 底部装饰带(圆点条、镂空回纹带、黑边,画布坐标,放在 0, 0);`nameplate(text, dye, size, string)` 挂在线上的竖排小牌(枢轴在线头);自己做的:`sp.prop(皮)`;`place(p, x, y, **kw)` 放上幕布或更新,`hide(p)`
+- 字体:`plaque` / `label`(牌匾、小牌):魏碑(macOS 按需下载的字体)→ 隶变 → 楷体 → 宋体,Linux 用 Noto Serif CJK,Windows 用华文新魏 / 楷体;可用 `INKPAINT_FONT_SHADOWPUPPET_PLAQUE` / `_LABEL` 指定
+- 染料 `DYES`:plain red crimson teal green ochre yellow blue brown pink black;色板常量 `SCREEN SCREEN_EDGE HIDE WOOD LACQUER GOLD SPILL ROD LAMPS`;`render()`、`composite()`、`stage(name)`、`save(path, stages_dir)`;`save('x.jpg')` 默认 quality 88、4:4:4 色度
+
**顺序**:都是先远后近、先大后小,文字最后叠加。水墨的雾要画在它该吞没的东西之后;水彩的叶梗要先画,并且只画在叶子外面。
## 三、毛病清单(都真实出现过)
@@ -1962,6 +1974,24 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask
| 分数外的圈压到「7」的头 | 圈的纵半径 0.66h → 0.70h,横向多留 0.30h,从左上方 −118° 起笔 |
| 113 张 1920×1080 阶段快照 | 给 `stages_dir`,`stage()` 当场写 PNG(compress_level=1),峰值内存约 0.78 GB |
+**皮影戏**
+
+| 问题 | 改法 |
+|---|---|
+| 幕布像一面白墙,颜色像印在纸上,不发光 | 光晕衰减太缓、热点太白:光晕半径缩到 0.47W × 0.64H,底亮度 0.20 → 0.10,热点压成琥珀 (1, 0.75, 0.37)、边缘深橙;色调曲线用柔肩,亮处只微微溢出 |
+| 衣服像渔网袜,一身全是小孔 | 镂空太密:大面积的袍子留实色,纹样只放在一段里(裙上云头 26、胸前鱼鳞 17、袖子一段云头),裤子只在外侧缝一列圆点;画布上一个纹样单元至少约 12 px |
+| 人偶细长、脖子长、头小 | 躯干加宽到约 90,腿缩短(大腿 100、小腿到鞋底 116),头单独放大 1.15 倍,脖子关节下移 7 |
+| 两肩一团黑 | 两只上臂都带护肩花,叠在云肩上:只让近侧那只带 |
+| 举起来的手臂盖住了脸 | 侧身时肩在头的正下方,近侧手臂抬过约 140° 就从脸前过:要高举就举远侧那只(向后上方),近侧手臂斜向前上(130–147°);亮相用一手高(远侧向后上)一手低(近侧向前下)加提膝 |
+| 离幕一点(d = 0.05)的人整个糊了 | 虚化长得太快、双影分得太小:σ = 0.5 + 16d,放大 1 + 0.30d(两个灯芯的影子分开约 5 px),得到一个清楚的影加一条软的双边,而不是失焦 |
+| 挂落和花牙子被照成一片橙色 | 溢光拿整块幕布算,木头后面的也算上了:只用露出来的幕布(× (1 − 木头遮罩)),木头正面是暗的,挨着亮处的边才有一圈暖光 |
+| 花牙子只是几根细线 | 改成一块四分之一圆的雕板,挖空中间、留宽边,里面三个涡卷 |
+| 鞠放进风流眼里像一朵淡花 | 太淡、孔太多:实心赭黄、红芯、六道黑缝线、每瓣一个梭形孔,半径 28 |
+| 两个红方人物挤在一起(翎子扫到同伴头上、同伴的手搭在球头背上) | 翎子给后仰踢球的那个,同伴戴三叉冠,左右拉开到 262 / 612;踢球的人往左让,脚停在左门柱左边 |
+| 动图里鲜红和绿裤子被量化成土红、灰绿 | 人偶最后才出场,均匀取样把这些颜色平均掉了:成品取样 ×8,再只从最后几帧的饱和色和冷色(青、绿)里切 105 色,最后 6 轮 k-means,末帧 p99 误差 34 → 16 |
+| 结尾灯闪三下多出 360 KB | 每闪一下整片幕布都变,要整帧重发:只暗一下(7%);点灯也从 7 帧减到 5 帧 |
+| 画戏台时峰值内存 1.2 GB | 浮雕打光在整张画布上算:只在横楣一条、两根柱子、台口一条上分段算,远处溢光用半分辨率,球门和底带用 2 倍超采样;峰值约 0.8 GB(出阶段约 0.9 GB) |
+
## 四、做成动画
- 各画风都有 `stage(name)` 和 `save(path, stages_dir)`,按阶段依次淡入叠化,就是「一幅画被逐步画出来」。README 里的动图就是这样做的。
@@ -1984,6 +2014,7 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask
- 描图纸叠层的动图(脚本在 `claude_drawing/overlay_work/make_gif_overlay.py`):阶段是 关灯 → 灯变暖 → 开灯 → 底图 → 每张叠片「抬起、偏着」→「放下」→ 胶片图例卡 → 贴胶带。一张纸落下,会让一大片带纹理的区域整体变几级、线条由糊变清,逐帧精确差分要 3–5 MB。做法:目标和屏上已显示颜色的差值拆成平滑分量(模糊 2 px)和细节残差,平滑分量超过阈值(叠化帧 12 级、关键帧 3 级)或单点超过阈值(30 / 16 级)才重发,只有单点超阈值的孤立像素(纸纹在阈值上下翻动)不发;开灯那几帧逐像素精确发送,其中的叠化帧不加抖动(加了每帧每个像素都变);最后一帧收紧阈值追平。73 帧约 1.9 MB,按解码结果逐帧自检。
- 粉彩界面的动图(脚本在 `claude_drawing/pastelui_work/make_gif_pastelui.py`):阶段是 圆形擦除铺开底色 → 窗口弹出 → 胶囊、标题、色条、左栏、正文逐行写出 → 面板弹出 → 徽章依次打勾 / 打叉(中间放大镜从第三行飞到天气预报上)→ 三个小图标探头。会动的东西不用叠化:范例里 `move()` 给每样东西几个缓动 / 回弹的中间姿态,存成 `mv_*` 阶段,动图里每个 50 毫秒硬切,就是真运动(写字是 reveal 从 0 到 1,徽章是绕自己中心从 0.3 倍回弹到 1);其余阶段用 70 毫秒的帧叠化。调色板先强制放进整套界面色,再按加权样本中值切分;固定 4×4 Bayer,没变的像素记成品红透明。107 帧、15.6 秒、约 0.35 MB,按解码结果逐帧自检。
- 阅卷批改的动图(脚本在 `claude_drawing/grading_work/make_gif_grading.py`):阶段是 桌面 → 答题卡抬着淡入、两帧落下 → 标准答案卡和纸条同样落下 → 夹上长尾夹 → 五行作答逐字出现 → 两个章各「落下两帧 → 压下停 360 毫秒 → 抬起 → 拿走」→ 红笔从右下角进来,给三道计算打勾,画波浪线、圈、引线、批注、叉,划答句,在标准答案卡上打勾打叉,写分数再圈起来,每一笔之间抬笔移过去 → 笔放回得分格旁。阶段名里带时间:带 `~` 的是运动帧(硬切、不叠化),`@毫秒` 是停留时间,其余是关键阶段(停 900 毫秒,相邻两个关键阶段之间 5 帧叠化),所以章和笔是真的在动。重发规则沿用描图纸叠层的平滑分量 / 细节残差阈值;帧一张张算、不全留在内存里;调色板 180 色中值切分(饱和像素 ×5、亮色 ×2)+ 75 色只从饱和像素里切(红笔、朱红印、深蓝页眉、木章),固定 4×4 Bayer。133 帧、21.4 秒、约 1.17 MB,按解码结果逐帧自检,末帧误差和单纯调色板量化相同。
+- 皮影戏的动图(脚本在 `claude_drawing/shadowpuppet_work/make_gif_shadowpuppet.py`):阶段是 黑场 → 灯点着、光晕一圈圈铺开、闪动 → 横楣带着灯笼从上面落下,灯笼晃着亮起来 → 底带和球门从下面升上来,边升边贴紧幕布(由虚变实)→ 四个人从两边侧幕滑进来,离幕远时又虚又是双影,边走边贴上幕布 → 站定 → 同伴挑球传过去 → 球头收腿、起脚,球画一道弧穿过风流眼,青方一个跳起扑空、一个指着球,同伴摆出亮相 → 全体带一点过冲定住 → 两块小牌顺着线落下 → 灯暗一下 → 成品。全部是真运动(`~` 运动帧),一个叠化都没有;阶段名的约定和阅卷批改一样(`~` 运动帧、`@毫秒` 停留)。重发规则同阅卷批改;调色板 150 色中值切分(成品取样 ×8、饱和像素 ×5、亮色 ×2)+ 105 色只从最后几帧的饱和色和冷色里切,再做 6 轮 k-means 收短误差尾巴;固定 4×4 Bayer。61 帧、10.8 秒、约 1.75 MB,按解码结果逐帧自检,末帧误差(p99 16)和单纯调色板量化相同。点灯那几帧和结尾灯暗一下要整帧重发,是最贵的几帧(各 75–130 KB)。
- 绘本角色动画的动图是真动画,不是阶段叠化:`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 遮罩按顺序显现。这个还没做成现成接口。
@@ -2054,6 +2085,7 @@ lib/ballpoint.py 圆珠笔涂鸦(复印纸纹、纤维与折痕;圆珠
lib/overlay.py 描图纸叠层(灯箱发光、黑线灰调底图与单色叠片、透过率相乘的油墨、背光纤维云纹、抬起时的漫射模糊与投影、卷角、打孔与定位钉、套准十字、绘图胶带、透明胶片)
lib/pastelui.py 粉彩界面(纯色粉彩底与光斑、距离场抗锯齿的窗口卡片与部件、CSS 式多层阴影、带姿态的图层、真像素放大镜、圆形擦除、三个扁平小图标)
lib/grading.py 阅卷批改(绿毛毡桌、带位姿和投影的纸与卡片、答题卡部件与装订齿孔、长尾夹、带进度和时间图的红笔 / 批注 / 作答 / 印章、比尔定律红墨、立体红笔与木章道具)
+lib/shadowpuppet.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_shadowpuppet_cuju.gif b/examples/drawing_shadowpuppet_cuju.gif
new file mode 100644
index 0000000..4796b20
Binary files /dev/null and b/examples/drawing_shadowpuppet_cuju.gif differ
diff --git a/examples/shadowpuppet_cuju.jpg b/examples/shadowpuppet_cuju.jpg
new file mode 100644
index 0000000..e9ac60e
Binary files /dev/null and b/examples/shadowpuppet_cuju.jpg differ
diff --git a/examples/shadowpuppet_cuju.py b/examples/shadowpuppet_cuju.py
new file mode 100644
index 0000000..a0640b9
--- /dev/null
+++ b/examples/shadowpuppet_cuju.py
@@ -0,0 +1,223 @@
+"""Example (shadow puppetry): 蹴鞠 · Cuju by Lamplight — a shadow-play match of the old Chinese football, at the
+moment the ball goes through the eye of the net.
+
+A carved proscenium (plaque 蹴鞠, an openwork valance, corner brackets, two red lanterns) frames a lamp-lit screen.
+On it, in dyed and hollow-carved donkey hide: a pailou archway as the goal (球门) with a lattice net and its round
+eye (风流眼), the ornamental floor band, and four players on jointed rods. On the left the red side: the captain has
+just kicked, one leg high, and his team-mate strikes the pose (亮相) with an arm over his head and a knee raised; on the
+right the teal side: one leaps for the ball a little off the cloth (so his edges go soft and double), the other points
+up at it. The ball sits in the eye. Two small plaques hang on threads: 球头 over the captain and 骁色 over the leaper
+(two of the positions of a cuju team).
+
+The draw-on (--stages) is real in-between motion: the lamp is lit and its glow spreads, the lintel drops in and the
+lanterns swing and light, the floor band and the goal come up pressed to the cloth, the players slide in from the
+wings blurred and doubled and sharpen as they are pressed to the screen, take their places, the captain kicks, the
+ball flies through the eye, everyone snaps into the final pose (亮相), the plaques come down on their threads, and the
+lamp gutters once before the last frame.
+No image model.
+python3 shadowpuppet_cuju.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 shadowpuppet import ShadowPuppet, Puppet
+
+out = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith('--') else 'shadowpuppet_cuju.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('SP_TIMING') else None
+
+W, H = 1920, 1080
+FLOOR = 932
+sp = ShadowPuppet(W, H, seed=11, keep_stages=bool(stages), stages_dir=stages)
+sp.screen()
+sp.proscenium('蹴鞠')
+lanterns = [sp.lantern(190, r=56), sp.lantern(W - 190, r=56)]
+border = sp.border()
+gate = sp.gate(w=270, h=540, net_h=240, eye=(0, -392), eye_r=44)
+ball = sp.ball(28)
+plate = sp.nameplate('球头', dye='red', size=30, string=30)
+plate2 = sp.nameplate('骁色', dye='teal', size=30, string=30)
+tick('props')
+
+# ===================================================================== the players
+S = 1.12
+captain = sp.figure(robe='red', trim='black', accent='ochre', trousers='teal', headdress='plume', pom='teal',
+ pattern='cloud', hands=('open', 'open'), scale=S, name='captain')
+mate = sp.figure(robe='red', trim='black', accent='ochre', trousers='green', headdress='crown', pom='teal',
+ pattern='flower', hands=('open', 'open'), scale=S, name='mate')
+leaper = sp.figure(robe='teal', trim='black', accent='ochre', trousers='red', headdress='plume', plume='ochre', pom='red',
+ pattern='cloud', hands=('open', 'open'), scale=S, name='leaper')
+pointer = sp.figure(robe='teal', trim='black', accent='ochre', trousers='ochre', headdress='crown', face='solid',
+ facedye='red', pom='red', pattern='flower', hands=('open', 'fist'), scale=S, name='pointer')
+for p in (captain, mate, leaper, pointer):
+ p.rod('torso', (4, -128), lean=-10)
+ p.rod('hand_f', (0, 16), lean=30)
+ p.rod('hand_b', (0, 16), lean=-30)
+tick('figures')
+
+# final poses (angles counter-clockwise as seen facing right; leaper and pointer are flipped to face left)
+FINAL = {
+ captain: dict(x=612, flip=False, rot=10, d=0.0, ground='shin_b',
+ angles=dict(torso=6, head=8, thigh_f=122, shin_f=-8, thigh_b=-12, shin_b=-4,
+ arm_f=-64, fore_f=34, hand_f=10, arm_b=74, fore_b=30)),
+ mate: dict(x=262, flip=False, rot=0, d=0.0, ground='shin_b',
+ angles=dict(torso=-3, head=12, thigh_f=82, shin_f=-100, thigh_b=-4,
+ arm_b=-112, fore_b=-18, hand_b=-14, arm_f=48, fore_f=24, hand_f=-26)),
+ leaper: dict(x=1338, flip=True, rot=-4, d=0.05, lift=58,
+ angles=dict(torso=-2, head=22, thigh_f=78, shin_f=-104, thigh_b=-26, shin_b=-56,
+ arm_f=147, fore_f=16, hand_f=8, arm_b=128, fore_b=24)),
+ pointer: dict(x=1648, flip=True, rot=-5, d=0.0, ground='shin_b',
+ angles=dict(torso=-4, head=10, thigh_f=30, shin_f=-34, thigh_b=-30, shin_b=-4,
+ arm_f=122, fore_f=16, arm_b=-58, fore_b=72)),
+}
+
+
+def set_final(p):
+ f = FINAL[p]
+ sp.place(p, x=f['x'], y=600, rot=f['rot'], d=f['d'], flip=f['flip'], **f['angles'])
+ if 'ground' in f: p.ground(FLOOR, [f['ground']])
+ else: p.ground(FLOOR - f['lift'])
+ return p.state()
+
+
+sp.place(border, 0, 0)
+sp.place(gate, W / 2, FLOOR)
+EYE = (W / 2, FLOOR - 392)
+sp.place(ball, EYE[0] + 10, EYE[1] - 2, rot=-20)
+finals = {p: set_final(p) for p in (captain, mate, leaper, pointer)}
+sp.place(plate, captain.point('head', (0, -60))[0] + 6, sp.box[1] + 4)
+sp.place(plate2, leaper.point('head', (0, -60))[0] + 10, sp.box[1] + 4)
+tick('placed')
+
+if stages:
+ # ================================================================= the draw-on: real in-between poses.
+ # Stage names carry the GIF timing: '~' = a motion frame (shown as is, no cross-fade), '@ms' = how long it stays.
+ ease_out = lambda t: 1 - (1 - t) ** 3
+ ease = lambda t: t * t * (3 - 2 * t)
+
+ def back(t, s=1.6):
+ t = t - 1
+ return 1 + t * t * ((s + 1) * t + s)
+
+ keep = {p: p.state() for p in sp.items}
+ for p in list(sp.items): sp.hide(p)
+ for ln in lanterns: ln.set(lit=0.0, swing=0.0)
+
+ # ---- in the dark, the lamp is lit behind the screen: a small glow that spreads, flickering
+ sp.frame(dy=-560); sp.lamp(0.0, 0.08)
+ sp.stage('dark@700')
+ for i, (rad, lv, fl) in enumerate(((0.07, 0.35, 0.0), (0.11, 0.55, 0.10), (0.17, 0.62, -0.08), (0.28, 0.8, 0.05),
+ (0.50, 0.92, -0.03))):
+ sp.lamp(lv, rad, fl); sp.stage(f'lamp~{i}@{160 if i < 3 else 120}')
+ sp.lamp(1.0, 1.0); sp.stage('lit@600')
+
+ # ---- the lintel drops in with the lanterns, which swing and light
+ for i, dy in enumerate((-430, -270, -120, -14, 12, -4)):
+ sp.frame(dy=dy)
+ for j, ln in enumerate(lanterns): ln.set(swing=(0, 0, 0, 2, 7, -5)[i] * (1 if j == 0 else -1))
+ sp.stage(f'frame~{i}@60')
+ sp.frame(dy=0)
+ for i, (lt, sw) in enumerate(((0.25, 3.5), (0.6, -2.5), (0.9, 1.4), (1.0, -0.5))):
+ for j, ln in enumerate(lanterns): ln.set(lit=lt, swing=sw * (1 if j == 0 else -1))
+ sp.stage(f'lantern~{i}@90')
+ for ln in lanterns: ln.set(swing=0.0)
+ sp.stage('frame@600')
+
+ # ---- the floor band and the goal come up from below, pressed to the cloth as they arrive
+ for i, t in enumerate((0.3, 0.6, 0.85, 1.0)):
+ u = ease_out(t)
+ sp.place(border, x=0, y=74 * (1 - u), d=0.45 * (1 - u))
+ sp.stage(f'border~{i}@60')
+ gs = keep[gate]
+ for i, t in enumerate((0.18, 0.36, 0.54, 0.72, 0.88, 1.0)):
+ sp.place(gate, x=gs['x'], y=gs['y'] + 640 * (1 - back(t, 1.1)), d=0.6 * (1 - t) ** 1.3)
+ sp.stage(f'gate~{i}@70')
+ sp.stage('gate@500')
+
+ # ---- the players slide in from the wings, far from the cloth (soft, doubled) and pressed flat as they arrive
+ READY = dict(torso=2, head=4, thigh_f=8, shin_f=-6, thigh_b=-8, shin_b=-2, arm_f=28, fore_f=38, hand_f=0,
+ arm_b=-22, fore_b=30, hand_b=0)
+ ready = {}
+ for p in (captain, mate, leaper, pointer):
+ sp.place(p, x=finals[p]['x'], y=600, rot=0, d=0.0, **READY); p.ground(FLOOR)
+ ready[p] = p.state()
+ start = {captain: -300, mate: -560, leaper: W + 300, pointer: W + 560}
+ n = 8
+ for i in range(1, n + 1):
+ t = i / n; u = ease_out(t); ph = i * 1.4
+ for p in (captain, mate, leaper, pointer):
+ sw = np.sin(ph + (0.8 if p in (mate, pointer) else 0)) * (1 - t) ** 0.6
+ ang = dict(READY, thigh_f=READY['thigh_f'] + 30 * sw, thigh_b=READY['thigh_b'] - 30 * sw,
+ shin_f=-6 - 24 * max(0.0, -sw), shin_b=-2 - 24 * max(0.0, sw),
+ arm_f=READY['arm_f'] - 26 * sw, arm_b=READY['arm_b'] + 26 * sw)
+ x = start[p] + (ready[p]['x'] - start[p]) * u
+ sp.place(p, x=x, y=600, rot=-4 * (1 - t), d=0.72 * (1 - t) ** 1.4, **ang); p.ground(FLOOR)
+ sp.stage(f'enter~{i}@70')
+ for p in (captain, mate, leaper, pointer): sp.place(p); p.load(ready[p])
+ sp.stage('ready@500')
+
+ # ---- the mate passes: a flick of the foot, the ball arcs over to the captain
+ def bez(p0, p1, p2, t):
+ return [(1 - t) ** 2 * a + 2 * (1 - t) * t * b + t * t * c for a, b, c in zip(p0, p1, p2)]
+
+ flick = (24, 52, 30, 14, 8)
+ toe = lambda p: p.point('shin_f', (34, 100))
+ for i, th in enumerate(flick):
+ mate.pose(thigh_f=th, shin_f=-6 - 0.3 * th); mate.ground(FLOOR, ['shin_b'])
+ if i >= 1:
+ t = i / (len(flick) - 1)
+ bx, by = bez((420, 840), (520, 560), (700, 820), t)
+ sp.place(ball, x=bx, y=by, rot=-50 * i, d=0.0)
+ sp.stage(f'pass~{i}@70')
+
+ # ---- the captain winds up and kicks; the ball flies through the eye. The leaper jumps for it, the pointer
+ # points, the mate swings into his pose
+ for i, (th, rt) in enumerate(((-22, -4), (-34, -6))):
+ captain.pose(thigh_f=th, shin_f=-30, arm_f=40, arm_b=-40, torso=-4); captain.set(rot=rt); captain.ground(FLOOR, ['shin_b'])
+ sp.place(ball, x=700 + 10 * i, y=840 + 20 * i, rot=-150 - 30 * i)
+ sp.stage(f'wind~{i}@{90 if i else 70}')
+ capf = finals[captain]
+ others = (mate, leaper, pointer)
+ ball_from = None
+ nk = 7
+ for i in range(1, nk + 1):
+ tk = min(1.0, i / 3) # the kick is over in three frames, the ball keeps flying
+ captain.load(Puppet.tween(ready[captain], capf, ease_out(tk)))
+ if i == 1:
+ captain.pose(thigh_f=60, shin_f=-20)
+ captain.ground(FLOOR, ['shin_b'])
+ if i == 1: ball_from = toe(captain)
+ tb = (i - 1) / (nk - 1)
+ bx, by = bez(ball_from, (870, 430), (EYE[0] + 10, EYE[1] - 2), ease(tb) * 0.6 + tb * 0.4)
+ sp.place(ball, x=bx, y=by, rot=-200 - 45 * i)
+ to = max(0.0, (i - 2) / (nk - 2))
+ for p in others:
+ p.load(Puppet.tween(ready[p], finals[p], ease_out(to)))
+ sp.place(p)
+ sp.stage(f'kick~{i}@{70 if i < nk else 120}')
+
+ # ---- 亮相: everyone snaps into the final pose with a small overshoot, and holds
+ for i, t in enumerate((0.55, 0.85)):
+ for p in (captain, mate, leaper, pointer):
+ p.load(Puppet.tween(ready[p], finals[p], back(t, 2.2)))
+ sp.stage(f'pose~{i}@70')
+ for p in (captain, mate, leaper, pointer): p.load(finals[p])
+ sp.place(ball, x=EYE[0] + 10, y=EYE[1] - 2, rot=-20)
+ sp.stage('liangxiang@1100')
+
+ # ---- the name plaques come down on their threads
+ for i, t in enumerate((0.35, 0.7, 0.92, 1.0)):
+ for pl in (plate, plate2):
+ st = keep[pl]
+ sp.place(pl, x=st['x'], y=st['y'] - 170 * (1 - back(t, 1.4)))
+ sp.stage(f'plates~{i}@70')
+
+ # ---- the lamp gutters once, then the final frame
+ sp.lamp(0.93, 1.0, -0.05); sp.stage('flicker~@110')
+ sp.lamp(1.0, 1.0)
+ for p, st in keep.items(): sp.place(p); p.load(st)
+
+img = sp.save(out, stages_dir=stages)
+tick('saved')
+print('saved', out)
diff --git a/lib/shadowpuppet.py b/lib/shadowpuppet.py
new file mode 100644
index 0000000..0b7cdd8
--- /dev/null
+++ b/lib/shadowpuppet.py
@@ -0,0 +1,1422 @@
+"""shadowpuppet — 皮影戏 / Shadow Puppetry: dyed-leather puppets pressed to a lamp-lit screen (numpy + Pillow only).
+
+A shadow-play stage seen from the audience. Behind a cloth screen an oil lamp burns; in front of it stands a carved
+wooden proscenium with a lacquered name plaque and red paper lanterns. Everything seen on the screen is lamp light
+that came through it:
+
+ screen the lamp's light through the cloth: palest and brightest round the hot spot behind the middle, deeper
+ amber toward the rim, with thread slubs, a faint fold or two and a vignette. `lamp(level, radius,
+ flicker)` dims it, shrinks it to a small glow (the lamp being lit) or makes it flicker.
+ leather a puppet piece is scraped, oiled donkey hide: translucent and dyed with transparent colour. A `Leather`
+ keeps coverage and an optical density per channel, so what reaches the eye is the lamp light times
+ exp(-density): vermilion, teal, ochre and green glow, black dye is nearly opaque, and where two pieces
+ overlap the densities add and it darkens, as with the real thing. Pieces are cut (`fill`), dyed in
+ fields (`dye`), inked along every cut edge (`edge`, `contour`) and punched with the hollow patterns of
+ the craft (`pattern`: dots, rings, plum blossoms, coins, fish scales, cloud heads, lattice, ice
+ cracks, stripes; `carve` cuts a line). The hide's thickness varies, so no dye is flat.
+ puppets a `Puppet` is a tree of pieces joined by thread knots, each with a pivot and an angle, so a pose is a
+ dict of joint angles (degrees counter-clockwise as seen with the figure facing right; a hanging limb
+ at +90 points forward). `figure()` builds the classic figure: a profile head with a hollow-carved
+ face (one long eye, a long brow) or a solid face with the features cut out, a helmet with pheasant
+ plumes or a crown with pompoms, a cloud collar, robe, sleeves with cuffs, hands, trousers and
+ thick-soled boots. Control rods are tied to the collar and the hands and run down past the screen.
+ distance every puppet has a distance from the screen `d` (0 = pressed flat). Lifted off the cloth its image
+ grows a little and blurs, and because the lamp has two wicks it splits into two offset shadows: the
+ soft double edge of a figure that is not quite pressed. Pieces can lift on their own (`away`). Rods
+ slant back toward the puppeteers, so they are sharp where they are tied on and soft lower down.
+ props the same leather: `gate()` (a pailou archway with a lattice net and a round eye), `ball()`,
+ `border()` (the ornamental floor band the puppets stand on), `nameplate()` (a small hanging plaque).
+ front `proscenium()`: a dark lacquered lintel with carved key-fret panels and a red plaque with gilt
+ characters, an openwork valance and corner brackets the screen glows through, pillars and a sill, all
+ lit by the light the screen spills onto them. `lantern()` hangs red paper lanterns lit from inside,
+ with tassels and a warm halo. Both have poses for the draw-on (the lintel drops in, lanterns swing).
+
+ import sys; sys.path.insert(0, 'lib')
+ from shadowpuppet import ShadowPuppet
+ sp = ShadowPuppet(1920, 1080, seed=3)
+ sp.screen(); sp.proscenium('蹴鞠')
+ sp.lantern(200); sp.lantern(1720)
+ sp.place(sp.border())
+ hero = sp.figure(robe='red', headdress='plume')
+ hero.rod('torso', (4, -136)); hero.rod('hand_f', (0, 16), lean=-60)
+ hero.pose(arm_f=150, fore_f=40, thigh_f=70, shin_f=-80)
+ sp.place(hero, x=700, y=640); hero.ground(932)
+ sp.save('puppet.jpg')
+"""
+import glob
+import os
+import numpy as np
+from PIL import Image, ImageDraw, ImageFont
+from core import blur, spline, noise2d, smoothstep
+
+# ---------------------------------------------------------------- palette
+SCREEN = (1.00, 0.75, 0.37) # lamp light through the cloth at the hot spot
+SCREEN_EDGE = (1.00, 0.44, 0.13) # ... toward the rim
+HIDE = (0.97, 0.87, 0.68) # scraped, oiled donkey hide (transmittance of undyed leather)
+DYES = { # transmittance of the dye alone (multiplied with the hide)
+ 'plain': (1.0, 1.0, 1.0),
+ 'red': (1.0, 0.20, 0.10), # vermilion
+ 'crimson': (0.86, 0.10, 0.12),
+ 'teal': (0.10, 0.64, 0.78),
+ 'green': (0.40, 0.78, 0.22),
+ 'ochre': (1.0, 0.72, 0.22),
+ 'yellow': (1.0, 0.92, 0.40),
+ 'blue': (0.22, 0.42, 0.95),
+ 'brown': (0.62, 0.34, 0.16),
+ 'pink': (1.0, 0.66, 0.56),
+ 'black': (0.10, 0.08, 0.065),
+}
+WOOD = (0.17, 0.075, 0.045) # dark lacquered wood
+LACQUER = (0.52, 0.045, 0.03) # plaque red
+GOLD = (0.95, 0.72, 0.32)
+SPILL = (1.0, 0.58, 0.26) # light the screen throws onto the frame
+ROD = (0.86, 0.88, 0.90) # absorbance of a control rod
+LAMPS = (((0.44, 0.60), 0.66), ((0.60, 0.54), 0.34)) # two wicks: foot point on the screen (fraction of W, H), share
+
+_MA = '/System/Library/AssetsV2/com_apple_MobileAsset_Font*/*/AssetData/'
+_FONT_TABLE = { # (glob, face index); first hit wins -- macOS, Linux, Windows. Override: $INKPAINT_FONT_SHADOWPUPPET_<KIND>
+ 'plaque': [(_MA + 'WeibeiSC-Bold.otf', 0), (_MA + 'Libian.ttc', 0), (_MA + 'Kaiti.ttc', 0),
+ ('/System/Library/Fonts/Supplemental/Songti.ttc', 1), ('/System/Library/Fonts/STHeiti Medium.ttc', 0),
+ ('/usr/share/fonts/**/NotoSerifCJK*Black*.tt[cf]', 0), ('/usr/share/fonts/**/NotoSerifCJK*Bold*.tt[cf]', 0),
+ ('/usr/share/fonts/**/NotoSansCJK*Bold*.tt[cf]', 0), ('C:/Windows/Fonts/STXINWEI.TTF', 0),
+ ('C:/Windows/Fonts/simkai.ttf', 0), ('C:/Windows/Fonts/msyhbd.ttc', 0)],
+}
+_FONT_TABLE['label'] = _FONT_TABLE['plaque']
+_font_cache = {}
+
+
+def font_path(kind='plaque'):
+ """(path, index) of the CJK font for `kind` ('plaque' / 'label'), or None"""
+ if kind in _font_cache: return _font_cache[kind]
+ env = os.environ.get('INKPAINT_FONT_SHADOWPUPPET_' + kind.upper())
+ hit = (env, 0) if env and os.path.exists(env) else None
+ if hit is None:
+ for pat, idx in _FONT_TABLE[kind]:
+ fs = sorted(glob.glob(pat, recursive=True))
+ if fs: hit = (fs[0], idx); break
+ if hit is None:
+ from core import cjk_font
+ p = cjk_font(); hit = (p, 0) if p else None
+ _font_cache[kind] = hit
+ return hit
+
+
+def _font(kind, size):
+ hit = font_path(kind)
+ if hit:
+ try: return ImageFont.truetype(hit[0], int(round(size)), index=hit[1])
+ except OSError: pass
+ return ImageFont.load_default(int(round(size)))
+
+
+def _rgb(c):
+ return np.array(DYES[c] if isinstance(c, str) else c, np.float32)
+
+
+def _dens(dye):
+ """optical density (per channel) of hide dyed with `dye`"""
+ return (-np.log(np.clip(np.array(HIDE, np.float32) * _rgb(dye), 1e-3, 1.0))).astype(np.float32)
+
+
+def _loop(pts, per=6):
+ """closed Catmull-Rom loop through pts"""
+ P = np.asarray(pts, np.float32); n = len(P); out = []
+ for i in range(n):
+ p0, p1, p2, p3 = P[(i - 1) % n], P[i], P[(i + 1) % n], P[(i + 2) % n]
+ 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 _grow(m, r):
+ """dilate a float mask by r px (alternating square / cross steps, so roughly round)"""
+ out = m.astype(np.float32)
+ for i in range(int(round(r))):
+ p = np.pad(out, 1, mode='edge')
+ if i % 2 == 0:
+ a = np.maximum(np.maximum(p[1:-1, :-2], p[1:-1, 2:]), out)
+ q = np.pad(a, ((1, 1), (0, 0)), mode='edge')
+ out = np.maximum(np.maximum(q[:-2], q[2:]), a)
+ else:
+ out = np.maximum.reduce([out, p[:-2, 1:-1], p[2:, 1:-1], p[1:-1, :-2], p[1:-1, 2:]])
+ return out
+
+
+def _shrink(m, r):
+ return 1 - _grow(1 - m, r)
+
+
+def _hash(i, j, seed):
+ return np.mod(np.sin(i * 127.1 + j * 311.7 + seed * 74.7) * 43758.5453, 1.0)
+
+
+def _hex(u, v, S):
+ """offset to the nearest centre of a hexagonal lattice with spacing S"""
+ rh = S * 0.8660254
+ j0 = np.floor(v / rh)
+ best = bu = bv = None
+ for dj in (0, 1):
+ jj = j0 + dj
+ off = np.mod(jj, 2) * S / 2
+ i = np.round((u - off) / S)
+ du, dv = u - (i * S + off), v - jj * rh
+ d2 = du * du + dv * dv
+ if best is None: best, bu, bv = d2, du, dv
+ else:
+ m = d2 < best
+ best = np.where(m, d2, best); bu = np.where(m, du, bu); bv = np.where(m, dv, bv)
+ return bu, bv
+
+
+def _scales(u, v, S, bar):
+ """fish-scale armour: rows of overlapping discs, the upper row on top; sd > 0 inside a hole"""
+ R, rh = 0.5 * S, 0.36 * S
+ j0 = np.floor(v / rh)
+ ds = []
+ for dj in (-1, 0, 1, 2):
+ jj = j0 + dj
+ off = np.mod(jj, 2) * S / 2
+ i = np.round((u - off) / S)
+ ds.append(np.hypot(u - (i * S + off), v - jj * rh))
+ ds = np.stack(ds)
+ inside = ds < R
+ own = np.argmax(inside, 0)
+ d_own = np.take_along_axis(ds, own[None], 0)[0]
+ rows = np.arange(len(ds))[:, None, None]
+ cover = np.where(rows < own[None], ds - R, 1e9).min(0)
+ sd = np.minimum(R - d_own, cover) - bar / 2
+ return np.where(inside.any(0), sd, -1.0)
+
+
+def _cloud(u, v, S):
+ """ruyi cloud heads: three lobes with a leather curl in each"""
+ du, dv = _hex(u, v, S)
+ sd = -1e9
+ for x, y, r in ((-0.17, 0.05, 0.12), (0.0, -0.05, 0.16), (0.17, 0.05, 0.12)):
+ sd = np.maximum(sd, r * S - np.hypot(du - x * S, dv - y * S))
+ sd = np.minimum(sd, 0.13 * S - dv)
+ curl = 1e9
+ for x, y, r in ((-0.15, 0.07, 0.04), (0.0, -0.02, 0.055), (0.15, 0.07, 0.04)):
+ curl = np.minimum(curl, np.hypot(du - x * S, dv - y * S) - r * S)
+ return np.minimum(sd, curl)
+
+
+def _ice(u, v, S, bar, seed):
+ """ice-crack lattice (jittered Voronoi cells)"""
+ ci, cj = np.floor(u / S), np.floor(v / S)
+ F1 = np.full(u.shape, 1e9, np.float32); F2 = F1.copy()
+ for di in (-1, 0, 1):
+ for dj in (-1, 0, 1):
+ i, j = ci + di, cj + dj
+ px = (i + 0.15 + 0.7 * _hash(i, j, seed)) * S
+ py = (j + 0.15 + 0.7 * _hash(i, j, seed + 17)) * S
+ d = np.hypot(u - px, v - py)
+ F2 = np.where(d < F1, F1, np.minimum(F2, d)); F1 = np.minimum(F1, d)
+ return (F2 - F1) / 2 - bar / 2
+
+
+def meander(x0, x1, y0, y1, unit=None, gap=0.0):
+ """key-fret (回纹) polylines filling the strip [x0, x1] x [y0, y1]: one hook per unit plus a baseline"""
+ h = y1 - y0; u = unit or h
+ n = max(1, int((x1 - x0) // u))
+ xs = x0 + ((x1 - x0) - n * u) / 2
+ key = [(0.0, 1.0), (0.0, 0.0), (0.84, 0.0), (0.84, 0.70), (0.30, 0.70), (0.30, 0.34), (0.58, 0.34)]
+ out = []
+ for i in range(n):
+ a = xs + i * u + gap
+ out.append([(a + px * (u - 2 * gap), y0 + py * h) for px, py in key])
+ out.append([(xs, y1), (xs + n * u, y1)])
+ return out
+
+
+# ================================================================ one piece of leather
+_PAD = 6
+
+
+class Leather:
+ """One piece of carved, dyed leather in its own frame. Coordinates are design units (multiplied by `scale` to
+ pixels); the pivot of the piece is the origin. Rasterised `ss` times finer and box-filtered at the end."""
+
+ def __init__(self, x0, y0, x1, y1, scale=1.0, ss=3, seed=0):
+ k = float(scale)
+ self.k, self.ss, self.seed = k, int(ss), int(seed)
+ self.x0 = int(np.floor(x0 * k)) - _PAD
+ self.y0 = int(np.floor(y0 * k)) - _PAD
+ self.w = int(np.ceil(x1 * k)) + _PAD - self.x0
+ self.h = int(np.ceil(y1 * k)) + _PAD - self.y0
+ H, W = self.h * self.ss, self.w * self.ss
+ self.A = np.zeros((H, W), np.float32) # coverage
+ self.D = np.zeros((H, W, 3), np.float32) # optical density where covered
+ self._grid = None
+
+ # ---------------------------------------------------------- geometry
+ def _px(self, pts):
+ P = np.asarray(pts, np.float64).reshape(-1, 2)
+ return [((x * self.k - self.x0) * self.ss - 0.5, (y * self.k - self.y0) * self.ss - 0.5) for x, y in P]
+
+ def grid(self):
+ """design-unit coordinates (X, Y) of every fine pixel centre"""
+ if self._grid is None:
+ H, W = self.A.shape
+ xs = (((np.arange(W) + 0.5) / self.ss + self.x0) / self.k).astype(np.float32)
+ ys = (((np.arange(H) + 0.5) / self.ss + self.y0) / self.k).astype(np.float32)
+ self._grid = np.meshgrid(xs, ys)
+ return self._grid
+
+ def _aa(self, sd):
+ return np.clip(0.5 + sd * self.k * self.ss, 0, 1).astype(np.float32)
+
+ def px(self, d):
+ """design units -> fine pixels"""
+ return d * self.k * self.ss
+
+ def poly(self, pts):
+ H, W = self.A.shape
+ im = Image.new('L', (W, H), 0)
+ ImageDraw.Draw(im).polygon(self._px(pts), fill=255)
+ return np.asarray(im, np.float32) / 255
+
+ def ellipse(self, cx, cy, rx, ry=None, rot=0.0):
+ ry = rx if ry is None else ry
+ X, Y = self.grid()
+ t = np.deg2rad(rot); c, s = np.cos(t), np.sin(t)
+ u = (X - cx) * c + (Y - cy) * s; v = -(X - cx) * s + (Y - cy) * c
+ return self._aa((1 - np.sqrt((u / rx) ** 2 + (v / ry) ** 2)) * min(rx, ry))
+
+ def ring(self, cx, cy, r0, r1):
+ X, Y = self.grid()
+ d = np.hypot(X - cx, Y - cy)
+ return self._aa(np.minimum(r1 - d, d - r0))
+
+ def below(self, y):
+ return self._aa(self.grid()[1] - y)
+
+ def above(self, y):
+ return self._aa(y - self.grid()[1])
+
+ def right_of(self, x):
+ return self._aa(self.grid()[0] - x)
+
+ def left_of(self, x):
+ return self._aa(x - self.grid()[0])
+
+ def stroke(self, pts, width):
+ """a round-capped polyline mask"""
+ H, W = self.A.shape
+ im = Image.new('L', (W, H), 0); d = ImageDraw.Draw(im)
+ P = self._px(pts); wpx = max(1, int(round(self.px(width))))
+ if len(P) > 1: d.line(P, fill=255, width=wpx, joint='curve')
+ r = wpx / 2
+ for (x, y) in (P[0], P[-1]): d.ellipse([x - r, y - r, x + r, y + r], fill=255)
+ return np.asarray(im, np.float32) / 255
+
+ @staticmethod
+ def ribbon(pts, w0, w1=None):
+ """outline polygon of a band along pts whose width runs from w0 to w1"""
+ P = np.asarray(pts, np.float32)
+ w = np.linspace(w0, w0 if w1 is None else w1, len(P)).astype(np.float32)
+ d = np.gradient(P, axis=0); d /= np.linalg.norm(d, axis=1, keepdims=True) + 1e-6
+ nrm = np.stack([-d[:, 1], d[:, 0]], 1)
+ return np.vstack([P + nrm * w[:, None] / 2, (P - nrm * w[:, None] / 2)[::-1]])
+
+ def text(self, s, x, y, size, kind='label', vertical=False, spacing=1.06):
+ H, W = self.A.shape
+ im = Image.new('L', (W, H), 0); d = ImageDraw.Draw(im)
+ f = _font(kind, self.px(size))
+ if vertical:
+ n = len(s)
+ for i, ch in enumerate(s):
+ d.text(self._px([(x, y + (i - (n - 1) / 2) * size * spacing)])[0], ch, font=f, fill=255, anchor='mm')
+ else:
+ d.text(self._px([(x, y)])[0], s, font=f, fill=255, anchor='mm')
+ return np.asarray(im, np.float32) / 255
+
+ def mask(self, shape):
+ if isinstance(shape, np.ndarray) and shape.shape == self.A.shape: return shape.astype(np.float32)
+ return self.poly(shape)
+
+ def inset(self, shape, width):
+ return _shrink(self.mask(shape), self.px(width))
+
+ def grow(self, shape, width):
+ return _grow(self.mask(shape), self.px(width))
+
+ # ---------------------------------------------------------- cutting and dyeing
+ def fill(self, shape, dye='plain'):
+ """add leather (a cut piece or a strip glued on) dyed `dye`; returns the mask"""
+ m = self.mask(shape)
+ self.D += m[..., None] * (_dens(dye) - self.D)
+ self.A = np.maximum(self.A, m)
+ return m
+
+ def dye(self, shape, dye):
+ """recolour the leather already there"""
+ m = self.mask(shape) * np.clip(self.A * 3, 0, 1)
+ self.D += m[..., None] * (_dens(dye) - self.D)
+ return m
+
+ def edge(self, width=2.0, dye='black', region=None):
+ """ink the cut edge of the piece (or of `region` within it)"""
+ R = self.A if region is None else self.mask(region) * self.A
+ band = np.clip(R - _shrink(R, self.px(width)), 0, 1)
+ self.D += band[..., None] * (_dens(dye) - self.D)
+ return band
+
+ contour = lambda self, region, width=1.4, dye='black': self.edge(width, dye, region)
+
+ def punch(self, shape, rim=0.8, dye='black'):
+ """cut a hole; the cut edge round it is inked `rim` wide"""
+ m = self.mask(shape)
+ if rim > 0:
+ ring = np.clip(_grow(m, self.px(rim)) - m, 0, 1) * self.A
+ self.D += ring[..., None] * (_dens(dye) - self.D)
+ self.A = self.A * (1 - m)
+ return m
+
+ def line(self, pts, width=1.6, dye='black'):
+ """a strip of leather (an inked line that is part of the piece)"""
+ return self.fill(self.stroke(pts, width), dye)
+
+ def carve(self, pts, width=1.4, rim=0.0):
+ """cut a thin line through"""
+ return self.punch(self.stroke(pts, width), rim)
+
+ def holes(self, kind, size, angle=0.0, origin=(0.0, 0.0), seed=0, **kw):
+ """the hole mask of a hollow pattern over the whole piece (see `pattern`)"""
+ X, Y = self.grid()
+ t = np.deg2rad(angle); c, s = np.cos(t), np.sin(t)
+ x, y = X - origin[0], Y - origin[1]
+ u, v = x * c + y * s, -x * s + y * c
+ S = float(size)
+ if kind == 'dots':
+ du, dv = _hex(u, v, S); sd = kw.get('r', 0.27) * S - np.hypot(du, dv)
+ elif kind == 'rings':
+ du, dv = _hex(u, v, S); d = np.hypot(du, dv)
+ sd = np.minimum(kw.get('r', 0.34) * S - d, d - kw.get('pin', 0.13) * S)
+ elif kind == 'flower':
+ du, dv = _hex(u, v, S); n = kw.get('petals', 5)
+ rp, rr = kw.get('r', 0.12) * S, kw.get('ring', 0.21) * S
+ sd = -1e9
+ for i in range(n):
+ a = 2 * np.pi * i / n - np.pi / 2
+ sd = np.maximum(sd, rp - np.hypot(du - rr * np.cos(a), dv - rr * np.sin(a)))
+ elif kind == 'coins':
+ du, dv = _hex(u, v, S); d = np.hypot(du, dv)
+ sd = np.minimum(kw.get('r', 0.36) * S - d, np.maximum(np.abs(du), np.abs(dv)) - kw.get('square', 0.11) * S)
+ elif kind == 'scales':
+ sd = _scales(u, v, S, kw.get('bar', 0.12) * S)
+ elif kind == 'cloud':
+ sd = _cloud(u, v, S)
+ elif kind == 'lattice':
+ b = kw.get('bar', 0.2) * S
+ fu = np.abs(np.mod(u, S) - S / 2); fv = np.abs(np.mod(v, S) - S / 2)
+ sd = np.minimum(S / 2 - b / 2 - fu, S / 2 - b / 2 - fv)
+ elif kind == 'stripes':
+ b = kw.get('bar', 0.45) * S
+ sd = S / 2 - b / 2 - np.abs(np.mod(u, S) - S / 2)
+ elif kind == 'ice':
+ sd = _ice(u, v, S, kw.get('bar', 0.13) * S, seed)
+ else:
+ raise ValueError(kind)
+ return self._aa(sd)
+
+ def pattern(self, region, kind, size, angle=0.0, margin=3.0, rim=0.7, origin=(0.0, 0.0), seed=0, **kw):
+ """punch a hollow pattern inside `region`, keeping `margin` of solid leather along its border.
+ kinds: dots, rings, flower (plum blossoms), coins, scales (fish-scale armour), cloud (ruyi heads),
+ lattice, stripes, ice (ice-crack lattice)"""
+ R = self.mask(region) * (self.A > 0.5)
+ h = self.holes(kind, size, angle, origin, seed, **kw) * _shrink(R, self.px(margin))
+ return self.punch(h, rim)
+
+ def finish(self, mottle=0.24, blotch=0.16, fibre=0.07):
+ """-> K (h, w, 3): the fraction of light each channel loses through the piece. The hide is scraped by hand,
+ so its thickness (and so every dye's depth) varies: `mottle` at ~30 px, `blotch` at ~90 px, `fibre` fine"""
+ H, W = self.A.shape
+ n = noise2d(H, W, 30 * self.ss, 3, self.seed + 3)
+ b = noise2d(H, W, 90 * self.ss, 2, self.seed + 5)
+ f = noise2d(H, W, 3 * self.ss, 2, self.seed + 4)
+ th = (1 + mottle * (2 * n - 1) + blotch * (2 * b - 1)) * (1 + fibre * (2 * f - 1))
+ K = self.A[..., None] * (1 - np.exp(-self.D * th[..., None]))
+ ss = self.ss
+ return K.reshape(self.h, ss, self.w, ss, 3).mean((1, 3)).astype(np.float32)
+
+
+# ================================================================ a jointed puppet
+def _R(a):
+ t = np.deg2rad(a); c, s = np.cos(t), np.sin(t)
+ return np.array([[c, s, 0.0], [-s, c, 0.0], [0.0, 0.0, 1.0]])
+
+
+def _T(x, y):
+ return np.array([[1.0, 0.0, x], [0.0, 1.0, y], [0.0, 0.0, 1.0]])
+
+
+class Puppet:
+ """A tree of leather pieces. `pose(**angles)` sets joint angles in degrees, counter-clockwise as seen with the
+ puppet facing right (a hanging limb at +90 points forward, a head at +10 looks up); `flip=True` faces it left.
+ x, y place the root pivot on the canvas; d is the distance from the screen (0 = pressed flat, 1 = far)."""
+
+ def __init__(self, sp, name='puppet', scale=1.0):
+ self.sp, self.name, self.k = sp, name, float(scale)
+ self.parts, self.order, self.angles = {}, [], {}
+ self.x = self.y = 0.0
+ self.rot, self.flip, self.d, self.alpha = 0.0, False, 0.0, 1.0
+ self.away, self.rods, self.soles = {}, [], {}
+ self.shown = False
+
+ def add(self, name, leather, parent=None, joint=(0, 0), knot=True):
+ K = leather.finish() if isinstance(leather, Leather) else leather
+ img = Image.fromarray((np.clip(K, 0, 1) * 255 + 0.5).astype(np.uint8), 'RGB')
+ self.parts[name] = dict(img=img, x0=leather.x0, y0=leather.y0, parent=parent,
+ joint=(joint[0] * self.k, joint[1] * self.k), knot=knot and parent is not None)
+ self.order.append(name)
+ self.angles.setdefault(name, 0.0)
+ return self
+
+ def pose(self, **angles):
+ for n, a in angles.items():
+ if n not in self.parts: raise KeyError(f'{self.name} has no part {n!r}')
+ self.angles[n] = float(a)
+ return self
+
+ def set(self, x=None, y=None, rot=None, d=None, flip=None, alpha=None, **angles):
+ if x is not None: self.x = float(x)
+ if y is not None: self.y = float(y)
+ if rot is not None: self.rot = float(rot)
+ if d is not None: self.d = float(d)
+ if flip is not None: self.flip = bool(flip)
+ if alpha is not None: self.alpha = float(alpha)
+ return self.pose(**angles)
+
+ def state(self):
+ return dict(x=self.x, y=self.y, rot=self.rot, d=self.d, alpha=self.alpha, angles=dict(self.angles))
+
+ def load(self, st):
+ self.set(x=st['x'], y=st['y'], rot=st['rot'], d=st['d'], alpha=st['alpha'], **st['angles'])
+ return self
+
+ @staticmethod
+ def tween(a, b, t):
+ """a state between two `state()`s"""
+ lerp = lambda p, q: p + (q - p) * t
+ return dict(x=lerp(a['x'], b['x']), y=lerp(a['y'], b['y']), rot=lerp(a['rot'], b['rot']), d=lerp(a['d'], b['d']),
+ alpha=lerp(a['alpha'], b['alpha']), angles={n: lerp(a['angles'][n], b['angles'][n]) for n in a['angles']})
+
+ def matrices(self):
+ F = np.diag([-1.0 if self.flip else 1.0, 1.0, 1.0])
+ M = {}
+ for n in self.order:
+ p = self.parts[n]
+ if p['parent'] is None:
+ M[n] = _T(self.x, self.y) @ F @ _R(self.rot + self.angles[n])
+ else:
+ M[n] = M[p['parent']] @ _T(*p['joint']) @ _R(self.angles[n])
+ return M
+
+ def point(self, part, pt=(0, 0), M=None):
+ """canvas position of a point given in the part's design units"""
+ M = (M or self.matrices())[part]
+ v = M @ np.array([pt[0] * self.k, pt[1] * self.k, 1.0])
+ return float(v[0]), float(v[1])
+
+ def rod(self, part, pt=(0, 0), lean=0.0, width=3.2):
+ """a control rod tied to `part` at `pt`, running down past the bottom of the screen, `lean` px sideways"""
+ self.rods.append(dict(part=part, pt=pt, lean=float(lean), width=float(width)))
+ return self
+
+ def ground(self, y_floor, parts=None):
+ """move the puppet up or down so the lowest sole of `parts` (default: all feet) rests on y_floor"""
+ M = self.matrices()
+ lows = [self.point(n, q, M)[1] for n in (parts or list(self.soles)) for q in self.soles[n]]
+ if lows: self.y += y_floor - max(lows)
+ return self
+
+
+# ================================================================ hanging lantern
+class Lantern:
+ def __init__(self, sp, x, top, r=56, drop=70, tassel=True, lit=1.0, swing=0.0, seed=0):
+ self.sp, self.x, self.top, self.r, self.drop = sp, float(x), float(top), float(r), float(drop)
+ self.tassel, self.lit, self.swing, self.seed = tassel, float(lit), float(swing), seed
+ self.shown = True
+ self._cache = {}
+
+ def set(self, lit=None, swing=None, shown=None):
+ if lit is not None: self.lit = float(lit)
+ if swing is not None: self.swing = float(swing)
+ if shown is not None: self.shown = bool(shown)
+ return self
+
+ def _draw(self, lit):
+ key = round(lit, 2)
+ if key in self._cache: return self._cache[key]
+ r, drop = self.r, self.drop
+ ry, cap = 0.84 * r, 0.16 * r
+ cy = drop + cap + ry
+ tas = 1.75 * r if self.tassel else 0.0
+ Hl = int(cy + ry + cap + 0.3 * r + tas + 10); Wl = int(2 * r + 30)
+ hx = Wl / 2
+ Y, X = np.mgrid[0:Hl, 0:Wl].astype(np.float32) + 0.5
+ rgb = np.zeros((Hl, Wl, 3), np.float32); A = np.zeros((Hl, Wl), np.float32)
+
+ def over(m, col):
+ nonlocal rgb, A
+ m = np.clip(m, 0, 1)
+ rgb = rgb * (1 - m[..., None]) + np.asarray(col, np.float32) * m[..., None]
+ A = np.maximum(A, m)
+
+ def lines(segs, width):
+ im = Image.new('L', (Wl * 2, Hl * 2), 0); d = ImageDraw.Draw(im)
+ for seg in segs: d.line([(x * 2, y * 2) for x, y in seg], fill=255, width=max(1, int(round(width * 2))))
+ return np.asarray(im, np.float32).reshape(Hl, 2, Wl, 2).mean((1, 3)) / 255
+
+ # string
+ over(lines([[(hx, 0), (hx, drop + 2)]], 2.2), (0.09, 0.05, 0.035))
+ # body: paper over bamboo ribs, lit from inside
+ u, v = (X - hx) / r, (Y - cy) / ry
+ q = np.sqrt(u * u + v * v)
+ body = np.clip((1 - q) * min(r, ry) + 0.5, 0, 1)
+ sv = np.sqrt(np.clip(1 - v * v, 1e-4, 1))
+ rib = np.zeros_like(q)
+ for kk in range(11):
+ ph = (kk + 0.5) * np.pi / 11 - np.pi / 2
+ rib = np.maximum(rib, np.clip(1.25 - np.abs(X - (hx + r * sv * np.sin(ph))), 0, 1))
+ paper = 1 + 0.05 * (noise2d(Hl, Wl, 6, 2, self.seed) - 0.5)
+ gather = smoothstep(0.62, 0.98, np.abs(v))
+ if lit > 0:
+ core = np.exp(-((X - hx) ** 2 + (Y - (cy + 0.22 * ry)) ** 2) / (2 * (0.42 * r) ** 2))
+ b = (0.42 + 0.62 * np.clip(1 - q * q, 0, 1) ** 0.7 + 0.55 * core) * paper * (1 - 0.35 * gather)
+ deep, mid, hot = np.array([0.46, 0.035, 0.03]), np.array([0.93, 0.16, 0.06]), np.array([1.0, 0.66, 0.26])
+ t1 = np.clip(b / 0.85, 0, 1)[..., None]; t2 = np.clip((b - 0.85) / 0.55, 0, 1)[..., None]
+ col_lit = deep + (mid - deep) * t1 + (hot - mid) * t2
+ else:
+ col_lit = 0
+ n_z = np.sqrt(np.clip(1 - q * q, 0, 1))
+ dif = np.clip(0.55 * n_z - 0.35 * u * 0.6 - 0.45 * v * 0.6, 0, 1)
+ col_off = np.array([0.30, 0.045, 0.035]) * (0.35 + 0.75 * dif)[..., None] * paper[..., None]
+ col = col_off * (1 - lit) + col_lit * lit
+ col = col * (1 - 0.55 * rib[..., None] * (0.6 + 0.4 * lit))
+ over(body, col)
+ # caps: black lacquer with a gilt band
+ for y0 in (drop, cy + ry - 0.04 * r):
+ cm = ((np.abs(X - hx) < 0.46 * r) & (Y >= y0) & (Y < y0 + cap)).astype(np.float32)
+ capc = np.array([0.07, 0.04, 0.03]) + 0.05 * lit
+ over(cm, capc)
+ gm = ((np.abs(X - hx) < 0.46 * r) & (np.abs(Y - (y0 + cap * 0.5)) < 1.2)).astype(np.float32)
+ over(gm, np.array(GOLD) * (0.55 + 0.35 * lit))
+ # tassel: a gilt knot and a red silk fringe
+ if self.tassel:
+ ky = cy + ry + cap + 0.12 * r
+ over(np.clip(0.11 * r - np.hypot(X - hx, Y - ky) + 0.5, 0, 1), np.array(GOLD) * (0.6 + 0.3 * lit))
+ rng = np.random.default_rng(self.seed + 5)
+ segs = []
+ for i in range(28):
+ s0 = rng.uniform(-0.12, 0.12) * r
+ s1 = s0 * 2.4 + rng.uniform(-0.08, 0.08) * r
+ L = tas * rng.uniform(0.82, 1.0)
+ segs.append([(hx + s0, ky + 0.06 * r), (hx + (s0 + s1) / 2, ky + 0.5 * L), (hx + s1, ky + L)])
+ fm = lines(segs, 1.3)
+ tcol = np.array([0.50, 0.04, 0.035])[None, None, :] * (1 + 0.9 * lit * np.clip(1 - (Y - ky) / tas, 0, 1))[..., None]
+ over(fm, tcol)
+ band = ((np.abs(X - hx) < 0.17 * r) & (np.abs(Y - (ky + 0.22 * r)) < 0.05 * r)).astype(np.float32)
+ over(band, np.array(GOLD) * (0.55 + 0.3 * lit))
+ out = (rgb, A, (hx, cy))
+ self._cache[key] = out
+ return out
+
+
+# ================================================================ the stage
+class ShadowPuppet:
+ DYES = DYES
+
+ def __init__(self, W=1920, H=1080, seed=0, keep_stages=True, stages_dir=None):
+ self.W, self.H, self.seed = W, H, seed
+ self.rng = np.random.default_rng(seed)
+ self.keep_stages = keep_stages # False: stage() is free
+ self.stages_dir = stages_dir # set: stage() writes each snapshot at once (keeps memory low)
+ self.stages, self._n_stages = [], 0
+ self.box = (0, 0, W, H) # the screen opening
+ self.hot = (0.5 * W, 0.56 * H)
+ self.lamps = [((fx * W, fy * H), w) for (fx, fy), w in LAMPS]
+ self.lamp_state = dict(level=1.0, radius=1.0, flicker=0.0)
+ self.items, self.lanterns = [], []
+ self._scr = None
+ self._L = None
+ self._prosc = None
+ self._frame = None
+ self.frame_pose = dict(dy=0.0, alpha=1.0)
+ self._post = None
+
+ def _seed(self):
+ return int(self.rng.integers(1 << 30))
+
+ # ------------------------------------------------------------ screen and lamp
+ def screen(self, colour=SCREEN, edge=SCREEN_EDGE, hot=None, weave=1.0, folds=2):
+ """the cloth screen lit from behind; hot = the point the lamp is behind (default just below the middle)"""
+ if hot is not None: self.hot = (float(hot[0]), float(hot[1]))
+ self._scr = dict(colour=np.array(colour, np.float32), edge=np.array(edge, np.float32), weave=weave, folds=folds)
+ self._Lbase = None; self._L = None
+ return self
+
+ def lamp(self, level=1.0, radius=1.0, flicker=0.0):
+ """lamp brightness 0..1, how far the glow has spread (0.15 = a small glow just lit, 1 = full) and a flicker
+ (a small +- brightness change)"""
+ st = dict(level=float(level), radius=float(radius), flicker=float(flicker))
+ if st != self.lamp_state: self._L = None
+ self.lamp_state = st
+ return self
+
+ def _screen_base(self):
+ if self._Lbase is None:
+ if self._scr is None: self.screen()
+ H, W = self.H, self.W
+ x0, y0, x1, y1 = self.box
+ Y, X = np.mgrid[0:H, 0:W].astype(np.float32)
+ hx, hy = self.hot
+ r2 = ((X - hx) / (0.47 * W)) ** 2 + ((Y - hy) / (0.64 * H)) ** 2
+ rng = np.random.default_rng(self.seed + 7)
+ sc = self._scr
+ sx = np.asarray(Image.fromarray(rng.normal(0, 1, (H, max(2, W // 9))).astype(np.float32)).resize((W, H), Image.BILINEAR))
+ sy = np.asarray(Image.fromarray(rng.normal(0, 1, (max(2, H // 9), W)).astype(np.float32)).resize((W, H), Image.BILINEAR))
+ tex = 1 + sc['weave'] * (0.010 * sx + 0.010 * sy) + 0.05 * (noise2d(H, W, 300, 3, self.seed + 8) - 0.5)
+ for i in range(sc['folds']):
+ fx = x0 + (x1 - x0) * rng.uniform(0.18, 0.82)
+ wob = fx + 6 * np.sin(Y / 140 + i)
+ tex -= 0.022 * np.exp(-((X - wob) / 3.5) ** 2)
+ tex += 0.010 * np.exp(-((X - wob - 6) / 5.0) ** 2)
+ ins = (np.clip(X - x0 + 0.5, 0, 1) * np.clip(x1 - X + 0.5, 0, 1) * np.clip(Y - y0 + 0.5, 0, 1) * np.clip(y1 - Y + 0.5, 0, 1))
+ self._Lbase = dict(r2=r2, tex=(tex * ins).astype(np.float32), X=X, Y=Y)
+ return self._Lbase
+
+ def _emission(self):
+ if self._L is None:
+ B = self._screen_base(); sc = self._scr; st = self.lamp_state
+ rad = max(0.05, st['radius'])
+ r2 = B['r2']
+ if st['flicker']:
+ hx, hy = self.hot
+ dx, dy = 14 * st['flicker'], -8 * st['flicker']
+ r2 = ((B['X'] - hx - dx) / (0.47 * self.W)) ** 2 + ((B['Y'] - hy - dy) / (0.64 * self.H)) ** 2
+ fall = np.exp(-r2 / rad ** 2)
+ b = st['level'] * (1 + 0.6 * st['flicker']) * (0.10 * min(1.0, rad) ** 3 + 0.95 * fall)
+ t = (fall ** 0.65)[..., None]
+ col = sc['edge'] + (sc['colour'] - sc['edge']) * t
+ self._L = (col * (b * B['tex'])[..., None]).astype(np.float32)
+ return self._L
+
+ # ------------------------------------------------------------ leather, puppets and props
+ def leather(self, x0, y0, x1, y1, scale=1.0, ss=3, seed=None):
+ return Leather(x0, y0, x1, y1, scale, ss, self._seed() if seed is None else seed)
+
+ def puppet(self, name='puppet', scale=1.0):
+ return Puppet(self, name, scale)
+
+ def prop(self, leather, name='prop'):
+ """a one-piece prop (its pivot is the leather's origin)"""
+ p = Puppet(self, name, leather.k)
+ p.add(name, leather)
+ return p
+
+ def place(self, p, x=None, y=None, **kw):
+ """put a puppet or prop on the screen (or update it); the first place() decides nothing about order:
+ light through stacked leather multiplies, so any order looks the same"""
+ p.set(x=x, y=y, **kw)
+ p.shown = True
+ if not any(it is p for it in self.items): self.items.append(p)
+ return p
+
+ def hide(self, p):
+ p.shown = False
+
+ def figure(self, **kw):
+ """a jointed figure; see _figure() for the options"""
+ return _figure(self, **kw)
+
+ def ball(self, r=22, dye='ochre', scale=1.0, seed=None):
+ """the leather ball (鞠): stitched panels cut as petals round a ring"""
+ L = self.leather(-r - 2, -r - 2, r + 2, r + 2, scale, seed=seed)
+ m = L.fill(L.ellipse(0, 0, r), dye)
+ core = L.dye(L.ellipse(0, 0, 0.36 * r), 'red')
+ for i in range(6): # six stitched panels: a seam from the core to the rim, a lens-shaped cut in each panel
+ a = 2 * np.pi * i / 6
+ L.dye(L.stroke([(np.cos(a) * 0.36 * r, np.sin(a) * 0.36 * r), (np.cos(a) * r, np.sin(a) * r)], max(1.6, 0.09 * r)), 'black')
+ b = a + np.pi / 6
+ L.punch(L.ellipse(np.cos(b) * 0.66 * r, np.sin(b) * 0.66 * r, 0.20 * r, 0.085 * r, rot=-np.degrees(b)), 0.8)
+ L.punch(L.ellipse(0, 0, 0.12 * r), 0.8)
+ L.contour(core, max(1.2, 0.06 * r))
+ L.edge(max(1.8, 0.08 * r))
+ return self.prop(L, 'ball')
+
+ def gate(self, w=280, h=560, net_h=250, eye=(0, -400), eye_r=44, post='red', beam='teal', roof='black',
+ net='ochre', trim='red', scale=1.0, seed=None):
+ """a pailou archway as a goal (球门): posts, a beam, a tiled roof with upturned eaves and ridge curls, and a
+ lattice net (窗棂) with a round eye (风流眼). Pivot: the middle of the floor line."""
+ hw = w / 2
+ L = self.leather(-hw - 80, -h - 120, hw + 80, 4, scale, ss=2, seed=seed)
+ # posts with stepped plinths
+ for s in (-1, 1):
+ x = s * hw
+ pm = L.fill([(x - 12, -h + 4), (x + 12, -h + 4), (x + 12, 0), (x - 12, 0)], post)
+ L.pattern(pm * L.below(-h + 40) * L.above(-50), 'coins', 25, angle=90, r=0.31, square=0.1, margin=3.5, origin=(x, 0))
+ L.fill([(x - 18, -44), (x + 18, -44), (x + 21, -32), (x - 21, -32)], net)
+ L.fill([(x - 24, -32), (x + 24, -32), (x + 28, 0), (x - 28, 0)], net)
+ # the net: a lattice panel between the posts with a ringed eye
+ ny0, ny1 = -h + 34, -h + 34 + net_h
+ nm = L.fill([(-hw + 10, ny0), (hw - 10, ny0), (hw - 10, ny1), (-hw + 10, ny1)], net)
+ ex, ey = eye
+ holes = L.holes('lattice', 27, 45, origin=(ex, ey), bar=0.2) * L.inset(nm, 7) * (1 - L.ellipse(ex, ey, eye_r + 14))
+ L.punch(holes, 0.8)
+ L.fill(L.ring(ex, ey, eye_r - 1, eye_r + 12), trim)
+ L.pattern(L.ring(ex, ey, eye_r + 1, eye_r + 11), 'dots', 7.5, r=0.22, margin=1.5, origin=(ex, ey))
+ L.punch(L.ellipse(ex, ey, eye_r), 0)
+ L.contour(nm, 2.4)
+ # fringe of scallops under the net
+ sc = 0
+ for i in range(int((w - 20) // 24)):
+ cx = -hw + 22 + i * 24
+ sc = np.maximum(sc, L.ellipse(cx, ny1 + 2, 11, 13) * L.below(ny1 - 1))
+ L.fill(sc, trim); L.pattern(sc, 'dots', 9, r=0.18, margin=2.5)
+ # beam
+ bm = L.fill([(-hw - 40, -h - 4), (hw + 40, -h - 4), (hw + 34, -h + 30), (-hw - 34, -h + 30)], beam)
+ L.pattern(bm, 'coins', 26, r=0.37, square=0.1, margin=4, origin=(0, -h + 13))
+ for s in (-1, 1): # brackets under the beam
+ L.fill(_loop([(s * (hw - 12), -h + 30), (s * (hw - 44), -h + 30), (s * (hw - 30), -h + 40), (s * (hw - 14), -h + 56)], 4), net)
+ # tiled roof with upturned eaves
+ e = hw + 64
+ roof_pts = np.vstack([spline([(-e - 6, -h - 34), (-e + 18, -h - 12), (-hw, -h - 6), (hw, -h - 6), (e - 18, -h - 12), (e + 6, -h - 34)], 8),
+ spline([(e + 6, -h - 34), (e - 20, -h - 30), (hw - 16, -h - 70), (-hw + 16, -h - 70), (-e + 20, -h - 30), (-e - 6, -h - 34)], 8)])
+ rm = L.fill(roof_pts, roof)
+ L.pattern(rm * L.below(-h - 66) * L.above(-h - 12), 'stripes', 13, bar=0.5, margin=4)
+ L.fill([(-hw + 10, -h - 82), (hw - 10, -h - 82), (hw - 6, -h - 66), (-hw + 6, -h - 66)], roof)
+ for s in (-1, 1): # ridge curls
+ curl = spline([(s * (hw - 14), -h - 74), (s * (hw + 4), -h - 92), (s * (hw - 6), -h - 112), (s * (hw - 26), -h - 108), (s * (hw - 24), -h - 96)], 8)
+ L.fill(L.ribbon(curl, 13, 6), roof)
+ L.punch(L.ellipse(s * (hw - 7), -h - 99, 4.2), 0.6)
+ jm = L.fill(L.ellipse(0, -h - 96, 13, 13), trim)
+ L.fill(_loop([(0, -h - 132), (8, -h - 112), (0, -h - 104), (-8, -h - 112)], 5), net)
+ L.pattern(jm, 'flower', 30, petals=5, r=0.1, ring=0.19, margin=1.5, origin=(0, -h - 96))
+ L.edge(2.2)
+ return self.prop(L, 'gate')
+
+ def border(self, y0=None, y1=None, x0=None, x1=None, dye='teal', trim='red', unit=None, seed=None):
+ """the ornamental floor band along the bottom of the screen: a dotted strip, a key-fret band, a dark rail.
+ Built in canvas coordinates (place it at x=0, y=0; move x to slide it in)"""
+ bx0, by0, bx1, by1 = self.box
+ x0 = bx0 - 4 if x0 is None else x0; x1 = bx1 + 4 if x1 is None else x1
+ y1 = by1 + 2 if y1 is None else y1; y0 = y1 - 70 if y0 is None else y0
+ L = self.leather(x0, y0, x1, y1, 1.0, ss=2, seed=seed)
+ h = y1 - y0
+ top = L.fill([(x0, y0), (x1, y0), (x1, y0 + 0.2 * h), (x0, y0 + 0.2 * h)], trim)
+ L.pattern(top, 'dots', 10, r=0.2, margin=3, origin=(0, y0 + 0.1 * h))
+ mid = L.fill([(x0, y0 + 0.2 * h), (x1, y0 + 0.2 * h), (x1, y1 - 0.14 * h), (x0, y1 - 0.14 * h)], dye)
+ L.fill([(x0, y1 - 0.14 * h), (x1, y1 - 0.14 * h), (x1, y1), (x0, y1)], 'black')
+ my0, my1 = y0 + 0.2 * h + 7, y1 - 0.14 * h - 7
+ for path in meander(x0 + 10, x1 - 10, my0, my1, unit or (my1 - my0) * 1.2):
+ L.carve(path, 3.6)
+ L.contour(top, 1.5); L.contour(mid, 1.5)
+ L.edge(1.6)
+ return self.prop(L, 'border')
+
+ def nameplate(self, text, dye='red', size=30, string=60, seed=None):
+ """a small vertical plaque on a thread: dark characters on pale hide in a dyed frame. Pivot: the top of the
+ thread"""
+ n = len(text); w = size + 22; h = n * size * 1.08 + 30
+ L = self.leather(-w / 2 - 6, -2, w / 2 + 6, string + h + 26, 1.0, seed=seed)
+ L.line([(0, 0), (0, string + 4)], 1.6)
+ L.fill(_loop([(-9, string + 2), (0, string - 8), (9, string + 2), (0, string + 8)], 4), 'ochre')
+ fr = L.fill([(-w / 2, string + 6), (w / 2, string + 6), (w / 2, string + 6 + h), (-w / 2, string + 6 + h)], dye)
+ pane = L.dye([(-w / 2 + 7, string + 13), (w / 2 - 7, string + 13), (w / 2 - 7, string - 1 + h), (-w / 2 + 7, string - 1 + h)], 'plain')
+ L.pattern(fr * (1 - L.grow(pane, 1)), 'dots', 7, r=0.2, margin=1.6)
+ L.fill(L.text(text, 0, string + 6 + h / 2, size, 'label', vertical=True), 'black')
+ L.contour(pane, 1.2)
+ tip = string + 6 + h
+ L.fill(_loop([(-8, tip), (8, tip), (0, tip + 18)], 4), 'ochre')
+ L.edge(1.5)
+ return self.prop(L, 'nameplate')
+
+ # ------------------------------------------------------------ the front: proscenium and lanterns
+ def proscenium(self, plaque='蹴鞠', top=150, valance=54, side=64, sill=80, bracket=170, plaque_w=420):
+ """the carved frame: lintel with key-fret panels and the plaque, an openwork valance and corner brackets,
+ pillars and a sill. Sets the screen opening to the space inside it"""
+ self.box = (side, top, self.W - side, self.H - sill)
+ self._prosc = dict(plaque=plaque, top=top, valance=valance, side=side, sill=sill, bracket=bracket, plaque_w=plaque_w)
+ self._Lbase = self._L = self._frame = None
+ return self
+
+ def frame(self, dy=0.0, alpha=1.0):
+ """pose of the lintel group (lintel, plaque, valance, brackets) for the draw-on: dy < 0 lifts it out of view"""
+ self.frame_pose = dict(dy=float(dy), alpha=float(alpha))
+ return self
+
+ def lantern(self, x, top=None, r=56, drop=70, tassel=True, lit=1.0, swing=0.0):
+ """a red paper lantern hanging from the lintel at x (top: where its string is tied)"""
+ top = (self._prosc['top'] if self._prosc else 0) if top is None else top
+ ln = Lantern(self, x, top, r, drop, tassel, lit, swing, self._seed())
+ self.lanterns.append(ln)
+ return ln
+
+ def _build_frame(self):
+ P = self._prosc; H, W = self.H, self.W
+ top, val, side, sill, br, pw = P['top'], P['valance'], P['side'], P['sill'], P['bracket'], P['plaque_w']
+ cx = W / 2
+ rng = np.random.default_rng(self.seed + 31)
+ Y, X = np.mgrid[0:H, 0:W].astype(np.float32)
+
+ def canvas():
+ im = Image.new('L', (W, H), 0); return im, ImageDraw.Draw(im)
+
+ def arr(im):
+ return np.asarray(im, np.float32) / 255
+
+ Ht = np.zeros((H, W), np.float32) # relief height, px
+ gild = np.zeros((H, W), np.float32)
+ red = np.zeros((H, W), np.float32)
+ At = np.zeros((H, W), np.float32) # lintel group
+ Ab = np.zeros((H, W), np.float32) # pillars and sill
+ vert = np.zeros((H, W), np.float32) # grain runs vertically here
+ # pillars (drawn first; the lintel and sill sit over them)
+ for a, b in ((0, side), (W - side, W)):
+ uu = (np.arange(a, b, dtype=np.float32) + 0.5 - (a + b) / 2) / ((b - a) / 2)
+ Ab[:, a:b] = 1; vert[:, a:b] = 1
+ Ht[:, a:b] = 3 + 10 * np.sqrt(np.clip(1 - uu * uu, 0, 1))[None, :]
+ inner = b - 3 if a == 0 else a + 1
+ gild[top + val:H - sill, inner:inner + 2] = 0.7
+ # sill
+ Ab[H - sill:] = 1; vert[H - sill:] = 0
+ yy = Y[H - sill:]
+ Ht[H - sill:] = 2 + 5 * np.sqrt(np.clip(1 - ((yy - (H - sill + 8)) / 7) ** 2, 0, 1))
+ gild[H - sill + 15:H - sill + 17] = 1
+ im, d = canvas()
+ for path in meander(side + 30, W - side - 30, H - sill + 28, H - 14, 46):
+ d.line([(x, y) for x, y in path], fill=255, width=5)
+ Ht += 3 * blur(arr(im), 0.9)
+ # lintel
+ At[:top] = 1
+ yy = Y[:top]
+ Ht[:top] = 2 + 4 * smoothstep(16, 8, yy) + 5 * np.sqrt(np.clip(1 - ((yy - (top - 12)) / 8) ** 2, 0, 1))
+ gild[17:19] = 1; gild[top - 3:top - 1] = 1
+ im, d = canvas()
+ panels = [(side + 22, cx - pw / 2 - 34), (cx + pw / 2 + 34, W - side - 22)]
+ for a, b in panels: d.rectangle([a, 30, b, top - 30], fill=255)
+ panel = arr(im)
+ lip = np.clip(_grow(panel, 4) - panel, 0, 1)
+ Ht += -4 * blur(panel, 1.0) + 2.5 * blur(lip, 0.8)
+ im, d = canvas()
+ for a, b in panels:
+ for path in meander(a + 6, b - 6, 40, top - 40, (top - 80) * 1.15):
+ d.line([(x, y) for x, y in path], fill=255, width=6)
+ Ht += 4.5 * blur(arr(im) * panel, 0.9)
+ # plaque: a raised board with a gilt fillet, a red lacquer field and gilt characters
+ bx0, bx1, by0, by1 = cx - pw / 2, cx + pw / 2, 12, top - 8
+ im, d = canvas(); d.rounded_rectangle([bx0, by0, bx1, by1], radius=12, fill=255); board = arr(im)
+ im, d = canvas(); d.rounded_rectangle([bx0 + 17, by0 + 15, bx1 - 17, by1 - 15], radius=5, fill=255); field = arr(im)
+ Ht = Ht * (1 - board) + board * (4 + 7 * blur(board, 3.0))
+ im, d = canvas(); d.rounded_rectangle([bx0 + 7, by0 + 6, bx1 - 7, by1 - 6], radius=9, outline=255, width=2)
+ d.rounded_rectangle([bx0 + 24, by0 + 22, bx1 - 24, by1 - 22], radius=3, outline=255, width=2)
+ gild = np.maximum(gild, arr(im))
+ red = field.copy()
+ fsize = (by1 - by0 - 30) * 0.80
+ im, d = canvas()
+ f = _font('plaque', fsize)
+ plaque = P['plaque']
+ n = len(plaque)
+ step = min(fsize * 1.32, (pw - 90) / max(1, n))
+ for i, ch in enumerate(plaque):
+ d.text((cx + (i - (n - 1) / 2) * step, (by0 + by1) / 2 + 2), ch, font=f, fill=255, anchor='mm')
+ glyph = arr(im) * field
+ gild = np.maximum(gild, glyph)
+ Ht += 3.5 * blur(glyph, 1.1)
+ gshadow = np.roll(np.roll(blur(glyph, 2.0), 3, 0), 2, 1) * field * (1 - glyph)
+ # valance: openwork key-fret between two rails
+ im, d = canvas()
+ d.rectangle([side, top, W - side, top + 7], fill=255)
+ d.rectangle([side, top + val - 9, W - side, top + val], fill=255)
+ for path in meander(side + 4, W - side - 4, top + 13, top + val - 15, (val - 26) * 1.25, gap=1.5):
+ d.line([(x, y) for x, y in path], fill=255, width=6)
+ for x in range(side, W - side, 8): # pearls along the bottom rail
+ d.ellipse([x + 1, top + val - 1, x + 6, top + val + 4], fill=255)
+ vm = arr(im)
+ # corner brackets: a carved quarter plate pierced with scrolls
+ im, d = canvas()
+ bh = br * 0.78
+ for s in (1, -1):
+ x0 = side if s == 1 else W - side
+ pts = [(x0 + s * br * np.cos(t), top + val + bh * np.sin(t)) for t in np.linspace(0, np.pi / 2, 48)]
+ d.polygon([(x0, top + val)] + pts, fill=255)
+ plate = arr(im)
+ im, d = canvas()
+ for s in (1, -1):
+ x0 = side if s == 1 else W - side
+ inner = [(x0 + s * (br - 13) * np.cos(t), top + val + (bh - 12) * np.sin(t)) for t in np.linspace(0.06, np.pi / 2 - 0.06, 40)]
+ d.polygon([(x0 + s * 11, top + val + 9)] + inner, fill=255)
+ hole = arr(im)
+ im, d = canvas()
+ for s in (1, -1):
+ x0 = side if s == 1 else W - side
+ for (u0, v0, rr, turns) in ((0.36, 0.40, 0.20, 1.6), (0.70, 0.17, 0.12, 1.4), (0.15, 0.78, 0.10, 1.3)):
+ c0x, c0y = x0 + s * br * u0, top + val + bh * v0
+ ts = np.linspace(0, turns * 2 * np.pi, 70)
+ rs = rr * br * (1 - ts / (turns * 2 * np.pi) * 0.75)
+ d.line([(c0x + s * r_ * np.cos(t), c0y - r_ * 0.85 * np.sin(t)) for r_, t in zip(rs, ts)], fill=255, width=9, joint='curve')
+ d.line([(x0 + s * br * 0.08, top + val + bh * 0.08), (x0 + s * br * 0.30, top + val + bh * 0.28)], fill=255, width=8)
+ bm = np.clip(plate * (1 - hole) + arr(im) * hole, 0, 1)
+ inside = ((X >= side) & (X < W - side)).astype(np.float32)
+ cm = np.maximum(vm, bm) * inside
+ At = np.maximum(At, cm)
+ Ht = Ht * (1 - cm) + cm * (2 + 3.5 * blur(cm, 1.2))
+ del X, plate, hole, vm, bm, cm, inside, panel, lip, board, field
+ # ---- shade, band by band (the frame is only a top band, two pillars and a sill; this keeps memory low)
+ l1 = np.array([-0.38, -0.50, 0.78]); l1 /= np.linalg.norm(l1)
+ l2 = np.array([0.0, 0.62, 0.78]); l2 /= np.linalg.norm(l2)
+ hv = l1 + np.array([0, 0, 1.0]); hv /= np.linalg.norm(hv)
+ gh = np.asarray(Image.fromarray(rng.normal(0, 1, (H, W // 50)).astype(np.float32)).resize((W, H), Image.BICUBIC))
+ gv = np.asarray(Image.fromarray(rng.normal(0, 1, (H // 50, W)).astype(np.float32)).resize((W, H), Image.BICUBIC))
+ fine = noise2d(H, W, 6, 2, self.seed + 32) - 0.5
+ gnoise = noise2d(H, W, 3, 2, self.seed + 33) - 0.5
+ # light the screen spills onto the frame: a tight rim on edges next to it and a broad warm wash
+ B = self._screen_base()
+ scr = B['tex'] * (np.exp(-B['r2']) * 0.95 + 0.10) * (1 - np.maximum(At, Ab))
+ near = blur(scr, 2.2)
+ h2, w2 = H // 2, W // 2
+ far = np.asarray(Image.fromarray(blur(scr[:h2 * 2, :w2 * 2].reshape(h2, 2, w2, 2).mean((1, 3)), 15.0)).resize((W, H), Image.BILINEAR))
+ del scr
+ rgb_full = np.zeros((H, W, 3), np.float32); spill_full = np.zeros((H, W, 3), np.float32)
+ Rt = int(top + val + bh + 16)
+ bands = [(0, Rt, 0, W), (Rt, H - sill - 4, 0, side + 2), (Rt, H - sill - 4, W - side - 2, W), (H - sill - 4, H, 0, W)]
+ for r0, r1, c0, c1 in bands:
+ sl = (slice(r0, r1), slice(c0, c1))
+ Hb = Ht[sl]
+ gy, gx = np.gradient(blur(Hb, 0.8))
+ nz = 1 / np.sqrt(gx * gx + gy * gy + 1)
+ nx, ny = -gx * nz, -gy * nz
+ d1 = np.clip(nx * l1[0] + ny * l1[1] + nz * l1[2], 0, 1)
+ d2 = np.clip(nx * l2[0] + ny * l2[1] + nz * l2[2], 0, 1)
+ spec = (np.clip(nx * hv[0] + ny * hv[1] + nz * hv[2], 0, 1) ** 40)[..., None]
+ vb = vert[sl]
+ grain = (gh[sl] * (1 - vb) + gv[sl] * vb) * 0.5 + 0.25 * fine[sl]
+ ao = 1 - 0.55 * np.clip((blur(Hb, 5) - Hb) / 3, 0, 1)
+ wood = np.array(WOOD, np.float32) * (0.82 + 0.36 * np.clip(grain, -1, 1))[..., None]
+ rgb = wood * ((0.30 + 0.62 * d1 + 0.22 * d2) * ao)[..., None] + 0.10 * spec
+ rd = red[sl][..., None]
+ if rd.any():
+ lac = np.array(LACQUER, np.float32) * ((0.8 + 0.35 * smoothstep(by1, by0, Y[sl])) * (0.55 + 0.6 * d1))[..., None]
+ lac = lac * (1 - 0.65 * gshadow[sl][..., None]) + 0.22 * spec
+ rgb = rgb * (1 - rd) + lac * rd
+ gd = gild[sl][..., None]
+ gold = np.array(GOLD, np.float32) * (0.38 + 0.80 * d1 + 0.25 * d2)[..., None] + 0.55 * spec * np.array([1, 0.9, 0.7], np.float32)
+ gold *= (0.92 + 0.12 * gnoise[sl])[..., None]
+ rgb_full[sl] = rgb * (1 - gd) + gold * gd
+ spill_full[sl] = ((1.1 * near[sl] + 0.40 * far[sl]) * (0.55 + 0.6 * d2) * (1 - 0.5 * gild[sl]))[..., None] * np.array(SPILL, np.float32)
+ layers = {}
+ for name, Am in (('base', Ab), ('top', At)):
+ ys = np.nonzero(Am.max(1) > 0)[0]
+ r0, r1 = int(ys.min()), int(ys.max()) + 1
+ layers[name] = dict(r0=r0, r1=r1, A=Am[r0:r1].copy(), rgb=rgb_full[r0:r1].copy(), spill=spill_full[r0:r1].copy())
+ self._frame = layers
+
+ def _front(self, I):
+ if self._prosc is not None:
+ if self._frame is None: self._build_frame()
+ st = self.lamp_state
+ lvl = st['level'] * min(1.0, st['radius']) ** 2 * (1 + 0.6 * st['flicker'])
+ for name in ('base', 'top'):
+ Ly = self._frame[name]
+ r0, r1 = Ly['r0'], Ly['r1']
+ A, rgb = Ly['A'], Ly['rgb'] + Ly['spill'] * lvl
+ if name == 'top':
+ fp = self.frame_pose
+ if fp['alpha'] <= 0: continue
+ dy = int(round(fp['dy']))
+ r0, r1 = r0 + dy, r1 + dy
+ A = A * fp['alpha']
+ if r1 <= 0: continue
+ if r0 < 0: A, rgb, r0 = A[-r0:], rgb[-r0:], 0
+ if r1 > self.H: A, rgb, r1 = A[:self.H - r0], rgb[:self.H - r0], self.H
+ a = A[..., None]
+ I[r0:r1] = I[r0:r1] * (1 - a) + rgb * a
+ for ln in self.lanterns:
+ if ln.shown: self._draw_lantern(I, ln)
+ return I
+
+ def _draw_lantern(self, I, ln):
+ rgb, A, (hx, cy) = ln._draw(ln.lit)
+ h, w = A.shape
+ dy = self.frame_pose['dy'] if self._prosc else 0.0
+ ox, oy = ln.x - hx, ln.top + dy
+ if ln.swing:
+ ch = [Image.fromarray(np.ascontiguousarray(c), 'F').rotate(ln.swing, Image.BICUBIC, center=(hx, 0))
+ for c in (rgb[..., 0], rgb[..., 1], rgb[..., 2], A)]
+ rgb = np.stack([np.asarray(c) for c in ch[:3]], -1); A = np.clip(np.asarray(ch[3]), 0, 1)
+ x0, y0 = int(round(ox)), int(round(oy))
+ ya, yb = max(0, y0), min(self.H, y0 + h); xa, xb = max(0, x0), min(self.W, x0 + w)
+ if ya >= yb or xa >= xb: return
+ a = A[ya - y0:yb - y0, xa - x0:xb - x0, None]
+ I[ya:yb, xa:xb] = I[ya:yb, xa:xb] * (1 - a) + rgb[ya - y0:yb - y0, xa - x0:xb - x0] * a
+ if ln.lit > 0: # warm halo in the air round it
+ t = np.deg2rad(ln.swing)
+ bx, by = ln.x + np.sin(t) * cy, oy + np.cos(t) * cy
+ sg = 1.7 * ln.r; R = int(3 * sg)
+ ya, yb = max(0, int(by - R)), min(self.H, int(by + R)); xa, xb = max(0, int(bx - R)), min(self.W, int(bx + R))
+ if ya < yb and xa < xb:
+ yy, xx = np.mgrid[ya:yb, xa:xb].astype(np.float32)
+ g = np.exp(-((xx - bx) ** 2 + (yy - by) ** 2) / (2 * sg * sg)) * 0.30 * ln.lit
+ I[ya:yb, xa:xb] += g[..., None] * np.array([1.0, 0.34, 0.10], np.float32)
+
+ # ------------------------------------------------------------ render
+ def _lampmat(self, li, d):
+ if li is None or d <= 0: return np.eye(3)
+ (fx, fy), _ = self.lamps[li]
+ m = 1 + 0.30 * d
+ return np.array([[m, 0, fx * (1 - m)], [0, m, fy * (1 - m)], [0, 0, 1.0]])
+
+ @staticmethod
+ def _sigma(d):
+ return 0.0 if d <= 0 else 0.5 + 16.0 * d
+
+ def _warp(self, part, M):
+ img, x0, y0 = part['img'], part['x0'], part['y0']
+ w, h = img.size
+ C = np.array([[x0, y0, 1], [x0 + w, y0, 1], [x0 + w, y0 + h, 1], [x0, y0 + h, 1]], np.float64)
+ Pc = C @ M.T
+ bx0, by0 = int(np.floor(Pc[:, 0].min())) - 1, int(np.floor(Pc[:, 1].min())) - 1
+ bx1, by1 = int(np.ceil(Pc[:, 0].max())) + 1, int(np.ceil(Pc[:, 1].max())) + 1
+ if bx1 <= 0 or by1 <= 0 or bx0 >= self.W or by0 >= self.H: return None
+ Li = np.linalg.inv(M[:2, :2]); t = M[:2, 2]
+ a, b = Li[0]; d_, e = Li[1]
+ c = a * (bx0 - t[0]) + b * (by0 - t[1]) - x0
+ f = d_ * (bx0 - t[0]) + e * (by0 - t[1]) - y0
+ out = img.transform((bx1 - bx0, by1 - by0), Image.AFFINE, (a, b, c, d_, e, f), resample=Image.BILINEAR)
+ return by0, bx0, np.asarray(out, np.float32) / 255
+
+ def _render_item(self, p, S):
+ Mw = p.matrices()
+ groups = {}
+ for n in p.order:
+ groups.setdefault(round(min(1.0, max(0.0, p.d + p.away.get(n, 0.0))), 2), []).append(n)
+ for de, names in groups.items():
+ sig = self._sigma(de)
+ for li in ((0, 1) if de > 0 else (None,)):
+ Lm = self._lampmat(li, de)
+ pieces = []
+ for n in names:
+ r = self._warp(p.parts[n], Lm @ Mw[n])
+ if r is not None: pieces.append(r)
+ if not pieces: continue
+ pad = int(3 * sig) + 3
+ y0 = min(r[0] for r in pieces) - pad; x0 = min(r[1] for r in pieces) - pad
+ y1 = max(r[0] + r[2].shape[0] for r in pieces) + pad; x1 = max(r[1] + r[2].shape[1] for r in pieces) + pad
+ buf = np.ones((y1 - y0, x1 - x0, 3), np.float32)
+ for (oy, ox, arr) in pieces:
+ buf[oy - y0:oy - y0 + arr.shape[0], ox - x0:ox - x0 + arr.shape[1]] *= 1 - arr * p.alpha
+ # thread knots at the joints
+ kr = 3.8 * p.k * (Lm[0, 0])
+ for n in names:
+ if not p.parts[n]['knot']: continue
+ v = Lm @ Mw[n] @ np.array([0, 0, 1.0])
+ cxk, cyk = v[0] - x0, v[1] - y0
+ ya, yb = int(cyk - kr - 4), int(cyk + kr + 5); xa, xb = int(cxk - kr - 4), int(cxk + kr + 5)
+ if ya < 0 or xa < 0 or yb > buf.shape[0] or xb > buf.shape[1]: continue
+ yy, xx = np.mgrid[ya:yb, xa:xb].astype(np.float32) + 0.5
+ dd = np.hypot(xx - cxk, yy - cyk)
+ knot = np.clip(kr - dd + 0.5, 0, 1) * 0.86 + np.clip(1.0 - np.abs(dd - kr - 1.4), 0, 1) * 0.25
+ buf[ya:yb, xa:xb] *= 1 - (knot * p.alpha)[..., None]
+ if sig > 0:
+ K = 1 - buf
+ buf = 1 - np.stack([blur(K[..., c], sig) for c in range(3)], -1)
+ for T in ((S[0], S[1]) if li is None else (S[li],)):
+ self._mul(T, buf, y0, x0)
+ # control rods: tied on at the puppet's distance, slanting back toward the puppeteers
+ for rd in p.rods:
+ A = p.point(rd['part'], rd['pt'], Mw)
+ d0 = min(1.0, p.d + p.away.get(rd['part'], 0.0)); d1 = min(1.0, d0 + 0.15)
+ B = (A[0] + rd['lean'], self.box[3] + 70)
+ for li in (0, 1):
+ a = self._lampmat(li, d0) @ np.array([A[0], A[1], 1.0]); b = self._lampmat(li, d1) @ np.array([B[0], B[1], 1.0])
+ self._rod(S[li], a, b, max(0.6, self._sigma(d0)), self._sigma(d1), rd['width'] * p.k, p.alpha)
+
+ def _mul(self, T, buf, y0, x0):
+ h, w = buf.shape[:2]
+ ya, yb = max(0, y0), min(self.H, y0 + h); xa, xb = max(0, x0), min(self.W, x0 + w)
+ if ya < yb and xa < xb:
+ T[ya:yb, xa:xb] *= buf[ya - y0:yb - y0, xa - x0:xb - x0]
+
+ def _rod(self, T, a, b, s0, s1, width, alpha):
+ pad = int(3 * max(s0, s1)) + 4
+ x0, x1 = int(min(a[0], b[0])) - pad, int(max(a[0], b[0])) + pad + 1
+ y0, y1 = int(min(a[1], b[1])) - pad, int(max(a[1], b[1])) + pad + 1
+ w, h = x1 - x0, y1 - y0
+ im = Image.new('L', (w * 2, h * 2), 0)
+ dr = ImageDraw.Draw(im)
+ wpx = max(1, int(round(width * 2)))
+ dr.line([((a[0] - x0) * 2, (a[1] - y0) * 2), ((b[0] - x0) * 2, (b[1] - y0) * 2)], fill=255, width=wpx)
+ r = wpx * 0.9
+ dr.ellipse([(a[0] - x0) * 2 - r, (a[1] - y0) * 2 - r, (a[0] - x0) * 2 + r, (a[1] - y0) * 2 + r], fill=255)
+ m = np.asarray(im, np.float32).reshape(h, 2, w, 2).mean((1, 3)) / 255
+ m0, m1 = blur(m, s0), blur(m, s1)
+ t = np.clip((np.arange(h, dtype=np.float32) + y0 - a[1]) / max(1.0, b[1] - a[1]), 0, 1)[:, None] ** 0.8
+ mm = (m0 * (1 - t) + m1 * t * (1 + 0.4 * t))
+ self._mul(T, 1 - alpha * mm[..., None] * np.array(ROD, np.float32), y0, x0)
+
+ def _bloom(self, E):
+ H, W = self.H, self.W
+ h2, w2 = H // 2, W // 2
+ Eh = E[:h2 * 2, :w2 * 2].reshape(h2, 2, w2, 2, 3).mean((1, 3))
+ out = E.copy()
+ for sg, amt in ((14, 0.15), (3, 0.06)):
+ b = np.stack([blur(Eh[..., c], sg) for c in range(3)], -1)
+ up = np.stack([np.asarray(Image.fromarray(b[..., c]).resize((w2 * 2, h2 * 2), Image.BILINEAR)) for c in range(3)], -1)
+ out[:h2 * 2, :w2 * 2] += amt * up
+ return out
+
+ def _postfx(self):
+ 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.30 * r ** 2 * 2.0
+ grain = 1 + 0.018 * (noise2d(H, W, 1.0, 1, self.seed + 99) - 0.5)
+ self._post = (vig * grain).astype(np.float32)
+ return self._post
+
+ def render(self):
+ H, W = self.H, self.W
+ L = self._emission()
+ S = [np.ones((H, W, 3), np.float32), np.ones((H, W, 3), np.float32)]
+ for p in self.items:
+ if p.shown and p.alpha > 0: self._render_item(p, S)
+ w1, w2 = self.lamps[0][1], self.lamps[1][1]
+ E = L * (w1 * S[0] + w2 * S[1])
+ del S
+ E = self._bloom(E)
+ k = 1.5
+ I = (1 - np.exp(-k * E)) / (1 - np.exp(-k)) # soft shoulder: the hot spot glows instead of clipping
+ I = self._front(I)
+ return I * self._postfx()[..., None]
+
+ def composite(self):
+ return Image.fromarray((np.clip(self.render(), 0, 1) * 255 + 0.5).astype(np.uint8))
+
+ def stage(self, name):
+ if not self.keep_stages: return
+ im = self.composite()
+ if self.stages_dir:
+ os.makedirs(self.stages_dir, exist_ok=True)
+ im.save(f'{self.stages_dir}/{self._n_stages:03d}_{name}.png', compress_level=1)
+ else:
+ self.stages.append((name, im))
+ self._n_stages += 1
+
+ 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)
+ sd = stages_dir or self.stages_dir
+ if sd and self.keep_stages:
+ os.makedirs(sd, exist_ok=True)
+ for i, (name, im) in enumerate(self.stages):
+ im.save(f'{sd}/{i:03d}_{name}.png', compress_level=1)
+ img.save(f'{sd}/{self._n_stages:03d}_final.png', compress_level=1)
+ return img
+
+
+# ================================================================ the figure
+def _figure(sp, robe='red', trim='black', accent='ochre', trousers='teal', face='hollow', skin='plain', facedye=None,
+ headdress='plume', plume='ochre', pom='red', pattern='cloud', hands=('open', 'open'), scale=1.0, seed=None,
+ name='figure'):
+ """A jointed shadow-puppet figure facing right (flip it to face left). Parts and joints:
+ pelvis (root, pivot at the hips) -- torso (waist) -- head (neck), arm_f / arm_b (shoulders) -- fore_f /
+ fore_b (elbows) -- hand_f / hand_b (wrists); thigh_f / thigh_b (hips) -- shin_f / shin_b (knees).
+ _f is the near limb, _b the far one. robe / trim / accent / trousers / skin are dye names; face 'hollow' (阳刻:
+ the face cut away, a fine profile line, one long eye, a long brow) or 'solid' (阴刻: the face left as dyed leather,
+ `facedye`, with the features cut out); headdress 'plume' (helmet + two pheasant plumes), 'crown' (crown with
+ pompoms and a tassel) or 'bun' (hair knot and a ribbon); pattern: the hollow pattern of the robe; hands: ('open' |
+ 'fist') for the near and far hand. At scale 1 the figure stands about 520 px from sole to helmet."""
+ k = float(scale)
+ rng = np.random.default_rng(sp._seed() if seed is None else seed)
+ sd = lambda: int(rng.integers(1 << 30))
+ P = Puppet(sp, name, k)
+ LW = 2.4
+ other = 'teal' if robe not in ('teal', 'green', 'blue') else 'red'
+
+ # ---- pelvis: tunic skirt with belt and buckle (root; pivot = hips)
+ L = Leather(-66, -46, 52, 108, k, seed=sd())
+ sk = L.fill(_loop([(-36, -34), (-40, 4), (-50, 56), (-58, 96), (-30, 104), (-6, 99), (20, 104), (46, 96), (42, 48), (35, 4), (31, -34)], 6), robe)
+ hem = L.dye(sk * L.below(84), trim)
+ L.pattern(sk * L.above(80) * L.below(-16), pattern, 26, margin=5, origin=(0, 30))
+ L.pattern(hem, 'dots', 10, r=0.24, margin=3, origin=(0, 94))
+ belt = L.fill([(-44, -41), (35, -41), (36, -18), (-45, -18)], accent)
+ L.pattern(belt, 'stripes', 7, bar=0.5, margin=3.2)
+ L.carve([(-7, 103), (-6, 46)], 2.0)
+ L.edge(LW); L.contour(hem, 1.6); L.contour(belt, 1.6)
+ bk = L.fill(L.ellipse(28, -29.5, 8, 7.5), other)
+ L.contour(bk, 1.5); L.punch(L.ellipse(28, -29.5, 2.4), 0)
+ P.add('pelvis', L)
+
+ def thigh():
+ L = Leather(-26, -20, 26, 112, k, seed=sd())
+ m = L.fill(_loop([(0, -17), (17, -11), (21, 26), (18, 70), (15, 106), (-15, 106), (-19, 70), (-21, 26), (-17, -11)], 6), trousers)
+ L.pattern(m * L.below(12) * L.above(92) * L.left_of(-4), 'dots', 11, angle=90, r=0.22, margin=3, origin=(-11, 30))
+ L.edge(LW)
+ return L
+
+ def shin():
+ L = Leather(-26, -18, 64, 122, k, seed=sd())
+ out = np.vstack([spline([(0, -15), (14, -9), (14, 36), (13, 84), (24, 92), (38, 96), (48, 97), (53, 92)], 5),
+ spline([(53, 92), (51, 106), (43, 116), (-18, 116), (-18, 103), (-15, 90), (-14, 36), (-15, -9), (0, -15)], 5)])
+ m = L.fill(out, trousers)
+ boot = L.dye(m * L.below(36), 'black')
+ sole = L.dye(m * L.below(103), 'plain')
+ L.pattern(m * L.above(33), 'lattice', 12, angle=45, bar=0.26, margin=3.5)
+ L.pattern(boot * L.above(98) * L.below(42), 'cloud', 21, margin=3.5, origin=(0, 66))
+ L.pattern(sole, 'dots', 8, r=0.2, margin=2.6, origin=(0, 110))
+ L.edge(LW); L.contour(sole, 1.8)
+ L.line([(-14, 37), (14, 37)], 2.4, accent)
+ return L
+
+ P.add('thigh_b', thigh(), 'pelvis', (-8, 0))
+ P.add('shin_b', shin(), 'thigh_b', (0, 100))
+
+ # ---- torso: robe, cloud collar, breastplate mirror, scale armour, sash (pivot = waist)
+ L = Leather(-52, -162, 58, 10, k, seed=sd())
+ tm = L.fill(_loop([(30, 4), (36, -34), (46, -84), (45, -112), (36, -130), (18, -142), (-8, -144), (-30, -136), (-42, -118), (-42, -66), (-35, 4)], 6), robe)
+ cm = L.fill(_loop([(-34, -128), (-22, -146), (18, -146), (40, -128), (47, -108), (35, -97), (23, -110), (10, -94), (-4, -107), (-18, -95), (-32, -105)], 6), accent)
+ sash = L.dye(tm * L.below(-20), trim)
+ mirror = L.fill(L.ellipse(14, -70, 17), other)
+ L.pattern(tm * (1 - L.grow(cm, 1.5)) * (1 - L.grow(mirror, 2)) * L.above(-24), 'scales', 17, margin=4.5, origin=(0, -96))
+ L.pattern(cm, 'cloud', 17, margin=3.2, origin=(4, -116))
+ L.pattern(mirror, 'flower', 40, petals=6, r=0.085, ring=0.2, margin=2, origin=(14, -70))
+ L.punch(L.ellipse(14, -70, 3), 0)
+ L.pattern(sash, 'dots', 8, r=0.22, margin=2.8, origin=(0, -8))
+ L.fill(L.ellipse(3, -142, 15, 6, rot=-6), trim)
+ L.edge(LW); L.contour(cm, 1.7); L.contour(sash, 1.6); L.contour(mirror, 1.8)
+ L.dye(L.ring(14, -70, 11.5, 13.3), 'black')
+ P.add('torso', L, 'pelvis', (-2, -30))
+
+ def arm(near):
+ L = Leather(-26, -26, 26, 94, k, seed=sd())
+ m = L.fill(_loop([(0, -20), (15, -15), (19, 4), (18, 40), (15, 88), (-15, 88), (-18, 40), (-19, 4), (-15, -15)], 6), robe)
+ L.pattern(m * L.below(16 if near else -4) * L.above(80), pattern, 22, margin=4, origin=(0, 50))
+ if near: # the shoulder guard only on the near arm (two would pile up over the collar)
+ md = L.fill(L.ellipse(0, -1, 14.5, 13.5), accent)
+ L.pattern(md, 'flower', 28, petals=5, r=0.11, ring=0.2, margin=1.5, origin=(0, -1))
+ L.contour(md, 1.6)
+ L.edge(LW)
+ return L
+
+ def fore():
+ L = Leather(-24, -16, 24, 82, k, seed=sd())
+ m = L.fill(_loop([(0, -13), (13, -9), (14, 28), (15, 52), (18, 78), (-18, 78), (-15, 52), (-14, 28), (-13, -9)], 6), robe)
+ cuff = L.dye(m * L.below(54), trim)
+ L.pattern(m * L.above(50) * L.below(4), 'dots', 14, r=0.2, margin=4, origin=(0, 26), angle=90)
+ L.pattern(cuff, 'dots', 7.5, r=0.22, margin=2.6, origin=(0, 66))
+ L.edge(LW); L.contour(cuff, 1.4)
+ L.line([(-16, 54), (16, 54)], 2.2, accent)
+ return L
+
+ def hand(kind):
+ L = Leather(-18, -8, 28, 54, k * 1.1, seed=sd())
+ if kind == 'fist':
+ L.fill(_loop([(-10, -2), (9, -2), (13, 10), (14, 26), (6, 33), (-8, 32), (-12, 18)], 5), skin)
+ L.edge(1.7)
+ for y in (13, 20, 27): L.carve([(3, y), (12, y - 1)], 1.1)
+ L.carve([(-4, 8), (6, 14)], 1.1)
+ else:
+ L.fill(_loop([(-9, -2), (9, -2), (11, 13), (9, 25), (-9, 25), (-11, 12)], 5), skin)
+ for i, x in enumerate((-7.2, -2.4, 2.4, 7.2)):
+ L.fill(L.ribbon(spline([(x, 20), (x * 1.12, 33), (x * 1.18 + 1.0, 45 - abs(i - 1.6) * 3.2)], 6), 4.6, 3.6), skin)
+ L.fill(L.ribbon(spline([(7, 7), (15, 17), (20, 28)], 6), 5.4, 3.8), skin)
+ L.edge(1.6)
+ for x in (-4.8, 0.0, 4.8): L.carve([(x * 1.1, 27), (x * 1.16, 36)], 0.9)
+ return L
+
+ def head():
+ L = Leather(-170, -240, 66, 12, k * 1.15, seed=sd())
+ L.fill([(-10, 10), (-11, -24), (7, -24), (9, 10)], skin)
+ front = spline([(4, -19), (11, -24.5), (17, -28.5), (18, -33), (15.8, -35.2), (19.2, -37.8), (18.4, -40.8), (21.6, -43.4),
+ (25.2, -45.4), (21, -50), (18.6, -55.5), (17.4, -60), (15.6, -67), (11, -74)], 5)
+ back = spline([(11, -74), (3, -74), (-1, -64), (-3.5, -50), (-4, -36), (0, -24), (4, -19)], 5)
+ fm = L.fill(np.vstack([front, back]), skin if face == 'hollow' else (facedye or skin))
+ hair = np.vstack([spline([(11, -74), (4, -81), (-8, -86), (-20, -82), (-27, -68), (-28, -52), (-23, -38), (-14, -27), (-9, -22)], 5),
+ spline([(-9, -22), (-2, -26), (-4, -36), (-3.5, -50), (-1, -64), (3, -74), (11, -74)], 5)])
+ hm = L.fill(hair, 'black')
+ L.carve(spline([(-22, -46), (-17, -60), (-8, -70)], 6), 1.0)
+ L.carve(spline([(-18, -36), (-13, -50), (-5, -60)], 6), 1.0)
+ ear = L.fill(L.ellipse(-6, -45, 4.8, 7.5, rot=10), skin)
+ L.contour(ear, 1.2); L.carve(spline([(-6, -50), (-8, -45), (-5, -41)], 5), 0.9)
+ brow = L.ribbon(spline([(3, -58.6), (9, -61.6), (17.4, -60.2)], 8), 3.0, 1.2)
+ eye_up = spline([(4, -53.6), (9.5, -55.8), (15.8, -53.6)], 8)
+ eye_lo = spline([(6.5, -52.6), (11, -51.4), (15.8, -53.4)], 8)
+ tail = L.ribbon(spline([(5, -53.8), (2, -55.2), (-0.5, -57.2)], 6), 1.6, 0.6)
+ if face == 'hollow':
+ L.edge(2.0, region=fm)
+ L.punch(L.inset(fm, 2.1) * (1 - L.grow(hm, 0.5)) * (1 - L.grow(ear, 1.2)), 0)
+ L.fill(brow, 'black'); L.line(eye_up, 1.5); L.line(eye_lo, 1.0); L.fill(tail, 'black')
+ L.fill(L.ellipse(12.0, -53.5, 1.9, 2.1), 'black')
+ L.line(spline([(18.6, -42.0), (20.4, -44.2), (22.6, -43.8)], 5), 1.1)
+ L.line([(15.8, -35.3), (12.6, -35.0)], 1.1)
+ else:
+ L.edge(2.0, region=fm)
+ L.punch(brow, 0); L.punch(tail, 0)
+ L.punch(L.poly(np.vstack([eye_up, eye_lo[::-1]])) * (1 - L.ellipse(12.0, -53.5, 1.9, 2.1)), 0)
+ L.carve(spline([(18.4, -42.2), (20.4, -44.2), (22.2, -43.8)], 5), 1.0)
+ L.carve([(15.6, -35.3), (12.4, -35.0)], 1.1)
+ if headdress == 'plume':
+ helm = np.vstack([spline([(13, -73), (14, -86), (10, -98), (0, -106), (-14, -104), (-25, -94), (-29, -78), (-28, -68)], 6),
+ spline([(-28, -68), (-10, -75), (13, -73)], 6)])
+ hl = L.fill(helm, robe)
+ L.pattern(hl * L.above(-80), 'scales', 11, margin=2.6, origin=(0, -100))
+ band = L.fill(L.ribbon(spline([(-30, -69), (-10, -75.5), (15, -74)], 8), 9, 8), accent)
+ L.pattern(band, 'dots', 6.2, r=0.22, margin=1.8, origin=(0, -72))
+ fl = L.fill(_loop([(5, -98), (16, -107), (20, -121), (15, -137), (11, -124), (3, -110)], 6), accent)
+ L.punch(L.ellipse(13, -114, 2.6, 4.5, rot=-25), 0.6)
+ for (px, py, pr) in ((16, -138, 7.5), (-25, -97, 6.5)):
+ pm = L.fill(L.ellipse(px, py, pr), pom)
+ L.pattern(pm, 'dots', pr * 0.9, r=0.2, margin=1.4, origin=(px, py))
+ plumes = [spline([(-7, -103), (-18, -146), (-44, -176), (-84, -192), (-126, -190), (-158, -176)], 10),
+ spline([(0, -105), (-6, -154), (-28, -194), (-66, -216), (-110, -220), (-146, -208)], 10)]
+ for pl in plumes:
+ pm = L.fill(L.ribbon(pl, 9.5, 2.6), plume)
+ seg = np.cumsum(np.r_[0, np.linalg.norm(np.diff(pl, axis=0), axis=1)])
+ for s0 in np.arange(14, seg[-1] - 6, 11.5):
+ i = np.searchsorted(seg, s0); i = min(max(i, 1), len(pl) - 2)
+ dvec = pl[i + 1] - pl[i - 1]; dvec = dvec / (np.linalg.norm(dvec) + 1e-6)
+ nrm = np.array([-dvec[1], dvec[0]])
+ wv = 9.5 + (2.6 - 9.5) * s0 / seg[-1]
+ L.dye(L.stroke([pl[i] - nrm * wv, pl[i] + nrm * wv], 3.4) * pm, 'black')
+ L.edge(1.2, region=pm)
+ L.edge(1.6, region=hl); L.contour(band, 1.3); L.contour(fl, 1.3)
+ elif headdress == 'crown':
+ cr = np.vstack([spline([(14, -73), (16, -90), (6, -104), (-6, -108), (-20, -102), (-28, -86), (-28, -68)], 6),
+ spline([(-28, -68), (-10, -75), (14, -73)], 6)])
+ crm = L.fill(cr, accent)
+ L.pattern(crm * L.above(-80), 'coins', 12, margin=2.4, origin=(0, -95))
+ for (x, y, s) in ((10, -104, 1.0), (-4, -112, 1.25), (-19, -106, 1.0)):
+ fl = L.fill(_loop([(x - 6 * s, y + 4), (x + 6 * s, y + 4), (x + 4 * s, y - 10 * s), (x, y - 22 * s), (x - 4 * s, y - 10 * s)], 5), accent)
+ L.contour(fl, 1.2)
+ pm = L.fill(L.ellipse(x, y - 22 * s - 5, 5.5 * s), pom)
+ L.contour(pm, 1.1)
+ band = L.fill(L.ribbon(spline([(-30, -69), (-10, -75.5), (16, -74)], 8), 8, 7), robe)
+ L.pattern(band, 'dots', 6, r=0.22, margin=1.7, origin=(0, -72))
+ L.line(spline([(-26, -70), (-32, -52), (-30, -32)], 6), 1.4)
+ tm_ = L.fill(L.ellipse(-30, -28, 4.8), pom); L.contour(tm_, 1.1)
+ L.edge(1.6, region=crm); L.contour(band, 1.3)
+ elif headdress == 'bun':
+ L.fill(L.ellipse(-10, -88, 13, 10, rot=-15), 'black')
+ L.carve(spline([(-18, -86), (-10, -94), (0, -90)], 6), 1.0)
+ rb = L.fill(L.ribbon(spline([(-14, -80), (-32, -70), (-44, -48), (-52, -26)], 8), 6, 3), accent)
+ L.pattern(rb, 'dots', 5, r=0.2, margin=1.3)
+ L.contour(rb, 1.1)
+ L.edge(1.4, region=1 - fm)
+ return L
+
+ P.add('arm_b', arm(False), 'torso', (-16, -122))
+ P.add('fore_b', fore(), 'arm_b', (0, 82))
+ P.add('hand_b', hand(hands[1]), 'fore_b', (0, 76))
+ P.add('head', head(), 'torso', (3, -135), knot=False)
+ P.add('thigh_f', thigh(), 'pelvis', (4, 2))
+ P.add('shin_f', shin(), 'thigh_f', (0, 100))
+ P.add('arm_f', arm(True), 'torso', (4, -118))
+ P.add('fore_f', fore(), 'arm_f', (0, 82))
+ P.add('hand_f', hand(hands[0]), 'fore_f', (0, 76))
+ P.soles = {'shin_f': [(-18, 116), (43, 116)], 'shin_b': [(-18, 116), (43, 116)]}
+ return P