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.
Python agent-skillsanimechinese-paintingclaudeclaude-codeclaude-skillscolored-pencilcreative-codingcross-stitcheditorial-illustrationgenerative-artink-wash-paintingoil-paintingpaper-collagepixel-artprocedural-generationrisographshanshuiukiyo-ewatercolor
Add exam grading style (62 total): an answer sheet on green felt, marked in red
cloveric3dff12b0430b
diff --git a/README.md b/README.mdindex 31018de..6b1cbda 100644--- a/README.md+++ b/README.md@@ -1,54 +1,55 @@# Claude Drawing · Claude 绘图-**Claude paints with code — no image model.** Sixty-one 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 and a pastel product-film UI.-**不用生图模型,Claude 用代码一笔一笔作画。** 六十一种画风,从水墨、油画到黏土、蓝晒、彩色玻璃花窗、罗马马赛克、代尔夫特蓝瓷砖、赛博朋克、光线追踪的小球海、低多边形 3D、热成像、X 光片、VHS 录像带、Synthwave 落日和产品发布片式的粉彩界面。+**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 落日、产品发布片式的粉彩界面和红笔批改的答题卡。[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>--| Watercolour · 水彩 | Paper collage · 剪纸拼贴 | Coloured pencil · 韩国彩铅 |+| Ink wash · 水墨(月印万川) | Watercolour · 水彩 | Watercolour washes · 水彩底纹 ||---|---|---|-|  |  |  |-| **Anime · 日本动漫** | **Editorial · 编辑风手绘** | **Impasto oil · 油画厚涂** |-|  |  |  |-| **Ukiyo-e · 浮世绘木版画** | **Pixel art · 像素风** | **Stop-motion clay · 黏土定格** |-|  |  |  |-| **Cyanotype · 蓝晒** | **Cross-stitch · 十字绣** | **Retro panel · 复古仪器面板** |-|  |  |  |-| **Sticker collage × receipt · 贴纸拼贴 · 小票** | **Lab notebook × stickers · 实验笔记本 · 贴纸** | **Chalkboard · 黑板板书** |-|  |  |  |-| **Cyberpunk · 赛博朋克** | **Hand-drawn cartoon · 卡通手绘** | **Continuous line art · 单线画** |-|  |  |  |-| **Soft 3D · 柔光 3D** | **Shape morph · 形变动画** | **Newspaper collage · 报刊拼贴** |-|  |  |  |-| **Aurora glass · 弥散玻璃** | **Bauhaus geometric · 包豪斯几何** | **Retro synthwave · 复古 Synthwave** |-|  |  |  |-| **Isometric 2.5D · 等轴 2.5D** | **Perler beads · 拼豆** | **Petroglyph · 岩画** |-|  |  |  |-| **Egyptian tomb painting · 古埃及墓室壁画** | **Roman mosaic · 罗马马赛克** | **Stained glass · 彩色玻璃花窗** |-|  |  |  |-| **Illuminated manuscript · 泥金手抄本** | **Leonardo codex · 达·芬奇手稿** | **Silhouette · 剪影** |-|  |  |  |-| **Letterpress poster · 凸版印刷海报** | **Soviet constructivism · 苏联构成主义** | **Art Deco · 装饰艺术** |-|  |  |  |-| **Golden-age comic · 黄金时代漫画** | **Pop silkscreen · 波普丝网** | **ASCII art (line printer) · ASCII 字符画** |-|  |  |  |-| **Low poly · 低多边形** | **Stencil graffiti · 喷漆模板涂鸦** | **Embroidered patches · 刺绣徽章** |-|  |  |  |-| **Blueprint · 蓝图工程图** | **Children's crayon · 儿童蜡笔画** | **Green-screen CRT · 绿屏终端** |-|  |  |  |-| **Thermal camera · 热成像** | **Delft tiles · 代尔夫特蓝瓷砖** | **Cave painting · 洞穴壁画** |-|  |  |  |-| **1-bit paint program · 1-bit 早期画图软件** | **Greek black-figure vase · 古希腊黑绘陶瓶** | **Graphite pencil · 铅笔素描** |-|  |  |  |-| **X-ray · X 光片** | **1930s rubber hose · 1930 年代黑白橡皮管动画** | **Linocut · 黑白麻胶版画** |-|  |  |  |-| **VHS home video · VHS 家庭录像** | **Flat vector · 扁平矢量** | **Storybook animation · 绘本角色动画** |-|  |  |  |-| **Ballpoint doodle · 圆珠笔涂鸦** | **Overlay sheets · 描图纸叠层** | **Pastel UI · 粉彩界面** |-|  |  |  |+|  |  |  |+| **Paper collage · 剪纸拼贴** | **Coloured pencil · 韩国彩铅** | **Anime · 日本动漫** |+|  |  |  |+| **Editorial · 编辑风手绘** | **Impasto oil · 油画厚涂** | **Ukiyo-e · 浮世绘木版画** |+|  |  |  |+| **Pixel art · 像素风** | **Stop-motion clay · 黏土定格** | **Cyanotype · 蓝晒** |+|  |  |  |+| **Cross-stitch · 十字绣** | **Retro panel · 复古仪器面板** | **Sticker collage × receipt · 贴纸拼贴 · 小票** |+|  |  |  |+| **Lab notebook × stickers · 实验笔记本 · 贴纸** | **Chalkboard · 黑板板书** | **Cyberpunk · 赛博朋克** |+|  |  |  |+| **Hand-drawn cartoon · 卡通手绘** | **Continuous line art · 单线画** | **Soft 3D · 柔光 3D** |+|  |  |  |+| **Shape morph · 形变动画** | **Newspaper collage · 报刊拼贴** | **Aurora glass · 弥散玻璃** |+|  |  |  |+| **Bauhaus geometric · 包豪斯几何** | **Retro synthwave · 复古 Synthwave** | **Isometric 2.5D · 等轴 2.5D** |+|  |  |  |+| **Perler beads · 拼豆** | **Petroglyph · 岩画** | **Egyptian tomb painting · 古埃及墓室壁画** |+|  |  |  |+| **Roman mosaic · 罗马马赛克** | **Stained glass · 彩色玻璃花窗** | **Illuminated manuscript · 泥金手抄本** |+|  |  |  |+| **Leonardo codex · 达·芬奇手稿** | **Silhouette · 剪影** | **Letterpress poster · 凸版印刷海报** |+|  |  |  |+| **Soviet constructivism · 苏联构成主义** | **Art Deco · 装饰艺术** | **Golden-age comic · 黄金时代漫画** |+|  |  |  |+| **Pop silkscreen · 波普丝网** | **ASCII art (line printer) · ASCII 字符画** | **Low poly · 低多边形** |+|  |  |  |+| **Stencil graffiti · 喷漆模板涂鸦** | **Embroidered patches · 刺绣徽章** | **Blueprint · 蓝图工程图** |+|  |  |  |+| **Children's crayon · 儿童蜡笔画** | **Green-screen CRT · 绿屏终端** | **Thermal camera · 热成像** |+|  |  |  |+| **Delft tiles · 代尔夫特蓝瓷砖** | **Cave painting · 洞穴壁画** | **1-bit paint program · 1-bit 早期画图软件** |+|  |  |  |+| **Greek black-figure vase · 古希腊黑绘陶瓶** | **Graphite pencil · 铅笔素描** | **X-ray · X 光片** |+|  |  |  |+| **1930s rubber hose · 1930 年代黑白橡皮管动画** | **Linocut · 黑白麻胶版画** | **VHS home video · VHS 家庭录像** |+|  |  |  |+| **Flat vector · 扁平矢量** | **Storybook animation · 绘本角色动画** | **Ballpoint doodle · 圆珠笔涂鸦** |+|  |  |  |+| **Overlay sheets · 描图纸叠层** | **Pastel UI · 粉彩界面** | **Exam grading · 阅卷批改** |+|  |  |  |### Gallery · 画廊@@ -56,68 +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> | **热气球小镇** · *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%"> |--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. No diffusion model, no API, no stock art. It is just Python with **numpy + Pillow** on a CPU: from 0.1 s (pixel art) to about 45 s (the soft 3D ray tracer) per 1920×1080 image.+| **秋日湖畔** · *Autumn Lake*<br><sub>Watercolour · 水彩</sub> | **水彩底纹** · *Watercolour Washes*<br><sub>Watercolour · 水彩 — a background for explainer videos · 讲解视频的背景</sub> |+| <img src="examples/watercolor_autumn.jpg" width="100%"> | <img src="examples/watercolor_washes.jpg" width="100%"> |+| **热气球小镇** · *Balloon Day*<br><sub>Paper collage · 剪纸拼贴</sub> | **午后甜点** · *Afternoon Dessert*<br><sub>Coloured pencil · 韩国彩铅</sub> |+| <img src="examples/papercut_balloons.jpg" width="100%"> | <img src="examples/colorpencil_dessert.jpg" width="100%"> |+| **夏空** · *Summer Sky*<br><sub>Anime · 日本动漫</sub> | **灵感生长** · *Growing Ideas*<br><sub>Editorial · 编辑风手绘</sub> |+| <img src="examples/anime_summer.jpg" width="100%"> | <img src="examples/editorial_ideas.jpg" width="100%"> |+| **麦田星空** · *Swirling Sky over the Wheat Field*<br><sub>Impasto oil · 油画厚涂</sub> | **富士曙** · *Fuji at Dawn*<br><sub>Ukiyo-e · 浮世绘</sub> |+| <img src="examples/oil_wheatfield.jpg" width="100%"> | <img src="examples/ukiyoe_fuji.jpg" width="100%"> |+| **雨夜咖啡店** · *Rainy Night Cafe*<br><sub>Pixel art · 像素风</sub> | **灯塔岛** · *Lighthouse Island*<br><sub>Stop-motion clay · 黏土定格</sub> |+| <img src="examples/pixel_rainy_cafe.png" width="100%"> | <img src="examples/clay_lighthouse.jpg" width="100%"> |+| **蓝晒植物** · *Sun-Print Botanicals*<br><sub>Cyanotype · 蓝晒</sub> | **家** · *Home Sampler*<br><sub>Cross-stitch · 十字绣</sub> |+| <img src="examples/cyanotype_botanicals.jpg" width="100%"> | <img src="examples/stitch_sampler.jpg" width="100%"> |+| **Aurora 64 收音机** · *Aurora 64 Radio*<br><sub>Vintage instrument panel · 复古仪器面板</sub> | **周末市集** · *Weekend Market*<br><sub>Sticker collage × receipt · 贴纸拼贴 · 小票</sub> |+| <img src="examples/panel_radio.jpg" width="100%"> | <img src="examples/sticker_market.jpg" width="100%"> |+| **咖啡萃取实验** · *Coffee Brewing Experiment*<br><sub>Lab notebook × stickers · 实验笔记本 · 贴纸</sub> | **为什么天空是蓝的** · *Why Is the Sky Blue?*<br><sub>Chalkboard · 黑板板书</sub> |+| <img src="examples/notebook_brewing.jpg" width="100%"> | <img src="examples/chalk_lesson.jpg" width="100%"> |+| **霓虹不夜城** · *Neon District*<br><sub>Cyberpunk · 赛博朋克</sub> | **早安吐司** · *Good Morning, Toast*<br><sub>Hand-drawn cartoon · 卡通手绘</sub> |+| <img src="examples/cyberpunk_neon_street.jpg" width="100%"> | <img src="examples/cartoon_toaster.jpg" width="100%"> |+| **岛上的气象站** · *Island Weather Station*<br><sub>Isometric 2.5D · 等轴 2.5D</sub> | **从这扇窗到那扇窗** · *From Window to Window*<br><sub>Continuous line art · 单线画</sub> |+| <img src="examples/isometric_weather_island.jpg" width="100%"> | <img src="examples/lineart_paper_plane.jpg" width="100%"> |+| **浮出** · *Rise*<br><sub>Soft 3D · 柔光 3D</sub> | **一滴水的旅程** · *A Drop's Round Trip*<br><sub>Shape morph · 形变动画</sub> |+| <img src="examples/soft3d_rise.jpg" width="100%"> | <img src="examples/morph_water_cycle.jpg" width="100%"> |+| **好奇心周刊 · 拆开看看** · *Curiosity Weekly · Take It Apart*<br><sub>Newspaper collage · 报刊拼贴</sub> | **晨间计划** · *Morning Plan*<br><sub>Aurora glassmorphism · 弥散玻璃</sub> |+| <img src="examples/newscollage_curiosity.jpg" width="100%"> | <img src="examples/aurora_morning.jpg" width="100%"> |+| **形与色** · *Form & Colour*<br><sub>Bauhaus geometric · 包豪斯几何</sub> | **海岸线 1987** · *Coastline 1987*<br><sub>Retro synthwave · 复古 Synthwave</sub> |+| <img src="examples/bauhaus_form_colour.jpg" width="100%"> | <img src="examples/synthwave_coastline.jpg" width="100%"> |+| **草莓杯垫** · *Strawberry Coaster*<br><sub>Perler beads · 拼豆</sub> | **迁徙季** · *Migration Season*<br><sub>Petroglyph · 岩画</sub> |+| <img src="examples/perler_strawberry_coaster.jpg" width="100%"> | <img src="examples/petroglyph_migration.jpg" width="100%"> |+| **尼罗河丰收** · *Harvest on the Nile*<br><sub>Egyptian tomb painting · 古埃及墓室壁画</sub> | **港口渔获** · *The Day's Catch*<br><sub>Roman mosaic · 罗马马赛克</sub> |+| <img src="examples/tomb_harvest.jpg" width="100%"> | <img src="examples/mosaic_harbor.jpg" width="100%"> |+| **四季之窗** · *Window of the Seasons*<br><sub>Stained glass · 彩色玻璃花窗</sub> | **星辰之书** · *Liber Stellarum*<br><sub>Illuminated manuscript · 泥金手抄本</sub> |+| <img src="examples/stainedglass_seasons.jpg" width="100%"> | <img src="examples/illuminated_starchart.jpg" width="100%"> |+| **扑翼机** · *The Ornithopter*<br><sub>Leonardo codex · 达·芬奇手稿</sub> | **剪影小像** · *Shades of the Wren Household*<br><sub>Silhouette · 剪影</sub> |+| <img src="examples/codex_ornithopter.jpg" width="100%"> | <img src="examples/silhouette_family.jpg" width="100%"> |+| **马戏团来了** · *The Circus Is Coming*<br><sub>Letterpress poster · 凸版印刷海报</sub> | **无线电** · *Radio*<br><sub>Soviet constructivism · 苏联构成主义</sub> |+| <img src="examples/letterpress_circus.jpg" width="100%"> | <img src="examples/constructivism_radio.jpg" width="100%"> |+| **夜行快车** · *Night Express*<br><sub>Art Deco · 装饰艺术</sub> | **火箭小队** · *Rocket Squad*<br><sub>Golden-age comic · 黄金时代漫画</sub> |+| <img src="examples/artdeco_express.jpg" width="100%"> | <img src="examples/comic_rocket.jpg" width="100%"> |+| **猫的六种心情** · *Six Moods of a Cat*<br><sub>Pop silkscreen · 波普丝网</sub> | **发射记录** · *Liftoff Trace*<br><sub>ASCII art (line printer) · ASCII 字符画(行式打印机)</sub> |+| <img src="examples/popart_cat_moods.jpg" width="100%"> | <img src="examples/lineprinter_launch.jpg" width="100%"> |+| **峡谷飞行** · *Canyon Run*<br><sub>Low poly · 低多边形</sub> | **放风筝** · *Hold On*<br><sub>Stencil graffiti · 喷漆模板涂鸦</sub> |+| <img src="examples/lowpoly_canyon.jpg" width="100%"> | <img src="examples/stencil_kite.jpg" width="100%"> |+| **三晚露营** · *Three Nights Out*<br><sub>Embroidered patches · 刺绣徽章</sub> | **灯塔剖面** · *Halvard Rock Light*<br><sub>Blueprint · 蓝图工程图</sub> |+| <img src="examples/patch_camping.jpg" width="100%"> | <img src="examples/blueprint_lighthouse.jpg" width="100%"> |+| **我的周末** · *My Weekend*<br><sub>Children's crayon · 儿童蜡笔画</sub> | **今天带伞吗** · *Bring an Umbrella?*<br><sub>Green-screen CRT terminal · 绿屏终端(荧光字符画)</sub> |+| <img src="examples/crayon_picnic.jpg" width="100%"> | <img src="examples/crt_weather.jpg" width="100%"> |+| **厨房里的温度** · *Kitchen Heat Map*<br><sub>Thermal camera · 热成像</sub> | **一阵风** · *The Gust*<br><sub>Delft tiles · 代尔夫特蓝瓷砖</sub> |+| <img src="examples/thermal_kitchen.jpg" width="100%"> | <img src="examples/delft_canal.jpg" width="100%"> |+| **篝火旁的岩洞** · *The Hunt by the Fire*<br><sub>Cave painting · 洞穴壁画</sub> | **窗台花园** · *Windowsill Garden*<br><sub>1-bit paint program · 1-bit 早期画图软件</sub> |+| <img src="examples/cave_hunt.jpg" width="100%"> | <img src="examples/macpaint_garden.jpg" width="100%"> |+| **赛跑与赛车** · *Games on a Vase*<br><sub>Greek black-figure vase · 古希腊黑绘陶瓶</sub> | **老街角的自行车** · *The Bread Run*<br><sub>Graphite pencil · 铅笔素描</sub> |+| <img src="examples/blackfigure_games.jpg" width="100%"> | <img src="examples/graphite_bicycle.jpg" width="100%"> |+| **行李安检** · *Security Check*<br><sub>X-ray · X 光片</sub> | **早晨的闹钟** · *Seven O'Clock*<br><sub>1930s rubber hose · 1930 年代黑白橡皮管动画</sub> |+| <img src="examples/xray_luggage.jpg" width="100%"> | <img src="examples/rubberhose_morning.jpg" width="100%"> |+| **雪夜归途** · *Homeward, First Snow*<br><sub>Linocut · 黑白麻胶版画</sub> | **吹蜡烛** · *Blow Out the Candles*<br><sub>VHS home video · VHS 家庭录像</sub> |+| <img src="examples/linocut_snowy_village.jpg" width="100%"> | <img src="examples/vhs_birthday.jpg" width="100%"> |+| **山间夜营** · *Night Camp*<br><sub>Flat vector · 扁平矢量</sub> | **小橡果的秋天** · *An Acorn's Autumn*<br><sub>Storybook animation · 绘本角色动画</sub> |+| <img src="examples/flatvector_night_camp.jpg" width="100%"> | <img src="examples/storybook_acorn.jpg" width="100%"> |+| **蛇梯棋大冒险** · *Snakes & Ladders, Round 7*<br><sub>Ballpoint doodle · 圆珠笔涂鸦</sub> | **海港步行图** · *Larkhaven on Foot*<br><sub>Overlay sheets · 描图纸叠层</sub> |+| <img src="examples/ballpoint_board_game.jpg" width="100%"> | <img src="examples/overlay_city_map.jpg" width="100%"> |+| **出发前,再查一遍行李** · *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.---@@ -125,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-one styles:+A [Claude Code](https://claude.com/claude-code) skill and a small painting library with sixty-two styles:| Style | Module | What makes it read as the real medium ||---|---|---|@@ -190,6 +193,7 @@ A [Claude Code](https://claude.com/claude-code) skill and a small painting libra| **Ballpoint doodle** | `lib/ballpoint.py` · `Ballpoint` | ballpoint ink is an oil paste a rolling ball lays down, kept as optical density, so a line drawn twice, a crossing or a blob goes darker and more saturated (blue deepens to blue-violet, never flat black); every stroke starts dry and thin, drifts in pressure and width, skips a few pixels now and then, drops gloops where the pen stops and at sharp turns, and flicks off in a little hook; outlines are gone over twice, slightly off; every stroke presses a groove into the copy paper that catches the raking light, and the sheet carries the blind indentations of a shopping list written on the page above; coloured pencil is wax on the paper tooth, hatched in quick slanted patches that run past the lines, light on big areas and pressed hard on small ones; the handwriting is the skeleton of a thin hand font re-drawn as pen strokes, each letter resized, tilted and lifted off a wandering baseline, with a word scribbled out and written again || **Overlay sheets (tracing paper on a light box)** | `lib/overlay.py` · `Overlay` | the picture is a product of transmittances: a warm light box glows through a base sheet printed in black line and grey tints, then through translucent sheets that each carry ONE ink, laid down on registration crosses; an ink's coverage is a screen tint (or a double hit above 100 %), and inks on different sheets multiply, so blue over yellow turns green, magenta over yellow red and magenta over blue violet; every sheet has its own paper tint, the cloudy fibre formation you only see against the light, stray fibres, a cut edge that reads as a thin dark line, punched holes that drop onto a steel peg bar; a lifted sheet is a little larger, throws a wide soft shadow you can see through it and blurs everything under it like the diffuser it is, then lands crisp with a thin contact shadow; curled corners, crepe drafting tape with torn ends, a clear film with a gloss sheen; the town under it is cut by recursive street splits into blocks with a ring of buildings and party walls, water-lined round the coast || **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 |Ask Claude to *"draw it yourself"*, *"paint this with code"*, or *"claude绘图"*, and name a style if you like. Claude then:@@ -304,6 +308,7 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages- **Ballpoint doodle**: draw what sits in front first (the pieces), then let every later line stop at it with `clip` — the snakes, the ladders, the grid and the pencil all go round the pieces, the way a pen lifts at something already drawn. Keep big pencil areas light (pressure ~0.4) and small ones saturated (0.7–0.9), and let the hatching run a few px past the lines. Use red only for "this move" (hops, ring, arrow, the conclusion) and blue/black for everything else. Put every label inside an empty square or the margin — text split by a grid line or crowded by a sweat drop reads as a mistake. Keep the fold and the blind indentations faint; they should be found, not seen.- **Overlay sheets**: think in light, not paint — every sheet only takes light away, so tints are coverage and overlaps come out of the multiply on their own. Draw every separation in the same laid-down canvas coordinates and print the same registration crosses on each, so they register by construction. Keep tracing paper clear (transmittance ~0.98, formation ~2 %), or three sheets turn the town grey. Reversed-out numbers show whatever is underneath, so keep stop markers off dark landmarks, and give a tram and a walking route their own side of the same road. Put tape and curled corners where there is nothing printed. Lift a sheet only a little (σ ~3 px of blur, a 20–35 px offset): it should read as hovering, not as a second picture.- **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.### Roadmap@@ -315,7 +320,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,加上一个小巧的绘图库,内置六十二种画风:| 画风 | 模块 | 为什么看起来像真的 ||---|---|---|@@ -380,6 +385,7 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages| **圆珠笔涂鸦** | `lib/ballpoint.py` · `Ballpoint` | 圆珠笔墨是滚珠压上去的油性墨膏,按光密度叠加:描两遍、交叉、墨团都会更深更饱和(蓝色叠成深蓝紫,不会是死黑);每一笔起笔干而细,压力和线宽一路漂移,偶尔断墨几像素,停笔和急转弯处掉墨团,抬笔甩出小钩;轮廓描两遍、略微错开;每一笔都在复印纸上压出凹槽,侧光下看得见,纸上还留着上一页购物单的无墨压痕;彩铅是挂在纸纹上的蜡,一块块斜向快速排线、出界,大面积轻、小面积重;手写字是细手写字体的骨架重新用笔描出来,每个字母各自缩放、倾斜、上下浮动,还有一个词划掉重写 || **描图纸叠层** | `lib/overlay.py` · `Overlay` | 画面就是一路透过率相乘:暖白灯箱从下面照上来,先透过一张黑线灰调的底图,再透过一张张只印一种油墨的半透明叠片,叠片对着套准十字放下;油墨按网点覆盖率算(超过 100% 是叠印加深),不同叠片的油墨正片叠底,蓝叠黄成绿、品红叠黄成红、品红叠蓝成紫;每张纸有自己的纸色、只有背光才看得见的云状纤维和零星纤维丝、一道细暗的裁切边、落在钢定位钉上的打孔;抬起的纸略放大、投一片透过纸也看得见的宽软阴影,并像漫射片一样把下面的东西都模糊掉,放下后才清晰,只剩一道贴边细影;卷角、撕口的皱纹绘图胶带、带光泽的透明胶片;底图里的小城用递归切分的街道切出街区,沿街一圈房屋和分户墙,海岸外一圈圈水线 || **粉彩界面** | `lib/pastelui.py` · `PastelUI` | 产品发布片里的一帧界面:整片纯色粉彩底(蓝 / 粉 / 黄 / 淡紫 / 薄荷 / 桃)加一大片柔光和几颗白色光斑;macOS 窗口卡片(磨砂外框、白色窗体、红黄绿三点、分栏)、侧面板、带圆点的小胶囊和步骤条、粗黑大标题压一条半透明色条、状态标签、圆形 ✓ / ✗ 徽章、文字高亮、嵌在正文里的引用标签和带尖角的小标签;所有形状都是有符号距离场、1 px 解析抗锯齿,阴影按 CSS box-shadow 算(偏移、模糊、扩展;一层染着底色的宽阴影加一层中性的近阴影),卡片浮起来却没有灰边;一切画进带姿态(位移、缩放、不透明度、从左往右揭开)和前后层次的图层,同一套画面既能弹出窗口、逐行写字、弹出徽章,也能让小图标从卡片后面探头;放大镜放大的是它下面真实的像素;节与节之间圆形擦除换底色;三个扁平小图标从卡片边探头——奶油色圆里的橙色星芒、紫色云朵里的 >_、橙色像素小怪 |+| **阅卷批改** | `lib/grading.py` · `Grading` | 绿毛毡桌上的一张答题卡,照真表格印:左边一排定位黑块、粗黑标题、姓名班级栏、考号格和涂好的圆泡、得分 / 阅卷人表格、分节、作答横线、斜纹阅卷栏;旁边是长尾夹夹住的标准答案卡。每张纸有自己的坐标和位姿,能从空中落到桌上(抬着时略大、投一片宽软的影,放下后只剩贴边细影);印刷之后写上去的东西都带「写到第几成」的进度和时间图,阶段快照能画出写到一半的笔画:考生的蓝黑作答、朱红橡皮章(毛边、成簇针孔、一头压得轻而细框断开飞白、边缘积墨、刚盖下的湿晕、轻微歪斜、纸面压出的凹痕),以及红笔的波浪线、越过起点的手画圈、弧形引线、用粗黑体按红墨处理的批注(不用手写字体)、叉、勾、一笔笔写出再圈起来的分数;墨按比尔定律算密度,笔走慢的拐弯处、压在印刷上都会更深;红笔按圆柱打光、投影从笔尖散开,上漆木章落下、压一下、再抬起 |对 Claude 说「claude绘图」「你自己画」「用代码画」,也可以指定画风。它会:1. **先定构图**:层次、焦点、留白,而且画面要图解内容本身;@@ -470,6 +476,7 @@ python3 examples/storybook_acorn.py out.jpg --gif out.gif # 绘本角python3 examples/ballpoint_board_game.py out.png # 圆珠笔涂鸦:蛇梯棋大冒险python3 examples/overlay_city_map.py out.jpg --stages stages/ # 描图纸叠层:海港步行图python3 examples/pastelui_packing.py out.jpg --stages stages/ # 粉彩界面:出发前,再查一遍行李+python3 examples/grading_math_quiz.py out.jpg --stages stages/ # 阅卷批改:数学单元测验```### 作画要点(Claude 交图前逐条自查)@@ -533,6 +540,7 @@ python3 examples/pastelui_packing.py out.jpg --stages stages/ # 粉彩界- **圆珠笔涂鸦**:先画在前面的东西(棋子),后画的线都用 `clip` 在它前面停住——蛇、梯子、格线、彩铅都绕开棋子,就像笔走到已经画好的东西前会抬起来。大面积彩铅轻压(约 0.4),小面积压重(0.7–0.9),排线出界几像素。红笔只留给「这一步」(跳格、圈、箭头、结论),其余用蓝、黑。每个标注都放进空格子或页边:被格线劈开、被汗滴挤住的字看起来像画错了。折痕和无墨压痕要淡,是「找得到」而不是「一眼看见」。- **描图纸叠层**:按「光」想,不按「颜料」想——每张纸只会挡光,所以浅色是网点覆盖率,叠色交给正片叠底自己算。所有分色片都用纸放下时的同一套画布坐标画,每张都印同一组套准十字,天然对得上。描图纸要透(透过率约 0.98、云纹约 2%),否则三张叠下来整座城发灰。反白数字露出的是下面那一层,所以站点别压在深色地标上;电车和步行路线在同一条路上要各走一边。胶带和卷角放在没印东西的地方。纸只抬一点(模糊 σ 约 3 px、偏 20–35 px),看上去是「悬着」,不是又一张画。- **粉彩界面**:一屏只讲一件事——一个大标题、一个主窗口、一个侧面板、一个状态,字少而大。底色平、卡片实心白,颜色只放在强调处(步骤条、标签、徽章、色条);绿色只留给「通过」,所以有 ✓ / ✗ 的画面用蓝底。小图标放在它探头的那张卡片下一层,让卡片自己挡住其余部分。放大镜要有地方放:对准一样东西,标签放在镜框外(镜片压在窄窄一列上会把日期和温度切成两半)。同一样东西的不同状态各画一层再切换;做动图时,会动的东西给几个中间姿态,不要叠化。+- **阅卷批改**:一张卷子讲一件批改的事——几道作答、一处错,所有红笔都指向它:下面波浪线、外面一个圈、一道引线拉到阅卷栏,批注和叉跟出错那行同高(把批注行排在阅卷栏第一行,引线才短)。字少而大,纹理交给表格本身(涂卡圆泡、定位黑块、斜纹)。圈要有地方:两边各要约 8 px 空白,所以让考生在写错的那个数前多空一格。印章要不匀但认得出(轻的那头压力约 0.64)。红墨按比尔定律算密度,0.8 以上只是略微变深,浓淡要靠密度范围(约 0.4–1.2)拉开,而不是换颜色。做动图时,笔和章给真正的中间帧(`~` 运动阶段),不要叠化。### 计划diff --git a/SKILL.md b/SKILL.mdindex 0b258fe..a91c8c6 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 窗口卡片、胶囊与粗黑标题色条、状态标签与 ✓ / ✗ 徽章、放大镜、从卡片边探头的扁平小图标)。用户说「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 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(绿毛毡桌上被红笔批改的答题卡:定位黑块、考号涂卡、得分格与阅卷栏、长尾夹夹住的标准答案卡、油墨不均的朱红印章、立体红笔、波浪线 / 圈 / 引线 / 批注 / 叉 / 圈起来的分数)。用户说「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 风 / 粉彩界面 / 窗口卡片 / 发布会界面」指粉彩界面(纯色底 + 白色实心窗口卡片),要磨砂玻璃和弥散渐变仍用弥散玻璃;「阅卷 / 批改 / 答题卡 / 判卷 / 红笔打分」指阅卷批改,实验记录里的红笔圈和便利贴仍用实验笔记本,带「已付」橡皮章的小票拼贴仍用贴纸拼贴 · 小票。---# Claude 绘图@@ -75,6 +75,7 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型| 圆珠笔涂鸦 | `lib/ballpoint.py` · `Ballpoint` | `examples/ballpoint_board_game.py` 蛇梯棋大冒险 · Snakes & Ladders, Round 7(午休时在复印纸上用蓝、红、黑三支圆珠笔画的 8×8 蛇梯棋,彩铅一行行涂成彩虹色格子;一局正在进行:骰子刚从页边弹过来、掷出 4,蜗牛从 10 跳四格到 14(红笔虚线弧标出 1-2-3-4),正顺着长梯子爬到 38(红圈、虚线箭头、+24!),小云从 47 被绿蛇滑下去,晕乎乎地喊 nooo~,骰子怪在 51 捂着脸;页边是彩旗、太阳、井字棋、纸飞机、星星串、山坡小房子、花盆,吐槽小纸条「who drew this snake so LONG?!」、记分卡、把 three 划掉改成 four、红笔结论 slow snail, fast ladder!;右下角还有上一页购物单压过来的无墨压痕) | 约 4 秒 || 描图纸叠层 | `lib/overlay.py` · `Overlay` | `examples/overlay_city_map.py` 海港步行图 · Larkhaven on Foot(暖白灯箱上,定位钉挂着一张黑线灰调的海边小城底图:递归切出的街区、沿街一圈房屋和分户墙、深色地标、海岸与防波堤、铁路、城堡山和岬角的等高线;三张单色叠片对着套准十字落下——蓝片(沿岸一圈圈水线、河、港湾、渡轮航线、2 路电车)、黄片(公园、集市广场、海滩)、品红片(六站步行路线,坐渡轮去灯塔);不同叠片的油墨正片叠底:植物园的池塘叠成绿、路线压过公园成红、压过海面成紫;描图纸背光下的纤维云纹、卷角、打孔、绘图胶带,旁边一张透明胶片上的图例卡) | 约 7 秒 || 粉彩界面 · 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 秒(含阶段) |各画风共用 `lib/core.py` 里的底层工具:噪声、模糊、样条曲线、多边形遮罩、有机轮廓 `blob_pts`、毛笔 `bristle_stroke`、中文字体查找;新四种还用到补零平移 `shift`、文字遮罩 `text_mask`、西文字体查找 `latin_font`/`load_font`,以及高度图打光 `height_normals`、`height_shadow`(沿光线步进的投影)、`ambient_occlusion`。@@ -139,7 +140,8 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型- 要「真的动起来」的小故事、一个可爱小角色的旅程或成长(从 A 到 B、出发—遇到—到达)、讲解片的片头片尾和转场、品牌吉祥物小动画、「一路走一路画出来」的过程感 → 绘本角色动画(`Storybook.gif()` 出真动画,`journey()` 出一张旅程总图;只要一条轮廓的变形用形变动画;要逐帧抖线的静态卡通插画用卡通手绘);- 上课 / 午休走神的随手涂鸦、纸上正在进行的游戏或计划(手画棋盘、寻宝图、清单、路线、比分)、学生和办公室日常的轻松小故事、讲解片里「在草稿纸上推演一步」的页 → 圆珠笔涂鸦(要铅笔图表、荧光笔和贴纸的实验记录用实验笔记本;要没有线稿、柔和的彩铅小物用韩国彩铅;要小孩的蜡笔画用儿童蜡笔画;要黑白石墨写生用铅笔素描);- 地图、路线与导览、城市 / 园区 / 校园平面图,「一层一层把信息加上去」的图解(底图 → 水系 → 绿地 → 路线),设计稿或方案的分层、叠加与对照,讲解片里「把几层信息叠起来看」的页 → 描图纸叠层(要正等轴的微缩模型用等轴 2.5D;要剖面、尺寸和施工说明用蓝图工程图;要三原色丝网海报用包豪斯几何);-- 产品发布片 / 科技讲解片的「界面 / 流程 / 检查结果」页,要明亮干净、像真产品截图的窗口卡片,一屏讲一件事(大标题 + 一个主窗口 + 一个侧面板 + 状态),一整部讲解片统一的主画面(每节换一种粉彩底、圆形擦除转场)→ 粉彩界面(要磨砂玻璃和弥散渐变用弥散玻璃;要等轴微缩模型用等轴 2.5D;要黑白早期界面用 1-bit 早期画图软件)。+- 产品发布片 / 科技讲解片的「界面 / 流程 / 检查结果」页,要明亮干净、像真产品截图的窗口卡片,一屏讲一件事(大标题 + 一个主窗口 + 一个侧面板 + 状态),一整部讲解片统一的主画面(每节换一种粉彩底、圆形擦除转场)→ 粉彩界面(要磨砂玻璃和弥散渐变用弥散玻璃;要等轴微缩模型用等轴 2.5D;要黑白早期界面用 1-bit 早期画图软件);+- 考试、作业、批改与打分,「对照标准答案逐条检查」的过程(评测、验收、审核、评分规则、哪里错了、为什么扣分),讲解片里的「怎么判对错 / 评分标准 / 检查结果」页 → 阅卷批改(要草稿纸上的随手推演用圆珠笔涂鸦;要实验记录、红笔圈和便利贴用实验笔记本;要明亮的产品界面里打 ✓ / ✗ 用粉彩界面)。每种画风一幅范例作为质量基准(范例都不用禅意主题);水墨另加一幅「月印万川」(留白托月、水面倒影)。@@ -977,6 +979,21 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask- 小图标(扁平矢量、无脸):`spark(cx, cy, size, spin)` 奶油色圆里的橙色星芒(白圈、暖色投影);`cloud(cx, cy, size, rot)` 紫色渐变云朵里的白色 >_(十一个圆平滑并集、径向渐变、光泽、投影);`critter(x, y, px=9, blink)` 橙色像素小怪(10 × 6 格,整数像素对齐)- 色板常量 `INK BLUE LILAC GREEN PINK YELLOW MINT PEACH CLAY LINE GREY FIELDS BOKEH`;`render()`、`composite()`、`save(path, stages_dir)`;`save('x.jpg')` 默认 quality 88、4:4:4 色度+**阅卷批改 `Grading`**:+- 思路:深绿毛毡桌上的一张答题卡被批改。每张纸是带位姿的对象:`Paper` 在自己的坐标系里存纸色(斑驳云纹、纤维、轻微起伏、零星纤维丝)、alpha(打孔处镂空)和所有印刷;坐标一律按**纸没转动时的画布坐标**给,纸自己的 `rot` 和 `place()` 的位姿在合成时才套上。抬起的纸略放大、投一片宽软偏移的影,放下后收成贴边细影。印刷是立即的(油墨乘进纸色;反白字用 `mode='knock'` 露出纸本身)。印刷之后写上去的一切都是保留对象 `Mark`,带 `progress`(0–1,写到第几成,可以来回设):每个 Mark 存一块密度图(比尔定律:纸色 × exp(−密度 × 油墨吸光度),叠在印刷和别的墨上自然加深)和一张时间图(每个像素第几成时被写到),所以阶段快照能画出写到一半的笔画。最后整幅乘一盏左上暖灯的衰减、暗角和细颗粒,桌面、纸和笔受同样的光照不均+- 构造:`Grading(W, H, seed, keep_stages=True, stages_dir=None)`(给了 `stages_dir`,`stage()` 当场写 PNG,不留在内存里);`desk(colour=FELT, nap)` 毛毡:大小两级斑驳、细绒、零星绒毛+- 纸:`sheet(x, y, w, h, tint, rot, stack=2)` 答题卡(下面再压 stack 张,错开几像素、略暗);`card(x, y, w, h, tint, rot)` 卡片 / 小纸条(四周留 110 px,给竖起来的夹子把手);`place(paper, lift, dx, dy, rot)` 放下(全 0)或抬起(第一次 place 决定叠放顺序)、`remove(paper)`;`paper.to_canvas(x, y)` 纸上坐标 → 当前位姿下的画布坐标;`paper.width(s, size, kind)` 量字宽+- 印刷:`text(s, x, y, size, kind='body', colour, anchor='ls', spacing, alpha, rot, mode='ink'|'knock'|'over')`(返回结尾 x)、`rect(x0, y0, x1, y1, fill, line, width, radius)`、`line(pts, width, colour, alpha, dash=(实, 虚))`、`ellipse`、`hatch` 斜纹、`grid` 浅方格、`rules(x0, x1, ys)` 作答横线、`band` 色带、`checkbox`、`circled(n, cx, cy)` 圆圈数字+- 答题卡部件:`timing_track(x, y0, y1, step=30)` 一排定位黑块、`corner_mark`、`holes(x, y0, y1, step, r)` 装订齿孔(真的镂空,露出桌面和纸影)、`title(s, x, y, size, sub)` 粗黑标题 + 字距拉开的西文副标题、`field(label, value, x, y, x1)` 灰色栏名 + 粗体内容 + 下划线、`ticket(x, y, digits)` 考号格 + 每位一列 0–9 涂卡圆泡(对应的那个涂黑)、`score_box(x, y, w, h, split, head, titles, note, lines)` 得分 / 阅卷人表格(返回得分格中心)、`fill_example(x, y)` 填涂示例、`section(x, y, num, title, sub, meta, x1)` 「一 题目」分节头(深色方块里反白序号)、`question(x0, y0, x1, y1, s)` 灰底题目框加左边竖条、`answer_frame(x0, y0, x1, y1, col, rows=[(栏名, y, 分隔线 y 或 None)], lines)` 作答框:左边浅方格加横线,x ≥ col 是斜纹阅卷栏(表头「阅卷栏 · 考生勿填」、虚线分行);`clip(x, y, w, handle)` 黑色长尾夹:夹在纸边上的亮黑钢夹,两根竖起的银色钢丝把手各横跨整个夹子(后面那根略低、在阴影里),在纸上和桌上都有投影+- 写上去的东西(返回 Mark 或 Group,都有 `progress` 和 `tip(p)`):+ - 红笔:`stroke(pts, width, colour, pressure, blob, feather, smooth, density)` 任意笔画(中性笔:落笔一颗墨珠,压力沿线漂移,拐弯处笔走慢、积墨更深,边缘略深,往纤维里洇一点,纸纹凸起处略淡);`wave(x0, x1, y, amp, period)` 周期和幅度都在漂的波浪线;`ring(cx, cy, rx, ry, tilt, a0, a1, grow)` 手画椭圆圈(越过起点再画一截、越画越大一点);`leader(p0, p1, bend)` 弧形引线;`underline`;`cross(cx, cy, s)` 两笔叉;`check(cx, cy, s)` 勾;`digits(s, x, y, h)` 按笔画骨架写数字(0–9,倾斜、略不规则);`score(s, cx, cy, h, ring=True)` 分数:先写数字再圈起来+ - `note(s, x, y, size, kind='bold', jitter)` 批注:粗黑体(不用手写体),每个字略歪、略错位,按红墨处理(字内浓淡、边缘积墨、淡淡洇开),逐字揭开+ - `answer(s, x, y, size)` 考生的蓝黑墨水作答,逐字出现+ - `stamp(cx, cy, label, w=None, h=64, rot, size, check=True, press=(0.64, 1.0))` 朱红橡皮章印:双线圆角框、粗黑字、✓;位移出的毛边、成簇的针孔空白、一头压得轻(细框在那头断开飞白)、边缘积墨、刚盖下的湿晕(`mark.wet` 0–1)、轻微歪斜、章周围纸面压出的一圈凹痕;盖下之前 progress = 0+- 道具:`pen(x, y, lift, angle=28)` 红笔,笔尖落在画布 (x, y),按圆柱打光:金属锥头和笔珠、带横纹的橡胶握把、镀铬环、上漆笔杆和一道窗光高光、笔夹和铆钉;投影从笔尖起沿笔身越拉越开、越来越软(笔尾被手抬着);`pen(None)` 收走。`write(mark, progress, lift)` 设进度并把笔尖放到书写前沿(动图逐帧用)。`stamper(mark, height)` 印章悬在印痕上方 height(0–1):上漆榉木章身(顺长木纹、倒角)、车出来的木把手(旋纹、高光),投影随高度变宽变软;height 0 就是压下去,印痕出现、带湿晕;`stamper(None)` 拿走+- 字体 `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 色度+**顺序**:都是先远后近、先大后小,文字最后叠加。水墨的雾要画在它该吞没的东西之后;水彩的叶梗要先画,并且只画在叶子外面。## 三、毛病清单(都真实出现过)@@ -1929,6 +1946,22 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask| 动图里橙色像素小怪和星芒变成粉色、绿色徽章变成青色、奶油色圆盘抖成粉点 | 这些颜色面积小、最后几秒才出现,中值切分分不到色位:把整套界面色(47 个精确色值)强制放进调色板,最后一帧取样 ×8 || 84 张阶段快照留在内存里,峰值 1.27 GB | `stage()` 存成 PNG 压缩字节(compress_level=1),峰值约 0.54 GB |+**阅卷批改**++| 问题 | 改法 |+|---|---|+| 红圈从「=」上压过去 | 「6(天)」前只有一个空格(约 11 px),放不下 3 px 宽的圈和两边的空白:让考生在「=」后空两格(约 23 px),圈的左边离「6」12 px、离「=」11 px,右边留 18 px |+| 引线斜着穿过整个作答区,又长又乱 | 阅卷栏里把「批注」排在第一行,和出错那一行同高,引线变成一道平缓的弧 |+| 印章压住阅卷栏的栏名 | 每行留出约 104 px,章高 60、字号 28,章心放在栏名基线下约 42 px |+| 印章一头太淡,「书写」两个字读不出来 | 轻的那头压力 0.52 → 0.58 → 0.64:还是一头发干、细框断开,但字认得出 |+| 红墨像电脑字,看不出浓淡 | 红色在绿、蓝通道吸收很强,密度 0.8 以上只是略微变深:让密度在 0.74 上下浮动(压力 ±0.20、两级斑驳、拐弯积墨最多 +0.26,实测约 0.4–1.2),边缘加深 0.18,洇开的软边模糊 1.7 px;批注字的斑驳按字号的 0.7 倍取尺度,一个字里就有浓有淡 |+| 波浪线像一条正弦曲线 | 周期和幅度都用 1D 噪声漂移,整条往下坡斜一点 |+| 长尾夹的把手像两根发卡 | 真夹子每根钢丝把手都横跨整个夹子:两腿插在夹子两端、顶上一根横梁;画两根,后面那根略矮、在阴影里 |+| 印章木块像一块饼干,把手像巧克力球 | 木纹方向反了(沿长边是高频):改成跨章身方向高频、沿长边低频再加一点扭曲;把手用同色系的木头,加车旋纹和根部一圈暗环 |+| 章压下去时纸上一圈青边 | 阴影色原来按毛毡调成偏绿,乘在米色纸上发青:改成近中性的 (0.15, 0.14, 0.12),毛毡上的影照样是绿的 |+| 分数外的圈压到「7」的头 | 圈的纵半径 0.66h → 0.70h,横向多留 0.30h,从左上方 −118° 起笔 |+| 113 张 1920×1080 阶段快照 | 给 `stages_dir`,`stage()` 当场写 PNG(compress_level=1),峰值内存约 0.78 GB |+## 四、做成动画- 各画风都有 `stage(name)` 和 `save(path, stages_dir)`,按阶段依次淡入叠化,就是「一幅画被逐步画出来」。README 里的动图就是这样做的。@@ -1950,6 +1983,7 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask- 大块色层整片交接的叠化(扁平矢量的夜蓝 → 橙 → 沙):调色板样本里加上 1/3、2/3 两张叠化帧,Bayer 只叠在两张关键帧不同的地方(整帧都叠更大;Floyd–Steinberg 更大,还会抖出透明占位色)。只有黑白两值的画风(1-bit 早期画图软件)缩小用 BOX、配固定灰阶调色板,不做中值切分。- 描图纸叠层的动图(脚本在 `claude_drawing/overlay_work/make_gif_overlay.py`):阶段是 关灯 → 灯变暖 → 开灯 → 底图 → 每张叠片「抬起、偏着」→「放下」→ 胶片图例卡 → 贴胶带。一张纸落下,会让一大片带纹理的区域整体变几级、线条由糊变清,逐帧精确差分要 3–5 MB。做法:目标和屏上已显示颜色的差值拆成平滑分量(模糊 2 px)和细节残差,平滑分量超过阈值(叠化帧 12 级、关键帧 3 级)或单点超过阈值(30 / 16 级)才重发,只有单点超阈值的孤立像素(纸纹在阈值上下翻动)不发;开灯那几帧逐像素精确发送,其中的叠化帧不加抖动(加了每帧每个像素都变);最后一帧收紧阈值追平。73 帧约 1.9 MB,按解码结果逐帧自检。- 粉彩界面的动图(脚本在 `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,按解码结果逐帧自检,末帧误差和单纯调色板量化相同。- 绘本角色动画的动图是真动画,不是阶段叠化:`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 遮罩按顺序显现。这个还没做成现成接口。@@ -2019,6 +2053,7 @@ lib/storybook.py 绘本角色动画(按时间取帧:带揭示图的场lib/ballpoint.py 圆珠笔涂鸦(复印纸纹、纤维与折痕;圆珠笔:干起笔、压力线宽、断墨、墨团、收笔小钩、描两遍、压痕;彩铅斜向排线出界;圆珠笔之字排线;字体骨架重描的手写、划掉重写、无墨压痕字)lib/overlay.py 描图纸叠层(灯箱发光、黑线灰调底图与单色叠片、透过率相乘的油墨、背光纤维云纹、抬起时的漫射模糊与投影、卷角、打孔与定位钉、套准十字、绘图胶带、透明胶片)lib/pastelui.py 粉彩界面(纯色粉彩底与光斑、距离场抗锯齿的窗口卡片与部件、CSS 式多层阴影、带姿态的图层、真像素放大镜、圆形擦除、三个扁平小图标)+lib/grading.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_grading_math_quiz.gif b/examples/drawing_grading_math_quiz.gifnew file mode 100644index 0000000..92b647bBinary files /dev/null and b/examples/drawing_grading_math_quiz.gif differdiff --git a/examples/grading_math_quiz.jpg b/examples/grading_math_quiz.jpgnew file mode 100644index 0000000..b6a359cBinary files /dev/null and b/examples/grading_math_quiz.jpg differdiff --git a/examples/grading_math_quiz.py b/examples/grading_math_quiz.pynew file mode 100644index 0000000..8a32601--- /dev/null+++ b/examples/grading_math_quiz.py@@ -0,0 +1,192 @@+"""Example (exam grading): 数学单元测验 · Unit Test, Graded — a primary-school maths quiz being marked on a green+felt desk. The answer sheet (two more sheets under it) is a printed form: timing marks, a heavy title, name and class+fields, a ticket number with its bubbles filled, a score / grader table, section one (three sums in a row) and+section two (a word problem in a tinted box, an answer box with ruled lines and a hatched grading column). On the+left, the answer key is clipped to a card with a black binder clip, and a slip gives the marking scheme.++The candidate writes the answers line by line in blue-black. Two rubber stamps land in the grading column (书写工整+✓, 列式正确 ✓): the set-up of the word problem is right. Then the red pen ticks the three sums, finds the slip in+128 ÷ 16 = 6: a wavy underline, a ring round 6(天), a leader out to the grading column, the note 应为 8 天 and a+cross; it underlines the 6 in the answer sentence too, ticks ① and crosses ② on the key, and writes 75 in the score+box, circled.+No image model.+python3 grading_math_quiz.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 grading import Grading, INK, GRAY, NAVY, PAPERS++out = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith('--') else 'grading_math_quiz.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('GRADING_TIMING') else None++W, H = 1920, 1080+g = Grading(W, H, seed=7, keep_stages=bool(stages), stages_dir=stages)+g.desk()+tick('desk')++# ===================================================================== the answer sheet (printed)+CX0, CX1, COL = 664, 1790, 1504+s = g.sheet(596, 28, 1250, 1110, stack=2)+s.corner_mark(612, 46); s.corner_mark(1806, 46)+s.timing_track(612, 104, 1130)+s.title('数学单元测验', CX0, 112, 50, sub='UNIT TEST · GRADE 3 · FORM A')+s.field('姓名', '林小禾', CX0, 214, 900)+s.field('班级', '三(2)班', 930, 214, 1118)+s.text('单元', CX0, 268, 19, 'body', GRAY)+s.text('第四单元 · 除法', CX0 + 54, 267, 22, 'body', INK)+s.line([(CX0 + 48, 278), (1118, 278)], 1.0, INK, 0.55)+s.ticket(1150, 98, '30215')+SCORE = s.score_box(1440, 64, note='满分 100', lines=('计算 ×3', '应用 ×1'))+s.fill_example(1440, 268)+s.line([(CX0, 298), (CX1, 298)], 2.2); s.line([(CX0, 303), (CX1, 303)], 0.8)++# section one: three sums in a row+s.section(CX0, 318, '一', '计算题', '每题 25 分')+SUMS = [('① 23 × 4 =', '92'), ('② 156 ÷ 3 =', '52'), ('③ 7 × 8 =', '56')]+SUM_X = [690, 1060, 1430]+SUM_Y = 410+sum_ans = []+for (q, a), x in zip(SUMS, SUM_X):+ end = s.text(q, x, SUM_Y, 32, 'body', INK)+ s.line([(end + 8, SUM_Y + 12), (end + 108, SUM_Y + 12)], 1.0, '#486880', 0.5)+ sum_ans.append((end + 22, a))++# section two: a word problem, an answer box with a grading column+s.section(CX0, 448, '二', '应用题', '25 分', meta='写出算式和答句', x1=CX1)+s.question(CX0, 494, CX1, 552, '一本书 128 页,每天读 16 页,几天能读完?', 30)+FY0, FY1 = 572, 924+LINES = [668, 762, 856]+s.answer_frame(CX0, FY0, CX1, FY1, col=COL, lines=[b + 12 for b in LINES],+ rows=[('批注', 630, 716), ('书写', 738, 820), ('列式', 842, None)])+s.text('第 1 页 · 共 2 页', (CX0 + CX1) / 2, 984, 15, 'body', GRAY, anchor='ms', spacing=2)+tick('sheet')++# ===================================================================== the answer key card and the slip+KX, KY, KW, KH = 70, 112, 506, 392+key = g.card(KX, KY, KW, KH, rot=-1.3)+key.band(KX, KY, KX + KW, KY + 96, NAVY)+key.text('标准答案', KX + 32, KY + 66, 46, 'heavy', mode='knock', spacing=4)+key.text('ANSWER KEY', KX + KW - 30, KY + 44, 13, 'latin', mode='knock', anchor='rs', spacing=3.5, alpha=0.75)+key.text('第二题', KX + KW - 30, KY + 74, 18, 'body', mode='knock', anchor='rs', spacing=1, alpha=0.85)+key.text('要 点', KX + 32, KY + 140, 19, 'bold', GRAY, spacing=4)+key.line([(KX + 32, KY + 156), (KX + KW - 32, KY + 156)], 1.0, INK, 0.25)+KEY_ROWS = [('列式 128 ÷ 16', KY + 206), ('得数 8 天', KY + 274)]+for i, (t, y) in enumerate(KEY_ROWS):+ key.circled(i + 1, KX + 52, y - 10)+ key.text(t, KX + 82, y, 30, 'bold', INK)+ key.checkbox(KX + KW - 74, y - 28, 30)+key.line([(KX + 32, KY + 322), (KX + KW - 32, KY + 322)], 1.2, GRAY, 0.5, dash=(5, 5))+key.text('验算', KX + 32, KY + 362, 20, 'body', GRAY)+key.text('16 × 8 = 128', KX + 86, KY + 362, 22, 'bold', INK)++SX, SY, SW, SH = 86, 590, 484, 182+slip = g.card(SX, SY, SW, SH, tint=PAPERS['slip'], rot=0.9)+slip.text('评分', SX + 26, SY + 46, 20, 'bold', INK, spacing=6)+slip.line([(SX + 26, SY + 64), (SX + SW - 26, SY + 64)], 1.0, INK, 0.25)+slip.text('每题 25 分', SX + 26, SY + 128, 44, 'heavy', INK, spacing=2)+slip.text('满分 100', SX + SW - 26, SY + 126, 20, 'body', GRAY, anchor='rs')+tick('cards')++# ===================================================================== what gets written+ans = [s.answer(a, x, SUM_Y, 32) for x, a in sum_ans]+EQ = '128 ÷ 16 = 6(天)' # a child's gap before the result+L1 = s.answer(EQ, 690, LINES[0], 34)+L2 = s.answer('答:6 天能读完。', 690, LINES[1], 34)+writing = ans + [L1, L2]++ST1 = s.stamp(1646, 780, '书写工整', h=60, size=28, rot=-2.5)+ST2 = s.stamp(1649, 884, '列式正确', h=60, size=28, rot=1.8)++x6a = 690 + s.width('128 ÷ 16 = ', 34); x6b = 690 + s.width(EQ, 34)+ticks = [s.check(x + s.width(a, 32) + 34, SUM_Y - 12, 30) for x, a in sum_ans]+wave = s.wave(x6a + 2, x6b - 8, LINES[0] + 13)+ring = s.ring((x6a + x6b) / 2 + 3, LINES[0] - 11, (x6b - x6a) / 2 + 15, 31)+NOTE = (1524, 686)+lead = s.leader(ring.tip(1.0), (NOTE[0] - 10, NOTE[1] - 14), bend=36)+note = s.note('应为 8 天', NOTE[0], NOTE[1], 32)+cross = s.cross(1750, 672, 20)+u6 = s.underline(690 + s.width('答:', 34) - 2, 690 + s.width('答:6', 34) + 4, LINES[1] + 10)+kc = key.check(KX + KW - 58, KY + 206 - 16, 30)+kx = key.cross(KX + KW - 59, KY + 274 - 13, 11, width=3.0)+score = s.score('75', SCORE[0] - 14, SCORE[1] + 10, 62)+red = ticks + [wave, ring, lead, note, cross, u6, kc, kx, score]+tick('marks')+REST = (1648, 238) # where the pen is put down at the end++if not stages:+ # ================================================================= just the finished picture+ g.place(s); g.place(key); g.place(slip)+ key.clip(KX + 250, KY + 2)+ for st in (ST1, ST2): st.progress = 1.0+ g.pen(*REST, lift=0.45)+ img = g.save(out)+ tick('saved')+ print('saved', out)+ sys.exit()++# ===================================================================== stage by stage (for the drawing GIF)+# names: 'x~...' are motion frames (shown briefly, no cross-fade), '@ms' sets how long a stage is held+for m in writing + red: m.progress = 0.0+for st in (ST1, ST2): st.progress = 0.0+g.stage('desk')+# the answer sheet comes down onto the felt+g.place(s, 1.0, -36, -64, -2.6); g.stage('sheet_up@260')+for k, (l, dx, dy, r) in enumerate([(0.55, -18, -30, -1.3), (0.2, -6, -10, -0.4)]):+ g.place(s, l, dx, dy, r); g.stage(f'sheet~{k}@80')+g.place(s); g.stage('sheet')+# the key card and the slip, then the clip+g.place(slip, 1.0, 30, 40, 3.0); g.place(key, 1.0, -40, -60, -3.5); g.stage('cards_up@260')+for k, l in enumerate((0.55, 0.2)):+ g.place(key, l, -40 * l, -60 * l, -3.5 * l); g.place(slip, l, 30 * l, 40 * l, 3.0 * l); g.stage(f'cards~{k}@80')+g.place(key); g.place(slip); g.stage('cards')+key.clip(KX + 250, KY + 2); g.stage('clip@600')+# the answers, line by line+for i, m in enumerate(writing):+ for k, p in enumerate((0.5,) if len(m.path[0]) < 6 else (0.34, 0.67)):+ m.progress = p; g.stage(f'ans{i}~{k}@110')+ m.progress = 1.0; g.stage(f'ans{i}@420')+# two stamps, one after the other: down, press, up+for i, st in enumerate((ST1, ST2)):+ for k, h in enumerate((0.9, 0.45)):+ g.stamper(st, h); g.stage(f'stamp{i}~down{k}@{110 if k == 0 else 70}')+ g.stamper(st, 0.0); g.stage(f'stamp{i}~press@360')+ g.stamper(st, 0.5); g.stage(f'stamp{i}~up@90')+ g.stamper(None); g.stage(f'stamp{i}@650')+for st in (ST1, ST2): st.wet = 0.0+++# the red pen: travels lifted between marks, writes each one+def canvas_of(m, p):+ paper = m.paper if hasattr(m, 'paper') else m.parts[0].paper+ return paper.to_canvas(*m.tip(p))+++def travel(m, name, n=1, ms=80, frm=None):+ x0, y0 = frm if frm else g._pen[:2]+ x1, y1 = canvas_of(m, 0.0)+ for k in range(1, n + 1):+ u = k / (n + 1)+ g.pen(x0 + (x1 - x0) * u, y0 + (y1 - y0) * u, lift=0.45 * np.sin(np.pi * u) + 0.08); g.stage(f'{name}~mv{k}@{ms}')+++def draw(m, n, name, ms=70):+ for k in range(1, n + 1):+ g.write(m, k / n); g.stage(f'{name}~{k}@{ms}')+++plan = [(ticks[0], 3, 'tick0'), (ticks[1], 3, 'tick1'), (ticks[2], 3, 'tick2'), (wave, 6, 'wave'), (ring, 9, 'ring'),+ (lead, 4, 'lead'), (note, 7, 'note'), (cross, 4, 'cross'), (u6, 2, 'under'), (kc, 3, 'keytick'), (kx, 3, 'keycross'),+ (score, 14, 'score')]+frm = (2060, 1180)+for i, (m, n, name) in enumerate(plan):+ travel(m, name, n=2 if i in (0, 9, 11) else 1, frm=frm); frm = None+ draw(m, n, name)+ if name in ('ring', 'note', 'cross', 'score'):+ g.stage(f'{name}_done@500')+g.pen(*REST, lift=0.45)+img = g.save(out, stages_dir=stages)+tick('saved')+print('saved', out)diff --git a/lib/grading.py b/lib/grading.pynew file mode 100644index 0000000..de4ac8b--- /dev/null+++ b/lib/grading.py@@ -0,0 +1,1252 @@+"""grading — 阅卷批改 / Exam Grading: an answer sheet on a green felt desk, marked in red (numpy + Pillow only).++A dark green felt desk under a warm lamp. On it, a beige answer sheet (a few more sheets stacked under it), an+answer-key card held by a black binder clip and a small slip. The sheet is printed: timing marks down the left edge,+corner marks, a heavy title, fields, a ticket number with bubble columns, a score / grader table, numbered sections,+ruled answer lines and a hatched grading column. Then the paper gets written on, and that is what animates:++ papers `Paper` keeps its own buffers (paper colour with mottle, fibres and a faint cockle; alpha with any+ punched holes) in its own frame. Draw on it in canvas coordinates *as if unrotated*; its resting+ rotation turns everything about its centre. `place(paper, lift, dx, dy, rot)` shows it: lifted it is a+ little larger and casts a wide, soft, offset shadow on the felt; laid down the shadow tightens to a+ contact line. Printing is immediate (multiplied into the paper); white type is `knock`ed out of a+ printed band, so it is the paper itself.+ marks everything written after printing is a retained `Mark` with `progress` 0..1 (how far it has been+ written), so stages can show it half done. Each mark has a density map (Beer-Lambert: the paper colour+ times exp(-density * absorbance of the ink), so ink over ink and ink over print deepen naturally) and a+ time map (when each pixel was reached). Kinds:+ - red pen strokes: wave underline, hand-drawn ellipse (overshoots its start and grows a little), a+ bowed leader, a cross, a check, a straight underline, any polyline; the score is digits drawn as+ pen strokes, circled. Gel ink: a bead of ink where the pen lands, pressure drifting along the line,+ slight feathering into the fibres, lighter where the tooth of the paper stands up.+ - `note`: an annotation in a bold sans (no handwriting fonts), each character nudged and turned a+ little, inked with the same red: denser rims, mottle, a faint bleed; revealed char by char.+ - `answer`: the candidate's writing in blue-black, revealed char by char.+ - `stamp`: a vermilion rubber-stamp impression -- double rounded border, heavy label, a check --+ ragged edges (displaced), clustered pin-hole voids, one end pressed lighter (dry-brush breaks in+ the thin border there), ink pooled along the rims, a wet bleed just after the press, a slight+ tilt, and the paper dented round the rubber.+ props `pen(x, y, lift)`: a red ballpoint seen from above, lying at an angle with its tip on (x, y): metal+ cone and ball, ribbed rubber grip, chrome rings, lacquered barrel with a window highlight, clip. It is+ shaded as a cylinder; its shadow starts at the tip and spreads and softens along the pen (the back end+ is held up). `stamper(impression, height)`: the wooden stamp block with its knob above the paper (or+ pressed on it at height 0, which inks the impression). `card.clip(x, y)`: a black binder clip with+ its wire handles up, on the card's top edge.+ light one warm lamp, upper left: everything (felt, papers, pen) gets the same gentle falloff, plus a+ vignette and a little grain.++ import sys; sys.path.insert(0, 'lib')+ from grading import Grading+ g = Grading(1920, 1080, seed=4)+ g.desk()+ s = g.sheet(600, 30, 1250, 1100, stack=2)+ s.title('数学单元测验', 664, 112, sub='UNIT TEST · FORM A')+ s.rules(664, 1480, [560, 630])+ a = s.answer('128 ÷ 16 = 6(天)', 690, 620)+ g.place(s, lift=1, dx=-30, dy=-40, rot=-2); g.stage('sheet_up')+ g.place(s); g.stage('sheet_down')+ st = s.stamp(1640, 610, '列式正确')+ g.stamper(st, 0.8); g.stage('hover'); g.stamper(st, 0); g.stage('press'); g.stamper(None)+ w = s.wave(690, 900, 632); r = s.ring(795, 610, 125, 34)+ for p in (0.3, 0.6, 1.0): g.write(w, p); g.stage(f'wave{p}')+ g.pen(1600, 230, lift=0.5)+ g.save('grading.jpg')+"""+import glob+import os+import numpy as np+from PIL import Image, ImageDraw, ImageFont+from core import blur, spline, noise2d, smoothstep, shift, load_font, fbm1d++INK = '#22262a' # printed black+GRAY = '#7a7366' # printed captions+RULE = '#486880' # blue-grey ruling and bubbles+ANSWER = '#1d2a4c' # the candidate's blue-black ink+PEN = '#c3121f' # red pen+STAMP = '#c7382c' # vermilion stamp pad+NAVY = '#24375a' # answer-key header band+FELT = '#3b5546' # green felt desk+PAPERS = {'sheet': '#f7f1e1', 'card': '#eff1eb', 'slip': '#f5eedc', 'white': '#fbfaf5'}+SHADOW = (0.15, 0.14, 0.12) # shadow tint (multiplies; near neutral so it stays green on felt and warm on paper)++_MA = '/System/Library/AssetsV2/com_apple_MobileAsset_Font*/*/AssetData/'+_FONT_TABLE = { # (glob, face index); first hit wins -- macOS, Linux, Windows. Override: $INKPAINT_FONT_GRADING_<KIND>+ 'heavy': [(_MA + 'Lantinghei.ttc', 2), ('/System/Library/Fonts/Hiragino Sans GB.ttc', 2),+ ('/System/Library/Fonts/STHeiti Medium.ttc', 1), ('/usr/share/fonts/**/NotoSansCJK*Black*.tt[cf]', 0),+ ('/usr/share/fonts/**/NotoSansCJK*Bold*.tt[cf]', 0), ('C:/Windows/Fonts/msyhbd.ttc', 0)],+ 'bold': [(_MA + 'PingFang.ttc', 11), ('/System/Library/Fonts/Hiragino Sans GB.ttc', 2),+ ('/System/Library/Fonts/STHeiti Medium.ttc', 1), ('/usr/share/fonts/**/NotoSansCJK*Bold*.tt[cf]', 0),+ ('C:/Windows/Fonts/msyhbd.ttc', 0)],+ 'medium': [(_MA + 'PingFang.ttc', 7), ('/System/Library/Fonts/STHeiti Medium.ttc', 1),+ ('/usr/share/fonts/**/NotoSansCJK*Medium*.tt[cf]', 0), ('/usr/share/fonts/**/NotoSansCJK*Regular*.tt[cf]', 0),+ ('C:/Windows/Fonts/msyh.ttc', 0)],+ 'body': [(_MA + 'PingFang.ttc', 3), ('/System/Library/Fonts/Hiragino Sans GB.ttc', 0),+ ('/System/Library/Fonts/STHeiti Light.ttc', 1), ('/usr/share/fonts/**/NotoSansCJK*Regular*.tt[cf]', 0),+ ('C:/Windows/Fonts/msyh.ttc', 0)],+ 'light': [(_MA + 'PingFang.ttc', 15), ('/System/Library/Fonts/STHeiti Light.ttc', 1),+ ('/usr/share/fonts/**/NotoSansCJK*Light*.tt[cf]', 0), ('C:/Windows/Fonts/msyhl.ttc', 0)],+ 'latin': [('/System/Library/Fonts/Avenir Next.ttc', 2), ('/System/Library/Fonts/HelveticaNeue.ttc', 10),+ ('/usr/share/fonts/**/DejaVuSans-Bold.ttf', 0), ('C:/Windows/Fonts/arialbd.ttf', 0)],+ 'latin_heavy': [('/System/Library/Fonts/Avenir Next.ttc', 8), ('/System/Library/Fonts/HelveticaNeue.ttc', 1),+ ('/usr/share/fonts/**/DejaVuSans-Bold.ttf', 0), ('C:/Windows/Fonts/arialbd.ttf', 0)],+ 'digits': [('/System/Library/Fonts/Supplemental/DIN Alternate Bold.ttf', 0), ('/System/Library/Fonts/Avenir Next.ttc', 0),+ ('/usr/share/fonts/**/DejaVuSans-Bold.ttf', 0), ('C:/Windows/Fonts/arialbd.ttf', 0)],+ 'mono': [('/System/Library/Fonts/Menlo.ttc', 0), ('/usr/share/fonts/**/DejaVuSansMono.ttf', 0), ('C:/Windows/Fonts/consola.ttf', 0)],+}+_FONTS = {}+++def hexc(h):+ h = h.lstrip('#')+ return np.array([int(h[i:i + 2], 16) for i in (0, 2, 4)], np.float32) / 255+++def _c(c):+ return hexc(c) if isinstance(c, str) else np.asarray(c, np.float32)+++def _absorb(c):+ """Beer-Lambert absorbance of an ink colour: density 1 over white paper gives exactly this colour"""+ return -np.log(np.clip(_c(c), 0.02, 1.0)).astype(np.float32)+++def font(kind, size):+ """PIL font: heavy (titles, stamps), bold (notes, headings), medium, body, light (CJK sans, PingFang /+ Lantinghei on macOS), latin, latin_heavy, digits, mono -- or any core.load_font style name"""+ key = (kind, int(size))+ if key in _FONTS: return _FONTS[key]+ f = None+ env = os.environ.get('INKPAINT_FONT_GRADING_' + kind.upper())+ cands = ([(env, 0)] if env and os.path.exists(env) else []) + _FONT_TABLE.get(kind, [])+ for pat, idx in cands:+ for p in glob.glob(pat, recursive=True):+ try:+ f = ImageFont.truetype(p, int(size), index=idx); break+ except OSError:+ continue+ if f: break+ if f is None:+ f = load_font('cjk_sans' if kind in ('heavy', 'bold', 'medium', 'body', 'light') else+ ('sans_bold' if kind in ('latin', 'latin_heavy', 'digits') else kind), size)+ _FONTS[key] = f+ return f+++def _resample(P, step=1.0):+ P = np.asarray(P, np.float32)+ seg = np.linalg.norm(np.diff(P, axis=0), axis=1)+ s = np.concatenate([[0], np.cumsum(seg)])+ L = float(s[-1])+ if L < 1e-3: return P[:1].repeat(2, 0), np.array([0.0, 1.0], np.float32), 1e-3+ t = np.linspace(0, L, max(2, int(L / step) + 1))+ return np.stack([np.interp(t, s, P[:, 0]), np.interp(t, s, P[:, 1])], 1).astype(np.float32), (t / L).astype(np.float32), L+++def _erode(m, r=1):+ """min filter (4-neighbour, r steps): erodes a mask, or spreads the earliest time of a time map"""+ out = m.copy()+ for _ in range(int(r)):+ b = out.copy()+ for dy, dx in ((0, 1), (0, -1), (1, 0), (-1, 0)):+ np.minimum(b, np.roll(np.roll(out, dy, 0), dx, 1), out=b)+ out = b+ return out+++def _quad(a, c, b, n=40):+ t = np.linspace(0, 1, n)[:, None]+ a, c, b = (np.asarray(v, np.float32) for v in (a, c, b))+ return ((1 - t) ** 2 * a + 2 * (1 - t) * t * c + t * t * b).astype(np.float32)+++def _sample(a, yy, xx):+ """bilinear sample of a 2-D array at float coordinates (clamped)"""+ H, W = a.shape+ xx = np.clip(xx, 0, W - 1.001); yy = np.clip(yy, 0, H - 1.001)+ x0 = xx.astype(np.int32); y0 = yy.astype(np.int32)+ fx = xx - x0; fy = yy - y0+ return (a[y0, x0] * (1 - fx) * (1 - fy) + a[y0, x0 + 1] * fx * (1 - fy) ++ a[y0 + 1, x0] * (1 - fx) * fy + a[y0 + 1, x0 + 1] * fx * fy)+++# ---------------------------------------------------------------- handwritten digits for the score (unit box 0.62 x 1, y down)+_DIGITS = {+ '0': [[(0.34, 0.02), (0.1, 0.12), (0.02, 0.5), (0.12, 0.9), (0.34, 1.0), (0.54, 0.88), (0.62, 0.5), (0.54, 0.12), (0.32, 0.0), (0.18, 0.08)]],+ '1': [[(0.14, 0.2), (0.36, 0.0)], [(0.36, 0.0), (0.35, 0.5), (0.34, 1.0)]],+ '2': [[(0.04, 0.24), (0.14, 0.06), (0.34, 0.0), (0.54, 0.1), (0.56, 0.32), (0.4, 0.56), (0.18, 0.8), (0.02, 0.98)], [(0.02, 0.98), (0.32, 0.97), (0.62, 0.95)]],+ '3': [[(0.04, 0.12), (0.26, 0.0), (0.5, 0.06), (0.54, 0.26), (0.38, 0.42), (0.2, 0.47)], [(0.2, 0.47), (0.46, 0.52), (0.6, 0.72), (0.5, 0.94), (0.26, 1.0), (0.02, 0.9)]],+ '4': [[(0.46, 0.0), (0.24, 0.36), (0.02, 0.68)], [(0.02, 0.68), (0.32, 0.67), (0.62, 0.66)], [(0.47, 0.3), (0.46, 0.65), (0.45, 1.0)]],+ '5': [[(0.14, 0.04), (0.11, 0.25), (0.08, 0.46)], [(0.08, 0.46), (0.3, 0.38), (0.52, 0.46), (0.6, 0.7), (0.48, 0.93), (0.24, 0.99), (0.02, 0.88)], [(0.14, 0.04), (0.38, 0.03), (0.6, 0.02)]],+ '6': [[(0.54, 0.04), (0.28, 0.1), (0.1, 0.36), (0.04, 0.68), (0.16, 0.94), (0.38, 1.0), (0.56, 0.86), (0.56, 0.62), (0.38, 0.5), (0.16, 0.56), (0.06, 0.7)]],+ '7': [[(0.02, 0.06), (0.32, 0.04), (0.6, 0.02)], [(0.6, 0.02), (0.48, 0.34), (0.38, 0.66), (0.3, 1.0)]],+ '8': [[(0.52, 0.12), (0.32, 0.0), (0.1, 0.1), (0.12, 0.32), (0.34, 0.48), (0.56, 0.64), (0.54, 0.9), (0.3, 1.0), (0.06, 0.88), (0.08, 0.64), (0.32, 0.48), (0.52, 0.32), (0.54, 0.16), (0.44, 0.04)]],+ '9': [[(0.56, 0.24), (0.42, 0.44), (0.18, 0.46), (0.04, 0.28), (0.14, 0.06), (0.36, 0.0), (0.56, 0.12), (0.58, 0.3)], [(0.58, 0.3), (0.54, 0.64), (0.44, 1.0)]],+}+++# ================================================================ marks (retained, with progress)+class Mark:+ """Ink put on a paper after printing. `progress` 0..1 is how far it has been written (1 = done, 0 = not yet).+ D is the density map of a local crop at (oy, ox) in paper-local pixels; T the time map (when each pixel was+ reached, 0..1) or None for marks that appear at once."""+ def __init__(self, paper, K, D, T, oy, ox, path=None, soft=0.01, kind='pen'):+ self.paper, self.K, self.D, self.T, self.oy, self.ox = paper, K, D, T, oy, ox+ self.path = path # (pts in paper coordinates, t) for tip(); pts sampled ~1 px+ self.soft = soft+ self.kind = kind+ self.progress = 1.0+ self.shade = None # multiplicative shading (stamp dent), applied with the ink+ self.wet = 0.0+ self.wetD = None++ def density(self):+ p = self.progress+ if p <= 0: return None+ D = self.D+ if self.wetD is not None and self.wet > 0: D = D + self.wetD * self.wet+ if p >= 1 or self.T is None: return D+ return D * np.clip((p - self.T) / self.soft + 1.0, 0, 1) * (self.T <= p + self.soft)++ def apply(self, rgb):+ D = self.density()+ if D is None: return+ h, w = D.shape+ sub = rgb[self.oy:self.oy + h, self.ox:self.ox + w]+ if self.shade is not None and self.progress > 0:+ sub *= self.shade[..., None]+ sub *= np.exp(-D[..., None] * self.K)++ def tip(self, p=None):+ """the writing front at progress p (default: current), in paper coordinates"""+ p = self.progress if p is None else p+ if self.path is None: return None+ pts, t = self.path+ i = int(np.clip(np.searchsorted(t, p), 0, len(pts) - 1))+ return float(pts[i, 0]), float(pts[i, 1])+++class Group:+ """Several marks written one after another (a cross, a score with its ring). Setting `progress` hands it out+ in proportion to each part's length; `tip()` follows the part being written."""+ def __init__(self, parts, weights=None):+ self.parts = list(parts)+ w = np.array(weights if weights is not None else [max(1.0, m.length) for m in self.parts], np.float64)+ self.edges = np.concatenate([[0], np.cumsum(w / w.sum())])+ self.length = float(sum(m.length for m in self.parts))+ self._p = 1.0++ @property+ def progress(self):+ return self._p++ @progress.setter+ def progress(self, p):+ self._p = p+ for m, a, b in zip(self.parts, self.edges[:-1], self.edges[1:]):+ m.progress = float(np.clip((p - a) / (b - a), 0, 1))++ def tip(self, p=None):+ p = self._p if p is None else p+ for m, a, b in zip(self.parts, self.edges[:-1], self.edges[1:]):+ if p <= b + 1e-9:+ return m.tip(float(np.clip((p - a) / (b - a), 0, 1)))+ return self.parts[-1].tip(1.0)+++# ================================================================ paper+class Paper:+ """One sheet or card on the desk. Coordinates are canvas coordinates of the paper as if unrotated; its own+ rotation (`rot`) and pose (`Grading.place`) are applied when composited."""++ def __init__(self, g, x, y, w, h, tint, rot, stack, radius, margin, seed, grain):+ self.g = g+ self.x0, self.y0, self.w, self.h = int(round(x)), int(round(y)), int(round(w)), int(round(h))+ self.rot = float(rot)+ self.M = int(margin)+ self.X0, self.Y0 = self.x0 - self.M, self.y0 - self.M+ self.LW, self.LH = self.w + 2 * self.M, self.h + 2 * self.M+ self.rng = np.random.default_rng(seed)+ self.seed = seed+ self.tint = _c(tint)+ self.marks = []+ self.state = None+ self._shadow_key = None+ LH, LW, M = self.LH, self.LW, self.M+ rgb = np.zeros((LH, LW, 3), np.float32)+ alpha = np.zeros((LH, LW), np.float32)+ # sheets stacked underneath (offset, a shade darker), then the paper itself+ for k, (ox, oy, tone) in enumerate(stack):+ m = self._rrect_local(M + ox, M + oy, M + ox + self.w, M + oy + self.h, radius)+ col = self.tint * tone+ e = np.clip(m - _erode(m, 1), 0, 1)+ rgb = rgb * (1 - m[..., None]) + (col * (1 - 0.16 * e[..., None])) * m[..., None]+ alpha = np.maximum(alpha, m)+ m = self._rrect_local(M, M, M + self.w, M + self.h, radius)+ mott = noise2d(LH, LW, 110, 4, seed + 1) - 0.5+ cock = noise2d(LH, LW, 420, 2, seed + 2) - 0.5+ fib = blur(self.rng.normal(0, 1, (LH, LW)).astype(np.float32), 0.7)+ fib /= fib.std() + 1e-6+ self.grain = np.clip(0.5 + 0.18 * fib + 0.6 * (noise2d(LH, LW, 3.0, 2, seed + 3) - 0.5), 0, 1).astype(np.float32)+ tex = 1 + grain * (0.045 * mott + 0.010 * fib + 0.028 * cock)+ base = self.tint[None, None, :] * tex[..., None]+ # stray fibres and specks+ im = Image.new('L', (LW, LH), 0); d = ImageDraw.Draw(im)+ for _ in range(int(self.w * self.h / 9000 * grain)):+ x, y = self.rng.uniform(M, M + self.w), self.rng.uniform(M, M + self.h)+ a = self.rng.uniform(0, np.pi); L = self.rng.uniform(4, 16)+ d.line([(x, y), (x + np.cos(a) * L, y + np.sin(a) * L)], fill=int(self.rng.uniform(20, 60)), width=1)+ for _ in range(int(self.w * self.h / 30000 * grain)):+ x, y = self.rng.uniform(M, M + self.w), self.rng.uniform(M, M + self.h)+ d.ellipse((x - 0.8, y - 0.8, x + 0.8, y + 0.8), fill=int(self.rng.uniform(40, 110)))+ sp = blur(np.asarray(im, np.float32) / 255, 0.5)+ base *= (1 - 0.30 * sp[..., None] * np.array([0.8, 0.9, 1.0], np.float32))+ e = np.clip(m - _erode(m, 1), 0, 1)+ base *= (1 - 0.13 * e[..., None])+ self.base = base.astype(np.float32) # unprinted paper: what knocked-out type shows+ self.rgb = (rgb * (1 - m[..., None]) + base * m[..., None]).astype(np.float32)+ self.alpha = np.maximum(alpha, m).astype(np.float32)+ self.mask = m.astype(np.float32) # the top sheet only (where printing can land)++ # ------------------------------------------------------------ coordinates+ def _rrect_local(self, x0, y0, x1, y1, r, ss=2):+ im = Image.new('L', (self.LW * ss, self.LH * ss), 0)+ ImageDraw.Draw(im).rounded_rectangle((x0 * ss, y0 * ss, x1 * ss - 1, y1 * ss - 1), radius=r * ss, fill=255)+ return np.asarray(im.resize((self.LW, self.LH), Image.BOX), np.float32) / 255++ def pose(self):+ """(centre x, centre y, scale, rotation deg) of the paper as currently placed"""+ lift, dx, dy, drot = self.state if self.state else (0.0, 0.0, 0.0, 0.0)+ return self.x0 + self.w / 2 + dx, self.y0 + self.h / 2 + dy, 1 + 0.035 * lift, self.rot + drot++ def to_canvas(self, x, y):+ """paper coordinates -> canvas coordinates under the current pose"""+ cx, cy, s, rot = self.pose()+ th = np.deg2rad(rot); c, si = np.cos(th), np.sin(th)+ u, v = (x - (self.x0 + self.w / 2)) * s, (y - (self.y0 + self.h / 2)) * s+ return cx + c * u + si * v, cy - si * u + c * v++ # ------------------------------------------------------------ low-level printing+ def _blank(self, x0, y0, x1, y1, ss=2):+ """an 'L' scratch image over the paper box (paper coords) -> (img, draw, lx0, ly0, lx1, ly1)"""+ lx0 = max(0, int(np.floor(x0 - self.X0)) - 2); ly0 = max(0, int(np.floor(y0 - self.Y0)) - 2)+ lx1 = min(self.LW, int(np.ceil(x1 - self.X0)) + 3); ly1 = min(self.LH, int(np.ceil(y1 - self.Y0)) + 3)+ if lx1 <= lx0 or ly1 <= ly0: return None+ im = Image.new('L', ((lx1 - lx0) * ss, (ly1 - ly0) * ss), 0)+ return im, ImageDraw.Draw(im), lx0, ly0, lx1, ly1++ def _ink(self, m, ly0, lx0, colour, alpha=1.0, mode='ink'):+ """print a coverage crop at local (ly0, lx0). mode 'ink' multiplies (offset ink), 'knock' restores the bare+ paper (white type out of a band), 'over' paints opaque"""+ h, w = m.shape+ a = (m * alpha * self.mask[ly0:ly0 + h, lx0:lx0 + w])[..., None]+ sub = self.rgb[ly0:ly0 + h, lx0:lx0 + w]+ if mode == 'ink':+ sub *= 1 - a * (1 - _c(colour))+ elif mode == 'knock':+ sub[:] = sub * (1 - a) + self.base[ly0:ly0 + h, lx0:lx0 + w] * a+ else:+ sub[:] = sub * (1 - a) + _c(colour) * a++ def _shape(self, fn, box, colour, alpha=1.0, mode='ink', ss=2):+ r = self._blank(*box, ss=ss)+ if r is None: return+ im, d, lx0, ly0, lx1, ly1 = r+ fn(d, lambda x, y: ((x - self.X0 - lx0) * ss, (y - self.Y0 - ly0) * ss), ss)+ m = np.asarray(im.resize((lx1 - lx0, ly1 - ly0), Image.BOX), np.float32) / 255+ self._ink(m, ly0, lx0, colour, alpha, mode)++ def _text_crop(self, s, x, y, size, kind, anchor, spacing, rot=0.0, jitter=0.0, seed=0):+ """text mask crop in local pixels + per-character x extents (paper coords) for reveal / tips"""+ f = font(kind, size)+ adv = [f.getlength(ch) for ch in s]+ total = sum(adv) + spacing * max(0, len(s) - 1)+ xs = x - total * {'l': 0.0, 'm': 0.5, 'r': 1.0}[anchor[0]]+ asc, desc = f.getmetrics()+ yb = {'s': y, 'm': y + (asc - desc) / 2 * 0.86, 't': y + asc, 'b': y - desc}.get(anchor[1], y)+ pad = int(size * 0.5) + 4+ r = self._blank(xs - pad, yb - asc - pad, xs + total + pad, yb + desc + pad, ss=1)+ if r is None: return None+ im, d, lx0, ly0, lx1, ly1 = r+ rng = np.random.default_rng(seed)+ ext = []+ cx = xs+ for ch, a in zip(s, adv):+ px, py = cx - self.X0 - lx0, yb - self.Y0 - ly0+ if jitter and ch.strip():+ g = Image.new('L', (int(size * 2), int(size * 2)), 0)+ ImageDraw.Draw(g).text((size * 0.5, size * 1.4), ch, font=f, fill=255, anchor='ls')+ g = g.rotate(rng.uniform(-1, 1) * 3.5 * jitter, resample=Image.BICUBIC, center=(size * 0.5 + a / 2, size * 1.0))+ ox_, oy_ = rng.uniform(-1, 1) * 1.6 * jitter, rng.uniform(-1, 1) * 2.2 * jitter+ im.paste(255, (int(round(px - size * 0.5 + ox_)), int(round(py - size * 1.4 + oy_))), g)+ else:+ d.text((px, py), ch, font=f, fill=255, anchor='ls')+ ext.append((cx, cx + a))+ cx += a + spacing+ m = np.asarray(im, np.float32) / 255+ if rot:+ m = np.asarray(Image.fromarray(m, 'F').rotate(rot, resample=Image.BICUBIC, center=(x - self.X0 - lx0, y - self.Y0 - ly0)), np.float32)+ return m, ly0, lx0, ext, yb - asc * 0.78, yb + desc * 0.2++ # ------------------------------------------------------------ printing (immediate)+ def text(self, s, x, y, size, kind='body', colour=INK, anchor='ls', spacing=0.0, alpha=1.0, rot=0.0, mode='ink'):+ """printed type. anchor: [l m r] + [s baseline, m middle, t top, b bottom]; mode 'knock' = white type out of a band"""+ r = self._text_crop(s, x, y, size, kind, anchor, spacing, rot)+ if r is None: return+ m, ly0, lx0 = r[:3]+ self._ink(m, ly0, lx0, colour, alpha, mode)+ return r[3][-1][1] if r[3] else x++ def width(self, s, size, kind='body', spacing=0.0):+ f = font(kind, size)+ return sum(f.getlength(ch) for ch in s) + spacing * max(0, len(s) - 1)++ def rect(self, x0, y0, x1, y1, fill=None, line=None, width=1.5, radius=0, alpha=1.0, mode='ink'):+ def fn(d, P, ss):+ a, b = P(x0, y0), P(x1, y1)+ if fill is not None:+ d.rounded_rectangle((a[0], a[1], b[0] - 1, b[1] - 1), radius=radius * ss, fill=255)+ if fill is not None:+ self._shape(fn, (x0, y0, x1, y1), fill, alpha, mode)+ if line is not None:+ def fl(d, P, ss):+ a, b = P(x0, y0), P(x1, y1)+ d.rounded_rectangle((a[0], a[1], b[0] - 1, b[1] - 1), radius=radius * ss, outline=255, width=max(1, int(round(width * ss))))+ self._shape(fl, (x0 - width, y0 - width, x1 + width, y1 + width), line, alpha)++ def line(self, pts, width=1.2, colour=INK, alpha=1.0, dash=None):+ P = np.asarray(pts, np.float32)+ if dash:+ Q, t, L = _resample(P, 0.5)+ on = ((t * L) % (dash[0] + dash[1])) < dash[0]+ segs, cur = [], []+ for q, o in zip(Q, on):+ if o: cur.append(q)+ elif cur: segs.append(cur); cur = []+ if cur: segs.append(cur)+ else:+ segs = [P]+ box = (P[:, 0].min() - width - 2, P[:, 1].min() - width - 2, P[:, 0].max() + width + 2, P[:, 1].max() + width + 2)++ def fn(d, Pm, ss):+ for sg in segs:+ if len(sg) < 2: continue+ d.line([Pm(x, y) for x, y in sg], fill=255, width=max(1, int(round(width * ss))))+ self._shape(fn, box, colour, alpha)++ def ellipse(self, cx, cy, rx, ry, fill=None, line=None, width=1.0, alpha=1.0):+ if fill is not None:+ self._shape(lambda d, P, ss: d.ellipse((*P(cx - rx, cy - ry), *P(cx + rx, cy + ry)), fill=255),+ (cx - rx, cy - ry, cx + rx, cy + ry), fill, alpha)+ if line is not None:+ self._shape(lambda d, P, ss: d.ellipse((*P(cx - rx, cy - ry), *P(cx + rx, cy + ry)), outline=255, width=max(1, int(round(width * ss)))),+ (cx - rx - width, cy - ry - width, cx + rx + width, cy + ry + width), line, alpha)++ def hatch(self, x0, y0, x1, y1, spacing=10.0, angle=45.0, width=2.0, colour=RULE, alpha=0.07):+ def fn(d, P, ss):+ a = np.deg2rad(angle); dx, dy = np.cos(a), -np.sin(a)+ n = int((x1 - x0 + y1 - y0) / spacing) + 4+ for k in range(-n, n):+ ox, oy = x0 + k * spacing / max(1e-3, abs(np.sin(a))), y1+ d.line([P(ox, oy), P(ox + dx * 3000, oy + dy * 3000)], fill=255, width=max(1, int(round(width * ss))))+ r = self._blank(x0, y0, x1, y1)+ if r is None: return+ im, d, lx0, ly0, lx1, ly1 = r+ fn(d, lambda x, y: ((x - self.X0 - lx0) * 2, (y - self.Y0 - ly0) * 2), 2)+ m = np.asarray(im.resize((lx1 - lx0, ly1 - ly0), Image.BOX), np.float32) / 255+ Y, X = np.mgrid[ly0:ly1, lx0:lx1]+ m *= ((X + self.X0 >= x0) & (X + self.X0 < x1) & (Y + self.Y0 >= y0) & (Y + self.Y0 < y1))+ self._ink(m, ly0, lx0, colour, alpha)++ def grid(self, x0, y0, x1, y1, step=14.0, colour=RULE, alpha=0.12, width=0.8):+ xs = np.arange(x0, x1 + 0.1, step); ys = np.arange(y0, y1 + 0.1, step)++ def fn(d, P, ss):+ for x in xs: d.line([P(x, y0), P(x, y1)], fill=255, width=max(1, int(round(width * ss))))+ for y in ys: d.line([P(x0, y), P(x1, y)], fill=255, width=max(1, int(round(width * ss))))+ self._shape(fn, (x0 - 2, y0 - 2, x1 + 2, y1 + 2), colour, alpha)++ def rules(self, x0, x1, ys, colour=RULE, alpha=0.45, width=1.0):+ """ruled answer lines at the given y's"""+ for y in ys:+ self.line([(x0, y), (x1, y)], width, colour, alpha)++ def timing_track(self, x, y0, y1, step=30.0, w=22.0, h=8.0, colour=INK):+ """OMR timing marks: a column of black dashes down the edge"""+ y = y0+ while y + h <= y1:+ self.rect(x, y, x + w, y + h, fill=colour, alpha=0.92)+ y += step++ def corner_mark(self, x, y, s=24.0, colour=INK):+ self.rect(x, y, x + s, y + s, fill=colour)++ def holes(self, x, y0, y1, step=34.0, r=6.5):+ """punched binding holes down the edge: cut through the paper (the felt shows) with a crushed rim"""+ ys = np.arange(y0, y1 + 0.1, step)+ im = Image.new('L', (self.LW * 2, self.LH * 2), 0); d = ImageDraw.Draw(im)+ for y in ys:+ lx, ly = (x - self.X0) * 2, (y - self.Y0) * 2+ d.ellipse((lx - r * 2, ly - r * 2, lx + r * 2, ly + r * 2), fill=255)+ cut = np.asarray(im.resize((self.LW, self.LH), Image.BOX), np.float32) / 255+ rim = np.clip(blur(cut, 1.4) - cut, 0, 1)+ self.rgb *= (1 - 0.35 * rim[..., None])+ self.alpha *= 1 - cut+ self.mask *= 1 - cut++ # ------------------------------------------------------------ answer-sheet furniture+ def title(self, s, x, y, size=52, sub=None, sub_size=15, colour=INK):+ """heavy title with a letter-spaced Latin subtitle under it"""+ self.text(s, x, y, size, 'heavy', colour, spacing=size * 0.04)+ if sub:+ self.text(sub, x + 2, y + sub_size * 2.3, sub_size, 'latin', GRAY, spacing=sub_size * 0.3)++ def field(self, label, value, x, y, x1, size=27, gap=54):+ """a form field: grey caption, bold value, a thin underline"""+ self.text(label, x, y, size * 0.7, 'body', GRAY)+ self.text(value, x + gap, y - 1, size, 'bold', INK)+ self.line([(x + gap - 6, y + 12), (x1, y + 12)], 1.0, INK, 0.55)++ def ticket(self, x, y, digits, box=44, gap=8, label='考号', sub='TICKET NO.'):+ """ticket number: boxed digits and a bubble column under each digit with the right bubble filled"""+ self.text(label, x, y - 12, 19, 'bold', INK)+ if sub: self.text(sub, x + 46, y - 13, 11, 'latin', GRAY, spacing=2.5)+ for i, dg in enumerate(digits):+ bx = x + i * (box + gap)+ self.rect(bx, y, bx + box, y + box - 2, fill='#fffdf6', mode='over')+ self.rect(bx, y, bx + box, y + box - 2, line=INK, width=1.3)+ self.text(dg, bx + box / 2, y + box * 0.72, box * 0.57, 'mono', INK, anchor='ms')+ for k in range(10):+ yy = y + box + 14 + k * 13.6+ if str(k) == dg:+ self.ellipse(bx + box / 2, yy, 13, 5.3, fill=INK)+ else:+ self.ellipse(bx + box / 2, yy, 13, 5.3, line=RULE, width=0.9, alpha=0.75)+ self.text(str(k), bx + box / 2, yy + 3.2, 8.5, 'mono', RULE, anchor='ms', alpha=0.9)++ def score_box(self, x, y, w=350, h=172, split=200, head=36, titles=('得分', '阅卷人'), note='满分 100', lines=()):+ """the score / grader table; returns the centre of the empty score cell"""+ self.rect(x, y, x + w, y + head, fill=INK, alpha=0.07)+ self.rect(x, y, x + w, y + h, line=INK, width=2.0)+ self.line([(x, y + head), (x + w, y + head)], 1.2)+ self.line([(x + split, y), (x + split, y + h)], 1.2)+ self.text(titles[0], x + split / 2, y + head * 0.7, 20, 'bold', INK, anchor='ms', spacing=6)+ self.text(titles[1], x + split + (w - split) / 2, y + head * 0.7, 20, 'bold', INK, anchor='ms', spacing=2)+ if note: self.text(note, x + split - 10, y + head + 24, 15, 'body', GRAY, anchor='rs')+ for k, s in enumerate(lines):+ self.text(s, x + split + (w - split) / 2, y + head + 56 + k * 32, 17, 'body', GRAY, anchor='ms')+ return x + split / 2, y + head + (h - head) / 2 + 4++ def fill_example(self, x, y):+ """the bubble-filling legend: 填涂示例 ● 正确 ✓ ✗ ◐ 错误"""+ self.text('填涂示例', x, y, 14, 'body', GRAY)+ self.ellipse(x + 80, y - 5, 12, 5, fill=INK)+ self.text('正确', x + 98, y, 14, 'body', GRAY)+ for k in range(3):+ cx = x + 150 + k * 34+ self.ellipse(cx, y - 5, 12, 5, line=RULE, width=0.9, alpha=0.8)+ if k == 0: self.line([(cx - 5, y - 5), (cx - 1, y - 2), (cx + 6, y - 9)], 1.3)+ if k == 1:+ self.line([(cx - 5, y - 9), (cx + 5, y - 1)], 1.3); self.line([(cx + 5, y - 9), (cx - 5, y - 1)], 1.3)+ if k == 2: self.ellipse(cx - 4, y - 5, 6, 4, fill=INK)+ self.text('错误', x + 254, y, 14, 'body', GRAY)++ def section(self, x, y, num, title, sub=None, meta=None, x1=None, size=26):+ """a numbered section head: dark square with the numeral knocked out, bold title, grey note"""+ s = size * 1.23+ self.rect(x, y, x + s, y + s, fill=INK)+ self.text(num, x + s / 2, y + s * 0.73, size * 0.77, 'bold', INK, anchor='ms', mode='knock')+ tx = x + s + 12+ end = self.text(title, tx, y + s * 0.78, size, 'bold', INK)+ if sub: self.text(sub, end + 14, y + s * 0.75, size * 0.73, 'body', GRAY)+ if meta and x1: self.text(meta, x1, y + s * 0.72, 16, 'body', GRAY, anchor='rs', spacing=1)++ def question(self, x0, y0, x1, y1, s, size=30, kind='body'):+ """the question in a tinted box with a dark bar on the left"""+ self.rect(x0, y0, x1, y1, fill=INK, alpha=0.05)+ self.rect(x0, y0, x0 + 4, y1, fill=INK)+ self.text(s, x0 + 24, (y0 + y1) / 2 + size * 0.36, size, kind, INK)++ def answer_frame(self, x0, y0, x1, y1, col=None, rows=(), head='阅卷栏', note='考生勿填', grid=14.0, lines=()):+ """the answer box: faint grid and ruled lines on the left, a hatched grading column (x >= col) on the+ right with a header row and dashed row separators; rows = [(caption, y_caption, y_separator or None)]"""+ cx = col if col else x1+ if grid: self.grid(x0, y0, cx, y1, grid)+ for y in lines: self.line([(x0 + 10, y), (cx - 12, y)], 1.0, RULE, 0.42)+ if col:+ self.hatch(col, y0, x1, y1)+ self.rect(col, y0, x1, y0 + 36, fill=INK, alpha=0.06)+ self.text(head, col + 18, y0 + 25, 18, 'bold', INK, spacing=4)+ if note: self.text(note, x1 - 14, y0 + 24, 13, 'body', GRAY, anchor='rs', spacing=1)+ self.line([(col, y0), (col, y1)], 1.5)+ self.line([(col + 4, y0), (col + 4, y1)], 0.6)+ self.line([(col, y0 + 36), (x1, y0 + 36)], 0.9)+ for cap, yc, ysep in rows:+ self.text(cap, col + 18, yc, 16, 'body', GRAY, spacing=1)+ if ysep: self.line([(col + 4, ysep), (x1, ysep)], 0.8, INK, 0.6, dash=(4, 4))+ self.rect(x0, y0, x1, y1, line=INK, width=1.5)++ def band(self, x0, y0, x1, y1, colour=NAVY):+ """a solid printed band (the answer key's header)"""+ self.rect(x0, y0, x1, y1, fill=colour)++ def checkbox(self, x, y, s=26, colour=INK):+ self.rect(x, y, x + s, y + s, line=colour, width=1.6, radius=2)++ def circled(self, n, cx, cy, r=15, size=19, colour=INK):+ """a printed circled number ①"""+ self.ellipse(cx, cy, r, r, line=colour, width=1.6)+ self.text(str(n), cx, cy + size * 0.36, size, 'bold', colour, anchor='ms')++ def clip(self, x, y, w=136.0, handle=74.0):+ """a black binder clip gripping the edge at (x, y) (paper coordinates, y on the edge), both wire handles+ folded up: two silver loops spanning the clip, the back one a little lower and in shadow"""+ lx, ly = x - self.X0, y - self.Y0+ ss = 3+ x0, x1 = max(0, int(lx - w / 2 - 50)), min(self.LW, int(lx + w / 2 + 50))+ y0, y1 = max(0, int(ly - handle - 40)), min(self.LH, int(ly + 70))+ cw, ch = x1 - x0, y1 - y0+ bx, by = lx - x0, ly - y0++ def draw(fn):+ im = Image.new('L', (cw * ss, ch * ss), 0)+ fn(ImageDraw.Draw(im))+ return np.asarray(im.resize((cw, ch), Image.BOX), np.float32) / 255+ top, bot = by - 17, by + 19+ P = lambda pts: [(px * ss, py * ss) for px, py in pts]+ body = draw(lambda d: d.rounded_rectangle(P([(bx - w / 2, top), (bx + w / 2, bot)]), radius=5 * ss, fill=255))+ # glossy black steel: a bright band near the top of the fold, a soft one low down, darker toward the ends+ Y = (np.arange(ch, dtype=np.float32)[:, None] - top) / (bot - top)+ X = (np.arange(cw, dtype=np.float32)[None, :] - bx) / (w / 2)+ sh = 0.045 + 0.30 * np.exp(-((Y - 0.18) / 0.08) ** 2) + 0.07 * np.exp(-((Y - 0.72) / 0.14) ** 2)+ sh = sh * (1 - 0.35 * X ** 4) + 0.02+ body_rgb = sh[..., None] * np.array([0.95, 0.97, 1.0], np.float32)+ # the wire handles: each a loop whose legs enter the clip near its ends+ wires, hil = [], []+ for k, (inset, hgt, dxo) in enumerate(((20, handle, 0.0), (26, handle - 12, -5.0))):+ lb, rb = bx - w / 2 + inset + dxo, bx + w / 2 - inset + dxo+ yt = top - hgt+ pts = spline([(lb, top + 4), (lb - 3, top - hgt * 0.5), (lb + 6, yt + 4), (lb + 18, yt), ((lb + rb) / 2, yt - 1),+ (rb - 18, yt), (rb - 6, yt + 4), (rb + 3, top - hgt * 0.5), (rb, top + 4)], 10)+ wires.append(draw(lambda d: d.line(P(pts), fill=255, width=int(4.6 * ss), joint='curve')))+ hil.append(draw(lambda d: d.line(P(pts - np.array([1.0, 1.2], np.float32)), fill=255, width=int(1.4 * ss), joint='curve')))+ front, back = wires[0], wires[1] * (1 - wires[0])+ wire_a = np.maximum(front, back)+ wire_rgb = np.where((front > back)[..., None],+ (0.50 + 0.42 * hil[0])[..., None] * np.array([0.92, 0.93, 0.95], np.float32),+ (0.34 + 0.30 * hil[1])[..., None] * np.array([0.90, 0.91, 0.93], np.float32))+ wire_a = wire_a * (1 - body)+ # shadows on the paper below (down and to the right; the raised handles throw theirs further)+ sub = self.rgb[y0:y1, x0:x1]+ on = self.mask[y0:y1, x0:x1]+ shad = np.clip(blur(shift(body, 5, 8), 3.5) * 0.62 + blur(shift(np.maximum(front, back), 14, 30), 3.0) * 0.30, 0, 0.8)+ sub *= (1 - shad * on)[..., None]+ a = np.maximum(body, wire_a)+ col = body_rgb * body[..., None] + wire_rgb * wire_a[..., None]+ sub[:] = sub * (1 - a[..., None]) + col+ self.alpha[y0:y1, x0:x1] = np.maximum(self.alpha[y0:y1, x0:x1], a)++ # ------------------------------------------------------------ marks (retained; set .progress to animate)+ def _add(self, m):+ self.marks.append(m)+ return m++ def stroke(self, pts, width=3.2, colour=PEN, pressure=0.16, blob=0.35, feather=0.22, smooth=False, seed=None, density=1.0):+ """a pen stroke along pts (paper coordinates). Gel ink: a bead where the pen lands, pressure drifting along+ the line, feathering into the fibres, lighter where the paper's tooth stands up. Returns a Mark"""+ r = np.random.default_rng(self.rng.integers(1 << 30) if seed is None else seed)+ P = spline(pts, 8) if smooth else np.asarray(pts, np.float32)+ Q, t, L = _resample(P, 1.0)+ n = len(Q)+ press = 1 + pressure * fbm1d(n, 60, 3, int(r.integers(1 << 30)))+ wv = width * (0.88 + 0.12 * press) * (0.75 + 0.25 * np.clip(t * L / 6, 0, 1))+ ss = 3+ pad = width * 3 + 6+ x0, y0 = Q[:, 0].min() - pad, Q[:, 1].min() - pad+ x1, y1 = Q[:, 0].max() + pad, Q[:, 1].max() + pad+ lx0 = max(0, int(np.floor(x0 - self.X0))); ly0 = max(0, int(np.floor(y0 - self.Y0)))+ lx1 = min(self.LW, int(np.ceil(x1 - self.X0))); ly1 = min(self.LH, int(np.ceil(y1 - self.Y0)))+ cw, ch = lx1 - lx0, ly1 - ly0+ cov = Image.new('L', (cw * ss, ch * ss), 0); dc = ImageDraw.Draw(cov)+ tim = Image.new('F', (cw * ss, ch * ss), 9.0); dt = ImageDraw.Draw(tim)+ S = [((q[0] - self.X0 - lx0) * ss, (q[1] - self.Y0 - ly0) * ss) for q in Q]+ for i in range(n - 1, 0, -1): # backwards: the earliest time wins where the stroke crosses itself+ wpx = wv[i] * ss+ dc.line([S[i - 1], S[i]], fill=255, width=max(1, int(round(wpx))))+ dt.line([S[i - 1], S[i]], fill=float(t[i]), width=max(1, int(round(wpx))) + 2)+ rr = wpx / 2+ dc.ellipse((S[i][0] - rr, S[i][1] - rr, S[i][0] + rr, S[i][1] + rr), fill=255)+ dt.ellipse((S[i][0] - rr - 1, S[i][1] - rr - 1, S[i][0] + rr + 1, S[i][1] + rr + 1), fill=float(t[i]))+ rr = wv[0] * ss / 2+ dc.ellipse((S[0][0] - rr, S[0][1] - rr, S[0][0] + rr, S[0][1] + rr), fill=255)+ dt.ellipse((S[0][0] - rr - 1, S[0][1] - rr - 1, S[0][0] + rr + 1, S[0][1] + rr + 1), fill=0.0)+ c = np.asarray(cov.resize((cw, ch), Image.BOX), np.float32) / 255+ T = np.asarray(tim, np.float32).reshape(ch, ss, cw, ss).min(axis=(1, 3))+ T = np.minimum(T, _erode(T, 3))+ Ty = np.where(T > 2, _erode(T, 6), T)+ D = self._gel(c, Ty, Q, t, wv, press, blob, feather, ly0, lx0, r, density)+ Ty = np.where(Ty > 2, 1.0, Ty)+ m = Mark(self, _absorb(colour), D, Ty.astype(np.float32), ly0, lx0, (Q, t), soft=max(0.004, 2.0 / max(L, 1)))+ m.length = L+ return self._add(m)++ def _gel(self, c, T, Q, t, wv, press, blob, feather, ly0, lx0, r, base=1.0):+ ch, cw = c.shape+ g = self.grain[ly0:ly0 + ch, lx0:lx0 + cw]+ Tc = np.clip(T, 0, 1)+ pn = np.interp(Tc, t, (press - 1) / max(1e-3, float(np.abs(press - 1).max())))+ # the pen slows down in turns and leaves more ink there+ d1 = np.gradient(Q, axis=0)+ ang = np.unwrap(np.arctan2(d1[:, 1], d1[:, 0]))+ curv = np.abs(np.gradient(ang))+ k = max(3, int(len(curv) * 0.02)) | 1+ curv = np.convolve(np.pad(curv, k, mode='edge'), np.ones(k) / k, 'same')[k:-k]+ pool = np.interp(Tc, t, np.clip(curv / 0.12, 0, 1))+ mott = noise2d(ch, cw, 9, 2, int(r.integers(1 << 30)))+ big = noise2d(ch, cw, 34, 2, int(r.integers(1 << 30)))+ D = c * base * (0.74 + 0.20 * pn + 0.22 * (mott - 0.5) + 0.26 * (big - 0.5) + 0.26 * pool) * (1 - 0.20 * smoothstep(0.55, 0.85, g))+ # the bead where the pen lands, a smaller one where it lifts+ Y, X = np.mgrid[0:ch, 0:cw].astype(np.float32)+ for k_, amp in ((0, blob), (len(Q) - 1, blob * 0.35)):+ qx, qy = Q[k_, 0] - self.X0 - lx0, Q[k_, 1] - self.Y0 - ly0+ D += amp * np.exp(-((X - qx) ** 2 + (Y - qy) ** 2) / (2 * (wv[k_] * 0.75) ** 2)) * np.clip(c * 1.5, 0, 1)+ # rims a touch darker, a faint feather into the fibres+ D += 0.18 * np.clip(c - _erode(c, 1), 0, 1)+ if feather:+ fb = blur(c, 1.7) * smoothstep(0.30, 0.75, g + 0.25 * (mott - 0.5))+ D += feather * fb * (1 - c)+ return D.astype(np.float32)++ def wave(self, x0, x1, y, amp=4.2, period=21.0, width=2.6, colour=PEN):+ """a wavy underline from x0 to x1: period and height drift like a hand's, and it wanders downhill a little"""+ r = np.random.default_rng(int(self.rng.integers(1 << 30)))+ n = max(60, int((x1 - x0) / 1.2))+ u = np.linspace(0, 1, n)+ ph = np.cumsum(1 + 0.18 * fbm1d(n, n / 3, 2, int(r.integers(1 << 30)))) / n * (x1 - x0) / period * 2 * np.pi+ a = amp * (1 + 0.22 * fbm1d(n, n / 4, 2, int(r.integers(1 << 30))))+ xs = x0 + (x1 - x0) * u + 1.2 * np.sin(ph)+ ys = y + a * np.sin(ph) + u * 2.0 + 0.8 * fbm1d(n, n / 2, 2, int(r.integers(1 << 30)))+ return self.stroke(np.stack([xs, ys], 1), width, colour, pressure=0.24, blob=0.25)++ def ring(self, cx, cy, rx, ry, tilt=-2.0, a0=-30.0, a1=352.0, grow=0.045, width=3.0, colour=PEN):+ """a hand-drawn ellipse round something: starts at a0, overshoots past its start and grows a little"""+ n = 220+ u = np.linspace(0, 1, n)+ a = np.deg2rad(a0 + (a1 - a0) * u)+ k = 1 + grow * u + 0.012 * np.sin(u * 11)+ ex, ey = rx * k * np.cos(a), ry * k * np.sin(a)+ tl = np.deg2rad(tilt)+ P = np.stack([cx + ex * np.cos(tl) - ey * np.sin(tl), cy + ex * np.sin(tl) + ey * np.cos(tl)], 1)+ return self.stroke(P, width, colour, pressure=0.24)++ def leader(self, p0, p1, bend=44.0, width=2.4, colour=PEN):+ """a bowed leader line from p0 to p1 (a quadratic curve lifted by `bend` px)"""+ p0, p1 = np.asarray(p0, np.float32), np.asarray(p1, np.float32)+ c = (p0 + p1) / 2 + np.array([30, -bend], np.float32)+ return self.stroke(_quad(p0, c, p1, 60), width, colour, pressure=0.14, blob=0.22, density=0.9)++ def underline(self, x0, x1, y, width=2.6, colour=PEN):+ xs = np.linspace(x0, x1, 30)+ ys = y + 1.4 * np.sin(np.linspace(0, np.pi, 30)) + np.linspace(0, 1.2, 30)+ return self.stroke(np.stack([xs, ys], 1), width, colour, pressure=0.1)++ def cross(self, cx, cy, s=22.0, width=3.6, colour=PEN):+ """a red cross: two quick bowed strokes. Returns a Group"""+ a = self.stroke(_quad((cx - 0.86 * s, cy - 0.95 * s), (cx + 0.1 * s, cy - 0.1 * s), (cx + 0.86 * s, cy + s), 24), width, colour, blob=0.3)+ b = self.stroke(_quad((cx + 0.9 * s, cy - s), (cx - 0.05 * s, cy - 0.05 * s), (cx - 0.95 * s, cy + 0.95 * s), 24), width, colour, blob=0.3)+ return Group([a, b])++ def check(self, cx, cy, s=24.0, width=3.4, colour=PEN):+ """a red check mark: short down-stroke, long flick up"""+ P = np.concatenate([_quad((cx - 0.5 * s, cy + 0.0 * s), (cx - 0.32 * s, cy + 0.16 * s), (cx - 0.14 * s, cy + 0.38 * s), 12),+ _quad((cx - 0.14 * s, cy + 0.38 * s), (cx + 0.1 * s, cy - 0.1 * s), (cx + 0.6 * s, cy - 0.55 * s), 20)[1:]])+ return self.stroke(P, width, colour, blob=0.3)++ def digits(self, s, x, y, h=80.0, width=4.6, colour=PEN, gap=0.16, slant=0.12):+ """a number written with the pen (each digit from stroke skeletons, slanted, a little irregular); (x, y) is+ the top-left. Returns a Group"""+ r = np.random.default_rng(self.rng.integers(1 << 30))+ parts = []+ cx = x+ for ch in s:+ for st in _DIGITS.get(ch, []):+ P = np.array(st, np.float32)+ P = P + r.normal(0, 0.012, P.shape)+ Px = cx + (P[:, 0] + slant * (1 - P[:, 1])) * h+ Py = y + P[:, 1] * h+ parts.append(self.stroke(np.stack([Px, Py], 1), width, colour, smooth=len(P) > 2, pressure=0.2, blob=0.3))+ cx += (0.62 + gap) * h+ return Group(parts)++ def score(self, s, cx, cy, h=80.0, width=4.6, ring=True, colour=PEN):+ """the score: digits centred on (cx, cy), then a ring round them. Returns a Group (digits, ring)"""+ n = len(s)+ wtot = (0.62 * n + 0.16 * (n - 1) + 0.12) * h+ dg = self.digits(s, cx - wtot / 2, cy - h / 2, h, width, colour)+ parts = list(dg.parts)+ if ring:+ parts.append(self.ring(cx + 2, cy + 1, wtot / 2 + h * 0.30, h * 0.70, tilt=-7, a0=-118, a1=-118 + 376, grow=0.06, width=width * 0.7, colour=colour))+ return Group(parts)++ def note(self, s, x, y, size=32, kind='bold', colour=PEN, anchor='ls', jitter=1.0, seed=None):+ """an annotation in a bold sans inked with the red pen: each character nudged and turned a little, denser+ rims, mottle and a faint bleed. Revealed character by character (top-left to bottom-right inside each)"""+ sd = int(self.rng.integers(1 << 30)) if seed is None else seed+ r = self._text_crop(s, x, y, size, kind, anchor, size * 0.04, jitter=jitter, seed=sd)+ m, ly0, lx0, ext, ytop, ybot = r+ ch, cw = m.shape+ rr = np.random.default_rng(sd)+ g = self.grain[ly0:ly0 + ch, lx0:lx0 + cw]+ mott = noise2d(ch, cw, 6, 2, sd + 1)+ big = noise2d(ch, cw, max(8, size * 0.7), 2, sd + 2)+ D = m * (0.66 + 0.22 * mott + 0.34 * big) * (1 - 0.18 * smoothstep(0.55, 0.85, g))+ D += 0.30 * np.clip(m - _erode(m, 1), 0, 1) * (0.6 + 0.8 * big)+ D += 0.20 * blur(m, 1.6) * smoothstep(0.3, 0.8, g + 0.2 * (mott - 0.5)) * (1 - m)+ X = np.arange(cw, dtype=np.float32)[None, :] + lx0 + self.X0+ Y = np.arange(ch, dtype=np.float32)[:, None] + ly0 + self.Y0+ T = np.full((ch, cw), 1.0, np.float32)+ n = len(ext)+ hh = max(1.0, ybot - ytop)+ tips, tt = [], []+ for i, (a, b) in enumerate(ext):+ lo = a - (size * 0.1 if i == 0 else 0); hi = b if i < n - 1 else b + size * 0.3+ inside = (X >= lo) & (X < hi)+ loc = np.clip(((X - a) + 0.5 * (Y - ytop)) / ((b - a) + 0.5 * hh), 0, 1)+ T = np.where(inside, (i + loc) / n, T)+ for u in np.linspace(0, 1, 12, endpoint=False):+ tips.append((a + (b - a) * u, ytop + hh * (0.5 + 0.42 * np.sin(u * np.pi * 4.5)))); tt.append((i + u) / n)+ T = np.where(X < ext[0][0], 0.0, T)+ tips.append((ext[-1][1], ytop + hh * 0.6)); tt.append(1.0)+ mk = Mark(self, _absorb(colour), D.astype(np.float32), T, ly0, lx0, (np.array(tips, np.float32), np.array(tt, np.float32)), soft=0.6 / max(n, 1) / 4, kind='note')+ mk.length = float(ext[-1][1] - ext[0][0]) * 1.5+ return self._add(mk)++ def answer(self, s, x, y, size=32, kind='body', colour=ANSWER, anchor='ls'):+ """the candidate's writing in blue-black, revealed character by character"""+ r = self._text_crop(s, x, y, size, kind, anchor, 0.0)+ m, ly0, lx0, ext, ytop, ybot = r+ ch, cw = m.shape+ X = np.arange(cw, dtype=np.float32)[None, :] + lx0 + self.X0+ n = len(ext)+ T = np.zeros((ch, cw), np.float32)+ for i, (a, b) in enumerate(ext):+ T = np.where(X >= a - 0.5, (i + np.clip((X - a) / max(1.0, b - a), 0, 1)) / n, T)+ g = self.grain[ly0:ly0 + ch, lx0:lx0 + cw]+ D = m * 0.95 * (1 - 0.08 * smoothstep(0.6, 0.9, g)) + 0.05 * blur(m, 1.0) * (1 - m)+ tips = np.array([((a + b) / 2, (ytop + ybot) / 2) for a, b in ext], np.float32)+ mk = Mark(self, _absorb(colour), D.astype(np.float32), T, ly0, lx0, (tips, (np.arange(n, dtype=np.float32) + 0.5) / n), soft=0.3 / max(n, 1), kind='answer')+ mk.length = float(ext[-1][1] - ext[0][0])+ return self._add(mk)++ def stamp(self, cx, cy, label, w=None, h=64.0, rot=-2.0, size=30, check=True, colour=STAMP, press=(0.64, 1.0), seed=None):+ """a rubber-stamp impression (hidden until pressed: progress 0; `Grading.stamper(mark, 0)` presses it):+ double rounded border, heavy label, a check; ragged, pin-holed, one end lighter, rims pooled, slightly+ turned, the paper dented round the rubber. press = (light end, heavy end) ink pressure."""+ sd = int(self.rng.integers(1 << 30)) if seed is None else seed+ r = np.random.default_rng(sd)+ f = font('heavy', size)+ sp = size * 0.1+ lw = sum(f.getlength(c) for c in label) + sp * (len(label) - 1)+ if w is None: w = lw + (size * 1.0 + 14 if check else 0) + 46+ ss = 3+ pw, ph = int(w + 60), int(h + 60)+ im = Image.new('L', (pw * ss, ph * ss), 0); d = ImageDraw.Draw(im)+ ox, oy = (pw - w) / 2, (ph - h) / 2+ d.rounded_rectangle(((ox + 2.2) * ss, (oy + 2.2) * ss, (ox + w - 2.2) * ss, (oy + h - 2.2) * ss), radius=7 * ss, outline=255, width=int(4.4 * ss))+ d.rounded_rectangle(((ox + 7) * ss, (oy + 7) * ss, (ox + w - 7) * ss, (oy + h - 7) * ss), radius=3.5 * ss, outline=255, width=int(1.6 * ss))+ x_text = pw / 2 - (lw + (size + 14 if check else 0)) / 2+ fb = font('heavy', size * ss)+ xx = x_text+ for c in label:+ d.text((xx * ss, (ph / 2 + size * 0.36) * ss), c, font=fb, fill=255, anchor='ls')+ xx += f.getlength(c) + sp+ if check:+ kx, ky, ks = xx + 14 + size * 0.5, ph / 2, size+ pts = [(kx - 0.5 * ks, ky + 0.02 * ks), (kx - 0.14 * ks, ky + 0.36 * ks), (kx + 0.5 * ks, ky - 0.4 * ks)]+ d.line([(px * ss, py * ss) for px, py in pts], fill=255, width=int(5.6 * ss), joint='curve')+ for px, py in (pts[0], pts[2]):+ d.ellipse(((px - 2.8) * ss, (py - 2.8) * ss, (px + 2.8) * ss, (py + 2.8) * ss), fill=255)+ mk = np.asarray(im.resize((pw, ph), Image.BOX), np.float32) / 255+ # ink spreads a hair, edges go ragged (displaced), then turn it+ mk = np.clip(blur(mk, 0.45) * 1.15, 0, 1)+ dx = (noise2d(ph, pw, 5, 2, sd + 1) - 0.5) * 2.6+ dy = (noise2d(ph, pw, 5, 2, sd + 2) - 0.5) * 2.6+ Yg, Xg = np.mgrid[0:ph, 0:pw].astype(np.float32)+ mk = _sample(mk, Yg + dy, Xg + dx)+ block = np.zeros((ph, pw), np.float32)+ bi = Image.new('L', (pw * ss, ph * ss), 0)+ ImageDraw.Draw(bi).rounded_rectangle(((ox - 4) * ss, (oy - 4) * ss, (ox + w + 4) * ss, (oy + h + 4) * ss), radius=10 * ss, fill=255)+ block = np.asarray(bi.resize((pw, ph), Image.BOX), np.float32) / 255+ # pressure: one end lighter, plus a blotchy field+ a = r.uniform(0, 2 * np.pi)+ ramp = ((Xg - pw / 2) * np.cos(a) + (Yg - ph / 2) * np.sin(a)) / (w / 2) * 0.5 + 0.5+ pr = press[0] + (press[1] - press[0]) * np.clip(ramp, 0, 1) ** 0.8 + 0.30 * (noise2d(ph, pw, 30, 3, sd + 3) - 0.5)+ clump = noise2d(ph, pw, 18, 3, sd + 4)+ speck = r.random((ph, pw)).astype(np.float32)+ void = speck < (0.06 + 0.62 * smoothstep(0.5, 0.85, clump)) * np.clip(1.25 - pr, 0.15, 1)+ fine = blur(void.astype(np.float32), 0.55)+ cov = mk * np.clip(smoothstep(0.34, 0.70, pr + 0.42 * (noise2d(ph, pw, 5, 2, sd + 5) - 0.5)) * 1.1, 0, 1) * (1 - 0.92 * fine)+ D = cov * (0.80 + 0.22 * np.clip(pr, 0, 1.1) + 0.16 * (noise2d(ph, pw, 10, 2, sd + 6) - 0.5)) + 0.22 * np.clip(mk - _erode(mk, 1), 0, 1) * cov+ wet = 0.30 * blur(cov, 1.6) * (1 - cov * 0.5)+ dent_hi = shift(blur(block, 2.0), -1, -1) - blur(block, 2.0)+ dent_lo = blur(block, 2.0) - shift(blur(block, 2.0), 1, 2)+ shade = 1 - 0.05 * np.clip(dent_lo, 0, 1) + 0.035 * np.clip(dent_hi, 0, 1) - 0.012 * block+ def turn(arr, fill):+ return np.asarray(Image.fromarray(arr.astype(np.float32), 'F').rotate(rot, resample=Image.BICUBIC, fillcolor=fill), np.float32)+ D, wet, shade = turn(D, 0.0), turn(wet, 0.0), turn(shade, 1.0)+ lx0, ly0 = int(round(cx - pw / 2 - self.X0)), int(round(cy - ph / 2 - self.Y0))+ g = self.grain[ly0:ly0 + ph, lx0:lx0 + pw]+ D = D * (1 - 0.18 * smoothstep(0.6, 0.9, g))+ m_ = Mark(self, _absorb(colour), D.astype(np.float32), None, ly0, lx0, None, kind='stamp')+ m_.shade = shade.astype(np.float32)+ m_.wetD = wet.astype(np.float32)+ m_.progress = 0.0+ m_.length = 1.0+ m_.geom = dict(cx=cx, cy=cy, w=w, h=h, rot=rot)+ return self._add(m_)+++# ================================================================ the scene+class Grading:+ PAPERS = PAPERS++ def __init__(self, W=1920, H=1080, seed=0, keep_stages=True, stages_dir=None):+ self.W, self.H = W, H+ self.seed = 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.items = []+ self.bg = np.ones((H, W, 3), np.float32) * hexc(FELT)+ self._pen = None+ self._stamper = None+ self._post = None++ def _seed(self):+ return int(self.rng.integers(1 << 30))++ # ------------------------------------------------------------ desk and light+ def desk(self, colour=FELT, nap=1.0):+ """green felt: soft mottle, fine fuzz, a few pills of lint"""+ H, W = self.H, self.W+ s = self.seed+ mott = noise2d(H, W, 260, 4, s + 11) - 0.5+ mid = noise2d(H, W, 40, 3, s + 12) - 0.5+ fz = blur(self.rng.normal(0, 1, (H, W)).astype(np.float32), 0.8)+ fz /= fz.std() + 1e-6+ tex = 1 + nap * (0.15 * mott + 0.07 * mid + 0.035 * fz)+ col = _c(colour)+ bg = col[None, None, :] * tex[..., None]+ im = Image.new('L', (W, H), 0); d = ImageDraw.Draw(im)+ for _ in range(int(900 * nap)):+ x, y = self.rng.uniform(0, W), self.rng.uniform(0, H)+ a = self.rng.uniform(0, np.pi); L = self.rng.uniform(3, 10)+ d.line([(x, y), (x + np.cos(a) * L, y + np.sin(a) * L)], fill=int(self.rng.uniform(40, 120)), width=1)+ lint = blur(np.asarray(im, np.float32) / 255, 0.6)+ bg = bg * (1 + 0.25 * lint[..., None])+ self.bg = bg.astype(np.float32)++ 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)+ # one warm lamp upper left: a broad, gentle falloff, then a vignette and a little grain+ dx, dy = X / W - 0.32, Y / H - 0.12+ lamp = 1.07 - 0.20 * np.clip(dx * dx * 1.1 + dy * dy * 0.9, 0, 1.4)+ r = np.hypot((X - W / 2) / W, (Y - H / 2) / H)+ vig = 1 - 0.16 * r ** 2 * 2.0+ grain = 1 + 0.014 * (noise2d(H, W, 1.0, 1, self.seed + 99) - 0.5)+ warm = np.array([1.015, 1.0, 0.975], np.float32)+ self._post = ((lamp * vig * grain)[..., None] * warm).astype(np.float32)+ return self._post++ # ------------------------------------------------------------ papers+ def sheet(self, x, y, w, h, tint=PAPERS['sheet'], rot=0.0, stack=2, radius=3, margin=40, seed=None, grain=1.0):+ """an answer sheet (with `stack` more sheets showing underneath). Returns a Paper"""+ st = [(9, 6, 0.93), (5, 3, 0.965)][-stack:] if stack else []+ return Paper(self, x, y, w, h, tint, rot, st, radius, margin, self._seed() if seed is None else seed, grain)++ def card(self, x, y, w, h, tint=PAPERS['card'], rot=0.0, radius=4, margin=110, seed=None, grain=1.0):+ """a card or slip (margin leaves room for a clip standing above its edge). Returns a Paper"""+ return Paper(self, x, y, w, h, tint, rot, [], radius, margin, self._seed() if seed is None else seed, grain)++ def place(self, paper, lift=0.0, dx=0.0, dy=0.0, rot=0.0):+ """show a paper: laid down (all zero), or lifted `lift` (0..1), held off by dx, dy px and turned rot degrees+ more. The first place() puts it on top of everything placed so far"""+ paper.state = (float(lift), float(dx), float(dy), float(rot))+ if not any(it is paper for it in self.items):+ self.items.append(paper)++ def remove(self, paper):+ self.items = [it for it in self.items if it is not paper]++ # ------------------------------------------------------------ props+ def pen(self, x=None, y=None, lift=0.0, angle=28.0, scale=1.0):+ """the red pen lying at `angle` degrees (tip toward upper left), tip on (x, y) in canvas coordinates;+ lift 0 = writing, 1 = held well above the paper. pen(None) puts it away"""+ self._pen = None if x is None else (float(x), float(y), float(lift), float(angle), float(scale))++ def write(self, mark, progress, lift=0.0, angle=28.0):+ """set a mark's progress and bring the pen tip to its writing front"""+ mark.progress = progress+ tp = mark.tip(progress)+ paper = mark.paper if hasattr(mark, 'paper') else mark.parts[0].paper+ if tp is not None:+ x, y = paper.to_canvas(*tp)+ self.pen(x, y, lift, angle)++ def stamper(self, mark=None, height=0.0):+ """the stamp above its impression at `height` (0..1); height 0 presses it (the impression appears, wet).+ stamper(None) takes it away"""+ if mark is None:+ self._stamper = None; return+ if height <= 1e-3:+ mark.progress = 1.0; mark.wet = 1.0+ self._stamper = (mark, float(height))++ # ------------------------------------------------------------ render+ def _paper_layers(self, p):+ rgb = p.rgb.copy()+ for m in p.marks:+ m.apply(rgb)+ return rgb, p.alpha++ def _warp(self, p, arrs):+ cx, cy, s, rot = p.pose()+ lift, dx, dy, drot = p.state+ LW, LH = p.LW, p.LH+ if s == 1 and rot == 0:+ ox, oy = int(round(p.X0 + dx)), int(round(p.Y0 + dy))+ return (oy, ox), arrs+ th = np.deg2rad(rot); c, si = np.cos(th), np.sin(th)+ corners = np.array([[-LW / 2, -LH / 2], [LW / 2, -LH / 2], [LW / 2, LH / 2], [-LW / 2, LH / 2]]) * s+ Pc = np.stack([cx + corners[:, 0] * c + corners[:, 1] * si, cy - corners[:, 0] * si + corners[:, 1] * c], 1)+ bx0, by0 = int(np.floor(Pc[:, 0].min())) - 2, int(np.floor(Pc[:, 1].min())) - 2+ bx1, by1 = int(np.ceil(Pc[:, 0].max())) + 2, int(np.ceil(Pc[:, 1].max())) + 2+ a, b = c / s, -si / s+ d_, e = si / s, c / s+ cc = LW / 2 + a * (bx0 - cx) + b * (by0 - cy)+ f = LH / 2 + d_ * (bx0 - cx) + e * (by0 - cy)+ out = []+ for arr in arrs:+ chans = [arr[..., k] for k in range(arr.shape[2])] if arr.ndim == 3 else [arr]+ ws = [np.asarray(Image.fromarray(np.ascontiguousarray(ch_, np.float32), 'F').transform(+ (bx1 - bx0, by1 - by0), Image.AFFINE, (a, b, cc, d_, e, f), resample=Image.BILINEAR), np.float32) for ch_ in chans]+ out.append(np.stack(ws, -1) if arr.ndim == 3 else ws[0])+ return (by0, bx0), out++ @staticmethod+ def _paste_box(H, W, oy, ox, h, w):+ y0, x0 = max(0, oy), max(0, ox)+ y1, x1 = min(H, oy + h), min(W, ox + w)+ if y1 <= y0 or x1 <= x0: return None+ return (slice(y0, y1), slice(x0, x1)), (slice(y0 - oy, y1 - oy), slice(x0 - ox, x1 - ox))++ def _shadow(self, I, A, oy, ox, lift):+ """the paper's shadow on whatever is under it: wide and soft while lifted, a contact line once down"""+ h, w = A.shape+ off = (5 + 34 * lift, 8 + 48 * lift)+ sig = 4.0 + 18 * lift+ pad = int(3 * sig + max(off) + 4)+ Ap = np.pad(A, pad)+ far = blur(shift(Ap, off[0], off[1]), sig) * (0.50 - 0.22 * lift)+ near = blur(shift(Ap, 1.5, 2.5), 1.6) * 0.42 * (1 - min(1.0, lift * 1.6))+ S = 1 - (1 - far) * (1 - near)+ hit = self._paste_box(self.H, self.W, oy - pad, ox - pad, h + 2 * pad, w + 2 * pad)+ if hit is None: return+ (cy_, cx_), (ly, lx) = hit+ I[cy_, cx_] *= 1 - S[ly, lx][..., None] * (1 - np.array(SHADOW, np.float32))++ def _render_pen(self, I, x, y, lift, angle, scale):+ H, W = self.H, self.W+ s = scale * (1 + 0.05 * lift)+ L, R = 664.0 * s, 19.0 * s+ th = np.deg2rad(angle)+ ax, ay = np.cos(th), np.sin(th) # along the pen, tip -> end+ bx_, by_ = -ay, ax # across+ # --- shadow: the tip is at height z0, the end is held up (z grows along the pen); light from the upper left+ z0 = 2 + 60 * lift+ k = 0.15+ dvec = np.array([0.50, 0.80], np.float32)+ ex, ey = x + ax * L, y + ay * L+ sx0 = int(min(x, ex) - R - 30); sy0 = int(min(y, ey) - R - 30)+ sx1 = int(max(x, ex) + (z0 + k * L) * dvec[0] + R + 60); sy1 = int(max(y, ey) + (z0 + k * L) * dvec[1] + R + 60)+ sx0, sy0, sx1, sy1 = max(0, sx0), max(0, sy0), min(W, sx1), min(H, sy1)+ if sx1 > sx0 and sy1 > sy0:+ Y, X = np.mgrid[sy0:sy1, sx0:sx1].astype(np.float32)+ px, py = X - x, Y - y+ da = dvec[0] * ax + dvec[1] * ay+ db = dvec[0] * bx_ + dvec[1] * by_+ uq = (px * ax + py * ay - z0 * da) / (1 + k * da)+ vq = px * bx_ + py * by_ - (z0 + k * uq) * db+ rad = np.where(uq < 38 * s, 2.2 * s + (uq / (38 * s)) * 10 * s, np.where(uq < 164 * s, 16 * s, R))+ inside = np.clip(rad - np.abs(vq) + 0.5, 0, 1) * np.clip(uq + 0.5, 0, 1) * np.clip(L - uq + 0.5, 0, 1)+ near_w = np.exp(-np.clip(uq, 0, None) / (140 * s))+ sh = blur(inside, 2.0 + 4 * lift) * (0.46 - 0.12 * lift) * near_w + blur(inside, 9.0 + 8 * lift) * 0.30 * (1 - near_w)+ I[sy0:sy1, sx0:sx1] *= 1 - np.clip(sh, 0, 1)[..., None] * (1 - np.array(SHADOW, np.float32))+ # --- the pen itself, shaded as a cylinder+ bx0 = int(min(x, ex) - R - 4); by0 = int(min(y, ey) - R - 4)+ bx1 = int(max(x, ex) + R + 4); by1 = int(max(y, ey) + R + 4)+ bx0, by0, bx1, by1 = max(0, bx0), max(0, by0), min(W, bx1), min(H, by1)+ if bx1 <= bx0 or by1 <= by0: return+ Y, X = np.mgrid[by0:by1, bx0:bx1].astype(np.float32)+ px, py = X - x, Y - y+ u = (px * ax + py * ay) / s+ v = (px * bx_ + py * by_) / s+ r = np.full(u.shape, 19.0, np.float32)+ r = np.where(u < 38, 2.2 + np.clip(u - 2, 0, None) / 36 * 9.8, r)+ r = np.where((u >= 38) & (u < 161), 16.0, r)+ r = np.where(u >= 642, 18.5 * np.sqrt(np.clip(1 - ((u - 642) / 22) ** 2, 0, 1)), r)+ r = np.where((u >= 611) & (u < 642), 18.5, r)+ a = np.clip((r - np.abs(v)) * s + 0.5, 0, 1) * np.clip(u * s + 0.5, 0, 1) * np.clip((664 - u) * s + 0.5, 0, 1)+ if a.max() <= 0: return+ nv = np.clip(v / np.maximum(r, 1e-3), -1, 1)+ nz = np.sqrt(np.clip(1 - nv * nv, 0, 1))+ # light from the upper left, in pen space: its across-component+ Lc = np.array([-0.45, -0.62, 0.64], np.float32); Lc /= np.linalg.norm(Lc)+ lb = Lc[0] * bx_ + Lc[1] * by_+ ndl = np.clip(nv * lb + nz * Lc[2], 0, 1)+ Hh = Lc + np.array([0, 0, 1], np.float32); Hh /= np.linalg.norm(Hh)+ hb = Hh[0] * bx_ + Hh[1] * by_+ ndh = np.clip(nv * hb + nz * Hh[2], 0, 1)+ col = np.zeros(u.shape + (3,), np.float32)+ # chrome: an environment of a bright window band and a dark band+ env = 0.50 + 0.48 * np.exp(-((nv - lb * 0.75) / 0.16) ** 2) - 0.30 * np.exp(-((nv + 0.35) / 0.22) ** 2) - 0.25 * (1 - nz) ** 2+ chrome = np.clip(env, 0.05, 1.0)[..., None] * np.array([0.92, 0.93, 0.95], np.float32)+ lac = np.array([0.74, 0.05, 0.07], np.float32)+ lacq = lac * (0.30 + 0.75 * ndl)[..., None] + (0.55 * ndh ** 60)[..., None] \+ + (0.42 * np.exp(-((nv - lb * 0.62) / 0.07) ** 2))[..., None] * np.array([1.0, 0.92, 0.9], np.float32)+ rub = np.array([0.075, 0.075, 0.085], np.float32) * (0.5 + 0.9 * ndl)[..., None] + (0.10 * ndh ** 10)[..., None]+ ridge = np.abs(((u - 48) % 8) - 4) < 1.1+ rub = np.where(((u >= 46) & (u < 156) & ridge)[..., None], rub * 0.35, rub)+ rub = np.where(((u >= 46) & (u < 156) & (np.abs(((u - 50.2) % 8) - 4) < 0.6))[..., None], rub + 0.05, rub)+ ball = np.array([0.24, 0.24, 0.26], np.float32) * (0.5 + 0.6 * ndl)[..., None]+ col = np.where((u < 3)[..., None], ball, col)+ col = np.where(((u >= 3) & (u < 38))[..., None], chrome * 0.95, col)+ col = np.where(((u >= 38) & (u < 161))[..., None], rub, col)+ col = np.where(((u >= 161) & (u < 171))[..., None], chrome, col)+ col = np.where(((u >= 171) & (u < 603))[..., None], lacq, col)+ col = np.where(((u >= 603) & (u < 611))[..., None], chrome, col)+ col = np.where((u >= 611)[..., None], lacq, col)+ # the clip: a chrome strip lying on top of the barrel, its shadow beside it, a rivet at its root+ clip_m = np.clip((v + 8.5) * s + 0.5, 0, 1) * np.clip((2 - v) * s + 0.5, 0, 1) * np.clip((u - 482) * s + 0.5, 0, 1) * np.clip((656 - u) * s + 0.5, 0, 1)+ clip_sh = np.clip((v - 2) * s + 0.5, 0, 1) * np.clip((6.5 - v) * s + 0.5, 0, 1) * (u > 486) * (u < 654)+ col *= (1 - 0.45 * clip_sh)[..., None]+ cenv = (0.62 + 0.36 * np.exp(-((v + 5.5) / 1.6) ** 2) - 0.25 * np.exp(-((v - 0.8) / 1.2) ** 2))+ col = col * (1 - clip_m[..., None]) + (np.clip(cenv, 0, 1)[..., None] * np.array([0.9, 0.91, 0.93], np.float32)) * clip_m[..., None]+ rv = np.hypot(u - 486, v + 3.2)+ rivet = np.clip((4.6 - rv) * s + 0.5, 0, 1)+ col = col * (1 - rivet[..., None]) + (0.55 + 0.4 * np.clip(-(u - 486 + v + 3.2) / 6, -1, 1))[..., None] * np.array([0.92, 0.92, 0.94], np.float32) * rivet[..., None]+ # a soft dark rim at the silhouette+ rim = 1 - 0.35 * (1 - nz) ** 3+ col *= rim[..., None]+ I[by0:by1, bx0:bx1] = I[by0:by1, bx0:bx1] * (1 - a[..., None]) + col * a[..., None]++ def _render_stamper(self, I, mark, height):+ p = mark.paper+ gm = mark.geom+ cx, cy = p.to_canvas(gm['cx'], gm['cy'])+ rot = gm['rot'] + p.pose()[3]+ s = 1 + 0.10 * height+ bw, bh = (gm['w'] + 22) * s, (gm['h'] + 22) * s+ pad = int(40 + 60 * height)+ size = int(max(bw, bh) + 2 * pad)+ ss = 2+ # shadow of the block on the paper+ th = np.deg2rad(rot)+ def rr_mask(w_, h_, r_, cx_, cy_):+ im = Image.new('L', (size * ss, size * ss), 0)+ ImageDraw.Draw(im).rounded_rectangle(((cx_ - w_ / 2) * ss, (cy_ - h_ / 2) * ss, (cx_ + w_ / 2) * ss, (cy_ + h_ / 2) * ss), radius=r_ * ss, fill=255)+ return np.asarray(im.rotate(np.rad2deg(th), resample=Image.BICUBIC).resize((size, size), Image.BOX), np.float32) / 255+ c0 = size / 2+ blk = rr_mask(bw, bh, 9 * s, c0, c0)+ oy, ox = int(round(cy - c0)), int(round(cx - c0))+ off = (4 + 46 * height, 6 + 64 * height)+ sig = 3 + 16 * height+ SP = int(3 * sig + max(off) + 4)+ Ap = np.pad(blk, SP)+ S = blur(shift(Ap, off[0], off[1]), sig) * (0.55 - 0.25 * height) + blur(shift(Ap, 1, 2), 1.5) * 0.4 * (height < 0.05)+ hit = self._paste_box(self.H, self.W, oy - SP, ox - SP, size + 2 * SP, size + 2 * SP)+ if hit is not None:+ (cy_, cx_), (ly, lx) = hit+ I[cy_, cx_] *= 1 - np.clip(S[ly, lx], 0, 1)[..., None] * (1 - np.array(SHADOW, np.float32))+ # the block: varnished beech, grain along its length, bevelled edges; a turned walnut knob in the middle+ Y, X = np.mgrid[0:size, 0:size].astype(np.float32)+ u = (X - c0) * np.cos(th) - (Y - c0) * np.sin(th)+ v = (X - c0) * np.sin(th) + (Y - c0) * np.cos(th)+ # long grain: fine variation across the block, slow along it, a little warp+ gr = noise2d(220, 14, 2.2, 3, self.seed + 5)+ warp = noise2d(40, 40, 14, 2, self.seed + 6) - 0.5+ vv = (v / bh * 0.5 + 0.5) * 219 + 9 * _sample(warp, (v / bh * 0.5 + 0.5) * 39, (u / bw * 0.5 + 0.5) * 39)+ grain = _sample(gr, vv, (u / bw * 0.5 + 0.5) * 13)+ wood = np.array([0.70, 0.49, 0.29], np.float32) * (0.86 + 0.24 * smoothstep(0.3, 0.8, grain))[..., None]+ bv = blur(blk, 3.0 * s)+ gy, gx = np.gradient(bv)+ lit = np.clip(-(gx * -0.55 + gy * -0.83) * 6.0, -1, 1)+ wood = wood * (1 + 0.45 * lit)[..., None] * (0.86 + 0.14 * np.clip(bv * 1.4, 0, 1))[..., None]+ # a lathe-turned knob: domed, varnished, with turning rings and a darker collar where it meets the block+ rk = min(bh * 0.40, 34 * s)+ rho = np.hypot(u, v) / rk+ knob = np.clip((1 - rho) * rk + 0.5, 0, 1)+ nzk = np.sqrt(np.clip(1 - (rho * 0.92) ** 2, 0, 1))+ Lk = np.array([-0.45, -0.62, 0.64], np.float32); Lk /= np.linalg.norm(Lk)+ nxk, nyk = (X - c0) / rk * 0.92, (Y - c0) / rk * 0.92+ dk = np.clip(nxk * Lk[0] + nyk * Lk[1] + nzk * Lk[2], 0, 1)+ Hk = (Lk + np.array([0, 0, 1], np.float32)); Hk /= np.linalg.norm(Hk)+ sk = np.clip(nxk * Hk[0] + nyk * Hk[1] + nzk * Hk[2], 0, 1) ** 30+ rings = 1 - 0.10 * (np.cos(rho * 9 * np.pi) > 0.6) - 0.22 * np.exp(-((rho - 0.86) / 0.05) ** 2)+ kcol = np.array([0.58, 0.35, 0.18], np.float32) * ((0.40 + 0.75 * dk) * rings)[..., None] + (0.45 * sk)[..., None]+ ksh = blur(shift(knob, 6 * s, 9 * s), 4 * s) * 0.45+ wood *= (1 - ksh)[..., None]+ col = wood * (1 - knob[..., None]) + kcol * knob[..., None]+ hit = self._paste_box(self.H, self.W, oy, ox, size, size)+ if hit is None: return+ (cy_, cx_), (ly, lx) = hit+ a = blk[ly, lx][..., None]+ I[cy_, cx_] = I[cy_, cx_] * (1 - a) + col[ly, lx] * a++ def render(self):+ I = self.bg.copy()+ for p in self.items:+ if p.state is None: continue+ rgb, A = self._paper_layers(p)+ (oy, ox), (rgb_w, A_w) = self._warp(p, [rgb * p.alpha[..., None], A])+ self._shadow(I, A_w, oy, ox, p.state[0])+ h, w = A_w.shape+ hit = self._paste_box(self.H, self.W, oy, ox, h, w)+ if hit is None: continue+ (cy_, cx_), (ly, lx) = hit+ a = A_w[ly, lx][..., None]+ I[cy_, cx_] = I[cy_, cx_] * (1 - a) + rgb_w[ly, lx]+ if self._stamper is not None:+ self._render_stamper(I, *self._stamper)+ if self._pen is not None:+ self._render_pen(I, *self._pen)+ return I++ def composite(self):+ I = self.render() * self._postfx()+ return Image.fromarray((np.clip(I, 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