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 ballpoint doodle style (59 total); draw-on GIFs for Moon River and Watercolour Washes
cloveric02fd85e2cfdb
diff --git a/README.md b/README.mdindex d74133b..1f44e98 100644--- a/README.md+++ b/README.md@@ -1,51 +1,54 @@# Claude Drawing · Claude 绘图-**Claude paints with code — no image model.** Fifty-eight styles, from ink wash and impasto oil to clay, cyanotype, stained glass, a Roman mosaic, Delft tiles, a cyberpunk street, a ray-traced ball pit, low-poly 3D, a thermal camera, an X-ray, a VHS tape and a synthwave sunset.-**不用生图模型,Claude 用代码一笔一笔作画。** 五十八种画风,从水墨、油画到黏土、蓝晒、彩色玻璃花窗、罗马马赛克、代尔夫特蓝瓷砖、赛博朋克、光线追踪的小球海、低多边形 3D、热成像、X 光片、VHS 录像带和 Synthwave 落日。+**Claude paints with code — no image model.** Fifty-nine styles, from ink wash and impasto oil to clay, cyanotype, stained glass, a Roman mosaic, Delft tiles, a cyberpunk street, a ray-traced ball pit, low-poly 3D, a thermal camera, an X-ray, a VHS tape and a synthwave sunset.+**不用生图模型,Claude 用代码一笔一笔作画。** 五十九种画风,从水墨、油画到黏土、蓝晒、彩色玻璃花窗、罗马马赛克、代尔夫特蓝瓷砖、赛博朋克、光线追踪的小球海、低多边形 3D、热成像、X 光片、VHS 录像带和 Synthwave 落日。[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 · 绘本角色动画** |-|  |  |  |+|  |  |  |+| **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 · 圆珠笔涂鸦** |+|  |  |  |### Gallery · 画廊@@ -53,66 +56,66 @@|---|---|| **八万四千法门** · *Many Paths, One Summit*<br><sub>Ink wash · 水墨</sub> | **月印万川** · *One Moon in Ten Thousand Rivers*<br><sub>Ink wash · 水墨</sub> || <img src="examples/bawansiqian.jpg" width="100%"> | <img src="examples/moon_river.jpg" width="100%"> |-| **秋日湖畔** · *Autumn Lake*<br><sub>Watercolour · 水彩</sub> | **水彩底纹** · *Watercolour Washes*<br><sub>Watercolour · 水彩 — a background for explainer videos · 讲解视频的背景</sub> |-| <img src="examples/watercolor_autumn.jpg" width="100%"> | <img src="examples/watercolor_washes.jpg" width="100%"> |-| **热气球小镇** · *Balloon Day*<br><sub>Paper collage · 剪纸拼贴</sub> | **午后甜点** · *Afternoon Dessert*<br><sub>Coloured pencil · 韩国彩铅</sub> |-| <img src="examples/papercut_balloons.jpg" width="100%"> | <img src="examples/colorpencil_dessert.jpg" width="100%"> |-| **夏空** · *Summer Sky*<br><sub>Anime · 日本动漫</sub> | **灵感生长** · *Growing Ideas*<br><sub>Editorial · 编辑风手绘</sub> |-| <img src="examples/anime_summer.jpg" width="100%"> | <img src="examples/editorial_ideas.jpg" width="100%"> |-| **麦田星空** · *Swirling Sky over the Wheat Field*<br><sub>Impasto oil · 油画厚涂</sub> | **富士曙** · *Fuji at Dawn*<br><sub>Ukiyo-e · 浮世绘</sub> |-| <img src="examples/oil_wheatfield.jpg" width="100%"> | <img src="examples/ukiyoe_fuji.jpg" width="100%"> |-| **雨夜咖啡店** · *Rainy Night Cafe*<br><sub>Pixel art · 像素风</sub> | **灯塔岛** · *Lighthouse Island*<br><sub>Stop-motion clay · 黏土定格</sub> |-| <img src="examples/pixel_rainy_cafe.png" width="100%"> | <img src="examples/clay_lighthouse.jpg" width="100%"> |-| **蓝晒植物** · *Sun-Print Botanicals*<br><sub>Cyanotype · 蓝晒</sub> | **家** · *Home Sampler*<br><sub>Cross-stitch · 十字绣</sub> |-| <img src="examples/cyanotype_botanicals.jpg" width="100%"> | <img src="examples/stitch_sampler.jpg" width="100%"> |-| **Aurora 64 收音机** · *Aurora 64 Radio*<br><sub>Vintage instrument panel · 复古仪器面板</sub> | **周末市集** · *Weekend Market*<br><sub>Sticker collage × receipt · 贴纸拼贴 · 小票</sub> |-| <img src="examples/panel_radio.jpg" width="100%"> | <img src="examples/sticker_market.jpg" width="100%"> |-| **咖啡萃取实验** · *Coffee Brewing Experiment*<br><sub>Lab notebook × stickers · 实验笔记本 · 贴纸</sub> | **为什么天空是蓝的** · *Why Is the Sky Blue?*<br><sub>Chalkboard · 黑板板书</sub> |-| <img src="examples/notebook_brewing.jpg" width="100%"> | <img src="examples/chalk_lesson.jpg" width="100%"> |-| **霓虹不夜城** · *Neon District*<br><sub>Cyberpunk · 赛博朋克</sub> | **早安吐司** · *Good Morning, Toast*<br><sub>Hand-drawn cartoon · 卡通手绘</sub> |-| <img src="examples/cyberpunk_neon_street.jpg" width="100%"> | <img src="examples/cartoon_toaster.jpg" width="100%"> |-| **岛上的气象站** · *Island Weather Station*<br><sub>Isometric 2.5D · 等轴 2.5D</sub> | **从这扇窗到那扇窗** · *From Window to Window*<br><sub>Continuous line art · 单线画</sub> |-| <img src="examples/isometric_weather_island.jpg" width="100%"> | <img src="examples/lineart_paper_plane.jpg" width="100%"> |-| **浮出** · *Rise*<br><sub>Soft 3D · 柔光 3D</sub> | **一滴水的旅程** · *A Drop's Round Trip*<br><sub>Shape morph · 形变动画</sub> |-| <img src="examples/soft3d_rise.jpg" width="100%"> | <img src="examples/morph_water_cycle.jpg" width="100%"> |-| **好奇心周刊 · 拆开看看** · *Curiosity Weekly · Take It Apart*<br><sub>Newspaper collage · 报刊拼贴</sub> | **晨间计划** · *Morning Plan*<br><sub>Aurora glassmorphism · 弥散玻璃</sub> |-| <img src="examples/newscollage_curiosity.jpg" width="100%"> | <img src="examples/aurora_morning.jpg" width="100%"> |-| **形与色** · *Form & Colour*<br><sub>Bauhaus geometric · 包豪斯几何</sub> | **海岸线 1987** · *Coastline 1987*<br><sub>Retro synthwave · 复古 Synthwave</sub> |-| <img src="examples/bauhaus_form_colour.jpg" width="100%"> | <img src="examples/synthwave_coastline.jpg" width="100%"> |-| **草莓杯垫** · *Strawberry Coaster*<br><sub>Perler beads · 拼豆</sub> | **迁徙季** · *Migration Season*<br><sub>Petroglyph · 岩画</sub> |-| <img src="examples/perler_strawberry_coaster.jpg" width="100%"> | <img src="examples/petroglyph_migration.jpg" width="100%"> |-| **尼罗河丰收** · *Harvest on the Nile*<br><sub>Egyptian tomb painting · 古埃及墓室壁画</sub> | **港口渔获** · *The Day's Catch*<br><sub>Roman mosaic · 罗马马赛克</sub> |-| <img src="examples/tomb_harvest.jpg" width="100%"> | <img src="examples/mosaic_harbor.jpg" width="100%"> |-| **四季之窗** · *Window of the Seasons*<br><sub>Stained glass · 彩色玻璃花窗</sub> | **星辰之书** · *Liber Stellarum*<br><sub>Illuminated manuscript · 泥金手抄本</sub> |-| <img src="examples/stainedglass_seasons.jpg" width="100%"> | <img src="examples/illuminated_starchart.jpg" width="100%"> |-| **扑翼机** · *The Ornithopter*<br><sub>Leonardo codex · 达·芬奇手稿</sub> | **剪影小像** · *Shades of the Wren Household*<br><sub>Silhouette · 剪影</sub> |-| <img src="examples/codex_ornithopter.jpg" width="100%"> | <img src="examples/silhouette_family.jpg" width="100%"> |-| **马戏团来了** · *The Circus Is Coming*<br><sub>Letterpress poster · 凸版印刷海报</sub> | **无线电** · *Radio*<br><sub>Soviet constructivism · 苏联构成主义</sub> |-| <img src="examples/letterpress_circus.jpg" width="100%"> | <img src="examples/constructivism_radio.jpg" width="100%"> |-| **夜行快车** · *Night Express*<br><sub>Art Deco · 装饰艺术</sub> | **火箭小队** · *Rocket Squad*<br><sub>Golden-age comic · 黄金时代漫画</sub> |-| <img src="examples/artdeco_express.jpg" width="100%"> | <img src="examples/comic_rocket.jpg" width="100%"> |-| **猫的六种心情** · *Six Moods of a Cat*<br><sub>Pop silkscreen · 波普丝网</sub> | **发射记录** · *Liftoff Trace*<br><sub>ASCII art (line printer) · ASCII 字符画(行式打印机)</sub> |-| <img src="examples/popart_cat_moods.jpg" width="100%"> | <img src="examples/lineprinter_launch.jpg" width="100%"> |-| **峡谷飞行** · *Canyon Run*<br><sub>Low poly · 低多边形</sub> | **放风筝** · *Hold On*<br><sub>Stencil graffiti · 喷漆模板涂鸦</sub> |-| <img src="examples/lowpoly_canyon.jpg" width="100%"> | <img src="examples/stencil_kite.jpg" width="100%"> |-| **三晚露营** · *Three Nights Out*<br><sub>Embroidered patches · 刺绣徽章</sub> | **灯塔剖面** · *Halvard Rock Light*<br><sub>Blueprint · 蓝图工程图</sub> |-| <img src="examples/patch_camping.jpg" width="100%"> | <img src="examples/blueprint_lighthouse.jpg" width="100%"> |-| **我的周末** · *My Weekend*<br><sub>Children's crayon · 儿童蜡笔画</sub> | **今天带伞吗** · *Bring an Umbrella?*<br><sub>Green-screen CRT terminal · 绿屏终端(荧光字符画)</sub> |-| <img src="examples/crayon_picnic.jpg" width="100%"> | <img src="examples/crt_weather.jpg" width="100%"> |-| **厨房里的温度** · *Kitchen Heat Map*<br><sub>Thermal camera · 热成像</sub> | **一阵风** · *The Gust*<br><sub>Delft tiles · 代尔夫特蓝瓷砖</sub> |-| <img src="examples/thermal_kitchen.jpg" width="100%"> | <img src="examples/delft_canal.jpg" width="100%"> |-| **篝火旁的岩洞** · *The Hunt by the Fire*<br><sub>Cave painting · 洞穴壁画</sub> | **窗台花园** · *Windowsill Garden*<br><sub>1-bit paint program · 1-bit 早期画图软件</sub> |-| <img src="examples/cave_hunt.jpg" width="100%"> | <img src="examples/macpaint_garden.jpg" width="100%"> |-| **赛跑与赛车** · *Games on a Vase*<br><sub>Greek black-figure vase · 古希腊黑绘陶瓶</sub> | **老街角的自行车** · *The Bread Run*<br><sub>Graphite pencil · 铅笔素描</sub> |-| <img src="examples/blackfigure_games.jpg" width="100%"> | <img src="examples/graphite_bicycle.jpg" width="100%"> |-| **行李安检** · *Security Check*<br><sub>X-ray · X 光片</sub> | **早晨的闹钟** · *Seven O'Clock*<br><sub>1930s rubber hose · 1930 年代黑白橡皮管动画</sub> |-| <img src="examples/xray_luggage.jpg" width="100%"> | <img src="examples/rubberhose_morning.jpg" width="100%"> |-| **雪夜归途** · *Homeward, First Snow*<br><sub>Linocut · 黑白麻胶版画</sub> | **吹蜡烛** · *Blow Out the Candles*<br><sub>VHS home video · VHS 家庭录像</sub> |-| <img src="examples/linocut_snowy_village.jpg" width="100%"> | <img src="examples/vhs_birthday.jpg" width="100%"> |-| **山间夜营** · *Night Camp*<br><sub>Flat vector · 扁平矢量</sub> | **小橡果的秋天** · *An Acorn's Autumn*<br><sub>Storybook animation · 绘本角色动画</sub> |-| <img src="examples/flatvector_night_camp.jpg" width="100%"> | <img src="examples/storybook_acorn.jpg" width="100%"> |--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. No diffusion model, no API, no stock art. It is just Python with **numpy + Pillow** on a CPU: from 0.1 s (pixel art) to about 45 s (the soft 3D ray tracer) per 1920×1080 image.+| **秋日湖畔** · *Autumn Lake*<br><sub>Watercolour · 水彩</sub> | **热气球小镇** · *Balloon Day*<br><sub>Paper collage · 剪纸拼贴</sub> |+| <img src="examples/watercolor_autumn.jpg" width="100%"> | <img src="examples/papercut_balloons.jpg" width="100%"> |+| **午后甜点** · *Afternoon Dessert*<br><sub>Coloured pencil · 韩国彩铅</sub> | **夏空** · *Summer Sky*<br><sub>Anime · 日本动漫</sub> |+| <img src="examples/colorpencil_dessert.jpg" width="100%"> | <img src="examples/anime_summer.jpg" width="100%"> |+| **灵感生长** · *Growing Ideas*<br><sub>Editorial · 编辑风手绘</sub> | **麦田星空** · *Swirling Sky over the Wheat Field*<br><sub>Impasto oil · 油画厚涂</sub> |+| <img src="examples/editorial_ideas.jpg" width="100%"> | <img src="examples/oil_wheatfield.jpg" width="100%"> |+| **富士曙** · *Fuji at Dawn*<br><sub>Ukiyo-e · 浮世绘</sub> | **雨夜咖啡店** · *Rainy Night Cafe*<br><sub>Pixel art · 像素风</sub> |+| <img src="examples/ukiyoe_fuji.jpg" width="100%"> | <img src="examples/pixel_rainy_cafe.png" width="100%"> |+| **灯塔岛** · *Lighthouse Island*<br><sub>Stop-motion clay · 黏土定格</sub> | **蓝晒植物** · *Sun-Print Botanicals*<br><sub>Cyanotype · 蓝晒</sub> |+| <img src="examples/clay_lighthouse.jpg" width="100%"> | <img src="examples/cyanotype_botanicals.jpg" width="100%"> |+| **家** · *Home Sampler*<br><sub>Cross-stitch · 十字绣</sub> | **Aurora 64 收音机** · *Aurora 64 Radio*<br><sub>Vintage instrument panel · 复古仪器面板</sub> |+| <img src="examples/stitch_sampler.jpg" width="100%"> | <img src="examples/panel_radio.jpg" width="100%"> |+| **周末市集** · *Weekend Market*<br><sub>Sticker collage × receipt · 贴纸拼贴 · 小票</sub> | **咖啡萃取实验** · *Coffee Brewing Experiment*<br><sub>Lab notebook × stickers · 实验笔记本 · 贴纸</sub> |+| <img src="examples/sticker_market.jpg" width="100%"> | <img src="examples/notebook_brewing.jpg" width="100%"> |+| **为什么天空是蓝的** · *Why Is the Sky Blue?*<br><sub>Chalkboard · 黑板板书</sub> | **霓虹不夜城** · *Neon District*<br><sub>Cyberpunk · 赛博朋克</sub> |+| <img src="examples/chalk_lesson.jpg" width="100%"> | <img src="examples/cyberpunk_neon_street.jpg" width="100%"> |+| **早安吐司** · *Good Morning, Toast*<br><sub>Hand-drawn cartoon · 卡通手绘</sub> | **岛上的气象站** · *Island Weather Station*<br><sub>Isometric 2.5D · 等轴 2.5D</sub> |+| <img src="examples/cartoon_toaster.jpg" width="100%"> | <img src="examples/isometric_weather_island.jpg" width="100%"> |+| **从这扇窗到那扇窗** · *From Window to Window*<br><sub>Continuous line art · 单线画</sub> | **浮出** · *Rise*<br><sub>Soft 3D · 柔光 3D</sub> |+| <img src="examples/lineart_paper_plane.jpg" width="100%"> | <img src="examples/soft3d_rise.jpg" width="100%"> |+| **一滴水的旅程** · *A Drop's Round Trip*<br><sub>Shape morph · 形变动画</sub> | **好奇心周刊 · 拆开看看** · *Curiosity Weekly · Take It Apart*<br><sub>Newspaper collage · 报刊拼贴</sub> |+| <img src="examples/morph_water_cycle.jpg" width="100%"> | <img src="examples/newscollage_curiosity.jpg" width="100%"> |+| **晨间计划** · *Morning Plan*<br><sub>Aurora glassmorphism · 弥散玻璃</sub> | **形与色** · *Form & Colour*<br><sub>Bauhaus geometric · 包豪斯几何</sub> |+| <img src="examples/aurora_morning.jpg" width="100%"> | <img src="examples/bauhaus_form_colour.jpg" width="100%"> |+| **海岸线 1987** · *Coastline 1987*<br><sub>Retro synthwave · 复古 Synthwave</sub> | **草莓杯垫** · *Strawberry Coaster*<br><sub>Perler beads · 拼豆</sub> |+| <img src="examples/synthwave_coastline.jpg" width="100%"> | <img src="examples/perler_strawberry_coaster.jpg" width="100%"> |+| **迁徙季** · *Migration Season*<br><sub>Petroglyph · 岩画</sub> | **尼罗河丰收** · *Harvest on the Nile*<br><sub>Egyptian tomb painting · 古埃及墓室壁画</sub> |+| <img src="examples/petroglyph_migration.jpg" width="100%"> | <img src="examples/tomb_harvest.jpg" width="100%"> |+| **港口渔获** · *The Day's Catch*<br><sub>Roman mosaic · 罗马马赛克</sub> | **四季之窗** · *Window of the Seasons*<br><sub>Stained glass · 彩色玻璃花窗</sub> |+| <img src="examples/mosaic_harbor.jpg" width="100%"> | <img src="examples/stainedglass_seasons.jpg" width="100%"> |+| **星辰之书** · *Liber Stellarum*<br><sub>Illuminated manuscript · 泥金手抄本</sub> | **扑翼机** · *The Ornithopter*<br><sub>Leonardo codex · 达·芬奇手稿</sub> |+| <img src="examples/illuminated_starchart.jpg" width="100%"> | <img src="examples/codex_ornithopter.jpg" width="100%"> |+| **剪影小像** · *Shades of the Wren Household*<br><sub>Silhouette · 剪影</sub> | **马戏团来了** · *The Circus Is Coming*<br><sub>Letterpress poster · 凸版印刷海报</sub> |+| <img src="examples/silhouette_family.jpg" width="100%"> | <img src="examples/letterpress_circus.jpg" width="100%"> |+| **无线电** · *Radio*<br><sub>Soviet constructivism · 苏联构成主义</sub> | **夜行快车** · *Night Express*<br><sub>Art Deco · 装饰艺术</sub> |+| <img src="examples/constructivism_radio.jpg" width="100%"> | <img src="examples/artdeco_express.jpg" width="100%"> |+| **火箭小队** · *Rocket Squad*<br><sub>Golden-age comic · 黄金时代漫画</sub> | **猫的六种心情** · *Six Moods of a Cat*<br><sub>Pop silkscreen · 波普丝网</sub> |+| <img src="examples/comic_rocket.jpg" width="100%"> | <img src="examples/popart_cat_moods.jpg" width="100%"> |+| **发射记录** · *Liftoff Trace*<br><sub>ASCII art (line printer) · ASCII 字符画(行式打印机)</sub> | **峡谷飞行** · *Canyon Run*<br><sub>Low poly · 低多边形</sub> |+| <img src="examples/lineprinter_launch.jpg" width="100%"> | <img src="examples/lowpoly_canyon.jpg" width="100%"> |+| **放风筝** · *Hold On*<br><sub>Stencil graffiti · 喷漆模板涂鸦</sub> | **三晚露营** · *Three Nights Out*<br><sub>Embroidered patches · 刺绣徽章</sub> |+| <img src="examples/stencil_kite.jpg" width="100%"> | <img src="examples/patch_camping.jpg" width="100%"> |+| **灯塔剖面** · *Halvard Rock Light*<br><sub>Blueprint · 蓝图工程图</sub> | **我的周末** · *My Weekend*<br><sub>Children's crayon · 儿童蜡笔画</sub> |+| <img src="examples/blueprint_lighthouse.jpg" width="100%"> | <img src="examples/crayon_picnic.jpg" width="100%"> |+| **今天带伞吗** · *Bring an Umbrella?*<br><sub>Green-screen CRT terminal · 绿屏终端(荧光字符画)</sub> | **厨房里的温度** · *Kitchen Heat Map*<br><sub>Thermal camera · 热成像</sub> |+| <img src="examples/crt_weather.jpg" width="100%"> | <img src="examples/thermal_kitchen.jpg" width="100%"> |+| **一阵风** · *The Gust*<br><sub>Delft tiles · 代尔夫特蓝瓷砖</sub> | **篝火旁的岩洞** · *The Hunt by the Fire*<br><sub>Cave painting · 洞穴壁画</sub> |+| <img src="examples/delft_canal.jpg" width="100%"> | <img src="examples/cave_hunt.jpg" width="100%"> |+| **窗台花园** · *Windowsill Garden*<br><sub>1-bit paint program · 1-bit 早期画图软件</sub> | **赛跑与赛车** · *Games on a Vase*<br><sub>Greek black-figure vase · 古希腊黑绘陶瓶</sub> |+| <img src="examples/macpaint_garden.jpg" width="100%"> | <img src="examples/blackfigure_games.jpg" width="100%"> |+| **老街角的自行车** · *The Bread Run*<br><sub>Graphite pencil · 铅笔素描</sub> | **行李安检** · *Security Check*<br><sub>X-ray · X 光片</sub> |+| <img src="examples/graphite_bicycle.jpg" width="100%"> | <img src="examples/xray_luggage.jpg" width="100%"> |+| **早晨的闹钟** · *Seven O'Clock*<br><sub>1930s rubber hose · 1930 年代黑白橡皮管动画</sub> | **雪夜归途** · *Homeward, First Snow*<br><sub>Linocut · 黑白麻胶版画</sub> |+| <img src="examples/rubberhose_morning.jpg" width="100%"> | <img src="examples/linocut_snowy_village.jpg" width="100%"> |+| **吹蜡烛** · *Blow Out the Candles*<br><sub>VHS home video · VHS 家庭录像</sub> | **山间夜营** · *Night Camp*<br><sub>Flat vector · 扁平矢量</sub> |+| <img src="examples/vhs_birthday.jpg" width="100%"> | <img src="examples/flatvector_night_camp.jpg" width="100%"> |+| **小橡果的秋天** · *An Acorn's Autumn*<br><sub>Storybook animation · 绘本角色动画</sub> | **蛇梯棋大冒险** · *Snakes & Ladders, Round 7*<br><sub>Ballpoint doodle · 圆珠笔涂鸦</sub> |+| <img src="examples/storybook_acorn.jpg" width="100%"> | <img src="examples/ballpoint_board_game.jpg" width="100%"> |++Every mark above is computed: paper fibres, ink washes and mist, dry-brush strokes, pigment granulation and blooms, torn-paper edges, pencil wax on paper tooth, cel-shaded clouds, risograph grain and halftones, lit impasto relief, woodblock grain and bokashi, dithered pixels, plasticine lit like a film set, sunlight through leaves on Prussian blue, twisted thread on Aida cloth, machined knobs behind a backlit dial, die-cut vinyl with a laminate gloss, streaky thermal print, graphite catching the tooth of graph paper, highlighter pooling at the start of a swipe, chalk dust settling under half-erased lessons, rain-lit neon glass mirrored in a wet street, a blue-pencil rough under boiling brush ink, an island ray-traced under one soft sun, a single unbroken gold line, candy balls with softbox glints, one outline morphing through six shapes, halftone photos cut out with scissors, frosted glass blurring the real pixels behind it, screen-printed primaries out of register, a slit sun sinking behind a neon grid played off tape, hollow fuse beads on a pegboard melting together under an iron, pits knocked through desert varnish, a red grid showing through flaking plaster, stones laid row by row along an outline, daylight through leaded glass, burnished gold that mirrors the room, left-handed hatching in iron-gall ink, black paper cut with scissors, wood type printed a hair out of register, red and black plates slipping apart, airbrush fades inside knife-cut friskets, Ben-Day dots on yellowed newsprint, one photo key pulled across hand-painted colour, characters struck through a fading ribbon, flat-shaded triangles dithered to 15 bits, spray drifting past cut card, satin stitches catching the light by their angle, ink lines printed white on Prussian blue, wax scribbles skipping the paper's pits, phosphor glowing behind curved glass, heat leaking out of a kitchen, cobalt fired into tin glaze tile by tile, ochre blown onto rock lit by a fire, 1-bit patterns in an old paint program, slip silhouettes incised to the clay, graphite that never quite reaches black, X-rays adding up through a suitcase, grey cels shot on scratched film, gouge marks in a rolled-up block, a birthday smeared onto tape, seven flat colours lifting off each other, an acorn squashing and stretching through a world drawn as it goes, ballpoint ink blobbing at every corner of a hand-drawn game. No diffusion model, no API, no stock art. It is just Python with **numpy + Pillow** on a CPU: from 0.1 s (pixel art) to about 45 s (the soft 3D ray tracer) per 1920×1080 image.---@@ -120,7 +123,7 @@ Every mark above is computed: paper fibres, ink washes and mist, dry-brush strok### What it is-A [Claude Code](https://claude.com/claude-code) skill and a small painting library with fifty-eight styles:+A [Claude Code](https://claude.com/claude-code) skill and a small painting library with fifty-nine styles:| Style | Module | What makes it read as the real medium ||---|---|---|@@ -182,6 +185,7 @@ A [Claude Code](https://claude.com/claude-code) skill and a small painting libra| **VHS home video** | `lib/vhs.py` · `VHSCamcorder` | not a retro filter over a picture but the three steps a home-video frame really went through, each one leaving its own marks. The room is painted as surface colour lit by its lamps (a dim warm ambient, a floor lamp that throws scallops up and down the wall, candle flames that light the cake and the child's hair from the front), with self-lit things in their own buffer and the child right in front of the lens on a defocus layer. A consumer CCD camcorder then sees it: hand-held roll, white balance left on 'outdoor' under tungsten bulbs (an orange room, a blue window), a soft highlight knee, bloom, vertical CCD smear through the flames only, a short lag tail, gain noise in the shadows — and its character generator mixes a chunky dot-matrix OSD into the signal, so REC, the counter and the date stamp go onto tape with the picture. Finally the tape: 480 lines, luma low-passed with the playback sharpness halo, chroma smeared ~6× wider, averaged over two lines and delayed to the right (reds bleed out of their outlines), streaky luma and chroma noise, line-by-line timebase jitter, flagging at the top, a tracking-error band, head-switching tear, dropouts and a lifted black level || **Flat vector** | `lib/flatvector.py` · `FlatVector` | an artboard of crisp anti-aliased geometric shapes (analytic circles, filleted polygons, tapered capsules, spline land profiles) combined with boolean ops, with no outlines anywhere; seven flat hues, every other colour a tone or mix of them; one light for the whole board, so every object splits into a lit face and a shade face (faceted ridge lines on the mountains, pines split down the middle, a cloud's belly cut from the cloud itself); the vector-paper depth cue: each lifted layer first drops a short, soft, night-blue shadow on what is already there, so every overlap shows a thin seam; glow as stacked flat translucent rings; a faint per-layer fibre and a fine, fixed print grain || **Storybook animation** | `lib/storybook.py` · `Storybook` | a real animation, not a draw-on: every piece of scenery is pre-painted once with a reveal map (the moment the pen or brush reaches each pixel), so ink lines draw along their length, washes spread with a darker wet front and props pop in with an overshoot — and the hills, flowers and banks are drawn exactly as the character passes (`follow`). The character is rendered every frame from implicit shapes in its own frame, squashed and stretched with a volume-preserving affine along its motion, rested exactly on the ground, lit by one fixed light so the highlight stays put while it rolls; poses come from eased, sprung and ballistic choreography plus impact lines, dust puffs, speed lines and ripples. The closing line writes itself in stroke order (skeleton walk), and the same scene renders a journey poster with the key poses multiply-exposed on a pencil motion arc |+| **Ballpoint doodle** | `lib/ballpoint.py` · `Ballpoint` | ballpoint ink is an oil paste a rolling ball lays down, kept as optical density, so a line drawn twice, a crossing or a blob goes darker and more saturated (blue deepens to blue-violet, never flat black); every stroke starts dry and thin, drifts in pressure and width, skips a few pixels now and then, drops gloops where the pen stops and at sharp turns, and flicks off in a little hook; outlines are gone over twice, slightly off; every stroke presses a groove into the copy paper that catches the raking light, and the sheet carries the blind indentations of a shopping list written on the page above; coloured pencil is wax on the paper tooth, hatched in quick slanted patches that run past the lines, light on big areas and pressed hard on small ones; the handwriting is the skeleton of a thin hand font re-drawn as pen strokes, each letter resized, tilted and lifted off a wandering baseline, with a word scribbled out and written again |Ask Claude to *"draw it yourself"*, *"paint this with code"*, or *"claude绘图"*, and name a style if you like. Claude then:@@ -293,6 +297,7 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages- **VHS home video**: light the room, don't tint it: give the scene real lamps (`light`, `floor_lamp`, a `light` on every flame `cake` returns) and keep the ambient low, so the camcorder has something to clip and the corners have something to be noisy in. Let only point sources go far over the top — anything big over ~2 turns the CCD smear into a pillar across the frame. One strong complementary colour against the tungsten orange (a blue window, a green sofa, a teal shirt) does more than any filter. Paint the near subject on `layer(defocus=)`, tilt the camera a degree or two, and put the OSD in through the camera (`rec`, `datestamp`, `zoom_bar`) so it smears with the tape; keep the tracking band at the bottom, off the subject. Make OSD text from the dot-matrix font only — 1-dot gaps fill in, so check 0/8, W, M after the tape.- **Flat vector**: win with a few big shapes and empty space, not with detail: three or four land layers, one moon, a generous sky, and one small story told with one or two warm accents. Seven colours; every other shade is a tone of one of them. One light for the whole board, with the shade faces always on the far side. With no outlines, choose each object's colour against what sits behind it (an orange tent goes on the sand, not in front of the orange hills). Lift layers a few pixels for a soft seam of shadow, and keep texture around 1% so flat fields still read as flat. Put translucent shapes over a single background colour only. People, if any, are tiny silhouettes.- **Storybook animation**: the story is the acting, so choreograph first — anticipation before every big move (squash and lean away), stretch along the velocity, squash on every landing with impact lines and dust, a spring settle afterwards — and let the world be drawn by the character (`follow=` with a lead of 150–350 px, `pre=` for what is left of the start). Give `soft` in pixels, not as a fraction of a 2000-px layer, or the paint front turns into fog. Keep the camera still: only what moves is re-encoded, so 151 frames stay near 0.6 MB. On the poster, pick poses that sit apart along the path, draw the end state itself instead of a ghost on top of it, and hide the props' final positions.+- **Ballpoint doodle**: draw what sits in front first (the pieces), then let every later line stop at it with `clip` — the snakes, the ladders, the grid and the pencil all go round the pieces, the way a pen lifts at something already drawn. Keep big pencil areas light (pressure ~0.4) and small ones saturated (0.7–0.9), and let the hatching run a few px past the lines. Use red only for "this move" (hops, ring, arrow, the conclusion) and blue/black for everything else. Put every label inside an empty square or the margin — text split by a grid line or crowded by a sweat drop reads as a mistake. Keep the fold and the blind indentations faint; they should be found, not seen.### Roadmap@@ -304,7 +309,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,加上一个小巧的绘图库,内置五十九种画风:| 画风 | 模块 | 为什么看起来像真的 ||---|---|---|@@ -366,6 +371,7 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages| **VHS 家庭录像** | `lib/vhs.py` · `VHSCamcorder` | 不是在画面上盖一层复古滤镜,而是照一帧家庭录像真实经过的三步来做,每一步留下自己的痕迹:房间画成表面颜色,再由屋里的灯照亮(暗暗的暖色环境光,落地灯在墙上照出上下两片扇形光,烛焰从前面照亮蛋糕和孩子的头发),会发光的东西单独一层,镜头跟前的孩子画在离焦图层里;然后交给一台家用 CCD 摄像机:手持微倾,白平衡停在「室外」拍钨丝灯(屋里发橙、窗外发蓝),高光软膝、泛光,只有烛焰拉出竖向拖影,高光身后一小段拖尾,暗处增益噪声——摄像机的字符发生器把粗点阵 OSD 混进信号,REC、计数器和日期跟画面一起上带;最后是录像带:480 行,亮度低通再加回放锐化光晕,色度宽约 6 倍、隔行平均、往右延迟(红色渗出轮廓),条状亮度噪声和横向色度噪声、逐行时基抖动、顶部偏摆、跟踪噪带、磁头切换撕裂、掉磁白点、抬高的黑电平 || **扁平矢量** | `lib/flatvector.py` · `FlatVector` | 矢量软件的画板:边缘干净、抗锯齿的几何形(解析圆、圆角多边形、锥形胶囊、样条地块),可以并、交、减,全画没有一根描边;七种平涂色,其余颜色都是它们的深浅或相互调和;整幅只有一个光源,每样东西都分成亮面和暗面(山的折线山脊,松树从中间劈开,云的暗面是云减去挪动后的自己);「矢量纸片」的层次:每抬起一层,先往已有画面投一道短而柔的夜蓝色阴影,所以每处重叠都有一道细缝;光是一圈圈叠起来的平涂半透明光环;每层极淡的纤维纹,加固定的细颗粒 || **绘本角色动画** | `lib/storybook.py` · `Storybook` | 是真动画,不是阶段叠化:每样风景都预画一次,并记一张「揭示图」(笔或刷子在第几时刻碰到每个像素),所以墨线沿着笔路画出来、水彩带着一道略深的湿边晕开、小物件回弹着冒出来;山坡、小花、河岸正好在角色经过时画上(`follow`)。角色每帧用隐式曲面现画,沿运动方向做保体积的挤压拉伸,最低点正好贴地,光照固定在世界里(滚动时高光不跟着转);动作由缓动、弹簧和抛物线编排,配冲击线、白色尘团、速度线和水波。结尾一行字按笔顺一笔笔写出来(走骨架),同一个场景还能出一张旅程总图:关键姿态多次曝光在铅笔运动弧上 |+| **圆珠笔涂鸦** | `lib/ballpoint.py` · `Ballpoint` | 圆珠笔墨是滚珠压上去的油性墨膏,按光密度叠加:描两遍、交叉、墨团都会更深更饱和(蓝色叠成深蓝紫,不会是死黑);每一笔起笔干而细,压力和线宽一路漂移,偶尔断墨几像素,停笔和急转弯处掉墨团,抬笔甩出小钩;轮廓描两遍、略微错开;每一笔都在复印纸上压出凹槽,侧光下看得见,纸上还留着上一页购物单的无墨压痕;彩铅是挂在纸纹上的蜡,一块块斜向快速排线、出界,大面积轻、小面积重;手写字是细手写字体的骨架重新用笔描出来,每个字母各自缩放、倾斜、上下浮动,还有一个词划掉重写 |对 Claude 说「claude绘图」「你自己画」「用代码画」,也可以指定画风。它会:1. **先定构图**:层次、焦点、留白,而且画面要图解内容本身;@@ -453,6 +459,7 @@ python3 examples/linocut_snowy_village.py out.png # 黑白麻python3 examples/vhs_birthday.py out.png # VHS 家庭录像:吹蜡烛python3 examples/flatvector_night_camp.py out.png # 扁平矢量:山间夜营python3 examples/storybook_acorn.py out.jpg --gif out.gif # 绘本角色动画:小橡果的秋天+python3 examples/ballpoint_board_game.py out.png # 圆珠笔涂鸦:蛇梯棋大冒险```### 作画要点(Claude 交图前逐条自查)@@ -513,6 +520,7 @@ python3 examples/storybook_acorn.py out.jpg --gif out.gif # 绘本角- **VHS 家庭录像**:给房间打光,不要给画面调色:放真实的灯(`light`、`floor_lamp`,`cake` 返回的每个火苗各放一盏 `light`),环境光压低,摄像机才有东西可以过曝、暗角才有地方出噪点。只让点光源远远超出上限——大面积超过约 2 的地方会把 CCD 拖影拉成一根贯穿画面的光柱。在钨丝灯的满屏橙里放一块强补色(蓝色的窗、绿色的沙发、青绿的衣服),比任何滤镜都管用。离镜头太近的主体画在 `layer(defocus=)` 里,镜头歪一两度,OSD 通过摄像机加(`rec`、`datestamp`、`zoom_bar`),让它跟着录像带一起糊;跟踪噪带放在底边,别压主体。OSD 只用点阵字库,1 点宽的缝会被填死,过了录像带检查 0/8、W、M 读不读得出来。- **扁平矢量**:靠几个大形状和留白取胜,不靠细节:三四层地形、一个月亮、大片天空,用一两处暖色讲一件小事。只用 7 色,其余都是它们的深浅。整幅一个光源,暗面永远在背光那边。没有描边,所以每样东西的颜色要对着它身后的颜色来定(橙色帐篷放在黄沙上,别放在橙色山丘前)。每层抬起几像素,留一道柔和的阴影缝;纹理控制在 1% 左右,平涂看上去还得是平的。半透明形状只放在单一底色上。要画人,只画很小的剪影。- **绘本角色动画**:故事靠表演,先编排动作——每个大动作前都要有预备(压扁、往反方向后仰),沿速度方向拉伸,每次落地压扁并配冲击线和尘团,之后用弹簧回稳——再让世界跟着角色画出来(`follow=` 提前量 150–350 px,起点左边那段用 `pre=`)。柔边按像素给,别写成 2000 px 宽层的比例,否则湿边变成一团雾。镜头别动:只有动的地方重新编码,151 帧才能压在 0.6 MB 左右。总图里选沿路分得开的姿态,终点画最后一帧本身,别再叠残影,道具终点位置也藏掉。+- **圆珠笔涂鸦**:先画在前面的东西(棋子),后画的线都用 `clip` 在它前面停住——蛇、梯子、格线、彩铅都绕开棋子,就像笔走到已经画好的东西前会抬起来。大面积彩铅轻压(约 0.4),小面积压重(0.7–0.9),排线出界几像素。红笔只留给「这一步」(跳格、圈、箭头、结论),其余用蓝、黑。每个标注都放进空格子或页边:被格线劈开、被汗滴挤住的字看起来像画错了。折痕和无墨压痕要淡,是「找得到」而不是「一眼看见」。### 计划diff --git a/SKILL.md b/SKILL.mdindex a99e741..d19eb1b 100644--- a/SKILL.md+++ b/SKILL.md@@ -1,6 +1,6 @@---name: claude绘图-description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型,由 Claude 用代码一笔一笔「画」出图片(程序化绘画)。内置五十八种画风:中国水墨、水彩、剪纸拼贴、韩国彩铅、日本动漫、编辑风手绘(Riso)、油画厚涂(梵高式流向笔触+颜料浮雕打光)、浮世绘木版画(晕色、木纹、墨线主版、青海波)、像素风(低分辨率+Bayer 抖动+像素字体)、黏土定格(高度图捏出的彩泥+影棚打光)、蓝晒(普鲁士蓝日光晒图,植物剪影透光)、十字绣(Aida 布十字绣+回针绣+缎面绣+法式结)、复古仪器面板(60 年代收音机/仪器正面:柚木、拉丝铝、旋钮、刻度窗、指示灯)、贴纸拼贴·小票(模切乙烯贴纸、热敏小票、和纸胶带、吊牌、橡皮章)、实验笔记本·贴纸(线圈方格本、铅笔图表、荧光笔、红笔圈、便利贴)、黑板板书(墨绿石板、粉笔颗粒、板擦残影、示意图与公式)、赛博朋克(雨夜霓虹街道、玻璃管霓虹招牌、全息广告、湿路面倒影)、卡通手绘(蓝铅笔稿、毛笔线、错位平涂、赛璐璐阴影、逐帧抖线)、等轴 2.5D(正等轴微缩模型、一个太阳照出三面明暗、悬浮数据卡)、单线画(一根不断开的线一笔画完、唯一点睛色)、柔光 3D(光线追踪的糖果色小球海和鼓鼓的软字、景深)、形变动画(一条轮廓依次变形、洋葱皮残影、缓动曲线)、报刊拼贴(牛皮纸、手撕旧报纸、网点老照片、勒索信拼贴字)、弥散玻璃(弥散渐变、磨砂玻璃卡片界面)、包豪斯几何(三原色几何、丝网印刷海报)、复古 Synthwave(切口落日、霓虹网格、镀铬字、录像带质感)、拼豆(钉板上的熔珠小管、熨烫熔合)、岩画(沙漠漆上凿出的凹坑图形、新旧凿痕、剥落)、古埃及墓室壁画(灰泥墙、红格起稿、分栏叙事、象形文字、剥落)、罗马马赛克(石子与玻璃沿轮廓一排排铺、灰缝、燕尾铭牌)、彩色玻璃花窗(哥特尖拱窗、通体着色玻璃、grisaille 彩绘与银染、铅条、透光)、泥金手抄本(羊皮纸、鹅毛笔哥特体、朱红标题、打磨金箔首字母)、达·芬奇手稿(铁胆墨水、左手排线、红粉笔、镜像手写、机械分解图)、剪影(黑纸剪出的侧影小像、薄金粉、椭圆金框)、凸版印刷海报(木活字、红黑双色错版、木刻插图)、苏联构成主义(红黑两版、斜条与楔形、西里尔大字、网点照片拼贴)、装饰艺术 Art Deco(1930 年代喷枪流线型海报、交替射线、阶梯高楼、金色 Deco 字)、黄金时代漫画(毛笔墨线、Ben-Day 网点、四色错版、新闻纸)、波普丝网(多格撞色平涂 + 错位的照相黑版)、ASCII 字符画(行式打印机、绿条连续纸、叠打)、低多边形(1999 年代 3D:平面着色、仿射贴图、逐顶点雾、15 位色抖动)、喷漆模板涂鸦(混凝土墙上多层卡纸模板喷绘、雾化与滴痕)、刺绣徽章(牛仔布上的机绣徽章:填充绣、缎面绣、锁边)、蓝图工程图(描图墨线晒成蓝底白线)、儿童蜡笔画(小孩在糙纸上的蜡笔涂抹)、绿屏终端 CRT(荧光字符画、扫描线、余辉)、热成像(先画温度场再上伪彩色)、代尔夫特蓝瓷砖(锡釉砖上的钴蓝手绘)、洞穴壁画(火光下的赭石、吹喷手印)、1-bit 早期画图软件(黑白整屏、8×8 图案填充)、古希腊黑绘陶瓶(黑釉剪影、刻线、饰带展开图)、铅笔素描(石墨排线、擦笔、边缘只剩线稿)、X 光片(安检透视、轮廓发亮、伪彩)、1930 年代黑白橡皮管动画(白手套、饼切眼、老胶片)、黑白麻胶版画(刻刀减法、手拓发花、套色错版)、VHS 家庭录像(钨丝灯偏色、色度渗色、REC)、扁平矢量(分层几何色块、七色、层间投影)、绘本角色动画(小角色挤压拉伸的真动画)。用户说「claude绘图」「用代码画」「你自己画」「不用生图模型画」「程序化绘画」,或点名以上任一画风(含黏土、彩泥、定格动画、蓝晒、晒图、十字绣、刺绣、复古面板、老式收音机、贴纸、小票、收据、手帐拼贴、实验笔记本、方格本、荧光笔、便利贴、黑板、板书、粉笔、赛博朋克、霓虹、雨夜街道、卡通、手绘卡通、逐帧手绘、抖线、等轴、2.5D、微缩模型、单线画、一笔画、线条动画、柔光 3D、3D 渲染、C4D 风、软糖字、小球海、形变、变形动画、报刊拼贴、剪报、达达、勒索信字、网点印刷、弥散渐变、玻璃拟态、毛玻璃、包豪斯、几何构成、丝网印刷、Synthwave、蒸汽波、合成器浪潮、80 年代复古、拼豆、拼拼豆、熔珠、熨豆、豆豆画、钉板、烫豆、岩画、岩刻、凿刻、石刻、沙漠漆、史前壁刻、大角羊、古埃及、埃及壁画、墓室壁画、法老时代、象形文字、尼罗河、底比斯、罗马马赛克、马赛克镶嵌、镶嵌画、石子拼画、地砖画、古罗马地板、彩色玻璃、彩绘玻璃、花窗、玻璃花窗、教堂花窗、哥特花窗、铅条玻璃、泥金手抄本、手抄本、彩饰手抄本、中世纪手稿、羊皮纸、哥特体、花体首字母、泥金、贴金、星盘、达芬奇、达·芬奇、达芬奇手稿、手稿风、文艺复兴手稿、发明手稿、镜像字、镜像书写、扑翼机、红粉笔、钢笔排线、机械草图、分解图、剪影、剪影肖像、侧影、侧面像、黑纸剪影、剪影小像、椭圆金框、乔治时代肖像、摄政时期肖像、凸版印刷、活版印刷、木活字、铅字海报、马戏团海报、复古海报、老海报、19 世纪海报、双色套印、错版、套色错位、木刻插图、构成主义、苏联海报、苏联构成主义、俄国先锋派、罗德琴科风、红黑海报、照片蒙太奇、照片拼贴海报、西里尔字、装饰艺术、装饰风、流线型、流线型海报、1930 年代海报、旅行海报、铁路海报、火车海报、喷枪画、喷笔画、阶梯高楼、射线背景、盖茨比风、黄金时代漫画、老漫画、复古漫画、美漫封面、漫画封面、Ben-Day 网点、本戴点、网点上色、四色印刷、四色错版、新闻纸、对白框、拟声字、1940 年代漫画、波普、波普艺术、波普丝网、沃霍尔风、丝网版画头像、撞色头像、多格重复头像、六宫格撞色头像、ASCII、字符画、字符艺术、文字画、行式打印机、绿条纸、连续打印纸、针孔打印纸、老电脑打印、叠打、低多边形、低面数、低模、多边形风、千禧年 3D、90 年代 3D、复古 3D 游戏、老游戏截图、PS1 风、N64 风、平面着色、线框、游戏 HUD、飞行游戏、穿环、喷漆、模板涂鸦、镂空模板、喷漆模板、模板喷绘、街头涂鸦、街头艺术、墙绘、滴漆、班克西风格、刺绣徽章、徽章、布章、臂章、刺绣贴、绣标、锁边、牛仔外套徽章、户外徽章、营地徽章、弧形条章、蓝图、工程图、施工图、蜡笔画、儿童画、绿屏终端、CRT、显像管、热成像、热像仪、温度图、代尔夫特、荷兰蓝瓷砖、洞穴壁画、史前壁画、赭石、1-bit、黑白画图软件、MacPaint 风、黑绘、古希腊陶瓶、希腊瓶画、铅笔素描、素描、铅笔画、X 光、X 光片、安检图像、橡皮管动画、黑白卡通、老动画、麻胶版画、黑白版画、藏书票、VHS、家庭录像、录像带、扁平插画、扁平风、矢量插画、绘本动画、角色动画、挤压拉伸),或 "draw it yourself", "paint with code", "procedural painting", "watercolor / collage / colored pencil / anime / editorial / impasto oil / ukiyo-e / pixel art / clay / claymation / cyanotype / sun print / cross-stitch / embroidery / retro instrument panel / vintage radio / sticker collage / receipt / lab notebook / graph paper / chalkboard / blackboard / cyberpunk / neon city / cartoon / hand-drawn animation / isometric / 2.5D / continuous line / one-line drawing / soft 3D / 3D render / puffy letters / ball pit / shape morph / morphing / newspaper collage / Dada / ransom note / halftone / glassmorphism / aurora gradient / Bauhaus / geometric poster / screen print / synthwave / retrowave / outrun / perler beads / hama beads / artkal / fuse beads / melty beads / pegboard beads / petroglyph / rock art / rock carving / desert varnish / Egyptian tomb painting / ancient Egypt / hieroglyphs / Theban tomb / Roman mosaic / floor mosaic / tesserae / opus vermiculatum / Pompeii mosaic / stained glass / leaded glass / church window / Gothic window / grisaille / illuminated manuscript / medieval manuscript / book of hours / gold leaf / illuminated initial / blackletter / vellum / astrolabe / da Vinci notebook / Leonardo codex / Renaissance sketchbook / mirror writing / iron-gall ink / red chalk / sanguine / ornithopter / exploded view / inventor's sketch / silhouette / silhouette portrait / cut-paper profile / shade portrait / Georgian portrait / Regency portrait / oval gilt frame / letterpress / wood type / playbill / circus poster / Victorian poster / two-colour misregistration / woodcut poster / constructivism / constructivist poster / Soviet avant-garde / Russian avant-garde / Rodchenko style / photomontage poster / art deco / streamline moderne / 1930s travel poster / railway poster / airbrush poster / sunburst rays / Gatsby style / golden age comic / vintage comic book / comic cover / Ben-Day dots / four-color printing / newsprint / speech balloon / pulp cover / pop art / Warhol-style / pop silkscreen / silkscreen portrait / repeated pop portrait grid / ASCII art / text art / typewriter art / line printer / greenbar / fanfold paper / tractor feed / overstrike / printer plot / low poly / low-poly / retro 3D / 90s 3D game / PS1 style / N64 style / software rasterizer / flat shading / affine texture mapping / vertex fog / game HUD / stencil / stencil graffiti / spray paint stencil / street art / drips and overspray / Banksy-style stencil / embroidered patch / embroidery patch / iron-on patch / sew-on patch / merit badge / camp badge / merrow border / rocker patch / denim jacket patches / blueprint / technical drawing / crayon / kid's drawing / CRT terminal / green screen / thermal camera / thermal imaging / Delft tiles / Delft blue / cave painting / ochre / Lascaux-style / 1-bit / MacPaint-style / black-figure / Greek vase / pencil drawing / graphite / X-ray / baggage scanner / rubber hose / 1930s cartoon / linocut / lino print / VHS / home video / flat vector / flat illustration / storybook animation / squash and stretch without an image model" 时使用;也用于需要逐步画出(draw-on)动画的插画。单独说「剪纸」指剪纸拼贴、「刺绣」指十字绣、「丝网印刷 / screen print」指包豪斯几何;「打马赛克」是打码,不是马赛克画风;单说「蓝图」指蓝图工程图,「蓝晒 / 晒图」仍指蓝晒;「铅笔 / 素描」指铅笔素描,「彩铅」指韩国彩铅;「像素」仍指像素风,「1-bit / 黑白画图软件」指 1-bit 早期画图软件;「霓虹」仍指赛博朋克。+description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型,由 Claude 用代码一笔一笔「画」出图片(程序化绘画)。内置五十九种画风:中国水墨、水彩、剪纸拼贴、韩国彩铅、日本动漫、编辑风手绘(Riso)、油画厚涂(梵高式流向笔触+颜料浮雕打光)、浮世绘木版画(晕色、木纹、墨线主版、青海波)、像素风(低分辨率+Bayer 抖动+像素字体)、黏土定格(高度图捏出的彩泥+影棚打光)、蓝晒(普鲁士蓝日光晒图,植物剪影透光)、十字绣(Aida 布十字绣+回针绣+缎面绣+法式结)、复古仪器面板(60 年代收音机/仪器正面:柚木、拉丝铝、旋钮、刻度窗、指示灯)、贴纸拼贴·小票(模切乙烯贴纸、热敏小票、和纸胶带、吊牌、橡皮章)、实验笔记本·贴纸(线圈方格本、铅笔图表、荧光笔、红笔圈、便利贴)、黑板板书(墨绿石板、粉笔颗粒、板擦残影、示意图与公式)、赛博朋克(雨夜霓虹街道、玻璃管霓虹招牌、全息广告、湿路面倒影)、卡通手绘(蓝铅笔稿、毛笔线、错位平涂、赛璐璐阴影、逐帧抖线)、等轴 2.5D(正等轴微缩模型、一个太阳照出三面明暗、悬浮数据卡)、单线画(一根不断开的线一笔画完、唯一点睛色)、柔光 3D(光线追踪的糖果色小球海和鼓鼓的软字、景深)、形变动画(一条轮廓依次变形、洋葱皮残影、缓动曲线)、报刊拼贴(牛皮纸、手撕旧报纸、网点老照片、勒索信拼贴字)、弥散玻璃(弥散渐变、磨砂玻璃卡片界面)、包豪斯几何(三原色几何、丝网印刷海报)、复古 Synthwave(切口落日、霓虹网格、镀铬字、录像带质感)、拼豆(钉板上的熔珠小管、熨烫熔合)、岩画(沙漠漆上凿出的凹坑图形、新旧凿痕、剥落)、古埃及墓室壁画(灰泥墙、红格起稿、分栏叙事、象形文字、剥落)、罗马马赛克(石子与玻璃沿轮廓一排排铺、灰缝、燕尾铭牌)、彩色玻璃花窗(哥特尖拱窗、通体着色玻璃、grisaille 彩绘与银染、铅条、透光)、泥金手抄本(羊皮纸、鹅毛笔哥特体、朱红标题、打磨金箔首字母)、达·芬奇手稿(铁胆墨水、左手排线、红粉笔、镜像手写、机械分解图)、剪影(黑纸剪出的侧影小像、薄金粉、椭圆金框)、凸版印刷海报(木活字、红黑双色错版、木刻插图)、苏联构成主义(红黑两版、斜条与楔形、西里尔大字、网点照片拼贴)、装饰艺术 Art Deco(1930 年代喷枪流线型海报、交替射线、阶梯高楼、金色 Deco 字)、黄金时代漫画(毛笔墨线、Ben-Day 网点、四色错版、新闻纸)、波普丝网(多格撞色平涂 + 错位的照相黑版)、ASCII 字符画(行式打印机、绿条连续纸、叠打)、低多边形(1999 年代 3D:平面着色、仿射贴图、逐顶点雾、15 位色抖动)、喷漆模板涂鸦(混凝土墙上多层卡纸模板喷绘、雾化与滴痕)、刺绣徽章(牛仔布上的机绣徽章:填充绣、缎面绣、锁边)、蓝图工程图(描图墨线晒成蓝底白线)、儿童蜡笔画(小孩在糙纸上的蜡笔涂抹)、绿屏终端 CRT(荧光字符画、扫描线、余辉)、热成像(先画温度场再上伪彩色)、代尔夫特蓝瓷砖(锡釉砖上的钴蓝手绘)、洞穴壁画(火光下的赭石、吹喷手印)、1-bit 早期画图软件(黑白整屏、8×8 图案填充)、古希腊黑绘陶瓶(黑釉剪影、刻线、饰带展开图)、铅笔素描(石墨排线、擦笔、边缘只剩线稿)、X 光片(安检透视、轮廓发亮、伪彩)、1930 年代黑白橡皮管动画(白手套、饼切眼、老胶片)、黑白麻胶版画(刻刀减法、手拓发花、套色错版)、VHS 家庭录像(钨丝灯偏色、色度渗色、REC)、扁平矢量(分层几何色块、七色、层间投影)、绘本角色动画(小角色挤压拉伸的真动画)、圆珠笔涂鸦(蓝红圆珠笔线稿、墨团、彩铅、页边涂鸦)。用户说「claude绘图」「用代码画」「你自己画」「不用生图模型画」「程序化绘画」,或点名以上任一画风(含黏土、彩泥、定格动画、蓝晒、晒图、十字绣、刺绣、复古面板、老式收音机、贴纸、小票、收据、手帐拼贴、实验笔记本、方格本、荧光笔、便利贴、黑板、板书、粉笔、赛博朋克、霓虹、雨夜街道、卡通、手绘卡通、逐帧手绘、抖线、等轴、2.5D、微缩模型、单线画、一笔画、线条动画、柔光 3D、3D 渲染、C4D 风、软糖字、小球海、形变、变形动画、报刊拼贴、剪报、达达、勒索信字、网点印刷、弥散渐变、玻璃拟态、毛玻璃、包豪斯、几何构成、丝网印刷、Synthwave、蒸汽波、合成器浪潮、80 年代复古、拼豆、拼拼豆、熔珠、熨豆、豆豆画、钉板、烫豆、岩画、岩刻、凿刻、石刻、沙漠漆、史前壁刻、大角羊、古埃及、埃及壁画、墓室壁画、法老时代、象形文字、尼罗河、底比斯、罗马马赛克、马赛克镶嵌、镶嵌画、石子拼画、地砖画、古罗马地板、彩色玻璃、彩绘玻璃、花窗、玻璃花窗、教堂花窗、哥特花窗、铅条玻璃、泥金手抄本、手抄本、彩饰手抄本、中世纪手稿、羊皮纸、哥特体、花体首字母、泥金、贴金、星盘、达芬奇、达·芬奇、达芬奇手稿、手稿风、文艺复兴手稿、发明手稿、镜像字、镜像书写、扑翼机、红粉笔、钢笔排线、机械草图、分解图、剪影、剪影肖像、侧影、侧面像、黑纸剪影、剪影小像、椭圆金框、乔治时代肖像、摄政时期肖像、凸版印刷、活版印刷、木活字、铅字海报、马戏团海报、复古海报、老海报、19 世纪海报、双色套印、错版、套色错位、木刻插图、构成主义、苏联海报、苏联构成主义、俄国先锋派、罗德琴科风、红黑海报、照片蒙太奇、照片拼贴海报、西里尔字、装饰艺术、装饰风、流线型、流线型海报、1930 年代海报、旅行海报、铁路海报、火车海报、喷枪画、喷笔画、阶梯高楼、射线背景、盖茨比风、黄金时代漫画、老漫画、复古漫画、美漫封面、漫画封面、Ben-Day 网点、本戴点、网点上色、四色印刷、四色错版、新闻纸、对白框、拟声字、1940 年代漫画、波普、波普艺术、波普丝网、沃霍尔风、丝网版画头像、撞色头像、多格重复头像、六宫格撞色头像、ASCII、字符画、字符艺术、文字画、行式打印机、绿条纸、连续打印纸、针孔打印纸、老电脑打印、叠打、低多边形、低面数、低模、多边形风、千禧年 3D、90 年代 3D、复古 3D 游戏、老游戏截图、PS1 风、N64 风、平面着色、线框、游戏 HUD、飞行游戏、穿环、喷漆、模板涂鸦、镂空模板、喷漆模板、模板喷绘、街头涂鸦、街头艺术、墙绘、滴漆、班克西风格、刺绣徽章、徽章、布章、臂章、刺绣贴、绣标、锁边、牛仔外套徽章、户外徽章、营地徽章、弧形条章、蓝图、工程图、施工图、蜡笔画、儿童画、绿屏终端、CRT、显像管、热成像、热像仪、温度图、代尔夫特、荷兰蓝瓷砖、洞穴壁画、史前壁画、赭石、1-bit、黑白画图软件、MacPaint 风、黑绘、古希腊陶瓶、希腊瓶画、铅笔素描、素描、铅笔画、X 光、X 光片、安检图像、橡皮管动画、黑白卡通、老动画、麻胶版画、黑白版画、藏书票、VHS、家庭录像、录像带、扁平插画、扁平风、矢量插画、绘本动画、角色动画、挤压拉伸、圆珠笔、圆珠笔涂鸦、原子笔、页边涂鸦、课本涂鸦、手画棋盘),或 "draw it yourself", "paint with code", "procedural painting", "watercolor / collage / colored pencil / anime / editorial / impasto oil / ukiyo-e / pixel art / clay / claymation / cyanotype / sun print / cross-stitch / embroidery / retro instrument panel / vintage radio / sticker collage / receipt / lab notebook / graph paper / chalkboard / blackboard / cyberpunk / neon city / cartoon / hand-drawn animation / isometric / 2.5D / continuous line / one-line drawing / soft 3D / 3D render / puffy letters / ball pit / shape morph / morphing / newspaper collage / Dada / ransom note / halftone / glassmorphism / aurora gradient / Bauhaus / geometric poster / screen print / synthwave / retrowave / outrun / perler beads / hama beads / artkal / fuse beads / melty beads / pegboard beads / petroglyph / rock art / rock carving / desert varnish / Egyptian tomb painting / ancient Egypt / hieroglyphs / Theban tomb / Roman mosaic / floor mosaic / tesserae / opus vermiculatum / Pompeii mosaic / stained glass / leaded glass / church window / Gothic window / grisaille / illuminated manuscript / medieval manuscript / book of hours / gold leaf / illuminated initial / blackletter / vellum / astrolabe / da Vinci notebook / Leonardo codex / Renaissance sketchbook / mirror writing / iron-gall ink / red chalk / sanguine / ornithopter / exploded view / inventor's sketch / silhouette / silhouette portrait / cut-paper profile / shade portrait / Georgian portrait / Regency portrait / oval gilt frame / letterpress / wood type / playbill / circus poster / Victorian poster / two-colour misregistration / woodcut poster / constructivism / constructivist poster / Soviet avant-garde / Russian avant-garde / Rodchenko style / photomontage poster / art deco / streamline moderne / 1930s travel poster / railway poster / airbrush poster / sunburst rays / Gatsby style / golden age comic / vintage comic book / comic cover / Ben-Day dots / four-color printing / newsprint / speech balloon / pulp cover / pop art / Warhol-style / pop silkscreen / silkscreen portrait / repeated pop portrait grid / ASCII art / text art / typewriter art / line printer / greenbar / fanfold paper / tractor feed / overstrike / printer plot / low poly / low-poly / retro 3D / 90s 3D game / PS1 style / N64 style / software rasterizer / flat shading / affine texture mapping / vertex fog / game HUD / stencil / stencil graffiti / spray paint stencil / street art / drips and overspray / Banksy-style stencil / embroidered patch / embroidery patch / iron-on patch / sew-on patch / merit badge / camp badge / merrow border / rocker patch / denim jacket patches / blueprint / technical drawing / crayon / kid's drawing / CRT terminal / green screen / thermal camera / thermal imaging / Delft tiles / Delft blue / cave painting / ochre / Lascaux-style / 1-bit / MacPaint-style / black-figure / Greek vase / pencil drawing / graphite / X-ray / baggage scanner / rubber hose / 1930s cartoon / linocut / lino print / VHS / home video / flat vector / flat illustration / storybook animation / squash and stretch / ballpoint / biro / ballpoint doodle / margin doodles / hand-drawn board game without an image model" 时使用;也用于需要逐步画出(draw-on)动画的插画。单独说「剪纸」指剪纸拼贴、「刺绣」指十字绣、「丝网印刷 / screen print」指包豪斯几何;「打马赛克」是打码,不是马赛克画风;单说「蓝图」指蓝图工程图,「蓝晒 / 晒图」仍指蓝晒;「铅笔 / 素描」指铅笔素描,「彩铅」指韩国彩铅;「像素」仍指像素风,「1-bit / 黑白画图软件」指 1-bit 早期画图软件;「霓虹」仍指赛博朋克;「喷漆 / 街头涂鸦」仍指喷漆模板涂鸦,「圆珠笔 / 随手涂鸦 / 页边涂鸦」指圆珠笔涂鸦。---# Claude 绘图@@ -72,6 +72,7 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型| VHS 家庭录像 | `lib/vhs.py` · `VHSCamcorder` | `examples/vhs_birthday.py` 吹蜡烛 · Blow Out the Candles(一家人生日录像里的一帧:70 年代客厅的圆环墙纸、胡桃木护墙板、兔耳天线电视、牛油果绿丝绒沙发、长毛地毯;彩带、HAPPY BIRTHDAY 三角小旗、戴派对帽的泰迪熊;茶几上的蛋糕四根蜡烛刚吹灭冒着烟、两根还亮着,过生日的孩子戴着尖帽从背后凑近、离镜头太近而虚焦;白平衡停在「室外」拍钨丝灯、烛焰过曝和 CCD 竖向拖影、点阵 OSD;录像带的色度渗色、跟踪噪带、磁头切换噪声、掉磁白点) | 约 6 秒 || 扁平矢量 | `lib/flatvector.py` · `FlatVector` | `examples/flatvector_night_camp.py` 山间夜营(七色限定色板,无描边的大块几何形一层层叠起来,层与层之间一道柔和投影,加极细颗粒;夜蓝天空里一轮带橙色光芒的月亮,紫色雪山分出亮面和折线暗面,品红、橙色两种山丘带,黄沙地;下午插在山顶的小旗下,一条虚线小路走之字形下山、穿过山丘,尽头是戴头灯走最后一段路的小小背包客;营地已经亮了:橙色 A 字帐篷门口透出光,篝火的光在沙地上铺成一圈圈平涂光环;几何松树、圆冠树、两朵平底云、一颗流星) | 约 1 秒 || 绘本角色动画 | `lib/storybook.py` · `Storybook` | `examples/storybook_acorn.py` 小橡果的秋天(真动画 + 旅程总图:米色纸上,枝头打盹的小橡果被晃醒、拉长掉下、落地压扁再弹起,追着一片红橡叶滚下山坡,山坡、小花、远山随它经过一笔笔画出来;跳上漂在小河上的橡叶,撞岸后空翻上岸,钻进土里发芽长成一棵还戴着橡果帽的小橡树;最后「hello, little oak」按笔顺写出来,彩纸屑飞起。总图把六个关键姿态多次曝光在铅笔运动弧上;加 `--gif out.gif` 出 15 fps 的真动画) | 约 1 秒(总图)/ 约 3 秒(151 帧动图) |+| 圆珠笔涂鸦 | `lib/ballpoint.py` · `Ballpoint` | `examples/ballpoint_board_game.py` 蛇梯棋大冒险 · Snakes & Ladders, Round 7(午休时在复印纸上用蓝、红、黑三支圆珠笔画的 8×8 蛇梯棋,彩铅一行行涂成彩虹色格子;一局正在进行:骰子刚从页边弹过来、掷出 4,蜗牛从 10 跳四格到 14(红笔虚线弧标出 1-2-3-4),正顺着长梯子爬到 38(红圈、虚线箭头、+24!),小云从 47 被绿蛇滑下去,晕乎乎地喊 nooo~,骰子怪在 51 捂着脸;页边是彩旗、太阳、井字棋、纸飞机、星星串、山坡小房子、花盆,吐槽小纸条「who drew this snake so LONG?!」、记分卡、把 three 划掉改成 four、红笔结论 slow snail, fast ladder!;右下角还有上一页购物单压过来的无墨压痕) | 约 4 秒 |各画风共用 `lib/core.py` 里的底层工具:噪声、模糊、样条曲线、多边形遮罩、有机轮廓 `blob_pts`、毛笔 `bristle_stroke`、中文字体查找;新四种还用到补零平移 `shift`、文字遮罩 `text_mask`、西文字体查找 `latin_font`/`load_font`,以及高度图打光 `height_normals`、`height_shadow`(沿光线步进的投影)、`ambient_occlusion`。@@ -133,7 +134,8 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型- 冬天、夜晚、乡村与小镇、民间故事和童话、节日贺卡和藏书票、「回家 / 守夜 / 一盏灯」这类温暖的小故事、要手作感又要强烈黑白对比的封面、讲解片里的「过去的冬夜 / 手工年代」页 → 黑白麻胶版画(要红黑两色的木活字海报用凸版印刷海报;要日式多色套印和晕色用浮世绘;要喷漆模板的街头感用喷漆模板涂鸦);- 家庭回忆、怀旧、「当年的那一天」(生日、过年、毕业、第一次……)、童年和老房子、found footage 式的悬念开场、讲解片里的「回到 80 年代 / 那时候的家 / 老录像里的证据」页 → VHS 家庭录像(要霓虹落日的 80 年代复古未来用复古 Synthwave;要老照片和剪报用报刊拼贴;要屏幕上的字符用 ASCII 字符画);- 风景、户外、旅行与露营、MG 动画式的场景背景和转场、讲解片的「场景 / 旅程 / 夜晚」页、要干净现代又有层次的插画 → 扁平矢量(要撕纸边和蜡笔的手作感用剪纸拼贴;要正等轴的微缩模型用等轴 2.5D;要 80 年代霓虹用复古 Synthwave);-- 要「真的动起来」的小故事、一个可爱小角色的旅程或成长(从 A 到 B、出发—遇到—到达)、讲解片的片头片尾和转场、品牌吉祥物小动画、「一路走一路画出来」的过程感 → 绘本角色动画(`Storybook.gif()` 出真动画,`journey()` 出一张旅程总图;只要一条轮廓的变形用形变动画;要逐帧抖线的静态卡通插画用卡通手绘)。+- 要「真的动起来」的小故事、一个可爱小角色的旅程或成长(从 A 到 B、出发—遇到—到达)、讲解片的片头片尾和转场、品牌吉祥物小动画、「一路走一路画出来」的过程感 → 绘本角色动画(`Storybook.gif()` 出真动画,`journey()` 出一张旅程总图;只要一条轮廓的变形用形变动画;要逐帧抖线的静态卡通插画用卡通手绘);+- 上课 / 午休走神的随手涂鸦、纸上正在进行的游戏或计划(手画棋盘、寻宝图、清单、路线、比分)、学生和办公室日常的轻松小故事、讲解片里「在草稿纸上推演一步」的页 → 圆珠笔涂鸦(要铅笔图表、荧光笔和贴纸的实验记录用实验笔记本;要没有线稿、柔和的彩铅小物用韩国彩铅;要小孩的蜡笔画用儿童蜡笔画;要黑白石墨写生用铅笔素描)。每种画风一幅范例作为质量基准(范例都不用禅意主题);水墨另加一幅「月印万川」(留白托月、水面倒影)。@@ -939,6 +941,18 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask- 输出:`frame(t)`;`gif(path, fps=15, t_end, hold)`:逐帧渲染(一次只留一帧浮点),共用一张加权调色板 + 固定 4×4 Bayer,没变的像素写成品红透明索引;`journey(times, t_world, arc, labels, prop_arcs, world_fx, final, props)` 旅程总图;`stage(name, t)` 存某时刻的关键帧,`save(path, stages_dir)`;`save('x.jpg')` 默认 quality 88、4:4:4 色度- 色板常量 `PAPER INK PENCIL GRASS MINT LAVENDER SUN WATER NUT CAP CONFETTI`++**圆珠笔涂鸦 `Ballpoint`**:+- 思路:圆珠笔墨是油性墨膏,靠滚珠压到纸上;颜色按光密度(比尔定律)叠加,描两遍、交叉、墨团都会更深更饱和(蓝色叠到深蓝紫,不会变成死黑)。每一笔:起笔头几像素滚珠是干的(细、淡、只挂在纸纹峰上)→ 压力 ±12% 漂移、线宽随之略变、手抖 → 偶尔断墨 2–9 px(墨断了,压痕还在)→ 停笔、急转弯、有时起笔处掉一个墨团 → 抬笔甩出 90–160° 的小钩。每一笔都在纸上压出凹槽,左上侧光下槽的左上壁暗、右下壁亮。彩铅是蜡,只挂在碰到的纸纹上:轻压颗粒发白,重压填进谷里;一块一块地斜向快速排线,出界、换方向,大面积浅、小面积重+- 构造:`Ballpoint(W, H, seed, ss=2, pen_width=2.5)`;`paper(tone, tooth=0.75, fibres=260, mottle, cockle=1.0, folds=[((x0, y0), (x1, y1))], vignette=0.09)` 灰米色复印纸:细纸纹、稀疏纤维、斑驳、低起伏和折痕(按左上光打光)、拍照的四角暗角+- 圆珠笔:`line(pts, pen='blue'|'red'|'black'|None, pressure, width, closed, smooth, wobble, bow, hook, gloop, skip, twice, start, clip, groove)`;`bow` 是徒手直线的侧弯(约 0.003–0.006 倍长度),`hook` / `gloop` / `skip` 是收笔小钩、墨团、断墨的几率,`twice` 是再描一遍(偏 0.6–1.6 px、只描一部分)的几率,`pen=None` 只压槽不出墨;`lines(paths, …)` 一批短笔画共用一次栅格化;`emboss(pts)` 无墨压痕+- 小件:`dot(x, y, r, pen)` 转一小圈压出的实心点;`eye(cx, cy, rx, ry, pen, look, shine)` 由外往里转圈涂实、留一个圆高光的眼睛;`face(cx, cy, size, mood='smile'|'grin'|'oh'|'dizzy'|'sleep'|'worry', pen, blush, look, rot)`;`dashes(pts, pen, dash, gap, pressure, smooth, clip)` 虚线(返回重采样后的路径,好接箭头);`arrow(tip, direction, size, pen)`;`ring(cx, cy, rx, ry, pen, turns, rot)` 不闭合、越画越往外的随手圈+- 彩铅:`pencil(mask, colour, angle, pressure, spacing, length=(40, 90), overshoot, width=2.9, jitter, bow, cross, clip, groove)` 斜向排线(`length` 是一段手腕笔画的长度,接缝逐行错开;`overshoot` 出界像素;`cross` 再叠一层角度);`pencil_line(pts, colour, pressure, width)` 单根彩铅线;颜色用 `PENCILS` 里的名字(leaf green lime mint teal sky blue violet lilac pink rose red orange peach yellow ochre brown tan grey cream)或 '#rrggbb'+- 圆珠笔排线:`pen_hatch(mask, pen, angle, spacing, pressure, length, overshoot, zigzag=0.85, cross, clip)` 来回不抬笔的之字排线,转折处带墨团(阴影、暗面、深色棋子)+- 手写:`write(s, x, y, size, pen, pressure, slant=7, spacing=1.04, jitter, anchor='l'|'m'|'r', rot, width, blind, hook, gloop)`,y 是基线,返回写出来的 (x0, y0, x1, y1);字形取自细手写字体的骨架(Zhang-Suen 细化后描成笔路径,按字缓存),每个字母单独缩放、倾斜、上下浮动,有起笔、墨团、小钩;中文用细黑体骨架;`blind=True` 是上一页透过来的无墨压痕字;`strike(box, pen, passes)` 来回划掉一个词;`underline(x0, x1, y, pen, wavy)`+- 遮罩和点:`poly(pts)`、`ellipse(cx, cy, rx, ry, rot)`、`band(pts, width)`、`tube(pts, w0, w1)` 由粗到细的身体(蛇、尾巴),`Ballpoint.tube_sides(pts, w0, w1)` 它的左右两条边(一笔描下去绕过尾尖再描回来);`circle_pts`、`star_pts`、`cloud_pts(cx, cy, w, h, bumps, seed, flat)`、`spiral_pts(cx, cy, r, turns, a0)`、`heart_pts`、`Ballpoint.resample(pts, step)`+- `stage(name)`、`save(path, stages_dir)`;`save('x.jpg')` 默认 quality 88、4:4:4;常量 `PENS PENCILS PAPER`;字体可用 `INKPAINT_FONT_BALLPOINT` / `INKPAINT_FONT_BALLPOINT_CJK` 指定(默认 macOS Noteworthy Light / 黑体-简 细体,Linux Kalam / Caveat / Noto Sans CJK,Windows Segoe Print / 微软雅黑)+**顺序**:都是先远后近、先大后小,文字最后叠加。水墨的雾要画在它该吞没的东西之后;水彩的叶梗要先画,并且只画在叶子外面。## 三、毛病清单(都真实出现过)@@ -1843,6 +1857,25 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask| 彩纸屑又小又全压在字上 | 纸屑放大(10–19 px),从字下方炸开、横向散得更开(spread 1500、起点宽 640) || 12.5 fps 时滚动一帧转四五十度,有点跳 | 改成 15 fps;GIF 延时只能写厘秒,按累计取整写成 7、7、6 厘秒交替,平均正好 15 fps |+**圆珠笔涂鸦**++| 问题 | 改法 |+|---|---|+| 蛇太细像蚯蚓,棋子小得读不出 | 蛇头宽 54 / 44 / 38 px(约半格到六成格),头比脖子宽;蜗牛、云放大 1.1–1.3 倍,云的脸 84 px |+| 梯子横档和格线从蜗牛、云身上穿过去 | 先画棋子,后画的蛇、梯子、格线都用棋子遮罩 `clip` 掉(笔走到已经画好的东西前就停住);格子上色也绕开蛇和棋子 |+| 跳格的红虚线像一串锯齿 V | 每跳一格用一条 14 点的抛物线弧(高 24 px)配箭头,不用三点样条 |+| 跳格的计数 1–4 压在格子编号上,「1」落在竖格线上整个看不见 | 弧的起止放到格子下部 0.4 格,数字放在弧顶、往右偏 13 px,离开格线 |+| 「+24!」被竖格线劈开、「nooo~」被汗滴和云挤住 | 标注整块放进一个空格子里;云只留一颗汗滴放在侧面,去掉两只手 |+| 折痕成了贯穿全画的一道亮白线 | 折痕的谷只深 0.1、宽 3 px,沿线加一点摆动,主要靠两侧纸面坡度不同带出的明暗 |+| 上一页透过来的无墨压痕字像白色浮雕字 | 盲压的槽深 ×0.55,只在侧光下隐约可见 |+| 手写字母互相撞(slow 看成 dow) | 每个字母的步进按它自己抖动后的字号算,字距默认 1.04,步进抖动降到 2% |+| 冒号、i 和 ! 的点丢了 | 字形骨架里小于 0.11 字号的连通块全部当「点」画,单像素的也算 |+| 格子编号末尾的墨团像小数点 | 小号数字的 gloop 降到 0.15 |+| 蛇头背后缺一段轮廓;鼻孔和嘴像多出来的眼睛 | 头的弧画到 ±148°,身体两侧从路径第 4 个点开始;去掉鼻孔和嘴,只留墨眼、彩铅腮红和红舌头 |+| 红笔沿梯子的虚线箭头从蜗牛壳上穿过去 | 箭头放到梯子没有棋子的那一侧(+40 px),再用棋子遮罩 `clip` |+| 墨线旁边的压痕亮边太抢、像浮雕 | 压痕打光增益 0.16 → 0.13,上限 ±0.1 |+| 动图里蛇和格子的彩铅颜色被量化成土褐色 | 两段调色板:150 色从「有色像素 ×5」的样本里中值切分,另外 104 色只从有色像素(饱和度 > 0.12)里切;49 帧约 0.6 MB |+## 四、做成动画- 各画风都有 `stage(name)` 和 `save(path, stages_dir)`,按阶段依次淡入叠化,就是「一幅画被逐步画出来」。README 里的动图就是这样做的。@@ -1928,6 +1961,7 @@ lib/linocut.py 黑白麻胶版画(整版减法刻:V 口 / U 口刀lib/vhs.py VHS 家庭录像(70 年代客厅:反照率 × 灯光 + 自发光、离焦图层;家用摄像机:手持倾斜、钨丝灯偏色、软膝、泛光、CCD 竖向拖影、拖尾、增益噪声、点阵 OSD;录像带:YIQ、亮度带宽与锐化光晕、色度带宽 / 隔行平均 / 延迟、噪声、时基抖动、跟踪噪带、磁头切换、掉磁)lib/flatvector.py 扁平矢量(分层几何色块、七色限定色板、层间柔和投影、细颗粒)lib/storybook.py 绘本角色动画(按时间取帧:带揭示图的场景层、follow 边走边画、隐式曲面角色挤压拉伸、动作编排、特效、按骨架笔顺手写、旅程总图)+lib/ballpoint.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/ballpoint_board_game.jpg b/examples/ballpoint_board_game.jpgnew file mode 100644index 0000000..e1d5127Binary files /dev/null and b/examples/ballpoint_board_game.jpg differdiff --git a/examples/ballpoint_board_game.py b/examples/ballpoint_board_game.pynew file mode 100644index 0000000..4e868c4--- /dev/null+++ b/examples/ballpoint_board_game.py@@ -0,0 +1,629 @@+"""Example (ballpoint doodle): Snakes & Ladders, Round 7 / 蛇梯棋大冒险 — a snakes-and-ladders board drawn with+ballpoint pens on a sheet of copy paper during a lunch break, coloured in with pencils, and a game in progress:+the die has just been thrown (it bounced across the margin and came up 4); the snail hopped four squares from 10+to 14, landed on the foot of the long ladder and is climbing it to 38 (red hops counted 1-2-3-4, a red ring, a+dashed arrow up the ladder, +24!); the cloud, who was on 47, is sliding down the green snake to 18; the dice+monster waits on 51 and looks worried. Margin doodles (bunting, a sun, a tic-tac-toe game, a paper plane, a house+on a hill, a flower pot, stars), a note complaining about the snake, the score card, a word crossed out and+written again, the conclusion in red -- and the ghost of a shopping list pressed through from the sheet above.+No image model.+python3 ballpoint_board_game.py [out.png] [--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 ballpoint import Ballpoint+from core import spline, blur, smoothstep++out = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith('--') else 'ballpoint_board_game.png'+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('BALLPOINT_TIMING') else None++W, H = 1920, 1080+b = Ballpoint(W, H, seed=7)+rng = b.rng+b.paper(folds=[((-40, 548), (1960, 530))], cockle=1.0)+tick('paper')++# ===================================================================== the board: geometry+CS, N = 94.0, 8+BX0, BY1 = 584.0, 898.0 # left edge, bottom edge+CX, CY = BX0 + CS * 4, BY1 - CS * 4+ROT = np.deg2rad(-0.8)+jx = rng.normal(0, 1.8, N + 1); jy = rng.normal(0, 1.8, N + 1)+++def B(u, v):+ """board coordinates (u columns from the left, v rows from the bottom; cell centres at k + 0.5) -> canvas"""+ u, v = np.asarray(u, np.float32), np.asarray(v, np.float32)+ x = BX0 + CS * u + np.interp(u, np.arange(N + 1), jx)+ y = BY1 - CS * v + np.interp(v, np.arange(N + 1), jy)+ dx, dy = x - CX, y - CY+ return np.stack([CX + dx * np.cos(ROT) - dy * np.sin(ROT), CY + dx * np.sin(ROT) + dy * np.cos(ROT)], -1)+++def cell(n):+ r = (n - 1) // N; k = (n - 1) % N+ c = k if r % 2 == 0 else N - 1 - k+ return c, r+++def ctr(n, du=0.0, dv=0.0):+ c, r = cell(n)+ return B(c + 0.5 + du, r + 0.5 + dv)+++def uvpath(ctrl, per=12):+ return spline(B([p[0] for p in ctrl], [p[1] for p in ctrl]), per)+++def xf(pts, cx, cy, s=1.0, rot=0.0):+ """local doodle coordinates -> canvas"""+ P = np.asarray(pts, np.float32) * s+ a = np.deg2rad(rot); c, sn = np.cos(a), np.sin(a)+ return np.stack([cx + P[:, 0] * c - P[:, 1] * sn, cy + P[:, 0] * sn + P[:, 1] * c], 1)+++# ---- snakes: (control points head -> tail in board units, head width, body pencil, band pencil)+SNAKES = [+ ([(1.5, 5.4), (0.62, 4.98), (0.52, 4.25), (1.3, 3.78), (2.25, 3.42), (2.38, 2.88), (1.75, 2.58), (1.45, 2.45)], 54, 'green', 'yellow'),+ ([(2.6, 7.42), (3.42, 7.18), (3.66, 6.58), (3.25, 6.08), (3.8, 5.7), (4.45, 5.5)], 44, 'orange', 'rose'),+ ([(7.42, 7.45), (6.82, 7.02), (7.02, 6.42), (6.55, 5.98), (6.5, 5.55)], 38, 'lilac', 'violet'),+]+# ---- ladders: (from square, to square)+LADDERS = [(14, 38), (23, 41)]+++def snake_geom(ctrl, w0):+ P = Ballpoint.resample(uvpath(ctrl, 12), 3.0)+ hd = P[0] - P[7]; hd /= np.linalg.norm(hd)+ k0 = 4+ L, R = Ballpoint.tube_sides(P[k0:], w0 * 0.8, 6.0, smooth=False)+ hc = P[0] + hd * 4+ return dict(P=P, hd=hd, hc=hc, L=L, R=R, rx=w0 * 0.66, ry=w0 * 0.58, w0=w0)+++SG = [snake_geom(c, w) for c, w, _, _ in SNAKES]+++def snake_mask(g):+ m = b.tube(g['P'][4:], g['w0'] * 0.8, 6.0)+ ang = np.degrees(np.arctan2(g['hd'][1], g['hd'][0]))+ return np.clip(m + b.ellipse(g['hc'][0], g['hc'][1], g['rx'], g['ry'], rot=ang), 0, 1)+++# ---- pieces+LAD = (ctr(14), ctr(38))+SNAIL = (LAD[0] + (LAD[1] - LAD[0]) * 0.55 + np.array([2, -12]), 1.1, -38.0) # (centre, scale, rotation)+CLOUD = (B(1.78, 3.66) + np.array([0, -30]), 1.3, 16.0)+DICEM = (ctr(51, 0.0, 0.02), 1.12)+DIE = (np.array([1520.0, 652.0]), 1.0)++SNAIL_BODY = [(-56, 12), (-30, 17), (0, 19), (28, 18), (46, 12), (54, -4), (53, -24), (43, -37), (31, -33), (26, -17),+ (12, -7), (-14, -3), (-40, 3), (-58, 9)]+SNAIL_SHELL = (-7, -27, 30)+++def snail_masks():+ (c, s, rot) = SNAIL+ body = b.poly(xf(spline(np.vstack([SNAIL_BODY, SNAIL_BODY[:1]]), 8), c[0], c[1], s, rot))+ sc = xf([SNAIL_SHELL[:2]], c[0], c[1], s, rot)[0]+ shell = b.ellipse(sc[0], sc[1], SNAIL_SHELL[2] * s, SNAIL_SHELL[2] * s * 0.96)+ return body, shell+++def cloud_pts():+ (c, s, rot) = CLOUD+ P = Ballpoint.cloud_pts(0, 0, 104, 66, bumps=7, seed=5)+ return xf(P, c[0], c[1], s, rot)+++def cube_pts(cx, cy, a, dx, dy):+ """front square (side a, centred) plus the top and right faces of a cube seen from the upper right"""+ x0, y0, x1, y1 = cx - a / 2, cy - a / 2, cx + a / 2, cy + a / 2+ front = np.array([(x0, y0), (x1, y0), (x1, y1), (x0, y1)], np.float32)+ top = np.array([(x0, y0), (x0 + dx, y0 - dy), (x1 + dx, y0 - dy), (x1, y0)], np.float32)+ side = np.array([(x1, y0), (x1 + dx, y0 - dy), (x1 + dx, y1 - dy), (x1, y1)], np.float32)+ return front, top, side+++def face_pt(q, u, v):+ """a point on a cube face given as 4 corners (u along the last edge, v along the first)"""+ return q[0] + (q[1] - q[0]) * v + (q[3] - q[0]) * u+++def dicem_geom():+ (c, s) = DICEM+ return cube_pts(c[0] - 6, c[1] + 6, 48 * s, 16 * s, 15 * s)+++# exclusion: where the grid lines stop and the squares are not coloured+smasks = [snake_mask(g) for g in SG]+sn_body, sn_shell = snail_masks()+cl_mask = b.poly(cloud_pts())+f_, t_, s_ = dicem_geom()+dm_mask = np.clip(b.poly(f_) + b.poly(t_) + b.poly(s_), 0, 1)+EX = np.clip(sum(smasks) + sn_body + sn_shell + cl_mask + dm_mask, 0, 1)+EXC = 1 - smoothstep(0.03, 0.3, blur(EX, 3.0))+PIECEC = 1 - smoothstep(0.03, 0.3, blur(np.clip(sn_body + sn_shell + cl_mask + dm_mask, 0, 1), 2.0))+tick('geometry')++# ===================================================================== 1. pen: the pieces and the die (drawn first, the board goes round them)+# -- snail climbing the ladder+(c, s, rot) = SNAIL+sc = xf([SNAIL_SHELL[:2]], c[0], c[1], s, rot)[0]+b.line(b.circle_pts(sc[0], sc[1], SNAIL_SHELL[2] * s, SNAIL_SHELL[2] * s * 0.96, a0=-100, a1=255), 'black', 0.85, hook=0.3, twice=0.5)+b.line(b.spiral_pts(sc[0] + 2, sc[1] + 1, SNAIL_SHELL[2] * s * 0.74, turns=2.1, a0=rot + 180), 'black', 0.8, smooth=False, hook=0.2)+body_pts = xf(spline(SNAIL_BODY, 8), c[0], c[1], s, rot)+b.line(body_pts, 'black', 0.82, clip=1 - smoothstep(0.2, 0.8, blur(sn_shell, 1.0)), hook=0.2)+for (p0, p1) in [((33, -34), (27, -55)), ((46, -33), (53, -53))]:+ q = xf([p0, p1], c[0], c[1], s, rot)+ b.line(q, 'black', 0.8, smooth=False, hook=0)+ b.dot(q[1][0], q[1][1], 3.6, 'black')+fc = xf([(41, -17)], c[0], c[1], s, rot)[0]+b.face(fc[0], fc[1], 44, 'grin', 'black', blush=None, rot=rot * 0.4)+for k in range(3): # little slime marks on the rung below+ q = xf([(-62 - k * 9, 20 + k * 3), (-68 - k * 9, 22 + k * 3)], c[0], c[1], s, rot)+ b.line(q, 'black', 0.6, smooth=False, hook=0, gloop=0.1)++# -- cloud sliding down the green snake+(c, s, rot) = CLOUD+b.line(cloud_pts(), 'blue', 0.85, closed=True, twice=0.6, hook=0.3)+b.face(c[0] + 2, c[1] + 4, 84, 'dizzy', 'blue', blush=None, rot=rot)+for (dx, dy) in [(62, -32)]: # a sweat drop+ q = xf([(dx, dy)], c[0], c[1], s, rot)[0]+ drop = [(q[0], q[1] - 9), (q[0] + 4.5, q[1] - 1), (q[0] + 4, q[1] + 4), (q[0], q[1] + 6), (q[0] - 4, q[1] + 4), (q[0] - 4.5, q[1] - 1)]+ b.line(drop, 'blue', 0.75, closed=True, hook=0)+g1 = SG[0]['P'] # its slide, dashed down the snake's back+j = int(np.argmin(np.hypot(*(g1 - c).T)))+P = b.dashes(g1[14:max(16, j - 30)], 'blue', 8, 6, 0.72, smooth=False)+b.arrow(P[-1], P[-1] - P[-6], 10, 'blue', 0.8)++# -- dice monster on 51, worried+front, top, side = dicem_geom()+(c, s) = DICEM+b.line(front, 'blue', 0.85, closed=True, smooth=False, twice=0.5)+b.line([top[0], top[1], top[2], top[3]], 'blue', 0.82, smooth=False, hook=0.2)+b.line([side[1], side[2], side[3]], 'blue', 0.82, smooth=False, hook=0.2)+fcx, fcy = front[:, 0].mean(), front[:, 1].mean()+b.face(fcx, fcy + 2, 46, 'worry', 'blue', blush=None)+for (u, v) in [(0.3, 0.3), (0.7, 0.7)]:+ p = face_pt(top, u, v); b.dot(p[0], p[1], 2.6, 'blue')+for (u, v) in [(0.25, 0.25), (0.5, 0.5), (0.75, 0.75)]:+ p = face_pt(np.array([side[0], side[3], side[2], side[1]]), v, u); b.dot(p[0], p[1], 2.4, 'blue')+for sx in (-11, 11): # legs and feet+ b.line([(fcx + sx, front[2, 1]), (fcx + sx + sx * 0.15, front[2, 1] + 11)], 'blue', 0.8, smooth=False, hook=0)+ b.line(b.circle_pts(fcx + sx * 1.3, front[2, 1] + 14, 6, 3.5), 'blue', 0.75, closed=True, hook=0)+b.line([(front[0, 0], fcy + 4), (front[0, 0] - 12, fcy - 6), (front[0, 0] - 15, fcy - 18)], 'blue', 0.8, hook=0.2) # hands to cheeks+b.line([(side[2, 0] - 2, fcy + 6), (side[2, 0] + 10, fcy - 2), (side[2, 0] + 14, fcy - 14)], 'blue', 0.8, hook=0.2)+b.write('!?', front[0, 0] - 22, front[0, 1] - 2, 30, 'blue', 0.85, anchor='r', rot=-8)++# -- the die, just thrown, in the right margin+(c, s) = DIE+front_d, top_d, side_d = cube_pts(c[0], c[1], 62, 24, 22)+b.line(front_d, 'black', 0.85, closed=True, smooth=False, twice=0.6)+b.line([top_d[0], top_d[1], top_d[2], top_d[3]], 'black', 0.85, smooth=False, hook=0.2)+b.line([side_d[1], side_d[2], side_d[3]], 'black', 0.85, smooth=False, hook=0.2)+for (u, v) in [(0.27, 0.27), (0.73, 0.27), (0.27, 0.73), (0.73, 0.73)]: # four on top+ p = face_pt(top_d, u, v); b.dot(p[0], p[1], 3.4, 'black')+fc_ = front_d.mean(0)+for (u, v) in [(-1, -1), (1, -1), (0, 0), (-1, 1), (1, 1)]: # five in front+ b.dot(fc_[0] + u * 17, fc_[1] + v * 17, 3.6, 'black')+scc = side_d.mean(0)+b.dot(scc[0], scc[1], 4.6, 'red') # the one, in red+b.stage('pen_pieces')+tick('pieces')++# ===================================================================== 2. pen: snakes and ladders (they stop at the pieces)+for g, (ctrl, w0, col, band) in zip(SG, SNAKES):+ ang = np.degrees(np.arctan2(g['hd'][1], g['hd'][0]))+ # head: from one side of the neck round the snout to the other+ head = b.circle_pts(g['hc'][0], g['hc'][1], g['rx'], g['ry'], a0=148, a1=-148, rot=ang)+ b.line(head[::-1], 'blue', 0.85, smooth=True, hook=0.2, twice=0.5, clip=PIECEC)+ # one stroke down the left side, round the tail tip, back up the right side+ tip = g['P'][-1] + (g['P'][-1] - g['P'][-3]) / 2.0+ body = np.vstack([g['L'], [tip], g['R'][::-1]])+ b.line(body, 'blue', 0.82, smooth=True, hook=0.3, twice=0.55, clip=PIECEC)+ # eyes and tongue+ hd, nv = g['hd'], np.array([-g['hd'][1], g['hd'][0]])+ for sg in (-1, 1):+ e = g['hc'] + hd * g['rx'] * 0.12 + nv * sg * g['ry'] * 0.46+ b.eye(e[0], e[1], g['w0'] * 0.13, g['w0'] * 0.15, 'black', look=(hd[0], hd[1]))+ t0 = g['hc'] + hd * (g['rx'] + 1)+ t1 = t0 + hd * 14+ b.line([t0, t1], 'red', 0.85, smooth=False, hook=0, gloop=0.2)+ for sg in (-1, 1):+ b.line([t1, t1 + hd * 7 + nv * sg * 5], 'red', 0.8, smooth=False, hook=0, gloop=0.2)++LG = []+for (n0, n1) in LADDERS:+ A, Bp = ctr(n0, 0.0, -0.1), ctr(n1, 0.0, 0.12)+ d = (Bp - A) / np.linalg.norm(Bp - A); nv = np.array([-d[1], d[0]])+ L_ = np.linalg.norm(Bp - A)+ half = 15.0+ rails = [(A + nv * sg * half - d * 6, Bp + nv * sg * half + d * 8) for sg in (-1, 1)]+ for r0, r1 in rails:+ b.line([r0, r1], 'black', 0.82, bow=0.004, hook=0.2, twice=0.5, clip=PIECEC)+ rungs = []+ for s in np.arange(16, L_ - 6, 25):+ p = A + d * (s + rng.normal(0, 1.2))+ rungs.append([p + nv * (half + rng.uniform(-1, 2)), p - nv * (half + rng.uniform(-1, 2.5)) + d * rng.normal(0, 1.2)])+ b.lines(rungs, 'black', 0.8, smooth=False, hook=0.15, gloop=0.35, clip=PIECEC)+ LG.append(dict(A=A, B=Bp, d=d, nv=nv, half=half, L=L_, rungs=rungs))+b.stage('pen_snakes_ladders')+tick('snakes')++# ===================================================================== 3. pen: the grid, numbers, the way round+for i in range(N + 1):+ for horiz in (False, True):+ e0, e1 = -rng.uniform(0.02, 0.1), N + rng.uniform(0.02, 0.12)+ P = B([i, i], [e0, e1]) if not horiz else B([e0, e1], [i, i])+ outer = i in (0, N)+ if rng.random() < 0.35 and not outer: # a long line drawn in two goes+ m = rng.uniform(0.4, 0.6)+ Q = P[0] + (P[1] - P[0]) * m+ b.line([P[0], Q + (P[1] - P[0]) * 0.01], 'black', 0.84, bow=0.004, clip=EXC, hook=0.25, twice=0.2)+ b.line([Q - (P[1] - P[0]) * 0.012 + rng.normal(0, 0.8, 2), P[1]], 'black', 0.84, bow=0.004, clip=EXC, hook=0.25, twice=0.2)+ else:+ b.line(P, 'black', 0.86 if outer else 0.84, bow=0.004, clip=EXC, hook=0.25, twice=0.9 if outer else 0.3)+for n in range(1, 65):+ c_, r_ = cell(n)+ for (du, dv, anc) in [(0.1, 0.72, 'l'), (0.9, 0.72, 'r'), (0.1, 0.12, 'l'), (0.9, 0.12, 'r')]:+ p = B(c_ + du, r_ + dv)+ ok = EX[int(p[1]) - 14:int(p[1]) + 4, int(p[0]) - (0 if anc == 'l' else 26):int(p[0]) + (26 if anc == 'l' else 0)].max() < 0.05+ if ok:+ b.write(str(n), p[0], p[1], 19, 'red' if n % 10 == 0 else 'blue', 0.78, slant=4, jitter=0.7, anchor=anc, hook=0.15,+ gloop=0.15)+ break+# U-turn arrows at the row ends: the counting snakes back and forth+for r_ in range(N - 1):+ right = (r_ % 2 == 0)+ u = N + 0.18 if right else -0.18+ P = [B(u - (0.02 if right else -0.02), r_ + 0.5), B(u + (0.2 if right else -0.2), r_ + 0.75), B(u + (0.2 if right else -0.2), r_ + 1.25),+ B(u - (0.02 if right else -0.02), r_ + 1.5)]+ Q = spline(P, 10)+ b.line(Q, 'blue', 0.7, smooth=False, hook=0, gloop=0.3)+ b.arrow(Q[-1], Q[-1] - Q[-4], 9, 'blue', 0.75)+# 64: a little flag+fl = ctr(64, 0.05, -0.05)+b.line([fl + (-8, 30), fl + (-8, -28)], 'black', 0.85, smooth=False, hook=0)+b.line([fl + (-8, -28), fl + (22, -18), fl + (-8, -8)], 'black', 0.85, smooth=False, hook=0.2)+b.stage('pen_grid')+tick('grid')++# ===================================================================== 4. pencil: the board, the snakes, the ladders+ROW_COLS = ['lime', 'lime', 'yellow', 'yellow', 'sky', 'sky', 'pink', 'pink']+for n in range(1, 65):+ c_, r_ = cell(n)+ if (c_ + r_) % 2: continue+ m = b.poly(B([c_, c_ + 1, c_ + 1, c_], [r_, r_, r_ + 1, r_ + 1]))+ b.pencil(m * EXC, ROW_COLS[r_], angle=58 + rng.normal(0, 7), pressure=0.42 if ROW_COLS[r_] != 'yellow' else 0.5,+ spacing=4.6, length=(40, 85), overshoot=5.5)+for g, m, (ctrl, w0, col, band) in zip(SG, smasks, SNAKES):+ m = m * PIECEC+ b.pencil(m, col, angle=rng.uniform(30, 70), pressure=0.62, spacing=3.8, length=(30, 60), overshoot=3.5)+ Lb, Rb = g['L'], g['R'] # bands across the back, heavier+ for i in range(6, len(Lb) - 8, 12):+ poly = np.vstack([Lb[i:i + 5], Rb[i:i + 5][::-1]])+ b.pencil(b.poly(poly) * m, band, angle=rng.uniform(20, 160), pressure=0.85, spacing=2.8, length=(10, 20), overshoot=2.0)+ spine = g['P'][4:]+ shade_band = b.poly(np.vstack([Rb, (Rb + (spine[:len(Rb)] - Rb) * 0.42)[::-1]])) * m+ b.pen_hatch(shade_band, 'blue', rng.uniform(30, 60), spacing=3.4, pressure=0.5, length=(10, 22), zigzag=0.7)+ b.pencil(b.ellipse(g['hc'][0], g['hc'][1], g['rx'] * 0.95, g['ry'] * 0.95, rot=np.degrees(np.arctan2(g['hd'][1], g['hd'][0]))) * m,+ col, angle=rng.uniform(100, 140), pressure=0.55, spacing=3.4, length=(20, 40), overshoot=2)+ hd, nv = g['hd'], np.array([-g['hd'][1], g['hd'][0]])+ for sg in (-1, 1):+ e = g['hc'] + hd * g['rx'] * 0.42 + nv * sg * g['ry'] * 0.66+ b.pencil(b.ellipse(e[0], e[1], g['w0'] * 0.1, g['w0'] * 0.07, rot=np.degrees(np.arctan2(hd[1], hd[0]))), 'rose', angle=60,+ pressure=0.8, spacing=2.4, length=(6, 12), overshoot=1)+for lg in LG:+ for sg in (-1, 1):+ r0 = lg['A'] + lg['nv'] * sg * lg['half'] - lg['d'] * 6+ r1 = lg['B'] + lg['nv'] * sg * lg['half'] + lg['d'] * 8+ b.pencil_line([r0 - lg['nv'] * sg * 3, r1 - lg['nv'] * sg * 3], 'ochre', 0.85, width=4.2, clip=PIECEC)+ b.pencil_line([r0 + lg['nv'] * sg * 1.5, r1 + lg['nv'] * sg * 1.5], 'brown', 0.55, width=2.6, clip=PIECEC)+ for rg in lg['rungs']:+ b.pencil_line(rg, 'tan', 0.8, width=3.6, smooth=False, clip=PIECEC)+b.stage('pencil_board')+tick('pencil board')++# ===================================================================== 5. pencil: the pieces+b.pencil(sn_shell, 'orange', angle=50, pressure=0.75, spacing=3.2, length=(16, 34), overshoot=2.5)+(c, s, rot) = SNAIL+b.pencil_line(b.spiral_pts(sc[0] + 2, sc[1] + 1, SNAIL_SHELL[2] * s * 0.6, turns=1.6, a0=rot + 200), 'yellow', 0.9, width=5)+b.pencil(sn_body * (1 - sn_shell), 'peach', angle=120, pressure=0.6, spacing=3.4, length=(16, 34), overshoot=2.5)+b.pencil(b.ellipse(fc[0] - 2, fc[1] + 6, 6, 4), 'pink', angle=60, pressure=0.7, spacing=2.4, length=(6, 10), overshoot=1)+b.pencil(cl_mask, 'sky', angle=62, pressure=0.42, spacing=4.0, length=(20, 46), overshoot=3.5)+cc = CLOUD[0]+YY = np.broadcast_to(np.arange(H, dtype=np.float32)[:, None], (H, W))+b.pen_hatch(cl_mask * smoothstep(cc[1] + 26, cc[1] + 46, YY), 'blue', 40, spacing=3.4, pressure=0.6, length=(14, 26))+del YY+f_, t_, s_ = dicem_geom()+b.pencil(b.poly(f_), 'lilac', angle=55, pressure=0.48, spacing=3.6, length=(18, 40), overshoot=2.5)+b.pencil(b.poly(t_), 'lilac', angle=15, pressure=0.3, spacing=3.6, length=(18, 40), overshoot=2.0)+b.pencil(b.poly(s_), 'violet', angle=80, pressure=0.55, spacing=3.2, length=(18, 40), overshoot=2.0)+b.pen_hatch(b.ellipse(fcx + 4, front[2, 1] + 16, 34, 5.5) * (1 - dm_mask), 'blue', 20, spacing=3.0, pressure=0.45, length=(14, 30))+for sx in (-1, 1):+ b.pencil(b.ellipse(fcx + sx * 14, fcy + 9, 5.5, 3.2), 'pink', angle=60, pressure=0.75, spacing=2.4, length=(6, 10), overshoot=1)+b.pencil(b.poly(side_d), 'grey', angle=75, pressure=0.42, spacing=3.4, length=(20, 40), overshoot=2.5)+b.pencil(b.poly(front_d), 'grey', angle=40, pressure=0.16, spacing=4.4, length=(20, 40), overshoot=2.5)+b.pencil(b.ellipse(DIE[0][0] + 8, DIE[0][1] + 40, 52, 9), 'grey', angle=10, pressure=0.32, spacing=3.6, length=(20, 50), overshoot=3)+b.stage('pencil_pieces')+tick('pencil pieces')++# ===================================================================== 6. margin doodles+# -- bunting across the top+P0, P1 = np.array([640.0, 44.0]), np.array([1300.0, 56.0])+xs_ = np.linspace(0, 1, 60)+string = np.stack([P0[0] + (P1[0] - P0[0]) * xs_, P0[1] + (P1[1] - P0[1]) * xs_ + 34 * 4 * xs_ * (1 - xs_)], 1)+b.line(string, 'blue', 0.8, smooth=False, hook=0.3)+b.line(b.circle_pts(P0[0], P0[1], 5, 5), 'blue', 0.85, closed=True, hook=0)+b.line(b.circle_pts(P1[0], P1[1], 5, 5), 'blue', 0.85, closed=True, hook=0)+FLAGC = ['yellow', 'sky', 'pink', 'lime']+for k in range(11):+ t0 = 0.05 + k * 0.083; t1 = t0 + 0.06+ a = string[int(t0 * 59)]; c2 = string[int(t1 * 59)]+ mid = (a + c2) / 2; nrm = np.array([-(c2 - a)[1], (c2 - a)[0]]); nrm /= np.linalg.norm(nrm)+ if nrm[1] < 0: nrm = -nrm+ tip = mid + nrm * 42+ tri = [a, tip, c2]+ b.line(tri, 'blue', 0.82, smooth=False, hook=0.25)+ b.pencil(b.poly(tri), FLAGC[k % 4], angle=rng.uniform(40, 80), pressure=0.6, spacing=3.4, length=(14, 30), overshoot=3)+ if k % 3 == 1:+ st = b.star_pts(mid[0] + nrm[0] * 15, mid[1] + nrm[1] * 15, 7)+ b.line(st, 'blue', 0.75, smooth=False, hook=0)++# -- the sun, top right+SX, SY, SR = 1736.0, 112.0, 50.0+b.line(b.circle_pts(SX, SY, SR, SR * 0.97), 'blue', 0.85, closed=True, twice=0.5)+b.pencil(b.ellipse(SX, SY, SR, SR * 0.97), 'yellow', angle=60, pressure=0.62, spacing=3.6, length=(20, 50), overshoot=4)+b.face(SX, SY + 4, 70, 'sleep', 'blue', blush='peach')+rays = []+for k in range(14):+ a = np.deg2rad(k * 360 / 14 + rng.normal(0, 3))+ r0, r1 = SR + 9, SR + (30 if k % 2 == 0 else 19) + rng.normal(0, 2)+ rays.append([(SX + np.cos(a) * r0, SY + np.sin(a) * r0), (SX + np.cos(a) * r1, SY + np.sin(a) * r1)])+b.lines(rays, 'blue', 0.8, smooth=False, hook=0.2)+for rr in rays[::2]:+ b.pencil_line(rr, 'orange', 0.7, width=3.4, smooth=False)+for (bx, by, bs) in [(1560, 70, 15), (1600, 102, 11), (1530, 118, 9)]:+ b.line([(bx - bs, by - bs * 0.3), (bx - bs * 0.45, by - bs * 0.55), (bx, by), (bx + bs * 0.45, by - bs * 0.6), (bx + bs, by - bs * 0.25)],+ 'blue', 0.75, hook=0.1)++# -- note card on the left (text comes later)+NX0, NY0, NX1, NY1 = 70.0, 236.0, 452.0, 370.0+card = [(NX0, NY0), (NX1, NY0 + 3), (NX1 + 2, NY1 - 26), (NX1 - 24, NY1 + 1), (NX0 + 2, NY1)]+b.line(card, 'blue', 0.82, closed=True, smooth=False, twice=0.4)+b.line([(NX1 + 2, NY1 - 26), (NX1 - 20, NY1 - 22), (NX1 - 24, NY1 + 1)], 'blue', 0.78, smooth=False, hook=0) # the folded corner+b.pencil(b.poly([(NX1 + 2, NY1 - 26), (NX1 - 20, NY1 - 22), (NX1 - 24, NY1 + 1)]), 'grey', 60, 0.35, 2.8, (6, 14), 1)+b.line(b.circle_pts(NX0 + 18, NY0 + 18, 5, 5), 'blue', 0.85, closed=True, hook=0)+b.dot(NX0 + 18, NY0 + 18, 2.0, 'blue')+# dashed arrow from the card to the long snake+arr = np.array([(NX1 + 10, 330), (520, 380), (565, 420), B(0.35, 4.55)], np.float32)+P = b.dashes(arr, 'blue', 10, 7, 0.8)+b.arrow(P[-1], P[-1] - P[-12], 13, 'blue', 0.8)++# -- tic-tac-toe, left middle+TX, TY, TS = 92.0, 452.0, 52.0+for k in (1, 2):+ b.line([(TX + k * TS + rng.normal(0, 2), TY - 6), (TX + k * TS + rng.normal(0, 2), TY + 3 * TS + 6)], 'blue', 0.8, bow=0.01, hook=0.2)+ b.line([(TX - 6, TY + k * TS + rng.normal(0, 2)), (TX + 3 * TS + 6, TY + k * TS + rng.normal(0, 2))], 'blue', 0.8, bow=0.01, hook=0.2)+for (i, j, m) in [(0, 0, 'x'), (1, 1, 'x'), (2, 0, 'o'), (0, 2, 'o'), (2, 2, 'x'), (1, 0, 'o')]:+ cx_, cy_ = TX + (i + 0.5) * TS, TY + (j + 0.5) * TS+ if m == 'x':+ b.line([(cx_ - 14, cy_ - 14), (cx_ + 14, cy_ + 13)], 'blue', 0.8, smooth=False, hook=0.2)+ b.line([(cx_ + 14, cy_ - 14), (cx_ - 13, cy_ + 14)], 'blue', 0.8, smooth=False, hook=0.2)+ else:+ b.line(b.circle_pts(cx_, cy_, 15, 14), 'blue', 0.8, closed=True)+b.line([(TX + 8, TY + 6), (TX + 3 * TS - 6, TY + 3 * TS - 8)], 'red', 0.85, bow=0.01, hook=0.3)++# -- paper plane with its looping dashed flight+PX, PY = 400.0, 486.0+plane = [(PX - 34, PY + 8), (PX + 32, PY - 12), (PX - 16, PY + 22), (PX - 34, PY + 8)]+b.line(plane, 'blue', 0.82, smooth=False, hook=0)+b.line([(PX + 32, PY - 12), (PX - 8, PY + 12), (PX - 12, PY + 32), (PX - 16, PY + 22)], 'blue', 0.8, smooth=False, hook=0.2)+b.pencil(b.poly(plane), 'sky', 60, 0.35, 3.4, (10, 24), 2)+loop = [(PX - 40, PY + 14), (PX - 90, PY + 40), (PX - 120, PY + 90), (PX - 80, PY + 130), (PX - 40, PY + 96), (PX - 70, PY + 60),+ (PX - 140, PY + 80), (PX - 200, PY + 150)]+b.dashes(loop, 'blue', 8, 7, 0.7)++# -- house on a hill, bottom left+hill = [(20, 1020), (120, 930), (250, 898), (390, 918), (520, 990)]+b.line(hill, 'blue', 0.82, hook=0.2)+HX, HY = 168.0, 900.0+house = [(HX, HY - 4), (HX, HY - 74), (HX + 92, HY - 74), (HX + 92, HY + 2)]+b.line(house, 'blue', 0.84, smooth=False, hook=0.2)+roof = [(HX - 12, HY - 70), (HX + 46, HY - 122), (HX + 104, HY - 70), (HX - 12, HY - 70)]+b.line(roof, 'blue', 0.84, smooth=False, hook=0.2)+b.line([(HX + 70, HY - 101), (HX + 70, HY - 130), (HX + 84, HY - 130), (HX + 84, HY - 88)], 'blue', 0.8, smooth=False, hook=0.1) # chimney+b.line(spline([(HX + 78, HY - 138), (HX + 70, HY - 152), (HX + 84, HY - 166), (HX + 74, HY - 184), (HX + 92, HY - 198),+ (HX + 82, HY - 218)], 8), 'blue', 0.7, hook=0.3)+b.line([(HX + 34, HY), (HX + 34, HY - 40), (HX + 56, HY - 40), (HX + 56, HY)], 'blue', 0.8, smooth=False, hook=0.1) # door+b.dot(HX + 51, HY - 20, 1.8, 'blue')+b.line([(HX + 10, HY - 60), (HX + 28, HY - 60), (HX + 28, HY - 44), (HX + 10, HY - 44), (HX + 10, HY - 60)], 'blue', 0.8, smooth=False, hook=0)+b.line([(HX + 64, HY - 60), (HX + 82, HY - 60), (HX + 82, HY - 44), (HX + 64, HY - 44), (HX + 64, HY - 60)], 'blue', 0.8, smooth=False, hook=0)+b.pencil(b.poly(roof), 'red', 50, 0.66, 3.2, (14, 30), 3)+b.pencil(b.poly(house + [(HX, HY - 4)]), 'cream', 70, 0.5, 3.6, (14, 30), 3)+b.pencil(b.poly([(HX + 10, HY - 60), (HX + 28, HY - 60), (HX + 28, HY - 44), (HX + 10, HY - 44)]), 'yellow', 30, 0.8, 2.6, (6, 12), 1)+b.pencil(b.poly([(HX + 64, HY - 60), (HX + 82, HY - 60), (HX + 82, HY - 44), (HX + 64, HY - 44)]), 'yellow', 30, 0.8, 2.6, (6, 12), 1)+TRX, TRY = 360.0, 838.0+crown = Ballpoint.cloud_pts(TRX, TRY, 96, 80, bumps=8, seed=11, flat=False)+b.line(crown, 'blue', 0.82, closed=True, hook=0.2)+b.line([(TRX - 7, TRY + 34), (TRX - 9, TRY + 78)], 'blue', 0.82, smooth=False, hook=0)+b.line([(TRX + 8, TRY + 34), (TRX + 10, TRY + 80)], 'blue', 0.82, smooth=False, hook=0)+b.pencil(b.poly(crown), 'green', 55, 0.6, 3.4, (16, 36), 3)+b.pencil(b.poly([(TRX - 7, TRY + 30), (TRX + 8, TRY + 30), (TRX + 10, TRY + 80), (TRX - 9, TRY + 78)]), 'brown', 80, 0.7, 3.0, (10, 20), 1.5)+for (ax, ay) in [(TRX - 22, TRY - 8), (TRX + 18, TRY - 16), (TRX + 4, TRY + 10)]:+ b.line(b.circle_pts(ax, ay, 6, 6), 'red', 0.8, closed=True, hook=0)+ b.pencil(b.ellipse(ax, ay, 6, 6), 'red', 50, 0.85, 2.4, (6, 12), 1)+hm = b.poly(np.vstack([np.array(hill, np.float32), [(520, 1080), (20, 1080)]]))+b.pencil(hm * smoothstep(0.0, 1.0, 1 - b.poly([(HX - 2, HY - 76), (HX + 94, HY - 76), (HX + 94, HY + 4), (HX - 2, HY + 4)])), 'lime', 62,+ 0.32, 5.0, (30, 60), 4)+grass = []+for k in range(26):+ gx = rng.uniform(40, 500); t_ = np.interp(gx, [h[0] for h in hill], [h[1] for h in hill])+ gy = t_ + rng.uniform(6, 60)+ for j in range(3):+ grass.append([(gx + j * 4, gy), (gx + j * 4 + rng.uniform(-6, 6), gy - rng.uniform(8, 16))])+b.lines(grass[:30], 'blue', 0.6, smooth=False, hook=0.1, gloop=0.2)+for gr in grass[30:]:+ b.pencil_line(gr, 'leaf', 0.7, width=2.6, smooth=False)++# -- stars here and there+for (x_, y_, r_) in [(560, 66, 13), (520, 150, 8), (40, 410, 10), (1880, 330, 10), (1390, 120, 12), (1380, 860, 9), (60, 820, 9)]:+ st = b.star_pts(x_, y_, r_, rot=rng.uniform(-110, -70))+ b.line(st, 'blue', 0.8, smooth=False, hook=0.1)+ b.pencil(b.poly(st), 'yellow', 60, 0.7, 2.6, (8, 16), 1.5)+b.line(b.spiral_pts(52, 700, 22, turns=3.0, a0=40), 'blue', 0.75, smooth=False, hook=0.3)+# a string of stars hung between two pins+s0, s1 = np.array([292.0, 662.0]), np.array([540.0, 650.0])+tt = np.linspace(0, 1, 40)[:, None]+thread = s0 + (s1 - s0) * tt + np.array([0, 1.0]) * 4 * tt * (1 - tt) * 34+b.line(thread, 'blue', 0.78, smooth=False, hook=0.2)+for p_ in (s0, s1):+ b.dot(p_[0], p_[1], 3.6, 'blue')+for k, (t_, hang, r_) in enumerate([(0.16, 22, 12), (0.38, 38, 14), (0.6, 26, 12), (0.82, 40, 13)]):+ q = thread[int(t_ * 39)]+ b.line([q, q + np.array([rng.normal(0, 1.5), hang])], 'blue', 0.7, smooth=False, hook=0, gloop=0.2)+ st = b.star_pts(q[0], q[1] + hang + r_ * 0.9, r_, rot=rng.uniform(-100, -80))+ b.line(st, 'blue', 0.8, smooth=False, hook=0.1)+ b.pencil(b.poly(st), 'yellow', rng.uniform(40, 80), 0.75, 2.6, (8, 16), 1.5)++# -- score card box, right (text comes later)+SCX0, SCY0, SCX1, SCY1 = 1420.0, 228.0, 1852.0, 458.0+b.line([(SCX0, SCY0), (SCX1, SCY0 + 2)], 'blue', 0.84, bow=0.004, hook=0.2)+b.line([(SCX1, SCY0 + 2), (SCX1 + 2, SCY1)], 'blue', 0.84, bow=0.004, hook=0.2)+b.line([(SCX1 + 2, SCY1), (SCX0 - 2, SCY1 - 1)], 'blue', 0.84, bow=0.004, hook=0.2)+b.line([(SCX0 - 2, SCY1 - 1), (SCX0, SCY0)], 'blue', 0.84, bow=0.004, hook=0.2)+b.line([(SCX0 + 4, SCY0 + 58), (SCX1 - 4, SCY0 + 60)], 'blue', 0.8, bow=0.004, hook=0.2)+b.line([(SCX0 + 190, SCY0 + 62), (SCX0 + 192, SCY1 - 6)], 'blue', 0.8, bow=0.004, hook=0.2)+# tiny icons+ix = SCX0 + 34+b.line(b.spiral_pts(ix, SCY0 + 92, 12, 2.0, 0), 'black', 0.8, smooth=False, hook=0)+b.line([(ix - 18, SCY0 + 104), (ix + 20, SCY0 + 104), (ix + 24, SCY0 + 92)], 'black', 0.8, hook=0)+b.pencil(b.ellipse(ix, SCY0 + 92, 12, 12), 'orange', 50, 0.65, 2.8, (8, 16), 1.5)+cl_i = Ballpoint.cloud_pts(ix, SCY0 + 148, 40, 26, bumps=6, seed=2)+b.line(cl_i, 'blue', 0.8, closed=True, hook=0)+b.pencil(b.poly(cl_i), 'sky', 60, 0.5, 3.0, (8, 16), 1.5)+fq, tq, sq = cube_pts(ix - 4, SCY0 + 202, 24, 8, 7)+b.line(fq, 'blue', 0.8, closed=True, smooth=False, hook=0)+b.line([tq[0], tq[1], tq[2], sq[2], sq[3]], 'blue', 0.8, smooth=False, hook=0)+b.pencil(b.poly(fq), 'lilac', 50, 0.55, 2.8, (8, 16), 1.5)++# -- the die's bounce across the margin+traj = [(1880, 492), (1800, 456), (1730, 520), (1700, 590), (1660, 548), (1610, 560), (1585, 612)]+P = b.dashes(traj, 'black', 9, 7, 0.7)+b.lines([[(1694, 604), (1688, 616)], [(1702, 606), (1708, 618)], [(1698, 608), (1698, 621)]], 'black', 0.7, smooth=False, hook=0)+b.lines([[(1462, 650), (1446, 646)], [(1464, 670), (1447, 676)], [(1478, 700), (1468, 712)]], 'black', 0.75, smooth=False, hook=0)++# -- flower pot, bottom right+FX, FY = 1800.0, 1000.0+pot = [(FX - 34, FY - 40), (FX + 34, FY - 40), (FX + 26, FY + 22), (FX - 26, FY + 22), (FX - 34, FY - 40)]+b.line(pot, 'blue', 0.82, smooth=False, hook=0.1)+b.line([(FX - 38, FY - 40), (FX + 38, FY - 40), (FX + 38, FY - 28), (FX - 36, FY - 28), (FX - 38, FY - 40)], 'blue', 0.8, smooth=False, hook=0)+b.pencil(b.poly(pot), 'orange', 70, 0.55, 3.2, (14, 30), 2.5)+b.line([(FX, FY - 42), (FX - 4, FY - 100), (FX + 2, FY - 150)], 'blue', 0.8, hook=0.1)+b.pencil_line([(FX, FY - 42), (FX - 4, FY - 100), (FX + 2, FY - 150)], 'leaf', 0.8, width=3.4)+for sg in (-1, 1):+ leaf = [(FX - 3, FY - 80), (FX - 3 + sg * 22, FY - 104), (FX - 3 + sg * 36, FY - 96), (FX - 3 + sg * 20, FY - 84), (FX - 3, FY - 80)]+ b.line(leaf, 'blue', 0.8, hook=0)+ b.pencil(b.poly(spline(leaf, 6)), 'green', 40, 0.65, 2.8, (8, 18), 1.5)+for k in range(5):+ a = np.deg2rad(k * 72 - 90)+ pc = (FX + 2 + np.cos(a) * 14, FY - 160 + np.sin(a) * 14)+ pe = b.circle_pts(pc[0], pc[1], 11, 7, rot=np.degrees(a))+ b.line(pe, 'blue', 0.8, closed=True, hook=0)+ b.pencil(b.ellipse(pc[0], pc[1], 11, 7, rot=np.degrees(a)), 'pink', 60, 0.7, 2.6, (8, 14), 1.5)+b.line(b.circle_pts(FX + 2, FY - 160, 6, 6), 'blue', 0.85, closed=True, hook=0)+b.pencil(b.ellipse(FX + 2, FY - 160, 6, 6), 'yellow', 60, 0.9, 2.4, (6, 10), 1)+# a little cube doodle and a heart+qf, qt, qs = cube_pts(1440, 960, 40, 14, 12)+b.line(qf, 'blue', 0.8, closed=True, smooth=False, hook=0)+b.line([qt[0], qt[1], qt[2], qt[3]], 'blue', 0.8, smooth=False, hook=0)+b.line([qs[1], qs[2], qs[3]], 'blue', 0.8, smooth=False, hook=0)+b.pen_hatch(b.poly(qs), 'blue', 70, spacing=3.2, pressure=0.6, length=(10, 20))+ht = b.heart_pts(1560, 1010, 30, rot=-12)+b.line(ht, 'red', 0.82, closed=True, hook=0.2)+b.pencil(b.poly(ht), 'rose', 55, 0.6, 3.0, (10, 20), 2)+b.stage('doodles')+tick('doodles')++# ===================================================================== 7. red pen: this move+# where the snail was (10): a dotted ghost ring+p10 = ctr(10)+for k in range(12):+ a = np.deg2rad(k * 30)+ b.dot(p10[0] + np.cos(a) * 24, p10[1] + 6 + np.sin(a) * 18, 1.9, 'red')+# four hops: 10 -> 11 -> 12 -> 13 -> 14, counted+for k, (n0, n1) in enumerate([(10, 11), (11, 12), (12, 13), (13, 14)]):+ a, c2 = ctr(n0, -0.1, -0.4), ctr(n1, 0.1, -0.4)+ tt = np.linspace(0, 1, 14)[:, None]+ arc = a + (c2 - a) * tt + np.array([0.0, -1.0]) * (4 * tt * (1 - tt)) * 24+ P = b.dashes(arc, 'red', 7, 5, 0.85, smooth=False)+ b.arrow(P[-1], P[-1] - P[-6], 9, 'red', 0.85)+ top_ = (a + c2) / 2 + np.array([13, -24]) # beside the grid line, not on it+ b.write(str(k + 1), top_[0], top_[1] - 5, 19, 'red', 0.85, anchor='m', hook=0.2, gloop=0.1)+# up the ladder+lg = LG[0]+side = lg['nv'] * 40 # on the free side of the ladder+P = b.dashes([lg['A'] + side + lg['d'] * 30, lg['A'] + side + lg['d'] * (lg['L'] * 0.5), lg['B'] + side - lg['d'] * 10],+ 'red', 13, 8, 0.85, clip=PIECEC)+b.arrow(P[-1], P[-1] - P[-14], 15, 'red', 0.88)+b.ring(SNAIL[0][0] - 4, SNAIL[0][1] - 10, 74, 58, 'red', 0.88, rot=-38)+p43 = B(5.1, 4.98)+b.write('+24!', p43[0], p43[1], 34, 'red', 0.88, anchor='l', rot=-6)+b.ring(DIE[0][0] + 6, DIE[0][1] - 2, 66, 60, 'red', 0.8)+b.write('4!', DIE[0][0] + 84, DIE[0][1] - 60, 40, 'red', 0.9, anchor='l')+b.stage('red_pen')+tick('red pen')++# ===================================================================== 8. notes, labels, the score+b.write('snakes & ladders', 64, 104, 62, 'blue', 0.84, slant=6)+b.write('lunch break - round 7', 72, 160, 30, 'red', 0.82, slant=6)+b.underline(66, 520, 120, 'blue', 0.8)+b.write('who drew this', NX0 + 40, NY0 + 58, 34, 'blue', 0.82)+b.write('snake so LONG?!', NX0 + 40, NY0 + 104, 34, 'blue', 0.82)+pn = B(3.0, 4.26)+b.write('nooo~', pn[0], pn[1], 28, 'blue', 0.8, rot=-8)+b.write('start', B(-0.05, -0.42)[0], B(-0.05, -0.42)[1] + 6, 26, 'blue', 0.8)+st0 = B(0.62, -0.32)+b.line([st0, st0 + np.array([10, -30])], 'blue', 0.8, smooth=False, hook=0)+b.arrow(st0 + np.array([10, -30]), (0.3, -1), 9, 'blue')+b.write('home', B(0.5, 8.1)[0], B(0.5, 8.1)[1] - 8, 22, 'blue', 0.8)+# score card+b.write('round 7', SCX0 + 22, SCY0 + 42, 34, 'red', 0.85)+b.write('where?', SCX0 + 214, SCY0 + 42, 30, 'blue', 0.8)+rows = [('snail', '10', '38'), ('cloud', '47', '18'), ('dice', '51', None)]+for k, (nm, a_, z_) in enumerate(rows):+ yb = SCY0 + 102 + k * 54+ b.write(nm, SCX0 + 62, yb, 30, 'blue', 0.8)+ bx_ = b.write(a_, SCX0 + 214, yb, 30, 'blue', 0.8)+ if z_:+ y_m = yb - 10+ b.line([(bx_[2] + 10, y_m), (bx_[2] + 46, y_m - 1)], 'blue', 0.8, smooth=False, hook=0)+ b.arrow((bx_[2] + 46, y_m - 1), (1, 0), 9, 'blue')+ b.write(z_, bx_[2] + 56, yb, 30, 'red' if k == 0 else 'blue', 0.82)+ b.write('ladder' if k == 0 else 'snake', bx_[2] + 104, yb, 20, 'blue', 0.7)+# the die note, with a word crossed out+bx1 = b.write('rolled a', 1416, 784, 32, 'blue', 0.82)+bx2 = b.write('three', bx1[2] + 14, 784, 32, 'blue', 0.82)+b.strike(bx2, 'blue', 0.85, passes=4)+b.write('four!', bx2[2] + 14, 784, 32, 'blue', 0.84)+b.write('(the snail asked for 4)', 1430, 828, 22, 'blue', 0.72)+# ghost of a shopping list pressed through from the sheet above+b.write('milk', 1606, 914, 34, None, 0.9, blind=True)+b.write('eggs x6', 1606, 958, 34, None, 0.9, blind=True)+b.write('glue stick', 1606, 1002, 34, None, 0.9, blind=True)+b.stage('notes')+tick('notes')++# ===================================================================== 9. the conclusion+cb = b.write('slow snail, fast ladder!', 960, 1004, 58, 'red', 0.88, anchor='m', slant=6)+b.underline(cb[0] - 6, cb[2] + 10, cb[3] + 12, 'red', 0.85, wavy=True)+b.write('next: dice', 1268, 1050, 26, 'blue', 0.8)+tick('conclusion')++img = b.save(out, stages_dir=stages)+tick('saved')+print('saved', out)diff --git a/examples/drawing_ballpoint_board_game.gif b/examples/drawing_ballpoint_board_game.gifnew file mode 100644index 0000000..5efe87dBinary files /dev/null and b/examples/drawing_ballpoint_board_game.gif differdiff --git a/examples/drawing_moon_river.gif b/examples/drawing_moon_river.gifnew file mode 100644index 0000000..f575582Binary files /dev/null and b/examples/drawing_moon_river.gif differdiff --git a/examples/drawing_watercolor_washes.gif b/examples/drawing_watercolor_washes.gifnew file mode 100644index 0000000..1f81534Binary files /dev/null and b/examples/drawing_watercolor_washes.gif differdiff --git a/examples/watercolor_washes.py b/examples/watercolor_washes.pyindex ac05ebc..9b2791d 100644--- a/examples/watercolor_washes.py+++ b/examples/watercolor_washes.py@@ -3,7 +3,7 @@ back-run blooms, granulation, splatters) in indigo / ochre-to-burnt-sienna / sagleaving open paper in the middle. Made as backgrounds for an explainer video: crisp UI cards sit on top of the paint(Opus 5.5 cost explainer, 2026-09). Two layouts; change the seed, or mirror / rotate the image, for more variants.Pure code, no image model.-python3 watercolor_washes.py [out.png] [--layout cover|bill] [--seed N]+python3 watercolor_washes.py [out.png] [--layout cover|bill] [--seed N] [--stages DIR]"""import os, syssys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'lib'))@@ -45,23 +45,29 @@ def grade(p, x0, y0, x1, y1, lo=0.35, hi=1.0):def cover(seed=5302):p = Watercolor(1920, 1080, seed=seed, paper_tone='#fdfbf6')p.paper()+ p.stage('paper')# thin ochre pass across the top-left, fading to the right (just a warm breath above the title card)p.glaze(sweep(p, [(-120, 150), (300, 70), (760, 40), (1060, 60)], 150, 50) * grade(p, 0, 100, 1060, 60, 0.2, 1), OCHRE, 0.5, edge=0.8, gran=0.5)+ p.stage('ochre_breath')# ochre -> burnt sienna pool, bottom-left, sienna dropped in wetoch = sweep(p, [(-160, 690), (220, 780), (560, 960), (820, 1160)], 300, 230)p.glaze(och * grade(p, 0, 1000, 700, 700, 0.55, 1), OCHRE, 0.72, edge=0.8, gran=0.55, bloom=2)p.glaze(blob(p, 120, 1000, 380, 190, rough=0.3, soft=26, ragged=0.5) * np.clip(och * 1.2, 0, 1), SIENNA, 0.62, edge=0.2, gran=0.6)+ p.stage('ochre_sienna')# sage band along the bottom, overlapping the ochre (mixes to olive where they cross)p.glaze(sweep(p, [(1560, 1160), (1150, 980), (760, 920), (420, 960)], 190, 120), SAGE, 0.66, edge=0.75, gran=0.45, bloom=1)+ p.stage('sage')# the big indigo sweep from the top-right corner diagonally down (ultramarine granulates hard)ind = sweep(p, [(2120, -120), (1760, 170), (1420, 400), (1100, 560)], 470, 190, rough=0.2)p.glaze(ind * grade(p, 1920, 0, 1150, 560, 0.5, 1), INDIGO, 0.85, edge=0.8, gran=0.8, bloom=3, variation=0.35)p.glaze(blob(p, 1860, 80, 470, 300, rough=0.3, soft=38, ragged=0.5) * np.clip(ind * 1.3, 0, 1), INDIGO_D, 0.55, edge=0.1, gran=0.65)+ p.stage('indigo')# teal pass along the lower rim of the indigo -> deep blue-green overlapp.glaze(sweep(p, [(2050, 560), (1700, 690), (1330, 770), (1000, 800)], 150, 90) * grade(p, 1920, 600, 1000, 800, 0.5, 1), TEAL, 0.7, edge=0.8, gran=0.55, bloom=1)# sage echo near the top, ochre spark inside the indigo (complementary glint)p.glaze(blob(p, 1190, 95, 170, 80, rot=0.35, rough=0.35, soft=3), SAGE, 0.5, edge=0.7, gran=0.4)p.glaze(blob(p, 1560, 620, 90, 55, rot=-0.3, rough=0.35, soft=10, ragged=0.45), OCHRE, 0.55, edge=0.4, gran=0.5)+ p.stage('teal_accents')# splattersp.splatter(INDIGO, n=44, box=(980, 0, 1900, 760), size=(1.5, 6), strength=0.75)p.splatter(INDIGO, n=7, box=(1050, 30, 1850, 700), size=(8, 14), strength=0.55)@@ -104,5 +110,6 @@ if __name__ == '__main__':seed = int(args[args.index('--seed') + 1]) if '--seed' in args else Nonefn = cover if layout == 'cover' else billp = fn(seed) if seed is not None else fn()- p.save(out)+ stages = args[args.index('--stages') + 1] if '--stages' in args else None+ p.save(out, stages_dir=stages)print('saved', out)diff --git a/lib/ballpoint.py b/lib/ballpoint.pynew file mode 100644index 0000000..bcaf84a--- /dev/null+++ b/lib/ballpoint.py@@ -0,0 +1,959 @@+"""ballpoint — doodling on a sheet of copy paper with ballpoint pens (blue, red, black) and a few coloured pencils:+pen line art, pencil hatching inside it, margin doodles, handwritten notes (numpy + Pillow only).++Model:+ paper grey-beige copy paper. A fine `tooth` height field (smoother than drawing paper), sparse fibres and+ a faint mottle; the sheet is not flat: low cockles and optional fold creases (a sharp valley with the+ two sides tilted differently) shade it under a soft light from the top left, and it is photographed,+ so the light falls off a little toward the corners. Nothing shows through from the back.+ ink ballpoint ink is a thick oil paste that a rolling ball lays down. A line is ~2.3 px wide and almost+ solid; its colour is an optical density (Beer-Lambert), so a line drawn twice, a crossing or a gloop+ gets darker and more saturated (blue goes to a deep blue-violet), never flat black. How a stroke goes:+ start the ball is dry for the first few px: thin, pale and grainy (ink only on the tooth peaks);+ body pressure drifts +-12 %; the width follows it a little; hand tremor and, on long straight+ lines, a slight bow;+ skips here and there the ball stops feeding for 2-9 px: a pale gap, but the groove is still there;+ gloops excess paste builds up on the ball and is dropped as a dark blob where the pen stops, at+ sharp turns, sometimes where it starts and every few hundred px on long lines;+ end a quick flick as the pen lifts (`hook`): the line curls back 90-160 degrees over 3-7 px;+ twice a line gone over again lands 0.6-1.6 px off the first one for part of its length.+ grooves every stroke presses a groove into the paper (deeper with pressure, a little for pencil too). The+ height field is lit from the top left: the upper-left wall of a groove darkens, the lower-right wall+ catches light. `emboss` / `write(blind=True)` press grooves with no ink -- the ghost of writing done on+ the sheet that lay on top.+ pencil coloured pencil is wax pigment that only sticks to the tooth it touches: light pressure grazes the+ peaks (grainy, pale), hard pressure fills the valleys. It is laid as quick parallel hatching (`pencil`),+ one patch at a time, strokes a little bowed, heavier in the middle than at the ends, running past the+ outline (`overshoot`) and changing direction from patch to patch; big areas light, small ones heavy.+ Layers multiply. `pen_hatch` is the same in ink: back-and-forth zigzag shading with gloops at the turns.+ writing the centre lines of a thin handwriting font (Zhang-Suen skeleton traced into pen paths, cached per+ character) are re-drawn as pen strokes: each letter re-sized, tilted and lifted off a wandering+ baseline, slanted, with pressure, start fade, gloops and hooks of its own. `strike` scribbles a word out.+ doodles `face` (inked eyes with a highlight, mouth, pencil blush), `eye`, `dot`, `dashes`, `arrow`, `ring`+ (a loose red-pen circle that overshoots), and point helpers `circle_pts`, `star_pts`, `cloud_pts`,+ `spiral_pts`, `heart_pts`.++ import sys; sys.path.insert(0, 'lib')+ from ballpoint import Ballpoint+ b = Ballpoint(1920, 1080, seed=4)+ b.paper()+ m = b.ellipse(960, 540, 160, 120)+ b.line(b.circle_pts(960, 540, 160, 120), 'blue', closed=True, twice=0.6)+ b.pencil(m, 'yellow', angle=60, pressure=0.45)+ b.face(960, 540, 90)+ b.write('hello there', 820, 760, 44, 'red')+ b.save('doodle.jpg')+"""+import glob+import os+import numpy as np+from PIL import Image, ImageDraw, ImageFont, ImageFilter+from core import blur, fbm1d, spline, noise2d, smoothstep, latin_font++# single-pass reflectance of a ballpoint line on white paper (its optical density is -ln of this)+PENS = {+ 'blue': (0.20, 0.235, 0.62),+ 'red': (0.80, 0.19, 0.21),+ 'black': (0.215, 0.20, 0.205),+}+# what heavily pressed coloured pencil looks like (light pressure gives a paler, grainier version)+PENCILS = {+ 'leaf': '#4f9a3e', 'green': '#6fb04c', 'lime': '#a5cc4e', 'mint': '#8ccfa6', 'teal': '#3f9e9a',+ 'sky': '#79b2e4', 'blue': '#3c6cc4', 'violet': '#8566c4', 'lilac': '#b49ddf', 'pink': '#ef86a6',+ 'rose': '#e2557a', 'red': '#d6403a', 'orange': '#f0862e', 'peach': '#f5b088', 'yellow': '#f5cf34',+ 'ochre': '#d39d3a', 'brown': '#97603a', 'tan': '#d8b07c', 'grey': '#9b9a98', 'cream': '#efdcae',+}+PAPER = '#e6e1d4'+SHEEN = (0.42, 0.36, 0.50) # what heavily worked ballpoint ink reflects (a dull violet-bronze)+LIGHT = (-0.6, -0.8) # toward the light, in the image plane: top left++_THIN_HAND = [('/System/Library/Fonts/Noteworthy.ttc', 0), ('/System/Library/Fonts/Supplemental/ChalkboardSE.ttc', 0),+ ('/System/Library/Fonts/MarkerFelt.ttc', 0), ('/usr/share/fonts/**/*Kalam*Light*.ttf', 0),+ ('/usr/share/fonts/**/*Caveat*.ttf', 0), ('C:/Windows/Fonts/segoepr.ttf', 0), ('C:/Windows/Fonts/comic.ttf', 0)]+_THIN_CJK = [('/System/Library/Fonts/STHeiti Light.ttc', 1), ('/System/Library/Fonts/Hiragino Sans GB.ttc', 0),+ ('/usr/share/fonts/**/NotoSansCJK*Light*.tt[cf]', 0), ('/usr/share/fonts/**/NotoSansCJK*Regular*.tt[cf]', 0),+ ('C:/Windows/Fonts/msyhl.ttc', 0), ('C:/Windows/Fonts/msyh.ttc', 0)]+_GS = 160 # glyphs are skeletonised at this size+_FONTS = {}+_GLYPHS = {}+++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 _font(kind):+ """thin handwriting font for 'latin' or 'cjk' ($INKPAINT_FONT_BALLPOINT / _BALLPOINT_CJK override)"""+ if kind in _FONTS: return _FONTS[kind]+ env = os.environ.get('INKPAINT_FONT_BALLPOINT' + ('_CJK' if kind == 'cjk' else ''))+ cands = [(env, 0)] if env and os.path.exists(env) else []+ for pat, idx in (_THIN_CJK if kind == 'cjk' else _THIN_HAND):+ fs = glob.glob(pat, recursive=True)+ if fs: cands.append((fs[0], idx))+ hit = latin_font('cjk' if kind == 'cjk' else 'hand')+ if hit: cands.append(hit)+ f = None+ for path, idx in cands:+ try:+ f = ImageFont.truetype(path, _GS, index=idx); break+ except OSError:+ continue+ _FONTS[kind] = f or ImageFont.load_default(_GS)+ return _FONTS[kind]+++def _thin(b):+ """Zhang-Suen thinning: boolean glyph -> one-pixel centre line"""+ I = b.astype(np.uint8).copy()+ changed = True+ while changed:+ changed = False+ for step in range(2):+ P = np.pad(I, 1)+ p2, p3, p4, p5 = P[:-2, 1:-1], P[:-2, 2:], P[1:-1, 2:], P[2:, 2:]+ p6, p7, p8, p9 = P[2:, 1:-1], P[2:, :-2], P[1:-1, :-2], P[:-2, :-2]+ nb = [p2, p3, p4, p5, p6, p7, p8, p9, p2]+ B = sum(x.astype(np.int32) for x in nb[:8])+ A = sum(((nb[i] == 0) & (nb[i + 1] == 1)).astype(np.int32) for i in range(8))+ c1, c2 = (p2 * p4 * p6, p4 * p6 * p8) if step == 0 else (p2 * p4 * p8, p2 * p6 * p8)+ m = (I == 1) & (B >= 2) & (B <= 6) & (A == 1) & (c1 == 0) & (c2 == 0)+ if m.any():+ I[m] = 0; changed = True+ # staircase corners: a pixel whose only two neighbours are an orthogonal pair (N+E ...) is redundant+ for _ in range(2):+ P = np.pad(I, 1)+ n, s, e, w = P[:-2, 1:-1], P[2:, 1:-1], P[1:-1, 2:], P[1:-1, :-2]+ tot = sum(x.astype(np.int32) for x in (n, s, e, w, P[:-2, 2:], P[2:, 2:], P[2:, :-2], P[:-2, :-2]))+ corner = (I == 1) & (tot == 2) & (((n & e) | (e & s) | (s & w) | (w & n)) == 1)+ ys, xs = np.nonzero(corner)+ for y, x in zip(ys[::2], xs[::2]): # every other one: never remove two touching pixels at once+ I[y, x] = 0+ return I.astype(bool)+++_NB = [(-1, 0), (0, 1), (1, 0), (0, -1), (-1, 1), (1, 1), (1, -1), (-1, -1)]+++def _trace(sk):+ """skeleton pixels -> list of pixel paths (endpoints first, then branches from junctions, then loops)"""+ pix = set(zip(*[a.tolist() for a in np.nonzero(sk)]))+ nbrs = lambda p: [(p[0] + dy, p[1] + dx) for dy, dx in _NB if (p[0] + dy, p[1] + dx) in pix]+ seen, paths = set(), []++ def walk(start):+ path, cur, d = [start], start, None+ seen.add(start)+ while True:+ cand = [q for q in nbrs(cur) if q not in seen]+ if not cand: break+ if d is None:+ q = min(cand, key=lambda q: abs(q[0] - cur[0]) + abs(q[1] - cur[1]))+ else:+ q = max(cand, key=lambda q: ((q[0] - cur[0]) * d[0] + (q[1] - cur[1]) * d[1]) / np.hypot(q[0] - cur[0], q[1] - cur[1]))+ nd = np.array([q[0] - cur[0], q[1] - cur[1]], np.float32); nd /= np.linalg.norm(nd)+ d = nd if d is None else 0.55 * d + 0.45 * nd+ d = d / (np.linalg.norm(d) + 1e-9)+ seen.add(q); path.append(q); cur = q+ return path++ for e in sorted([p for p in pix if len(nbrs(p)) == 1], key=lambda p: (p[1] + p[0] * 0.4)):+ if e not in seen: paths.append(walk(e))+ while True:+ rest = [p for p in pix if p not in seen]+ if not rest: break+ touching = [p for p in rest if any(q in seen for q in nbrs(p))]+ s = min(touching or rest)+ path = walk(s)+ anchor = [q for q in nbrs(s) if q in seen and q not in path]+ if anchor: path = [anchor[0]] + path+ if len(path) > 3:+ close = [q for q in nbrs(path[-1]) if q in seen and q != path[-2]]+ if close: path.append(close[0])+ paths.append(path)+ return paths+++def _components(sk):+ """label 8-connected components of a small boolean image -> list of pixel-coordinate arrays"""+ pix = set(zip(*[a.tolist() for a in np.nonzero(sk)]))+ comps = []+ while pix:+ st = [pix.pop()]; comp = list(st)+ while st:+ p = st.pop()+ for dy in (-1, 0, 1):+ for dx in (-1, 0, 1):+ q = (p[0] + dy, p[1] + dx)+ if q in pix:+ pix.remove(q); st.append(q); comp.append(q)+ comps.append(np.array(comp))+ return comps+++def _smooth(P, k=2, it=2):+ P = np.asarray(P, np.float32)+ if len(P) < 5: return P+ for _ in range(it):+ Q = P.copy()+ for i in range(1, len(P) - 1):+ a, b = max(0, i - k), min(len(P), i + k + 1)+ Q[i] = P[a:b].mean(0)+ P = Q+ return P+++def _resample(P, step):+ P = np.asarray(P, np.float32)+ if len(P) < 2: return P+ seg = np.hypot(*np.diff(P, axis=0).T)+ s = np.concatenate([[0], np.cumsum(seg)])+ if s[-1] < 1e-3: return P[:1]+ n = max(2, int(s[-1] / step) + 1)+ t = np.linspace(0, s[-1], n)+ return np.stack([np.interp(t, s, P[:, 0]), np.interp(t, s, P[:, 1])], 1).astype(np.float32)+++def _closed_spline(P, per=8):+ P = np.asarray(P, np.float32)+ n = len(P)+ E = np.vstack([P[-1:], P, P[:2]])+ out = []+ for i in range(1, n + 1):+ p0, p1, p2, p3 = E[i - 1], E[i], E[i + 1], E[i + 2]+ for t in np.linspace(0, 1, per, endpoint=False):+ t2, t3 = t * t, t * t * t+ out.append(0.5 * ((2 * p1) + (-p0 + p2) * t + (2 * p0 - 5 * p1 + 4 * p2 - p3) * t2 + (-p0 + 3 * p1 - 3 * p2 + p3) * t3))+ out.append(P[0])+ return np.array(out, np.float32)+++def _glyph(ch):+ """(paths, dots, advance) of one character, normalised to size 1, baseline at y = 0, origin at x = 0"""+ if ch in _GLYPHS: return _GLYPHS[ch]+ kind = 'cjk' if ord(ch) >= 0x2E80 else 'latin'+ f = _font(kind)+ adv = f.getlength(ch) / _GS+ if not ch.strip():+ _GLYPHS[ch] = ([], [], adv); return _GLYPHS[ch]+ S = int(_GS * 1.9); ox, oy = int(_GS * 0.4), int(_GS * 1.3)+ im = Image.new('L', (S, S), 0)+ ImageDraw.Draw(im).text((ox, oy), ch, font=f, fill=255, anchor='ls')+ g = np.asarray(im) > 110+ if kind == 'cjk':+ g = np.asarray(im.filter(ImageFilter.MaxFilter(3))) > 110+ sk = _thin(g)+ paths, dots = [], []+ for comp in _components(sk):+ h, w = np.ptp(comp[:, 0]), np.ptp(comp[:, 1])+ if max(h, w) < 0.11 * _GS:+ c = comp.mean(0); dots.append(((c[1] - ox) / _GS, (c[0] - oy) / _GS))+ continue+ sub = np.zeros_like(sk); sub[comp[:, 0], comp[:, 1]] = True+ for p in _trace(sub):+ P = np.array([(x, y) for y, x in p], np.float32)+ L = np.hypot(*np.diff(P, axis=0).T).sum() if len(P) > 1 else 0+ if L < 0.07 * _GS: continue+ P = _resample(_smooth(P), 3.0)+ paths.append(np.stack([(P[:, 0] - ox) / _GS, (P[:, 1] - oy) / _GS], 1))+ _GLYPHS[ch] = (paths, dots, adv)+ return _GLYPHS[ch]+++class Ballpoint:+ PENS = PENS+ PENCILS = PENCILS++ def __init__(self, W=1920, H=1080, seed=0, ss=2, pen_width=2.5):+ self.W, self.H, self.ss = W, H, ss+ self.pen_w = pen_width+ self.rng = np.random.default_rng(seed)+ self.D = np.zeros((H, W, 3), np.float32) # optical density: ink + pencil+ self.I = np.zeros((H, W), np.float32) # amount of ink (for the sheen of heavy ink)+ self.G = np.zeros((H, W), np.float32) # grooves pressed by pen and pencil (px, negative)+ self.tooth = np.full((H, W), 0.5, np.float32)+ self.base = np.ones((H, W, 3), np.float32) * hexc(PAPER)+ self.relief_shade = np.ones((H, W), np.float32) # cockles and folds, already lit+ self.light = np.ones((H, W), np.float32)+ self.stages = []++ # ------------------------------------------------------------ small helpers+ def _seed(self):+ return int(self.rng.integers(1 << 30))++ def _grid(self):+ return (np.arange(self.H, dtype=np.float32)[:, None], np.arange(self.W, dtype=np.float32)[None, :])++ def _box(self, x0, y0, x1, y1):+ x0, y0 = max(0, int(np.floor(x0))), max(0, int(np.floor(y0)))+ x1, y1 = min(self.W, int(np.ceil(x1)) + 1), min(self.H, int(np.ceil(y1)) + 1)+ if x1 <= x0 or y1 <= y0: return None+ return (slice(y0, y1), slice(x0, x1))++ def _mask_box(self, M, pad=2, thr=0.02):+ rows = np.nonzero((M > thr).any(1))[0]+ if not len(rows): return None+ cols = np.nonzero((M[rows[0]:rows[-1] + 1] > thr).any(0))[0]+ return self._box(cols[0] - pad, rows[0] - pad, cols[-1] + pad, rows[-1] + pad)++ # ------------------------------------------------------------ paper+ def paper(self, tone=PAPER, tooth=0.75, fibres=260, mottle=0.014, cockle=1.0, folds=(), vignette=0.09):+ """copy paper: fine tooth, sparse fibres, mottle, cockles and fold creases lit from the top left,+ the soft light fall-off of a photographed sheet. folds: [((x0, y0), (x1, y1)), ...] crease lines"""+ H, W = self.H, self.W+ r = np.random.default_rng(self._seed())+ t = blur(r.random((H, W), dtype=np.float32), tooth)+ t -= t.mean(); t /= (t.std() + 1e-6)+ t2 = blur(r.random((H, W), dtype=np.float32), tooth * 2.6)+ t2 -= t2.mean(); t2 /= (t2.std() + 1e-6)+ t = 0.72 * t + 0.28 * t2; del t2+ t /= (t.std() + 1e-6)+ self.tooth = np.clip(0.5 + t * 0.19, 0, 1).astype(np.float32); del t+ base = hexc(tone)+ mot = (noise2d(H, W, 220, 3, self._seed()) - 0.5) * mottle * 2+ mot += (noise2d(H, W, 30, 2, self._seed()) - 0.5) * mottle * 0.6+ f = 1 + mot+ gy, gx = np.gradient(blur(self.tooth, 0.5))+ f += (gx * 0.6 + gy * 0.8) * 0.035 # the tooth itself, barely, in raking light+ self.base = (base[None, None, :] * f[..., None]).astype(np.float32)+ # fibres: short faint curls, a few darker, most lighter than the sheet+ if fibres:+ im = Image.new('L', (W, H), 128); d = ImageDraw.Draw(im)+ for _ in range(int(fibres)):+ x, y = r.uniform(0, W), r.uniform(0, H)+ a = r.uniform(0, np.pi); L = r.uniform(6, 22); c = r.uniform(-1, 1) * 0.08+ pts = []+ for k in range(6):+ a += c; x += np.cos(a) * L / 6; y += np.sin(a) * L / 6; pts.append((x, y))+ d.line(pts, fill=int(128 + (r.choice([-1, 1], p=[0.35, 0.65])) * r.uniform(10, 26)), width=1)+ fib = blur((np.asarray(im, np.float32) - 128) / 128, 0.6) * 0.09+ self.base *= (1 + fib)[..., None]+ # relief: low cockles + folds, lit from the top left+ YY, XX = self._grid()+ rel = (noise2d(H, W, 420, 3, self._seed()) - 0.5) * 14 * cockle+ for (p0, p1) in folds:+ p0, p1 = np.array(p0, np.float32), np.array(p1, np.float32)+ dv = p1 - p0; dv /= np.linalg.norm(dv)+ dist = (XX - p0[0]) * dv[1] - (YY - p0[1]) * dv[0]+ dist = dist + fbm1d(W + H, 160, 3, self._seed())[np.clip(((XX + YY) * 0 + XX * abs(dv[0]) + YY * abs(dv[1])).astype(int), 0, W + H - 1)] * 2.5+ rel = rel - 0.1 * np.exp(-(dist / 3.0) ** 2) + 0.024 * np.abs(dist) * np.exp(-np.abs(dist) / 320)+ gy, gx = np.gradient(rel.astype(np.float32))+ self.relief_shade = (1 + np.clip((gx * 0.6 + gy * 0.8) * 0.55, -0.07, 0.07)).astype(np.float32)+ del rel, gx, gy+ rr = np.hypot((XX - W * 0.46) / (W * 0.62), (YY - H * 0.42) / (H * 0.68))+ self.light = (1.0 - vignette * smoothstep(0.35, 1.25, rr) - 0.02 * (XX / W) - 0.015 * (YY / H)).astype(np.float32)++ # ------------------------------------------------------------ masks+ def _paint(self, P_all, pad, feather, draw):+ M = np.zeros((self.H, self.W), np.float32)+ P = np.asarray(P_all, np.float32).reshape(-1, 2)+ sl = self._box(P[:, 0].min() - pad - 3 * feather - 2, P[:, 1].min() - pad - 3 * feather - 2,+ P[:, 0].max() + pad + 3 * feather + 2, P[:, 1].max() + pad + 3 * feather + 2)+ if sl is None: return M+ x0, y0 = sl[1].start, sl[0].start+ w, h = sl[1].stop - x0, sl[0].stop - y0+ im = Image.new('L', (w * 2, h * 2), 0)+ draw(ImageDraw.Draw(im), lambda p: (float(p[0] - x0) * 2, float(p[1] - y0) * 2))+ a = np.asarray(im.resize((w, h), Image.BILINEAR), np.float32) / 255+ M[sl] = blur(a, feather) if feather else a+ return M++ def poly(self, pts, feather=0.6):+ """filled polygon mask (0..1)"""+ P = np.asarray(pts, np.float32)+ return self._paint(P, 2, feather, lambda d, T: d.polygon([T(p) for p in P], fill=255))++ def ellipse(self, cx, cy, rx, ry=None, rot=0.0, feather=0.6):+ ry = rx if ry is None else ry+ return self.poly(self.circle_pts(cx, cy, rx, ry, rot=rot, n=max(24, int((rx + ry) * 0.6))), feather)++ def band(self, pts, width, feather=0.6, smooth=True):+ """mask of a thick polyline"""+ P = spline(pts, 10) if (smooth and len(pts) > 2) else np.asarray(pts, np.float32)++ def draw(d, T):+ Q = [T(p) for p in P]+ d.line(Q, fill=255, width=max(1, int(round(width * 2))), joint='curve')+ for q in (Q[0], Q[-1]):+ d.ellipse([q[0] - width, q[1] - width, q[0] + width, q[1] + width], fill=255)+ return self._paint(P, width, feather, draw)++ def tube(self, pts, w0, w1, feather=0.6):+ """mask of a tapering body along a path: width w0 at the first point to w1 at the last (snake, tail)"""+ P = _resample(spline(pts, 10) if len(pts) > 2 else pts, 3.0)+ L, R = self.tube_sides(P, w0, w1)+ return self.poly(np.vstack([L, R[::-1]]), feather)++ @staticmethod+ def tube_sides(pts, w0, w1, smooth=True):+ """left and right outlines of a tapering body (for drawing its two edges with the pen)"""+ P = _resample(spline(pts, 10) if (smooth and len(pts) > 2) else pts, 3.0)+ tan = np.gradient(P, axis=0); tan /= (np.linalg.norm(tan, axis=1, keepdims=True) + 1e-6)+ nrm = np.stack([-tan[:, 1], tan[:, 0]], 1)+ t = np.linspace(0, 1, len(P))[:, None]+ hw = (w0 + (w1 - w0) * t) / 2+ return P + nrm * hw, P - nrm * hw++ # ------------------------------------------------------------ point helpers+ @staticmethod+ def resample(pts, step=3.0):+ """a polyline re-spaced to one point every `step` px"""+ return _resample(pts, step)++ @staticmethod+ def circle_pts(cx, cy, rx, ry=None, a0=0.0, a1=360.0, rot=0.0, n=None):+ """points on an ellipse arc (degrees, clockwise on screen)"""+ ry = rx if ry is None else ry+ n = n or max(10, int(abs(a1 - a0) / 360 * 2 * np.pi * max(rx, ry) / 3))+ t = np.deg2rad(np.linspace(a0, a1, n))+ x, y = rx * np.cos(t), ry * np.sin(t)+ a = np.deg2rad(rot); c, s = np.cos(a), np.sin(a)+ return np.stack([cx + x * c - y * s, cy + x * s + y * c], 1).astype(np.float32)++ @staticmethod+ def star_pts(cx, cy, r, inner=0.45, n=5, rot=-90.0):+ a = np.deg2rad(rot) + np.arange(2 * n) * np.pi / n+ rr = np.where(np.arange(2 * n) % 2 == 0, r, r * inner)+ P = np.stack([cx + rr * np.cos(a), cy + rr * np.sin(a)], 1)+ return np.vstack([P, P[:1]]).astype(np.float32)++ @staticmethod+ def cloud_pts(cx, cy, w, h, bumps=7, seed=0, flat=True):+ """scalloped cloud outline: arcs bulging out of an ellipse; a flatter bottom if `flat`"""+ r = np.random.default_rng(seed)+ ang = np.sort(np.linspace(0, 2 * np.pi, bumps, endpoint=False) + r.normal(0, 0.12, bumps))+ pts = []+ for i in range(bumps):+ a0, a1 = ang[i], ang[(i + 1) % bumps] + (2 * np.pi if i == bumps - 1 else 0)+ for t in np.linspace(0, 1, 9, endpoint=False):+ a = a0 + (a1 - a0) * t+ bulge = np.sin(np.pi * t) * (0.20 + 0.06 * r.random() if t == 0 else 0.22)+ ry = h / 2 * (0.62 if (flat and np.sin(a) > 0.2) else 1.0)+ k = 1 + bulge * (0.35 if (flat and np.sin(a) > 0.35) else 1.0)+ pts.append((cx + np.cos(a) * w / 2 * k, cy + np.sin(a) * ry * k))+ pts.append(pts[0])+ return np.array(pts, np.float32)++ @staticmethod+ def spiral_pts(cx, cy, r, turns=2.5, a0=0.0, inward=True, n=None):+ n = n or int(turns * 2 * np.pi * r / 4) + 8+ t = np.linspace(0, 1, n)+ rad = r * (1 - t) if inward else r * t+ a = np.deg2rad(a0) + t * turns * 2 * np.pi+ return np.stack([cx + rad * np.cos(a), cy + rad * np.sin(a)], 1).astype(np.float32)++ @staticmethod+ def heart_pts(cx, cy, s, rot=0.0):+ t = np.linspace(0, 2 * np.pi, 60)+ x = 16 * np.sin(t) ** 3; y = -(13 * np.cos(t) - 5 * np.cos(2 * t) - 2 * np.cos(3 * t) - np.cos(4 * t))+ a = np.deg2rad(rot); c, sn = np.cos(a), np.sin(a)+ x, y = x * s / 32, y * s / 32+ return np.stack([cx + x * c - y * sn, cy + x * sn + y * c], 1).astype(np.float32)++ # ------------------------------------------------------------ the pen: one stroke+ def _prep(self, pts, pressure, width, closed, smooth, wobble, bow, hook, gloop, skip, start, step=1.5,+ overlap=None):+ r = self.rng+ P = np.asarray(pts, np.float32)+ if len(P) == 0: return None+ if closed and smooth and len(P) > 3:+ if np.hypot(*(P[0] - P[-1])) < 1e-3: P = P[:-1]+ P = _closed_spline(P, 8)+ elif closed:+ P = np.vstack([P, P[:1]])+ elif smooth and len(P) > 2:+ P = spline(P, 8)+ P = _resample(P, step)+ if closed and len(P) > 8: # the pen does not close exactly: overshoot or fall short+ ov = r.uniform(-3, 9) if overlap is None else overlap+ k = int(abs(ov) / step)+ if ov > 0 and k: P = np.vstack([P, P[1:k + 1]])+ elif k: P = P[:-k]+ n = len(P)+ if n < 2:+ return dict(Q=P, w=np.full(1, width * 1.15, np.float32), v=np.full(1, pressure * 1.3, np.float32),+ p=np.full(1, pressure, np.float32), gl=[(P[0, 0], P[0, 1], width * 0.75, 0.0, 0.8)], skip=False)+ L = (n - 1) * step+ tan = np.gradient(P, axis=0); tan /= (np.linalg.norm(tan, axis=1, keepdims=True) + 1e-6)+ nrm = np.stack([-tan[:, 1], tan[:, 0]], 1)+ t = np.linspace(0, 1, n, dtype=np.float32)+ off = np.zeros(n, np.float32)+ if wobble:+ off += fbm1d(n, max(3, 55 / step), 3, self._seed()) * wobble+ off += fbm1d(n, max(2, 9 / step), 2, self._seed()) * wobble * 0.18+ if bow:+ off += 4 * t * (1 - t) * bow * L * (1 if r.random() < 0.5 else -1)+ P = P + nrm * off[:, None]+ # pressure: drift, dry start, ease at the end+ v = pressure * (1 + 0.12 * fbm1d(n, max(4, 80 / step), 2, self._seed()))+ if start:+ s0 = r.uniform(3, 10)+ v *= 0.32 + 0.68 * smoothstep(0, s0, t * L)+ v *= 0.8 + 0.2 * (1 - smoothstep(L - 3, L, t * L))+ p = v.copy()+ gl = []+ # gloops: where the pen stops, sharp turns, sometimes the start, now and then along long lines+ k = 3+ if n > 2 * k + 2:+ a1 = P[k:-k] - P[:-2 * k]; a2 = P[2 * k:] - P[k:-k]+ cosang = (a1 * a2).sum(1) / (np.linalg.norm(a1, axis=1) * np.linalg.norm(a2, axis=1) + 1e-6)+ turn = np.degrees(np.arccos(np.clip(cosang, -1, 1)))+ for i in range(1, len(turn) - 1):+ if turn[i] > 55 and turn[i] >= turn[i - 1] and turn[i] >= turn[i + 1] and r.random() < gloop * 0.8:+ j = i + k+ gl.append((P[j, 0], P[j, 1], width * r.uniform(0.62, 0.95), np.arctan2(tan[j, 1], tan[j, 0]), r.uniform(0.6, 1.2)))+ if r.random() < gloop * 0.62:+ gl.append((P[-1, 0], P[-1, 1], width * r.uniform(0.62, 1.0), np.arctan2(tan[-1, 1], tan[-1, 0]), r.uniform(0.7, 1.4)))+ if r.random() < gloop * 0.3:+ gl.append((P[0, 0], P[0, 1], width * r.uniform(0.55, 0.85), np.arctan2(tan[0, 1], tan[0, 0]), r.uniform(0.5, 1.0)))+ s_ = r.uniform(150, 450)+ while s_ < L - 20:+ if r.random() < gloop * 0.35:+ j = int(s_ / step)+ gl.append((P[j, 0], P[j, 1], width * r.uniform(0.55, 0.8), np.arctan2(tan[j, 1], tan[j, 0]), r.uniform(0.5, 1.0)))+ s_ += r.uniform(150, 450)+ # skips: the ball stops feeding for a few px; the groove stays+ has_skip = False+ if skip and L > 25:+ m = r.poisson(L / 320 * skip * (1.5 - min(pressure, 1.0)))+ for _ in range(m):+ c0 = r.uniform(8, L - 8); ln = r.uniform(2, 9)+ g = 1 - smoothstep(ln / 2, ln / 2 + 1.5, np.abs(t * L - c0))+ v = v * (1 - g * r.uniform(0.65, 0.95)); has_skip = True+ # hook: the flick as the pen lifts+ if hook and r.random() < hook and n > 6:+ d = P[-1] - P[-4]; d /= (np.linalg.norm(d) + 1e-6)+ nr = np.array([-d[1], d[0]], np.float32)+ sgn = 1.0 if nr[1] < 0 else -1.0 # curl toward the top of the page, mostly+ if r.random() < 0.25: sgn = -sgn+ hl = r.uniform(3, 7) * width / 2.3; turn = np.deg2rad(r.uniform(90, 160)) * sgn+ m = 6; pts_h = []; q = P[-1].copy(); ang = np.arctan2(d[1], d[0])+ for i in range(m):+ ang += turn / m+ q = q + np.array([np.cos(ang), np.sin(ang)], np.float32) * hl / m+ pts_h.append(q.copy())+ H_ = np.array(pts_h, np.float32)+ P = np.vstack([P, H_])+ fall = np.linspace(0.85, 0.3, m, dtype=np.float32) * v[-1]+ v = np.concatenate([v, fall]); p = np.concatenate([p, fall])+ w = width * (0.8 + 0.24 * np.clip(v / max(pressure, 1e-3), 0, 1.25))+ return dict(Q=P.astype(np.float32), w=w.astype(np.float32), v=v.astype(np.float32), p=p.astype(np.float32),+ gl=gl, skip=has_skip)++ def _raster(self, strokes, key='v'):+ """prepared strokes -> (coverage, groove coverage or None, slices); ss x supersampled, box-filtered"""+ strokes = [s for s in strokes if s is not None and len(s['Q'])]+ if not strokes: return None, None, None+ allp = np.concatenate([s['Q'] for s in strokes])+ pad = max(float(np.max(s['w'])) for s in strokes) * 2 + 4+ sl = self._box(allp[:, 0].min() - pad, allp[:, 1].min() - pad, allp[:, 0].max() + pad, allp[:, 1].max() + pad)+ if sl is None: return None, None, None+ ss = self.ss+ x0, y0 = sl[1].start, sl[0].start+ bw, bh = sl[1].stop - x0, sl[0].stop - y0+ need_g = any(s['skip'] for s in strokes)+ ims = [Image.new('L', (bw * ss, bh * ss), 0)] + ([Image.new('L', (bw * ss, bh * ss), 0)] if need_g else [])+ dr = [ImageDraw.Draw(im) for im in ims]+ off = np.array([x0, y0], np.float32)+ for s in strokes:+ Q = (s['Q'] - off) * ss+ for di, vals in zip(dr, [s['v'], s['p']][:len(dr)]):+ n = len(Q)+ if n == 1:+ r_ = s['w'][0] * ss / 2+ di.ellipse([Q[0, 0] - r_, Q[0, 1] - r_, Q[0, 0] + r_, Q[0, 1] + r_], fill=int(255 * min(1, vals[0])))+ continue+ ww = np.maximum(1, np.round((s['w'][:-1] + s['w'][1:]) * 0.5 * ss)).astype(int)+ vv = np.round(np.clip((vals[:-1] + vals[1:]) * 0.5, 0, 1) * 40).astype(int) # 40 levels+ q = Q.tolist()+ i = 0+ while i < n - 1: # runs of equal width and value: one call each+ j = i + 1+ while j < n - 1 and ww[j] == ww[i] and vv[j] == vv[i] and j - i < 40: j += 1+ if vv[i] > 0:+ di.line([tuple(c) for c in q[i:j + 1]], fill=int(vv[i] * 255 / 40), width=int(ww[i]), joint='curve')+ i = j+ cov = np.asarray(ims[0].resize((bw, bh), Image.BOX), np.float32) / 255+ gro = np.asarray(ims[1].resize((bw, bh), Image.BOX), np.float32) / 255 if need_g else None+ return cov, gro, sl++ def _gloops(self, strokes, sl):+ """the blobs: soft-edged teardrops of extra ink, in the box `sl`"""+ h, w = sl[0].stop - sl[0].start, sl[1].stop - sl[1].start+ out = None+ for s in strokes:+ if s is None: continue+ for (x, y, rad, ang, k) in s['gl']:+ x_, y_ = x - sl[1].start, y - sl[0].start+ R = int(rad * 2.2 + 3)+ X0, Y0 = int(x_) - R, int(y_) - R+ xs0, ys0 = max(0, X0), max(0, Y0); xs1, ys1 = min(w, X0 + 2 * R + 1), min(h, Y0 + 2 * R + 1)+ if xs1 <= xs0 or ys1 <= ys0: continue+ if out is None: out = np.zeros((h, w), np.float32)+ yy, xx = np.mgrid[ys0:ys1, xs0:xs1].astype(np.float32)+ c, sn = np.cos(ang), np.sin(ang)+ u = (xx - x_) * c + (yy - y_) * sn - rad * 0.25; v_ = -(xx - x_) * sn + (yy - y_) * c+ d = np.sqrt((u / 1.3) ** 2 + v_ ** 2) - rad+ out[ys0:ys1, xs0:xs1] += np.clip(0.5 - d / 0.9, 0, 1) * k+ return out++ def _ink(self, strokes, pen, clip=None, groove=1.0):+ cov, gro, sl = self._raster(strokes)+ if sl is None: return+ gl = self._gloops(strokes, sl)+ if gro is None: gro = cov.copy()+ if gl is not None:+ gro = np.maximum(gro, np.clip(gl, 0, 1))+ if clip is not None:+ cov = cov * clip[sl]; gro = gro * clip[sl]+ if gl is not None: gl = gl * clip[sl]+ if pen is not None:+ t = self.tooth[sl]+ reach = 0.48 + 0.6 * np.sqrt(np.clip(cov, 0, 1))+ resp = smoothstep(1.0 - reach - 0.2, 1.0 - reach + 0.2, t)+ amt = cov * (0.22 + 0.78 * resp)+ if gl is not None: amt = amt + gl * (0.75 + 0.25 * resp)+ dens = -np.log(np.array(PENS[pen] if isinstance(pen, str) else pen, np.float32))+ self.D[sl] += amt[..., None] * dens+ self.I[sl] += amt+ if groove:+ self.G[sl] -= blur(gro, 0.55) * 0.9 * groove++ def line(self, pts, pen='blue', pressure=0.82, width=None, closed=False, smooth=True, wobble=0.55, bow=0.0,+ hook=0.3, gloop=0.5, skip=0.6, twice=0.0, start=True, clip=None, groove=1.0):+ """one ballpoint stroke through `pts`. pen: 'blue' 'red' 'black' (or an RGB reflectance), None = blind+ groove only. bow: sideways bow as a fraction of length (freehand straight lines ~0.003-0.006).+ hook / gloop: chances of a lift-off flick and of ink blobs; skip: how often the ball skips;+ twice: chance (0..1) the line is gone over again, slightly off, for part of its length"""+ width = width or self.pen_w+ s = self._prep(pts, pressure, width, closed, smooth, wobble, bow, hook, gloop, skip, start)+ if s is None: return+ self._ink([s], pen, clip, groove)+ if twice and self.rng.random() < twice and len(s['Q']) > 8:+ Q = s['Q']; n = len(Q)+ i0 = int(self.rng.uniform(0, 0.25) * n); i1 = n - int(self.rng.uniform(0, 0.3) * n)+ if i1 - i0 > 4:+ tan = np.gradient(Q, axis=0); tan /= (np.linalg.norm(tan, axis=1, keepdims=True) + 1e-6)+ nrm = np.stack([-tan[:, 1], tan[:, 0]], 1)+ off = (self.rng.uniform(0.6, 1.6) * (1 if self.rng.random() < 0.5 else -1)+ + fbm1d(n, max(4, n / 4), 2, self._seed()) * 0.7)+ s2 = self._prep((Q + nrm * off[:, None])[i0:i1], pressure * 0.85, width, False, False, wobble * 0.5, 0,+ hook * 0.5, gloop * 0.5, skip, True)+ self._ink([s2], pen, clip, groove)++ def lines(self, paths, pen='blue', pressure=0.8, width=None, smooth=True, wobble=0.5, hook=0.25, gloop=0.4,+ skip=0.5, clip=None, closed=False, groove=1.0):+ """many short strokes in one go (they share one raster: crossings do not add up)"""+ width = width or self.pen_w+ S = [self._prep(p, pressure, width, closed, smooth, wobble, 0.0, hook, gloop, skip, True) for p in paths if len(p)]+ self._ink(S, pen, clip, groove)++ def emboss(self, pts, pressure=0.8, width=None, smooth=True):+ """a groove with no ink: what writing on the sheet above leaves behind (shows only in raking light)"""+ self.line(pts, None, pressure, width, smooth=smooth, hook=0.2, gloop=0.0, skip=0.0)++ # ------------------------------------------------------------ marks made of strokes+ def dot(self, x, y, r=3.0, pen='blue', pressure=0.95):+ """a pressed dot: a tiny circling of the pen, ink pooled in the middle"""+ if r <= 2.0:+ s = self._prep([(x, y)], pressure, self.pen_w * r / 1.3, False, False, 0, 0, 0, 1, 0, False)+ self._ink([s], pen); return+ P = self.spiral_pts(x, y, max(0.5, r - self.pen_w * 0.45), turns=max(1.2, r / 1.6), a0=self.rng.uniform(0, 360))+ s = self._prep(P, pressure, self.pen_w, False, False, 0.15, 0, 0, 0, 0, False)+ s['gl'].append((x, y, r * 0.7, 0.0, 0.6))+ self._ink([s], pen)++ def eye(self, cx, cy, rx, ry=None, pen='black', look=(0.0, 0.0), shine=0.32, pressure=0.95):+ """an inked oval eye: the pen circles inward until it is solid, leaving a round highlight"""+ ry = ry or rx+ hx, hy = cx - rx * 0.32 + look[0] * rx * 0.2, cy - ry * 0.34 + look[1] * ry * 0.2+ hr = min(rx, ry) * shine+ clip = None+ if shine:+ clip = 1 - self.ellipse(hx, hy, hr, hr, feather=0.5)+ turns = max(rx, ry) / (self.pen_w * 0.62)+ t = np.linspace(0, 1, int(turns * 2 * np.pi * max(rx, ry) / 2.5) + 8)+ a = t * turns * 2 * np.pi + self.rng.uniform(0, 6.28)+ k = np.clip(1 - t, 0, 1)+ P = np.stack([cx + (rx - self.pen_w * 0.45) * k * np.cos(a), cy + (ry - self.pen_w * 0.45) * k * np.sin(a)], 1)+ s = self._prep(P, pressure, self.pen_w * 1.05, False, False, 0.1, 0, 0, 0.3, 0.2, False)+ self._ink([s], pen, clip)+ self.line(self.circle_pts(cx, cy, rx, ry), pen, pressure, closed=True, hook=0, gloop=0.4, skip=0.2, clip=clip)++ def face(self, cx, cy, size, mood='smile', pen='black', blush='pink', look=(0.0, 0.0), rot=0.0):+ """a doodle face: inked eyes, mouth, pencil blush. mood: smile, grin, oh, dizzy, sleep, worry"""+ a = np.deg2rad(rot); c, s = np.cos(a), np.sin(a)+ T = lambda x, y: (cx + x * c - y * s, cy + x * s + y * c)+ e = size * 0.11; gap = size * 0.2+ for sx in (-1, 1):+ ex, ey = T(sx * gap, -size * 0.04)+ if mood == 'dizzy':+ self.line(self.spiral_pts(ex, ey, e * 1.15, turns=2.3, a0=self.rng.uniform(0, 360)), pen, 0.8, smooth=False,+ hook=0.2, gloop=0.4, skip=0.1)+ elif mood == 'sleep':+ self.line([T(sx * gap - e, -size * 0.04), T(sx * gap, size * 0.02), T(sx * gap + e, -size * 0.04)], pen, 0.8,+ hook=0.3, gloop=0.3)+ else:+ self.eye(ex, ey, e * 0.92, e * 1.12, pen, look)+ if mood in ('smile', 'grin', 'sleep'):+ mw = size * (0.1 if mood != 'grin' else 0.15)+ self.line([T(-mw, size * 0.1), T(0, size * 0.1 + mw * (0.8 if mood != 'grin' else 0.9)), T(mw, size * 0.1)], pen,+ 0.8, hook=0.15, gloop=0.3)+ elif mood == 'oh':+ mx, my = T(0, size * 0.15)+ self.line(self.circle_pts(mx, my, size * 0.05, size * 0.065), pen, 0.85, closed=True, hook=0)+ elif mood == 'dizzy':+ mx, my = T(0, size * 0.16)+ self.line(self.circle_pts(mx, my, size * 0.06, size * 0.075), pen, 0.85, closed=True, hook=0)+ elif mood == 'worry':+ self.line([T(-size * 0.09, size * 0.16), T(-size * 0.03, size * 0.12), T(size * 0.03, size * 0.16), T(size * 0.09, size * 0.12)],+ pen, 0.8, hook=0.1)+ if blush:+ for sx in (-1, 1):+ bx, by = T(sx * gap * 1.55, size * 0.09)+ self.pencil(self.ellipse(bx, by, size * 0.08, size * 0.045, rot=rot), blush, angle=self.rng.uniform(40, 70),+ pressure=0.7, spacing=2.6, overshoot=1.5, length=(8, 14))++ def dashes(self, pts, pen='red', dash=11.0, gap=8.0, pressure=0.85, smooth=True, clip=None):+ """a dashed line along a path: each dash its own little stroke; returns the resampled path"""+ P = _resample(spline(pts, 10) if (smooth and len(pts) > 2) else np.asarray(pts, np.float32), 1.0)+ L = len(P); out = []; i = int(self.rng.uniform(0, gap))+ while i < L - 2:+ dl = int(dash * self.rng.uniform(0.8, 1.2))+ out.append(P[i:min(L, i + dl)])+ i += dl + int(gap * self.rng.uniform(0.8, 1.25))+ self.lines([q for q in out if len(q) > 1], pen, pressure, smooth=False, hook=0.05, gloop=0.35, skip=0.1, wobble=0.25,+ clip=clip)+ return P++ def arrow(self, tip, direction, size=16.0, pen='red', pressure=0.85, spread=28.0):+ """an arrowhead: two quick strokes back from the tip (direction: the way the arrow points)"""+ d = np.array(direction, np.float32); d /= (np.linalg.norm(d) + 1e-6)+ tip = np.array(tip, np.float32)+ for sg in (-1, 1):+ a = np.deg2rad(spread + self.rng.normal(0, 4)) * sg+ c, s = np.cos(a), np.sin(a)+ back = -np.array([d[0] * c - d[1] * s, d[0] * s + d[1] * c])+ self.line([tip + back * size * self.rng.uniform(0.9, 1.1), tip], pen, pressure, smooth=False, hook=0.0, gloop=0.6)++ def ring(self, cx, cy, rx, ry=None, pen='red', pressure=0.85, turns=1.12, rot=0.0):+ """a quick loose circle around something: overshoots its start and drifts outward"""+ ry = ry or rx+ a0 = self.rng.uniform(-150, -60)+ t = np.linspace(0, 1, 120)+ a = np.deg2rad(a0 + t * 360 * turns)+ k = 1 + 0.07 * t + 0.03 * np.sin(t * 7 + self.rng.uniform(0, 6))+ P = np.stack([rx * k * np.cos(a), ry * k * np.sin(a)], 1)+ ra = np.deg2rad(rot); c, s = np.cos(ra), np.sin(ra)+ P = np.stack([cx + P[:, 0] * c - P[:, 1] * s, cy + P[:, 0] * s + P[:, 1] * c], 1)+ self.line(P, pen, pressure, smooth=False, wobble=0.9, hook=0.5, gloop=0.6, skip=0.3)++ # ------------------------------------------------------------ hatching: coloured pencil and pen+ def _hatch_paths(self, mask, angle, spacing, length, overshoot, jitter, bow):+ sl = self._mask_box(mask, pad=2, thr=0.3)+ if sl is None: return []+ r = self.rng+ M = mask[sl]+ y0, x0 = sl[0].start, sl[1].start+ h, w = M.shape+ a = np.deg2rad(angle)+ d = np.array([np.cos(a), np.sin(a)], np.float32); nv = np.array([-d[1], d[0]], np.float32)+ c = np.array([x0 + w / 2, y0 + h / 2], np.float32)+ R = np.hypot(w, h) / 2 + 4+ out = []+ o = -R + r.uniform(0, spacing)+ ts = np.arange(-R, R, 1.5, dtype=np.float32)+ Lp = r.uniform(*length)+ cut0 = r.uniform(0, Lp)+ while o < R:+ base = c + nv * o+ X = base[0] + d[0] * ts; Y = base[1] + d[1] * ts+ ix = np.clip((X - x0).astype(int), 0, w - 1); iy = np.clip((Y - y0).astype(int), 0, h - 1)+ ins = (M[iy, ix] > 0.5) & (X >= x0) & (X < x0 + w) & (Y >= y0) & (Y < y0 + h)+ if ins.any():+ e = np.diff(np.concatenate([[0], ins.astype(np.int8), [0]]))+ st, en = np.nonzero(e == 1)[0], np.nonzero(e == -1)[0] - 1+ for s0, s1 in zip(st, en):+ u0, u1 = ts[s0] - r.uniform(-1.5, overshoot), ts[s1] + r.uniform(-1.5, overshoot)+ # break long runs into wrist-length strokes, seams staggered from row to row+ k0 = np.floor((u0 - cut0) / Lp); seams = cut0 + Lp * np.arange(k0 + 1, np.ceil((u1 - cut0) / Lp))+ seams = seams + r.normal(0, Lp * 0.06, len(seams))+ bounds = [u0] + [sm for sm in seams if u0 + 6 < sm < u1 - 6] + [u1]+ for b0, b1 in zip(bounds[:-1], bounds[1:]):+ b0 -= r.uniform(0, 2.5); b1 += r.uniform(0, 2.5)+ if b1 - b0 < 3: continue+ tt = np.linspace(0, 1, max(3, int((b1 - b0) / 6)), dtype=np.float32)[:, None]+ bend = bow * (b1 - b0) * r.uniform(0.5, 1.3)+ oo = o + r.normal(0, jitter * 0.3)+ P = c + nv * oo + d * (b0 + (b1 - b0) * tt) + nv * (4 * tt * (1 - tt) * bend)+ out.append(P)+ o += spacing * r.uniform(0.82, 1.18)+ return out++ def pencil(self, mask, colour, angle=60.0, pressure=0.45, spacing=4.2, length=(40, 90), overshoot=5.0, width=2.9,+ jitter=1.0, bow=0.04, cross=None, clip=None, groove=0.25):+ """coloured-pencil hatching inside `mask`: parallel quick strokes, heavier mid-stroke than at the ends,+ overshooting the outline a little. colour: a PENCILS name or '#rrggbb'. cross: a second angle laid+ over the first (darker, interleaved)"""+ col = hexc(PENCILS.get(colour, colour)) if isinstance(colour, str) else np.asarray(colour, np.float32)+ for ang in [angle] + ([cross] if cross is not None else []):+ paths = self._hatch_paths(mask, ang + self.rng.normal(0, 2.0), spacing, length, overshoot, jitter, bow)+ if not paths: continue+ self._wax(paths, col, pressure, width, clip, groove)++ def pencil_line(self, pts, colour, pressure=0.6, width=3.0, smooth=True, wobble=0.6, clip=None):+ """a single coloured-pencil line (grass blades, rays, a rainbow band)"""+ col = hexc(PENCILS.get(colour, colour)) if isinstance(colour, str) else np.asarray(colour, np.float32)+ P = spline(pts, 8) if (smooth and len(pts) > 2) else np.asarray(pts, np.float32)+ self._wax([P], col, pressure, width, clip, 0.25, wobble)++ def _wax(self, paths, col, pressure, width, clip, groove, wobble=0.35):+ r = self.rng+ allp = np.concatenate(paths)+ pad = width * 2 + 4+ sl = self._box(allp[:, 0].min() - pad, allp[:, 1].min() - pad, allp[:, 0].max() + pad, allp[:, 1].max() + pad)+ if sl is None: return+ ss = self.ss+ x0, y0 = sl[1].start, sl[0].start+ bw, bh = sl[1].stop - x0, sl[0].stop - y0+ im = Image.new('L', (bw * ss, bh * ss), 0); d = ImageDraw.Draw(im)+ off = np.array([x0, y0], np.float32)+ for P in paths:+ P = _resample(P, 3.0)+ n = len(P)+ if n < 2: continue+ if wobble:+ tan = np.gradient(P, axis=0); tan /= (np.linalg.norm(tan, axis=1, keepdims=True) + 1e-6)+ P = P + np.stack([-tan[:, 1], tan[:, 0]], 1) * (fbm1d(n, max(3, n / 3), 2, self._seed()) * wobble)[:, None]+ Q = ((P - off) * ss).tolist()+ pr = pressure * r.uniform(0.8, 1.15)+ wd = max(1, int(round(width * ss * r.uniform(0.85, 1.15))))+ k = max(1, n // 5)+ parts = [(0, k + 1, 0.55), (k, n - k, 1.0), (n - k - 1, n, 0.45)] if n > 4 else [(0, n, 0.85)]+ for a_, b_, f in parts:+ seg = Q[a_:b_]+ if len(seg) >= 2:+ d.line([tuple(q) for q in seg], fill=int(255 * min(1, pr * f)), width=wd, joint='curve')+ cov = np.asarray(im.resize((bw, bh), Image.BOX), np.float32) / 255+ if clip is not None: cov = cov * clip[sl]+ t = self.tooth[sl]+ reach = 0.16 + 0.62 * np.sqrt(np.clip(cov, 0, 1))+ resp = smoothstep(1.0 - reach - 0.11, 1.0 - reach + 0.11, t)+ amt = cov * (0.1 + 0.9 * resp) * 0.95+ self.D[sl] += amt[..., None] * (-np.log(np.clip(col, 0.02, 1)))+ if groove: self.G[sl] -= blur(cov, 0.6) * 0.3 * groove++ def pen_hatch(self, mask, pen='blue', angle=50.0, spacing=3.2, pressure=0.7, length=(30, 60), overshoot=3.0,+ zigzag=0.85, cross=None, clip=None):+ """ballpoint shading: parallel strokes laid back and forth without lifting the pen (`zigzag` share),+ gloops at the turns; cross: a second pass at another angle"""+ for ang in [angle] + ([cross] if cross is not None else []):+ paths = self._hatch_paths(mask, ang + self.rng.normal(0, 2.0), spacing, length, overshoot, 1.0, 0.03)+ if not paths: continue+ chains = []+ if zigzag:+ cur = None+ for P in paths:+ if cur is not None and self.rng.random() < zigzag and len(cur) < 9 and \+ np.hypot(*(cur[-1][-1] - P[-1])) < spacing * 3.5 + 6:+ cur.append(P[::-1] if len(cur) % 2 else P)+ else:+ if cur: chains.append(np.vstack(cur))+ cur = [P]+ if cur: chains.append(np.vstack(cur))+ else:+ chains = paths+ S = [self._prep(P, pressure * self.rng.uniform(0.85, 1.1), self.pen_w * 0.95, False, False, 0.3, 0, 0.1, 0.35, 0.3, True)+ for P in chains if len(P) > 1]+ self._ink(S, pen, clip)++ # ------------------------------------------------------------ handwriting+ def write(self, s, x, y, size=34.0, pen='blue', pressure=0.8, slant=7.0, spacing=1.04, jitter=1.0, anchor='l',+ rot=0.0, width=None, blind=False, hook=0.3, gloop=0.4):+ """handwrite `s` with its baseline at y. anchor 'l' / 'm' / 'r' on x; rot: the whole line tilted (deg,+ clockwise); blind: grooves only (writing that came through from the sheet on top). Returns the+ (x0, y0, x1, y1) box of what was written"""+ r = self.rng+ width = width or self.pen_w+ G = [_glyph(ch) for ch in s]+ scs = size * (1 + r.normal(0, 0.05 * jitter, len(s))) # each letter its own size ...+ advs = np.array([g[2] * sc * spacing * (1 + r.normal(0, 0.02 * jitter)) for g, sc in zip(G, scs)], np.float32)+ tot = float(advs.sum())+ xs = x - tot * {'l': 0.0, 'm': 0.5, 'r': 1.0}[anchor] + np.concatenate([[0], np.cumsum(advs)[:-1]])+ drift = fbm1d(max(4, len(s) + 2), 3, 2, self._seed()) * size * 0.045 * jitter+ ra = np.deg2rad(rot); cr, sr = np.cos(ra), np.sin(ra)+ sh = np.tan(np.deg2rad(slant))+ strokes, boxes = [], []+ for i, (ch, (paths, dots, _)) in enumerate(zip(s, G)):+ if not paths and not dots: continue+ sc = scs[i] # ... and its advance to match+ a = np.deg2rad(r.normal(0, 2.5 * jitter)); ca, sa = np.cos(a), np.sin(a)+ dy = drift[i] + r.normal(0, size * 0.012 * jitter)++ def T(P, xi=xs[i], sc=sc, ca=ca, sa=sa, dy=dy):+ P = np.asarray(P, np.float32) * sc+ px, py = P[:, 0] - P[:, 1] * sh, P[:, 1]+ px, py = px * ca - py * sa, px * sa + py * ca+ gx, gy = xi + px, y + py + dy+ return np.stack([x + (gx - x) * cr - (gy - y) * sr, y + (gx - x) * sr + (gy - y) * cr], 1)+ for P in paths:+ Q = T(P)+ strokes.append(self._prep(Q, pressure * r.uniform(0.88, 1.08), width, False, False, 0.25 * jitter, 0,+ hook if P is paths[-1] else hook * 0.4, gloop, 0.25, True))+ boxes.append(Q)+ for (dx_, dy_) in dots:+ Q = T([(dx_, dy_)])[0]+ strokes.append(self._prep([Q, Q + r.normal(0, 0.6, 2)], pressure * 1.1, width * 1.2, False, False, 0, 0, 0,+ 1.0, 0, False))+ boxes.append(Q[None])+ if not strokes: return (x, y, x, y)+ self._ink(strokes, None if blind else pen, groove=0.55 if blind else 1.0)+ B = np.concatenate(boxes)+ return (float(B[:, 0].min()), float(B[:, 1].min()), float(B[:, 0].max()), float(B[:, 1].max()))++ def strike(self, box, pen='blue', pressure=0.85, passes=3):+ """scribble a word out: the pen goes back and forth through its middle a few times"""+ x0, y0, x1, y1 = box+ h = y1 - y0; ym = y0 + h * 0.55+ pts = []+ for k in range(passes + 1):+ xx = (x0 - 4 + self.rng.uniform(-3, 3)) if k % 2 == 0 else (x1 + 4 + self.rng.uniform(-3, 3))+ pts.append((xx, ym + self.rng.normal(0, h * 0.09) + (k - passes / 2) * h * 0.06))+ P = []+ for a, b in zip(pts[:-1], pts[1:]):+ P.extend(_resample(np.array([a, b], np.float32), 3.0)[:-1].tolist())+ P.append(pts[-1])+ self.line(np.array(P, np.float32), pen, pressure, smooth=False, wobble=1.0, hook=0.3, gloop=0.8, skip=0.2)++ def underline(self, x0, x1, y, pen='red', pressure=0.85, wavy=False, twice=0.5):+ if wavy:+ xs = np.linspace(x0, x1, int((x1 - x0) / 3) + 2)+ P = np.stack([xs, y + np.sin((xs - x0) / 9.0) * 3.2], 1)+ self.line(P, pen, pressure, smooth=False, hook=0.4, wobble=0.5)+ else:+ self.line([(x0, y), (x1, y + self.rng.normal(0, 2))], pen, pressure, bow=0.006, hook=0.5, twice=twice)++ # ------------------------------------------------------------ output+ def composite(self):+ gy, gx = np.gradient(blur(self.G, 0.55))+ shade = 1 + np.clip((gx * 0.6 + gy * 0.8) * 0.13, -0.1, 0.1)+ del gx, gy+ img = self.base * np.exp(-self.D)+ heavy = smoothstep(1.4, 3.2, self.I)+ img += (np.array(SHEEN, np.float32) - img) * (heavy * 0.14)[..., None]+ img *= (shade * self.relief_shade * self.light)[..., None]+ return Image.fromarray((np.clip(img, 0, 1) * 255 + 0.5).astype(np.uint8))++ def stage(self, name):+ self.stages.append((name, self.composite()))++ def save(self, path, stages_dir=None, quality=88):+ img = self.composite()+ if str(path).lower().endswith(('.jpg', '.jpeg')): img.save(path, quality=quality, subsampling=0)+ else: img.save(path)+ if stages_dir:+ os.makedirs(stages_dir, exist_ok=True)+ for i, (name, im) in enumerate(self.stages):+ im.save(f"{stages_dir}/{i:02d}_{name}.png")+ img.save(f"{stages_dir}/{len(self.stages):02d}_final.png")+ return img