Skip to content

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

Add blue picture book style (66 total): a soft-blue picture-book spread

cloveric24ae932a8d9d
diff --git a/README.md b/README.md
index 9367452..6317877 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# Claude Drawing · Claude 绘图
-**Claude paints with code — no image model.** Sixty-five styles, from ink wash and impasto oil to clay, cyanotype, stained glass, a Roman mosaic, Delft tiles, a cyberpunk street, a ray-traced ball pit, low-poly 3D, a thermal camera, an X-ray, a VHS tape, a synthwave sunset, a pastel product-film UI, an answer sheet marked in red, a lamp-lit shadow-puppet play, pen-and-wash sketch cards and retro gouache picture-book portraits.
-**不用生图模型,Claude 用代码一笔一笔作画。** 六十五种画风,从水墨、油画到黏土、蓝晒、彩色玻璃花窗、罗马马赛克、代尔夫特蓝瓷砖、赛博朋克、光线追踪的小球海、低多边形 3D、热成像、X 光片、VHS 录像带、Synthwave 落日、产品发布片式的粉彩界面、红笔批改的答题卡、油灯下的皮影戏、钢笔淡彩的速写小卡和复古水粉的绘本大头像。
+**Claude paints with code — no image model.** Sixty-six styles, from ink wash and impasto oil to clay, cyanotype, stained glass, a Roman mosaic, Delft tiles, a cyberpunk street, a ray-traced ball pit, low-poly 3D, a thermal camera, an X-ray, a VHS tape, a synthwave sunset, a pastel product-film UI, an answer sheet marked in red, a lamp-lit shadow-puppet play, pen-and-wash sketch cards, retro gouache picture-book portraits and a soft-blue picture-book spread.
+**不用生图模型,Claude 用代码一笔一笔作画。** 六十六种画风,从水墨、油画到黏土、蓝晒、彩色玻璃花窗、罗马马赛克、代尔夫特蓝瓷砖、赛博朋克、光线追踪的小球海、低多边形 3D、热成像、X 光片、VHS 录像带、Synthwave 落日、产品发布片式的粉彩界面、红笔批改的答题卡、油灯下的皮影戏、钢笔淡彩的速写小卡、复古水粉的绘本大头像和蓝调绘本的雨天跨页。
[English](#english) · [中文](#中文)
@@ -50,8 +50,8 @@
| ![ballpoint](examples/drawing_ballpoint_board_game.gif) | ![overlay](examples/drawing_overlay_city_map.gif) | ![pastelui](examples/drawing_pastelui_packing.gif) |
| **Exam grading · 阅卷批改** | **Shadow puppetry · 皮影戏** | **Pen & wash · 钢笔淡彩** |
| ![grading](examples/drawing_grading_math_quiz.gif) | ![shadowpuppet](examples/drawing_shadowpuppet_cuju.gif) | ![penwash](examples/drawing_penwash_neighbours.gif) |
-| **Retro gouache · 复古水粉** | **Ink wash · 水墨(月印万川)** | **Watercolour washes · 水彩底纹** |
-| ![gouache](examples/drawing_gouache_rainy_day.gif) | ![moonriver](examples/drawing_moon_river.gif) | ![washes](examples/drawing_watercolor_washes.gif) |
+| **Retro gouache · 复古水粉** | **Blue picture book · 蓝调绘本** | **Ink wash · 水墨(月印万川)** |
+| ![gouache](examples/drawing_gouache_rainy_day.gif) | ![bluebook](examples/drawing_bluebook_shared_umbrella.gif) | ![moonriver](examples/drawing_moon_river.gif) |
### Gallery · 画廊
@@ -59,72 +59,74 @@
|---|---|
| **八万四千法门** · *Many Paths, One Summit*<br><sub>Ink wash · 水墨</sub> | **月印万川** · *One Moon in Ten Thousand Rivers*<br><sub>Ink wash · 水墨</sub> |
| <img src="examples/bawansiqian.jpg" width="100%"> | <img src="examples/moon_river.jpg" width="100%"> |
-| **秋日湖畔** · *Autumn Lake*<br><sub>Watercolour · 水彩</sub> | **热气球小镇** · *Balloon Day*<br><sub>Paper collage · 剪纸拼贴</sub> |
-| <img src="examples/watercolor_autumn.jpg" width="100%"> | <img src="examples/papercut_balloons.jpg" width="100%"> |
-| **午后甜点** · *Afternoon Dessert*<br><sub>Coloured pencil · 韩国彩铅</sub> | **夏空** · *Summer Sky*<br><sub>Anime · 日本动漫</sub> |
-| <img src="examples/colorpencil_dessert.jpg" width="100%"> | <img src="examples/anime_summer.jpg" width="100%"> |
-| **灵感生长** · *Growing Ideas*<br><sub>Editorial · 编辑风手绘</sub> | **麦田星空** · *Swirling Sky over the Wheat Field*<br><sub>Impasto oil · 油画厚涂</sub> |
-| <img src="examples/editorial_ideas.jpg" width="100%"> | <img src="examples/oil_wheatfield.jpg" width="100%"> |
-| **富士曙** · *Fuji at Dawn*<br><sub>Ukiyo-e · 浮世绘</sub> | **雨夜咖啡店** · *Rainy Night Cafe*<br><sub>Pixel art · 像素风</sub> |
-| <img src="examples/ukiyoe_fuji.jpg" width="100%"> | <img src="examples/pixel_rainy_cafe.png" width="100%"> |
-| **灯塔岛** · *Lighthouse Island*<br><sub>Stop-motion clay · 黏土定格</sub> | **蓝晒植物** · *Sun-Print Botanicals*<br><sub>Cyanotype · 蓝晒</sub> |
-| <img src="examples/clay_lighthouse.jpg" width="100%"> | <img src="examples/cyanotype_botanicals.jpg" width="100%"> |
-| **家** · *Home Sampler*<br><sub>Cross-stitch · 十字绣</sub> | **Aurora 64 收音机** · *Aurora 64 Radio*<br><sub>Vintage instrument panel · 复古仪器面板</sub> |
-| <img src="examples/stitch_sampler.jpg" width="100%"> | <img src="examples/panel_radio.jpg" width="100%"> |
-| **周末市集** · *Weekend Market*<br><sub>Sticker collage × receipt · 贴纸拼贴 · 小票</sub> | **咖啡萃取实验** · *Coffee Brewing Experiment*<br><sub>Lab notebook × stickers · 实验笔记本 · 贴纸</sub> |
-| <img src="examples/sticker_market.jpg" width="100%"> | <img src="examples/notebook_brewing.jpg" width="100%"> |
-| **为什么天空是蓝的** · *Why Is the Sky Blue?*<br><sub>Chalkboard · 黑板板书</sub> | **霓虹不夜城** · *Neon District*<br><sub>Cyberpunk · 赛博朋克</sub> |
-| <img src="examples/chalk_lesson.jpg" width="100%"> | <img src="examples/cyberpunk_neon_street.jpg" width="100%"> |
-| **早安吐司** · *Good Morning, Toast*<br><sub>Hand-drawn cartoon · 卡通手绘</sub> | **岛上的气象站** · *Island Weather Station*<br><sub>Isometric 2.5D · 等轴 2.5D</sub> |
-| <img src="examples/cartoon_toaster.jpg" width="100%"> | <img src="examples/isometric_weather_island.jpg" width="100%"> |
-| **从这扇窗到那扇窗** · *From Window to Window*<br><sub>Continuous line art · 单线画</sub> | **浮出** · *Rise*<br><sub>Soft 3D · 柔光 3D</sub> |
-| <img src="examples/lineart_paper_plane.jpg" width="100%"> | <img src="examples/soft3d_rise.jpg" width="100%"> |
-| **一滴水的旅程** · *A Drop's Round Trip*<br><sub>Shape morph · 形变动画</sub> | **好奇心周刊 · 拆开看看** · *Curiosity Weekly · Take It Apart*<br><sub>Newspaper collage · 报刊拼贴</sub> |
-| <img src="examples/morph_water_cycle.jpg" width="100%"> | <img src="examples/newscollage_curiosity.jpg" width="100%"> |
-| **晨间计划** · *Morning Plan*<br><sub>Aurora glassmorphism · 弥散玻璃</sub> | **形与色** · *Form & Colour*<br><sub>Bauhaus geometric · 包豪斯几何</sub> |
-| <img src="examples/aurora_morning.jpg" width="100%"> | <img src="examples/bauhaus_form_colour.jpg" width="100%"> |
-| **海岸线 1987** · *Coastline 1987*<br><sub>Retro synthwave · 复古 Synthwave</sub> | **草莓杯垫** · *Strawberry Coaster*<br><sub>Perler beads · 拼豆</sub> |
-| <img src="examples/synthwave_coastline.jpg" width="100%"> | <img src="examples/perler_strawberry_coaster.jpg" width="100%"> |
-| **迁徙季** · *Migration Season*<br><sub>Petroglyph · 岩画</sub> | **尼罗河丰收** · *Harvest on the Nile*<br><sub>Egyptian tomb painting · 古埃及墓室壁画</sub> |
-| <img src="examples/petroglyph_migration.jpg" width="100%"> | <img src="examples/tomb_harvest.jpg" width="100%"> |
-| **港口渔获** · *The Day's Catch*<br><sub>Roman mosaic · 罗马马赛克</sub> | **四季之窗** · *Window of the Seasons*<br><sub>Stained glass · 彩色玻璃花窗</sub> |
-| <img src="examples/mosaic_harbor.jpg" width="100%"> | <img src="examples/stainedglass_seasons.jpg" width="100%"> |
-| **星辰之书** · *Liber Stellarum*<br><sub>Illuminated manuscript · 泥金手抄本</sub> | **扑翼机** · *The Ornithopter*<br><sub>Leonardo codex · 达·芬奇手稿</sub> |
-| <img src="examples/illuminated_starchart.jpg" width="100%"> | <img src="examples/codex_ornithopter.jpg" width="100%"> |
-| **剪影小像** · *Shades of the Wren Household*<br><sub>Silhouette · 剪影</sub> | **马戏团来了** · *The Circus Is Coming*<br><sub>Letterpress poster · 凸版印刷海报</sub> |
-| <img src="examples/silhouette_family.jpg" width="100%"> | <img src="examples/letterpress_circus.jpg" width="100%"> |
-| **无线电** · *Radio*<br><sub>Soviet constructivism · 苏联构成主义</sub> | **夜行快车** · *Night Express*<br><sub>Art Deco · 装饰艺术</sub> |
-| <img src="examples/constructivism_radio.jpg" width="100%"> | <img src="examples/artdeco_express.jpg" width="100%"> |
-| **火箭小队** · *Rocket Squad*<br><sub>Golden-age comic · 黄金时代漫画</sub> | **猫的六种心情** · *Six Moods of a Cat*<br><sub>Pop silkscreen · 波普丝网</sub> |
-| <img src="examples/comic_rocket.jpg" width="100%"> | <img src="examples/popart_cat_moods.jpg" width="100%"> |
-| **发射记录** · *Liftoff Trace*<br><sub>ASCII art (line printer) · ASCII 字符画(行式打印机)</sub> | **峡谷飞行** · *Canyon Run*<br><sub>Low poly · 低多边形</sub> |
-| <img src="examples/lineprinter_launch.jpg" width="100%"> | <img src="examples/lowpoly_canyon.jpg" width="100%"> |
-| **放风筝** · *Hold On*<br><sub>Stencil graffiti · 喷漆模板涂鸦</sub> | **三晚露营** · *Three Nights Out*<br><sub>Embroidered patches · 刺绣徽章</sub> |
-| <img src="examples/stencil_kite.jpg" width="100%"> | <img src="examples/patch_camping.jpg" width="100%"> |
-| **灯塔剖面** · *Halvard Rock Light*<br><sub>Blueprint · 蓝图工程图</sub> | **我的周末** · *My Weekend*<br><sub>Children's crayon · 儿童蜡笔画</sub> |
-| <img src="examples/blueprint_lighthouse.jpg" width="100%"> | <img src="examples/crayon_picnic.jpg" width="100%"> |
-| **今天带伞吗** · *Bring an Umbrella?*<br><sub>Green-screen CRT terminal · 绿屏终端(荧光字符画)</sub> | **厨房里的温度** · *Kitchen Heat Map*<br><sub>Thermal camera · 热成像</sub> |
-| <img src="examples/crt_weather.jpg" width="100%"> | <img src="examples/thermal_kitchen.jpg" width="100%"> |
-| **一阵风** · *The Gust*<br><sub>Delft tiles · 代尔夫特蓝瓷砖</sub> | **篝火旁的岩洞** · *The Hunt by the Fire*<br><sub>Cave painting · 洞穴壁画</sub> |
-| <img src="examples/delft_canal.jpg" width="100%"> | <img src="examples/cave_hunt.jpg" width="100%"> |
-| **窗台花园** · *Windowsill Garden*<br><sub>1-bit paint program · 1-bit 早期画图软件</sub> | **赛跑与赛车** · *Games on a Vase*<br><sub>Greek black-figure vase · 古希腊黑绘陶瓶</sub> |
-| <img src="examples/macpaint_garden.jpg" width="100%"> | <img src="examples/blackfigure_games.jpg" width="100%"> |
-| **老街角的自行车** · *The Bread Run*<br><sub>Graphite pencil · 铅笔素描</sub> | **行李安检** · *Security Check*<br><sub>X-ray · X 光片</sub> |
-| <img src="examples/graphite_bicycle.jpg" width="100%"> | <img src="examples/xray_luggage.jpg" width="100%"> |
-| **早晨的闹钟** · *Seven O'Clock*<br><sub>1930s rubber hose · 1930 年代黑白橡皮管动画</sub> | **雪夜归途** · *Homeward, First Snow*<br><sub>Linocut · 黑白麻胶版画</sub> |
-| <img src="examples/rubberhose_morning.jpg" width="100%"> | <img src="examples/linocut_snowy_village.jpg" width="100%"> |
-| **吹蜡烛** · *Blow Out the Candles*<br><sub>VHS home video · VHS 家庭录像</sub> | **山间夜营** · *Night Camp*<br><sub>Flat vector · 扁平矢量</sub> |
-| <img src="examples/vhs_birthday.jpg" width="100%"> | <img src="examples/flatvector_night_camp.jpg" width="100%"> |
-| **小橡果的秋天** · *An Acorn's Autumn*<br><sub>Storybook animation · 绘本角色动画</sub> | **蛇梯棋大冒险** · *Snakes & Ladders, Round 7*<br><sub>Ballpoint doodle · 圆珠笔涂鸦</sub> |
-| <img src="examples/storybook_acorn.jpg" width="100%"> | <img src="examples/ballpoint_board_game.jpg" width="100%"> |
-| **海港步行图** · *Larkhaven on Foot*<br><sub>Overlay sheets · 描图纸叠层</sub> | **出发前,再查一遍行李** · *Pack Check*<br><sub>Pastel UI · 粉彩界面</sub> |
-| <img src="examples/overlay_city_map.jpg" width="100%"> | <img src="examples/pastelui_packing.jpg" width="100%"> |
-| **数学单元测验** · *Unit Test, Graded*<br><sub>Exam grading · 阅卷批改</sub> | **蹴鞠** · *Cuju by Lamplight*<br><sub>Shadow puppetry · 皮影戏</sub> |
-| <img src="examples/grading_math_quiz.jpg" width="100%"> | <img src="examples/shadowpuppet_cuju.jpg" width="100%"> |
-| **街角速写** · *Sketchbook Neighbours*<br><sub>Pen & wash · 钢笔淡彩</sub> | **雨天三人像** · *Rainy-Day Portraits*<br><sub>Retro gouache · 复古水粉</sub> |
-| <img src="examples/penwash_neighbours.jpg" width="100%"> | <img src="examples/gouache_rainy_day.jpg" width="100%"> |
-
-Every mark above is computed: paper fibres, ink washes and mist, dry-brush strokes, pigment granulation and blooms, torn-paper edges, pencil wax on paper tooth, cel-shaded clouds, risograph grain and halftones, lit impasto relief, woodblock grain and bokashi, dithered pixels, plasticine lit like a film set, sunlight through leaves on Prussian blue, twisted thread on Aida cloth, machined knobs behind a backlit dial, die-cut vinyl with a laminate gloss, streaky thermal print, graphite catching the tooth of graph paper, highlighter pooling at the start of a swipe, chalk dust settling under half-erased lessons, rain-lit neon glass mirrored in a wet street, a blue-pencil rough under boiling brush ink, an island ray-traced under one soft sun, a single unbroken gold line, candy balls with softbox glints, one outline morphing through six shapes, halftone photos cut out with scissors, frosted glass blurring the real pixels behind it, screen-printed primaries out of register, a slit sun sinking behind a neon grid played off tape, hollow fuse beads on a pegboard melting together under an iron, pits knocked through desert varnish, a red grid showing through flaking plaster, stones laid row by row along an outline, daylight through leaded glass, burnished gold that mirrors the room, left-handed hatching in iron-gall ink, black paper cut with scissors, wood type printed a hair out of register, red and black plates slipping apart, airbrush fades inside knife-cut friskets, Ben-Day dots on yellowed newsprint, one photo key pulled across hand-painted colour, characters struck through a fading ribbon, flat-shaded triangles dithered to 15 bits, spray drifting past cut card, satin stitches catching the light by their angle, ink lines printed white on Prussian blue, wax scribbles skipping the paper's pits, phosphor glowing behind curved glass, heat leaking out of a kitchen, cobalt fired into tin glaze tile by tile, ochre blown onto rock lit by a fire, 1-bit patterns in an old paint program, slip silhouettes incised to the clay, graphite that never quite reaches black, X-rays adding up through a suitcase, grey cels shot on scratched film, gouge marks in a rolled-up block, a birthday smeared onto tape, seven flat colours lifting off each other, an acorn squashing and stretching through a world drawn as it goes, ballpoint ink blobbing at every corner of a hand-drawn game, inks multiplying through tracing paper on a light box, window cards floating on a pastel field over shadows tinted by it, a vermilion stamp running dry at one end, red ink pooling where the pen slowed down, dyed donkey hide glowing on a lamp-lit screen and gouache scumbled dry over a toned board, knit stitch by stitch. No diffusion model, no API, no stock art. It is just Python with **numpy + Pillow** on a CPU: from 0.1 s (pixel art) to about 45 s (the soft 3D ray tracer) per 1920×1080 image.
+| **秋日湖畔** · *Autumn Lake*<br><sub>Watercolour · 水彩</sub> | **水彩底纹** · *Watercolour Washes*<br><sub>Watercolour · 水彩 — a background for explainer videos · 讲解视频的背景</sub> |
+| <img src="examples/watercolor_autumn.jpg" width="100%"> | <img src="examples/watercolor_washes.jpg" width="100%"> |
+| **热气球小镇** · *Balloon Day*<br><sub>Paper collage · 剪纸拼贴</sub> | **午后甜点** · *Afternoon Dessert*<br><sub>Coloured pencil · 韩国彩铅</sub> |
+| <img src="examples/papercut_balloons.jpg" width="100%"> | <img src="examples/colorpencil_dessert.jpg" width="100%"> |
+| **夏空** · *Summer Sky*<br><sub>Anime · 日本动漫</sub> | **灵感生长** · *Growing Ideas*<br><sub>Editorial · 编辑风手绘</sub> |
+| <img src="examples/anime_summer.jpg" width="100%"> | <img src="examples/editorial_ideas.jpg" width="100%"> |
+| **麦田星空** · *Swirling Sky over the Wheat Field*<br><sub>Impasto oil · 油画厚涂</sub> | **富士曙** · *Fuji at Dawn*<br><sub>Ukiyo-e · 浮世绘</sub> |
+| <img src="examples/oil_wheatfield.jpg" width="100%"> | <img src="examples/ukiyoe_fuji.jpg" width="100%"> |
+| **雨夜咖啡店** · *Rainy Night Cafe*<br><sub>Pixel art · 像素风</sub> | **灯塔岛** · *Lighthouse Island*<br><sub>Stop-motion clay · 黏土定格</sub> |
+| <img src="examples/pixel_rainy_cafe.png" width="100%"> | <img src="examples/clay_lighthouse.jpg" width="100%"> |
+| **蓝晒植物** · *Sun-Print Botanicals*<br><sub>Cyanotype · 蓝晒</sub> | **家** · *Home Sampler*<br><sub>Cross-stitch · 十字绣</sub> |
+| <img src="examples/cyanotype_botanicals.jpg" width="100%"> | <img src="examples/stitch_sampler.jpg" width="100%"> |
+| **Aurora 64 收音机** · *Aurora 64 Radio*<br><sub>Vintage instrument panel · 复古仪器面板</sub> | **周末市集** · *Weekend Market*<br><sub>Sticker collage × receipt · 贴纸拼贴 · 小票</sub> |
+| <img src="examples/panel_radio.jpg" width="100%"> | <img src="examples/sticker_market.jpg" width="100%"> |
+| **咖啡萃取实验** · *Coffee Brewing Experiment*<br><sub>Lab notebook × stickers · 实验笔记本 · 贴纸</sub> | **为什么天空是蓝的** · *Why Is the Sky Blue?*<br><sub>Chalkboard · 黑板板书</sub> |
+| <img src="examples/notebook_brewing.jpg" width="100%"> | <img src="examples/chalk_lesson.jpg" width="100%"> |
+| **霓虹不夜城** · *Neon District*<br><sub>Cyberpunk · 赛博朋克</sub> | **早安吐司** · *Good Morning, Toast*<br><sub>Hand-drawn cartoon · 卡通手绘</sub> |
+| <img src="examples/cyberpunk_neon_street.jpg" width="100%"> | <img src="examples/cartoon_toaster.jpg" width="100%"> |
+| **岛上的气象站** · *Island Weather Station*<br><sub>Isometric 2.5D · 等轴 2.5D</sub> | **从这扇窗到那扇窗** · *From Window to Window*<br><sub>Continuous line art · 单线画</sub> |
+| <img src="examples/isometric_weather_island.jpg" width="100%"> | <img src="examples/lineart_paper_plane.jpg" width="100%"> |
+| **浮出** · *Rise*<br><sub>Soft 3D · 柔光 3D</sub> | **一滴水的旅程** · *A Drop's Round Trip*<br><sub>Shape morph · 形变动画</sub> |
+| <img src="examples/soft3d_rise.jpg" width="100%"> | <img src="examples/morph_water_cycle.jpg" width="100%"> |
+| **好奇心周刊 · 拆开看看** · *Curiosity Weekly · Take It Apart*<br><sub>Newspaper collage · 报刊拼贴</sub> | **晨间计划** · *Morning Plan*<br><sub>Aurora glassmorphism · 弥散玻璃</sub> |
+| <img src="examples/newscollage_curiosity.jpg" width="100%"> | <img src="examples/aurora_morning.jpg" width="100%"> |
+| **形与色** · *Form & Colour*<br><sub>Bauhaus geometric · 包豪斯几何</sub> | **海岸线 1987** · *Coastline 1987*<br><sub>Retro synthwave · 复古 Synthwave</sub> |
+| <img src="examples/bauhaus_form_colour.jpg" width="100%"> | <img src="examples/synthwave_coastline.jpg" width="100%"> |
+| **草莓杯垫** · *Strawberry Coaster*<br><sub>Perler beads · 拼豆</sub> | **迁徙季** · *Migration Season*<br><sub>Petroglyph · 岩画</sub> |
+| <img src="examples/perler_strawberry_coaster.jpg" width="100%"> | <img src="examples/petroglyph_migration.jpg" width="100%"> |
+| **尼罗河丰收** · *Harvest on the Nile*<br><sub>Egyptian tomb painting · 古埃及墓室壁画</sub> | **港口渔获** · *The Day's Catch*<br><sub>Roman mosaic · 罗马马赛克</sub> |
+| <img src="examples/tomb_harvest.jpg" width="100%"> | <img src="examples/mosaic_harbor.jpg" width="100%"> |
+| **四季之窗** · *Window of the Seasons*<br><sub>Stained glass · 彩色玻璃花窗</sub> | **星辰之书** · *Liber Stellarum*<br><sub>Illuminated manuscript · 泥金手抄本</sub> |
+| <img src="examples/stainedglass_seasons.jpg" width="100%"> | <img src="examples/illuminated_starchart.jpg" width="100%"> |
+| **扑翼机** · *The Ornithopter*<br><sub>Leonardo codex · 达·芬奇手稿</sub> | **剪影小像** · *Shades of the Wren Household*<br><sub>Silhouette · 剪影</sub> |
+| <img src="examples/codex_ornithopter.jpg" width="100%"> | <img src="examples/silhouette_family.jpg" width="100%"> |
+| **马戏团来了** · *The Circus Is Coming*<br><sub>Letterpress poster · 凸版印刷海报</sub> | **无线电** · *Radio*<br><sub>Soviet constructivism · 苏联构成主义</sub> |
+| <img src="examples/letterpress_circus.jpg" width="100%"> | <img src="examples/constructivism_radio.jpg" width="100%"> |
+| **夜行快车** · *Night Express*<br><sub>Art Deco · 装饰艺术</sub> | **火箭小队** · *Rocket Squad*<br><sub>Golden-age comic · 黄金时代漫画</sub> |
+| <img src="examples/artdeco_express.jpg" width="100%"> | <img src="examples/comic_rocket.jpg" width="100%"> |
+| **猫的六种心情** · *Six Moods of a Cat*<br><sub>Pop silkscreen · 波普丝网</sub> | **发射记录** · *Liftoff Trace*<br><sub>ASCII art (line printer) · ASCII 字符画(行式打印机)</sub> |
+| <img src="examples/popart_cat_moods.jpg" width="100%"> | <img src="examples/lineprinter_launch.jpg" width="100%"> |
+| **峡谷飞行** · *Canyon Run*<br><sub>Low poly · 低多边形</sub> | **放风筝** · *Hold On*<br><sub>Stencil graffiti · 喷漆模板涂鸦</sub> |
+| <img src="examples/lowpoly_canyon.jpg" width="100%"> | <img src="examples/stencil_kite.jpg" width="100%"> |
+| **三晚露营** · *Three Nights Out*<br><sub>Embroidered patches · 刺绣徽章</sub> | **灯塔剖面** · *Halvard Rock Light*<br><sub>Blueprint · 蓝图工程图</sub> |
+| <img src="examples/patch_camping.jpg" width="100%"> | <img src="examples/blueprint_lighthouse.jpg" width="100%"> |
+| **我的周末** · *My Weekend*<br><sub>Children's crayon · 儿童蜡笔画</sub> | **今天带伞吗** · *Bring an Umbrella?*<br><sub>Green-screen CRT terminal · 绿屏终端(荧光字符画)</sub> |
+| <img src="examples/crayon_picnic.jpg" width="100%"> | <img src="examples/crt_weather.jpg" width="100%"> |
+| **厨房里的温度** · *Kitchen Heat Map*<br><sub>Thermal camera · 热成像</sub> | **一阵风** · *The Gust*<br><sub>Delft tiles · 代尔夫特蓝瓷砖</sub> |
+| <img src="examples/thermal_kitchen.jpg" width="100%"> | <img src="examples/delft_canal.jpg" width="100%"> |
+| **篝火旁的岩洞** · *The Hunt by the Fire*<br><sub>Cave painting · 洞穴壁画</sub> | **窗台花园** · *Windowsill Garden*<br><sub>1-bit paint program · 1-bit 早期画图软件</sub> |
+| <img src="examples/cave_hunt.jpg" width="100%"> | <img src="examples/macpaint_garden.jpg" width="100%"> |
+| **赛跑与赛车** · *Games on a Vase*<br><sub>Greek black-figure vase · 古希腊黑绘陶瓶</sub> | **老街角的自行车** · *The Bread Run*<br><sub>Graphite pencil · 铅笔素描</sub> |
+| <img src="examples/blackfigure_games.jpg" width="100%"> | <img src="examples/graphite_bicycle.jpg" width="100%"> |
+| **行李安检** · *Security Check*<br><sub>X-ray · X 光片</sub> | **早晨的闹钟** · *Seven O'Clock*<br><sub>1930s rubber hose · 1930 年代黑白橡皮管动画</sub> |
+| <img src="examples/xray_luggage.jpg" width="100%"> | <img src="examples/rubberhose_morning.jpg" width="100%"> |
+| **雪夜归途** · *Homeward, First Snow*<br><sub>Linocut · 黑白麻胶版画</sub> | **吹蜡烛** · *Blow Out the Candles*<br><sub>VHS home video · VHS 家庭录像</sub> |
+| <img src="examples/linocut_snowy_village.jpg" width="100%"> | <img src="examples/vhs_birthday.jpg" width="100%"> |
+| **山间夜营** · *Night Camp*<br><sub>Flat vector · 扁平矢量</sub> | **小橡果的秋天** · *An Acorn's Autumn*<br><sub>Storybook animation · 绘本角色动画</sub> |
+| <img src="examples/flatvector_night_camp.jpg" width="100%"> | <img src="examples/storybook_acorn.jpg" width="100%"> |
+| **蛇梯棋大冒险** · *Snakes & Ladders, Round 7*<br><sub>Ballpoint doodle · 圆珠笔涂鸦</sub> | **海港步行图** · *Larkhaven on Foot*<br><sub>Overlay sheets · 描图纸叠层</sub> |
+| <img src="examples/ballpoint_board_game.jpg" width="100%"> | <img src="examples/overlay_city_map.jpg" width="100%"> |
+| **出发前,再查一遍行李** · *Pack Check*<br><sub>Pastel UI · 粉彩界面</sub> | **数学单元测验** · *Unit Test, Graded*<br><sub>Exam grading · 阅卷批改</sub> |
+| <img src="examples/pastelui_packing.jpg" width="100%"> | <img src="examples/grading_math_quiz.jpg" width="100%"> |
+| **蹴鞠** · *Cuju by Lamplight*<br><sub>Shadow puppetry · 皮影戏</sub> | **街角速写** · *Sketchbook Neighbours*<br><sub>Pen & wash · 钢笔淡彩</sub> |
+| <img src="examples/shadowpuppet_cuju.jpg" width="100%"> | <img src="examples/penwash_neighbours.jpg" width="100%"> |
+| **雨天三人像** · *Rainy-Day Portraits*<br><sub>Retro gouache · 复古水粉</sub> | **借伞** · *The Shared Umbrella*<br><sub>Blue picture book · 蓝调绘本</sub> |
+| <img src="examples/gouache_rainy_day.jpg" width="100%"> | <img src="examples/bluebook_shared_umbrella.jpg" width="100%"> |
+
+Every mark above is computed: paper fibres, ink washes and mist, dry-brush strokes, pigment granulation and blooms, torn-paper edges, pencil wax on paper tooth, cel-shaded clouds, risograph grain and halftones, lit impasto relief, woodblock grain and bokashi, dithered pixels, plasticine lit like a film set, sunlight through leaves on Prussian blue, twisted thread on Aida cloth, machined knobs behind a backlit dial, die-cut vinyl with a laminate gloss, streaky thermal print, graphite catching the tooth of graph paper, highlighter pooling at the start of a swipe, chalk dust settling under half-erased lessons, rain-lit neon glass mirrored in a wet street, a blue-pencil rough under boiling brush ink, an island ray-traced under one soft sun, a single unbroken gold line, candy balls with softbox glints, one outline morphing through six shapes, halftone photos cut out with scissors, frosted glass blurring the real pixels behind it, screen-printed primaries out of register, a slit sun sinking behind a neon grid played off tape, hollow fuse beads on a pegboard melting together under an iron, pits knocked through desert varnish, a red grid showing through flaking plaster, stones laid row by row along an outline, daylight through leaded glass, burnished gold that mirrors the room, left-handed hatching in iron-gall ink, black paper cut with scissors, wood type printed a hair out of register, red and black plates slipping apart, airbrush fades inside knife-cut friskets, Ben-Day dots on yellowed newsprint, one photo key pulled across hand-painted colour, characters struck through a fading ribbon, flat-shaded triangles dithered to 15 bits, spray drifting past cut card, satin stitches catching the light by their angle, ink lines printed white on Prussian blue, wax scribbles skipping the paper's pits, phosphor glowing behind curved glass, heat leaking out of a kitchen, cobalt fired into tin glaze tile by tile, ochre blown onto rock lit by a fire, 1-bit patterns in an old paint program, slip silhouettes incised to the clay, graphite that never quite reaches black, X-rays adding up through a suitcase, grey cels shot on scratched film, gouge marks in a rolled-up block, a birthday smeared onto tape, seven flat colours lifting off each other, an acorn squashing and stretching through a world drawn as it goes, ballpoint ink blobbing at every corner of a hand-drawn game, inks multiplying through tracing paper on a light box, window cards floating on a pastel field over shadows tinted by it, a vermilion stamp running dry at one end, red ink pooling where the pen slowed down, dyed donkey hide glowing on a lamp-lit screen, gouache scumbled dry over a toned board, knit stitch by stitch, and dry pastel blue under a scratchy brush line, with chalk rain on top. 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.
---
@@ -132,7 +134,7 @@ Every mark above is computed: paper fibres, ink washes and mist, dry-brush strok
### What it is
-A [Claude Code](https://claude.com/claude-code) skill and a small painting library with sixty-five styles:
+A [Claude Code](https://claude.com/claude-code) skill and a small painting library with sixty-six styles:
| Style | Module | What makes it read as the real medium |
|---|---|---|
@@ -201,6 +203,7 @@ A [Claude Code](https://claude.com/claude-code) skill and a small painting libra
| **Shadow puppetry (皮影戏)** | `lib/shadowpuppet.py` · `ShadowPuppet` | a shadow play seen from the audience, where everything on the screen is lamp light that came through it: a cloth screen lit by an oil lamp behind the middle (pale gold at the hot spot, deep amber toward the rim, thread slubs, a fold or two); puppets of scraped donkey hide kept as coverage plus an optical density per channel, so vermilion, teal, ochre and green glow, black dye is almost opaque and pieces darken where they overlap, in any order; pieces are cut, dyed in fields, inked along every cut edge and punched with the craft's hollow patterns (dots, rings, plum blossoms, coins, fish scales, ruyi cloud heads, lattice, ice cracks, stripes), and the hide's uneven thickness leaves no dye flat; a figure is a tree of jointed pieces with thread knots and an angle per joint (a hollow-carved or solid face in profile with one long eye and a long brow, a helmet with barred pheasant plumes or a crown with pompoms, cloud collar, breastplate mirror, scale armour, cuffs, thick-soled boots), with control rods tied to the collar and the hands; a puppet off the cloth grows, blurs and splits into two shadows (the lamp has two wicks), the soft double edge of a figure not quite pressed, and rods are sharp where they are tied and soft lower down; props come from the same leather (a pailou goal with a lattice net and a round eye, a stitched ball, a key-fret floor band, hanging name plaques); in front, a carved proscenium (key-fret lintel, a red lacquer plaque with raised gilt characters, an openwork valance and corner brackets the screen glows through) lit only by the light the screen spills onto its edges, and red paper lanterns lit from inside, with tassels and a warm halo |
| **Pen & wash (钢笔淡彩)** | `lib/penwash.py` · `PenWash` | small cold-press sketch cards made the way a sketcher makes them — a fineliner line first, loose watercolour after, then the cards photographed on a table. Each card is its own sheet (paper tooth lit by the window, a cut edge that is not quite straight), drawn unturned and laid down at a slight angle. The ink line is near-uniform but hand-made: low-frequency wobble and tremor, width drifting a few per cent, a dot where the tip rested, a flick at some ends; closed shapes are one to three strokes that stop short or run past the join on the tangent, box corners overshoot, a stretch is sometimes gone over twice; parts have a depth, so an outline stops where a part in front covers it. Washes start from the intended region and are then painted loosely: slipped 2–5 px off the line (spilling over on one side, leaving white paper inside the line on the other), an edge re-found on a wandering threshold that follows the tooth, a darker dried rim, granulation in the valleys of the paper, faint flat-brush streaks, density mottle, wet-in-wet drops for cheeks and crust, cockling where the paper got wet — and a gentler slip for small shapes, so a nose never turns into a white ring. A flat background block that does not fill the card is painted around the figure with a white halo; opaque white gouache glints go on last. Ink and pigments are optical densities, so overlaps darken and mix. Helpers for goofy characters: big round glasses, dot eyes, tufts, simple hands, limbs, inked frames, ground lines. The photo: oak planks with cathedral grain and butt joints, soft card shadows and lit cut edges, a fineliner and a water brush shaded as cylinders (the clear barrel refracts what is under it), window fall-off, vignette and grain |
| **Retro gouache (复古水粉)** | `lib/gouache.py` · `GouachePortrait` | picture-book character portraits in opaque gouache, painted the way a gouache painter works, dark to light and big to small: a warm imprimatura scrubbed onto the board, an umber underdrawing, a background laid solid and then scumbled with a nearly dry brush in lighter and darker mixes, flat masses, forms modelled in a few value steps, textures, features and dry-brush highlights, then the grain of the printed page. Every coat is opaque (it replaces what is under it), and a wet brush picks up a little of the layer below. One stroke is a flat brush dragged along a short arc: the hairs carry different loads, so streaks run along it; the paint runs out as it goes, so the tail breaks into specks where only the tooth of the board catches it; the sides are ragged and the head is rounded. Edges are crisp but wander and break on the tooth. Forms are inflated into a dome (an exact ellipsoid for noses, bobbles and pearls), lit from the upper left, quantised into soft steps and mapped onto five mixed colours, then brushed over with short strokes that follow the form, so the steps meet in brushy seams; core shadows under a brim, a nose or a beard are thin multiply glazes, and cheeks are powdery blush. Knit is modelled stitch by stitch (V-shaped legs with twisted plies, cables twisting in a column, ribbing with sunken purl columns) and multiplied onto the paint, so the large value steps survive. Hair, brows, beards, curls and bobbles are thousands of tapered strands that follow a flow field and are sorted by the light. Felt is mottle, fibres and a fuzzy silhouette. Helpers for goofy faces: round eyes with lids and catchlights (a `look` that can go cross-eyed), big bulbous noses with nostrils and a glint, big ears |
+| **Blue picture book (蓝调绘本)** | `lib/bluebook.py` · `BlueBook` | a page of a soft-blue modern picture book, drawn the way the illustrator works and then printed: colour blocks, a loose ink line, dark masses scribbled in, small accents, chalk whites, weather, print. The palette is held to three blues (powder, cornflower, a deep teal-blue), black ink and paper white, with only a little coral, flesh pink and mustard. Every tool works on one paper tooth, equalised so that "the tool reaches where the tooth is higher than 1 − contact" turns a pressure straight into a coverage fraction, and pre-dragged in eight directions so the bare specks a dry tool skips are drawn out along its stroke. An ink stroke is a brush or ink-pencil line: the path wobbles and trembles, the pressure lands fast, lifts slowly and swells and thins on the way, the hairs carry different loads and run dry along the stroke so the line breaks into dry white streaks, and its edge wanders with the tooth; every pixel knows its arc length and its offset across the mark (Pillow rasterises segment ids, numpy projects exactly). Closed shapes are not closed: a contour is one to three strokes that stop short or run past the join, now and then gone over again a couple of px off. Dark masses are zigzag scribbles that turn past the outline, one wrist-sized patch at a time. Colour is dry crayon, pastel or dry gouache laid loosely after the idea of the shape: the region slips a few px, its edge wanders, its border dries out, it goes on in stroke lanes with a mottled density, and white specks of paper show through; wax is semi-opaque (over white it is the colour, over ink it stays dark, blue over blue goes deeper) and the line always stays on top. The background is a rough-sided block that stops short of the page edge, its border brushed along itself and dragged dry. White chalk sits only on the tooth peaks over the blue; rain is short dry strokes with splashes, ripples, flicked spatter and fine speckle. Character helpers: big round heads drawn open, dot eyes with a white glint, tiny smiles, stippled blush and freckles, and fluffy white animals whose outline is a run of scalloped ink tufts with chalk fur crossing into the blue. The print step adds a slight softness, lifted blacks, paper speck, a centre gutter fold and tiny page numbers |
Ask Claude to *"draw it yourself"*, *"paint this with code"*, or *"claude绘图"*, and name a style if you like. Claude then:
@@ -325,6 +328,12 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages
- concentric curls become cinnamon rolls (make each curl a ring round a dark hollow);
- two rounded collar flaps become cushions.
Finish with dry-brush highlights on the lit side; on domes, drag them down the slope. For the GIF, force a few true dark neutrals into the palette, or the pupils turn navy.
+- **Blue picture book**: keep the palette honest — three blues, black ink, paper white and only a touch of coral, pink and mustard; a fourth hue makes it a different book. Coverage comes from pressure alone (about 0.95 leaves only fine specks of paper); let mottle and stroke lanes change the density of the pigment, not the coverage, or the blue field turns into scratched chalk. Reserve the white things (the bear, faces, the umbrella, the hair) when you lay the background block and colour those accents on white paper: wax over blue goes muddy, so a small accent on a dark ground needs opaque gouache. Draw the ink after the colour blocks and let colour laid later slide off it (`over_ink`), so the line stays on top. Dark masses should be clumps, not a band: threshold "darker toward the bottom + low-frequency noise", and keep blades and scribbles off the characters with `clip`. Watch for accidental reads:
+ - an arm raised across the face hides the face (route both arms on the far side of the head);
+ - a snail on a dark bench is a mustard disc (put it in front of something pale);
+ - flat, round, mid-blue trees are balloons;
+ - rain of one length and one colour is digital rain (use three values and a wide range of lengths).
+ Leave the print step (gutter, page numbers, lifted blacks) for last, and lift only the blacks, or the white paper goes grey.
### Roadmap
@@ -336,7 +345,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,加上一个小巧的绘图库,内置六十六种画风:
| 画风 | 模块 | 为什么看起来像真的 |
|---|---|---|
@@ -405,6 +414,7 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages
| **皮影戏** | `lib/shadowpuppet.py` · `ShadowPuppet` | 观众这边看到的一场皮影,幕布上的一切都是透过来的灯光。幕布由一盏油灯从背后照亮:灯后面淡金,往外深琥珀,带纱线粗节和一两道折痕。人偶是刮薄的驴皮,按覆盖率加每个通道的光密度来算,所以朱红、青绿、赭黄、绿色透亮,黑色几乎不透,两块皮相叠处更深,和先后顺序无关;每块皮可以剪、分区染色、沿剪边描黑,打出皮影的各种镂空纹样(圆点、圆环、梅花、铜钱、鱼鳞、如意云头、方格、冰裂、条孔),皮厚不匀让染色不会死平。关节人偶是一棵带线结、每个关节一个角度的皮件树(阳刻空脸或阴刻脸的侧面像,一只长眼一道长眉;带黑横斑的雉翎盔或绒球三叉冠;云肩、护心镜、鱼鳞甲、袖口、厚底靴),操纵杆绑在领口和手上。离开幕布的人偶会变大、变虚,又因为灯有两个灯芯分成两个影,就是没贴紧时那种软的双边;操纵杆绑的地方清楚,往下越来越虚。同一套皮还做道具:牌楼式球门(窗棂网和风流眼)、缝线的鞠、回纹底带、挂在线上的小牌。幕前是雕花戏台(回纹横楣、红漆凸起金字牌匾、透空挂落和花牙子,幕布的光从镂空处透出来),只被幕布溢出的光照亮边缘;还有内有烛光的红纸灯笼,带穗子和一圈暖光 |
| **钢笔淡彩** | `lib/penwash.py` · `PenWash` | 照速写人的顺序画在冷压水彩小卡上:先针管笔线稿,再松散淡彩,最后把卡片放在桌上拍下来。每张卡是独立的一张纸(窗光照出的纸纹、略不直的切边),不转着画,放下时才带一个小角度。墨线几乎等宽但是手画的:低频手抖加颤动、线宽漂几个百分点、落笔一个小墨点、有的收尾一甩;闭合形状由一到三笔组成,接口停早留缺口或冲过头沿切线出头,方框的角相互出头,偶尔一段描两遍;部件分前后,被前面部件盖住的轮廓线自动断开。淡彩先算「本来要涂的区域」,再像手快那样涂:整块错位 2–5 px(一边出线、另一边在线里留白缝),边缘用游走的阈值重新取、顺着纸纹,干边更深,颗粒沉在纸纹的谷里,淡淡的平刷条纹,浓淡斑驳,腮红和面包烤色湿中湿滴进去,打湿处纸面起皱;小形状错位缩小,鼻子不会变成白圈。不铺满卡片的背景色块绕开人物、留一圈白边;白色水粉高光最后上。墨和颜料都按光密度叠加,相叠变深、混色。带画呆萌小人的部件:大圆眼镜、点点眼、翘头发、简单的手、四肢、手绘边框、地线。照片:带「山纹」年轮和拼接缝的橡木桌、卡片的软阴影和受光的切边、按圆柱打光的针管笔和水笔(透明水杆折射下面的东西)、窗光衰减、暗角和颗粒 |
| **复古水粉** | `lib/gouache.py` · `GouachePortrait` | 用不透明水粉画复古绘本里的大头像,照水粉画家的顺序从暗到亮、从大到小:画板上先刷一层暖色托底,用赭色起稿;背景先满载铺平,再用半干的笔蘸亮一点、暗一点的同色皴擦;然后平涂大块,用几阶色值塑形,再上质感、五官和干笔高光,最后是印刷书页的颗粒。每一层都不透明(盖住下面),湿笔会带起一点底色。一笔是扁笔沿短弧拖过去:鬃毛含色不同,所以顺着笔有条纹;颜料越拖越少,笔尾只在纸纹凸起上留下断续的丝和点;两侧毛边,落笔处圆头。边缘利落,但会游走、在纸纹上断开。形体先鼓成穹顶(鼻子、绒球、珍珠用精确的椭球),左上方一盏灯,受光分成几个软台阶、映射到五个调出来的颜色,再用顺着形体的短笔一笔笔盖上去,台阶之间是带笔触的接缝;帽檐、鼻子、胡子下面的暗部是一层薄薄的正片叠底,腮红是粉状的。毛衣一针一针地算:V 字两条带捻股的纱线、交替在前的麻花、凹下去的反针罗纹,乘到已有的颜料上,大的明暗不丢。头发、眉毛、胡子、卷发、绒球是成千上万根锥形细线,沿流向场走、按受光分档。毛毡是斑驳、短纤维和毛茸茸的轮廓。呆萌五官:带眼皮和高光的圆眼(`look` 可以对成斗鸡眼)、带鼻孔和亮点的大鼻子、大耳朵 |
+| **蓝调绘本** | `lib/bluebook.py` · `BlueBook` | 一页软蓝色调的现代绘本,照绘本画家的顺序画、再印出来:先上色块,再松松地勾墨线,乱线排出暗部,加一点点睛色,压白粉笔,然后是天气,最后印刷。颜色守在三阶蓝(粉蓝、矢车菊蓝、深青蓝)、黑墨和纸白,只点一点珊瑚红、粉色腮红和芥末黄。所有工具都落在同一张纸纹上:纸纹做过直方图均衡,「工具碰到纸纹高于 1 − 接触压力的地方」就直接等于覆盖率;纸纹还预先沿八个方向拖开,干的工具漏掉的白点会顺着笔拉成短道。一笔墨线是毛笔或墨铅笔:路径带手抖和细颤,落笔快、收笔慢,沿途粗细起伏;几根笔毛含墨不同、越画越干,线会断成顺着笔的干白道,边缘随纸纹游走;每个像素都知道自己在这一笔上的弧长和横向偏移(Pillow 画线段序号,numpy 精确投影)。闭合的形状不闭合:一个轮廓分一到三笔,在接头前停下或冲过接头,偶尔再描一遍、偏开一两 px。暗部是转折冲出轮廓的之字乱线,一次一个手腕的范围。颜色是干蜡笔、粉彩或干水粉,按大概的形状松松地涂:整体错开几 px,边缘游走,靠边处变干,一道道笔道、浓淡斑驳,纸纹白点透出来;蜡是半透明的(白纸上是本色,墨上仍是黑,蓝上加蓝更深),墨线永远在颜色上面。背景是一块毛边、不到纸边的色块,边缘顺着边刷、拖干。白粉笔只挂在纸纹凸起上,压在蓝上;雨是短的干笔,加水花、水纹、甩点和细尘。角色部件:开口的大圆脑袋、带白高光的点点眼、小小的笑、点彩腮红和雀斑,白色毛绒动物的轮廓是一串扇贝形的墨线小弧,白毛越过边缘压在蓝上。印刷一步加轻微柔化、抬黑、细纸点、中缝折痕和小页码 |
对 Claude 说「claude绘图」「你自己画」「用代码画」,也可以指定画风。它会:
1. **先定构图**:层次、焦点、留白,而且画面要图解内容本身;
@@ -499,6 +509,7 @@ python3 examples/grading_math_quiz.py out.jpg --stages stages/ # 阅卷批
python3 examples/shadowpuppet_cuju.py out.jpg --stages stages/ # 皮影戏:蹴鞠
python3 examples/penwash_neighbours.py out.jpg --stages stages/ # 钢笔淡彩:街角速写
python3 examples/gouache_rainy_day.py out.jpg --stages stages/ # 复古水粉:雨天三人像
+python3 examples/bluebook_shared_umbrella.py out.jpg --stages stages/ # 蓝调绘本:借伞
```
### 作画要点(Claude 交图前逐条自查)
@@ -572,6 +583,12 @@ python3 examples/gouache_rainy_day.py out.jpg --stages stages/ # 复古水
- 同心的卷发像肉桂卷(让每个卷是绕着暗色空洞的环);
- 两片鼓鼓的衣领像靠垫。
最后在受光面拖干笔高光,穹顶要顺坡拖。做动图时强制放几个深中性色,否则瞳孔会被量化成藏青。
+- **蓝调绘本**:颜色要守住:三阶蓝、黑墨、纸白,珊瑚红、粉色、芥末黄只点一点;多一种颜色就是另一本书了。覆盖率只由压力决定(0.95 左右只留细白点),斑驳和笔道只改颜料浓淡、不改覆盖,否则整片蓝像刮花的粉笔。铺背景色块时先把白的东西留出来(熊、脸、伞、头发),这些点缀色涂在白纸上:蜡笔盖在蓝上会发闷,深底上的小点缀要用不透明的水粉。墨线在色块之后画,之后再上的颜色在墨上挂不住(`over_ink`),线才一直在上面。暗部要一团一团,不要一条带:按「越往下越暗 + 低频噪声」取阈值,草叶和乱线用 `clip` 避开角色。小心看错:
+ - 举起的胳膊从脸前横过去,脸就没了(两只胳膊都走头的另一侧);
+ - 深色长椅上的蜗牛只是一个芥末黄圆盘(让它落在浅色的东西前面);
+ - 平涂的圆形中蓝远树像气球;
+ - 一样长、一样颜色的雨是数码雨(用三种深浅,长短拉开)。
+ 印刷(中缝、页码、抬黑)放到最后,而且只抬黑,否则白纸会变灰。
### 计划
diff --git a/SKILL.md b/SKILL.md
index 46895f9..0f36b40 100644
--- a/SKILL.md
+++ b/SKILL.md
@@ -1,6 +1,6 @@
---
name: claude绘图
-description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型,由 Claude 用代码一笔一笔「画」出图片(程序化绘画)。内置六十五种画风:中国水墨、水彩、剪纸拼贴、韩国彩铅、日本动漫、编辑风手绘(Riso)、油画厚涂(梵高式流向笔触+颜料浮雕打光)、浮世绘木版画(晕色、木纹、墨线主版、青海波)、像素风(低分辨率+Bayer 抖动+像素字体)、黏土定格(高度图捏出的彩泥+影棚打光)、蓝晒(普鲁士蓝日光晒图,植物剪影透光)、十字绣(Aida 布十字绣+回针绣+缎面绣+法式结)、复古仪器面板(60 年代收音机/仪器正面:柚木、拉丝铝、旋钮、刻度窗、指示灯)、贴纸拼贴·小票(模切乙烯贴纸、热敏小票、和纸胶带、吊牌、橡皮章)、实验笔记本·贴纸(线圈方格本、铅笔图表、荧光笔、红笔圈、便利贴)、黑板板书(墨绿石板、粉笔颗粒、板擦残影、示意图与公式)、赛博朋克(雨夜霓虹街道、玻璃管霓虹招牌、全息广告、湿路面倒影)、卡通手绘(蓝铅笔稿、毛笔线、错位平涂、赛璐璐阴影、逐帧抖线)、等轴 2.5D(正等轴微缩模型、一个太阳照出三面明暗、悬浮数据卡)、单线画(一根不断开的线一笔画完、唯一点睛色)、柔光 3D(光线追踪的糖果色小球海和鼓鼓的软字、景深)、形变动画(一条轮廓依次变形、洋葱皮残影、缓动曲线)、报刊拼贴(牛皮纸、手撕旧报纸、网点老照片、勒索信拼贴字)、弥散玻璃(弥散渐变、磨砂玻璃卡片界面)、包豪斯几何(三原色几何、丝网印刷海报)、复古 Synthwave(切口落日、霓虹网格、镀铬字、录像带质感)、拼豆(钉板上的熔珠小管、熨烫熔合)、岩画(沙漠漆上凿出的凹坑图形、新旧凿痕、剥落)、古埃及墓室壁画(灰泥墙、红格起稿、分栏叙事、象形文字、剥落)、罗马马赛克(石子与玻璃沿轮廓一排排铺、灰缝、燕尾铭牌)、彩色玻璃花窗(哥特尖拱窗、通体着色玻璃、grisaille 彩绘与银染、铅条、透光)、泥金手抄本(羊皮纸、鹅毛笔哥特体、朱红标题、打磨金箔首字母)、达·芬奇手稿(铁胆墨水、左手排线、红粉笔、镜像手写、机械分解图)、剪影(黑纸剪出的侧影小像、薄金粉、椭圆金框)、凸版印刷海报(木活字、红黑双色错版、木刻插图)、苏联构成主义(红黑两版、斜条与楔形、西里尔大字、网点照片拼贴)、装饰艺术 Art Deco(1930 年代喷枪流线型海报、交替射线、阶梯高楼、金色 Deco 字)、黄金时代漫画(毛笔墨线、Ben-Day 网点、四色错版、新闻纸)、波普丝网(多格撞色平涂 + 错位的照相黑版)、ASCII 字符画(行式打印机、绿条连续纸、叠打)、低多边形(1999 年代 3D:平面着色、仿射贴图、逐顶点雾、15 位色抖动)、喷漆模板涂鸦(混凝土墙上多层卡纸模板喷绘、雾化与滴痕)、刺绣徽章(牛仔布上的机绣徽章:填充绣、缎面绣、锁边)、蓝图工程图(描图墨线晒成蓝底白线)、儿童蜡笔画(小孩在糙纸上的蜡笔涂抹)、绿屏终端 CRT(荧光字符画、扫描线、余辉)、热成像(先画温度场再上伪彩色)、代尔夫特蓝瓷砖(锡釉砖上的钴蓝手绘)、洞穴壁画(火光下的赭石、吹喷手印)、1-bit 早期画图软件(黑白整屏、8×8 图案填充)、古希腊黑绘陶瓶(黑釉剪影、刻线、饰带展开图)、铅笔素描(石墨排线、擦笔、边缘只剩线稿)、X 光片(安检透视、轮廓发亮、伪彩)、1930 年代黑白橡皮管动画(白手套、饼切眼、老胶片)、黑白麻胶版画(刻刀减法、手拓发花、套色错版)、VHS 家庭录像(钨丝灯偏色、色度渗色、REC)、扁平矢量(分层几何色块、七色、层间投影)、绘本角色动画(小角色挤压拉伸的真动画)、圆珠笔涂鸦(蓝红圆珠笔线稿、墨团、彩铅、页边涂鸦)、描图纸叠层(灯箱上的黑线底图 + 一张张单色描图纸叠片:正片叠底、套准十字、定位钉、绘图胶带)、粉彩界面 · Pastel UI(产品发布片式的界面画面:纯色粉彩底与大光斑、macOS 窗口卡片、胶囊与粗黑标题色条、状态标签与 ✓ / ✗ 徽章、放大镜、从卡片边探头的扁平小图标)、阅卷批改 · Exam Grading(绿毛毡桌上被红笔批改的答题卡:定位黑块、考号涂卡、得分格与阅卷栏、长尾夹夹住的标准答案卡、油墨不均的朱红印章、立体红笔、波浪线 / 圈 / 引线 / 批注 / 叉 / 圈起来的分数)、皮影戏 · Shadow Puppetry(油灯照亮的幕布上,雕空、透明染色的驴皮关节人偶:镂空纹样、阳刻空脸、雉翎盔头、线结与操纵杆、离幕时虚化的双影;雕花戏台、红漆金字牌匾、红灯笼)、钢笔淡彩 · Pen & Wash(速写小卡上的针管笔线稿 + 松散淡彩:线条抖、出头、不闭合,颜色错位出线、留白缝、干边与颗粒,不铺满的背景色块;大头、圆眼镜、点点眼、红鼻子的呆萌小人;卡片拍在木桌上,旁边放着针管笔和水笔)、复古水粉 · Retro Gouache(复古绘本风的水粉大头像:不透明水粉从暗到亮一层层盖上去,单色背景用干笔皴擦;大红鼻子、腮红、圆眼和大耳朵用几阶色值塑出来;看得见针脚的毛衣和毛线帽,一根根的头发和胡子,毛毡;最后是印刷书页的纸纹)。用户说「claude绘图」「用代码画」「你自己画」「不用生图模型画」「程序化绘画」,或点名以上任一画风(含黏土、彩泥、定格动画、蓝晒、晒图、十字绣、刺绣、复古面板、老式收音机、贴纸、小票、收据、手帐拼贴、实验笔记本、方格本、荧光笔、便利贴、黑板、板书、粉笔、赛博朋克、霓虹、雨夜街道、卡通、手绘卡通、逐帧手绘、抖线、等轴、2.5D、微缩模型、单线画、一笔画、线条动画、柔光 3D、3D 渲染、C4D 风、软糖字、小球海、形变、变形动画、报刊拼贴、剪报、达达、勒索信字、网点印刷、弥散渐变、玻璃拟态、毛玻璃、包豪斯、几何构成、丝网印刷、Synthwave、蒸汽波、合成器浪潮、80 年代复古、拼豆、拼拼豆、熔珠、熨豆、豆豆画、钉板、烫豆、岩画、岩刻、凿刻、石刻、沙漠漆、史前壁刻、大角羊、古埃及、埃及壁画、墓室壁画、法老时代、象形文字、尼罗河、底比斯、罗马马赛克、马赛克镶嵌、镶嵌画、石子拼画、地砖画、古罗马地板、彩色玻璃、彩绘玻璃、花窗、玻璃花窗、教堂花窗、哥特花窗、铅条玻璃、泥金手抄本、手抄本、彩饰手抄本、中世纪手稿、羊皮纸、哥特体、花体首字母、泥金、贴金、星盘、达芬奇、达·芬奇、达芬奇手稿、手稿风、文艺复兴手稿、发明手稿、镜像字、镜像书写、扑翼机、红粉笔、钢笔排线、机械草图、分解图、剪影、剪影肖像、侧影、侧面像、黑纸剪影、剪影小像、椭圆金框、乔治时代肖像、摄政时期肖像、凸版印刷、活版印刷、木活字、铅字海报、马戏团海报、复古海报、老海报、19 世纪海报、双色套印、错版、套色错位、木刻插图、构成主义、苏联海报、苏联构成主义、俄国先锋派、罗德琴科风、红黑海报、照片蒙太奇、照片拼贴海报、西里尔字、装饰艺术、装饰风、流线型、流线型海报、1930 年代海报、旅行海报、铁路海报、火车海报、喷枪画、喷笔画、阶梯高楼、射线背景、盖茨比风、黄金时代漫画、老漫画、复古漫画、美漫封面、漫画封面、Ben-Day 网点、本戴点、网点上色、四色印刷、四色错版、新闻纸、对白框、拟声字、1940 年代漫画、波普、波普艺术、波普丝网、沃霍尔风、丝网版画头像、撞色头像、多格重复头像、六宫格撞色头像、ASCII、字符画、字符艺术、文字画、行式打印机、绿条纸、连续打印纸、针孔打印纸、老电脑打印、叠打、低多边形、低面数、低模、多边形风、千禧年 3D、90 年代 3D、复古 3D 游戏、老游戏截图、PS1 风、N64 风、平面着色、线框、游戏 HUD、飞行游戏、穿环、喷漆、模板涂鸦、镂空模板、喷漆模板、模板喷绘、街头涂鸦、街头艺术、墙绘、滴漆、班克西风格、刺绣徽章、徽章、布章、臂章、刺绣贴、绣标、锁边、牛仔外套徽章、户外徽章、营地徽章、弧形条章、蓝图、工程图、施工图、蜡笔画、儿童画、绿屏终端、CRT、显像管、热成像、热像仪、温度图、代尔夫特、荷兰蓝瓷砖、洞穴壁画、史前壁画、赭石、1-bit、黑白画图软件、MacPaint 风、黑绘、古希腊陶瓶、希腊瓶画、铅笔素描、素描、铅笔画、X 光、X 光片、安检图像、橡皮管动画、黑白卡通、老动画、麻胶版画、黑白版画、藏书票、VHS、家庭录像、录像带、扁平插画、扁平风、矢量插画、绘本动画、角色动画、挤压拉伸、圆珠笔、圆珠笔涂鸦、原子笔、页边涂鸦、课本涂鸦、手画棋盘、描图纸、硫酸纸、叠片、叠层、分色片、灯箱、拷贝台、透光台、套准、定位钉、粉彩界面、粉彩 UI、Dot 风、Dot 那种风格、产品发布会界面、发布会质感、窗口卡片、macOS 窗口、界面卡片、讲解片界面页、小图标探头、阅卷、阅卷批改、批改、判卷、改卷、改作业、答题卡、试卷、考卷、测验卷、红笔批改、红笔打分、打分数、盖章批改、朱红印章、标准答案卡、长尾夹、讲解片评测 / 打分页、皮影、皮影戏、影子戏、驴皮影、灯影戏、皮影人偶、雕花戏台、戏台牌匾、亮相、钢笔淡彩、淡彩、淡彩速写、钢笔淡彩小人、针管笔、勾线笔、针管笔加水彩、线稿上色、速写卡片、速写本小人、水彩小卡、城市速写、街头速写、水笔、自来水笔、复古水粉、水粉、水粉画、不透明水粉、哑光丙烯、复古绘本、绘本插画、绘本大头像、童书插画、复古童书、大头像、大鼻子人物、针织毛衣、麻花毛衣、毛线帽、毛毡帽、卷发、胡子),或 "draw it yourself", "paint with code", "procedural painting", "watercolor / collage / colored pencil / anime / editorial / impasto oil / ukiyo-e / pixel art / clay / claymation / cyanotype / sun print / cross-stitch / embroidery / retro instrument panel / vintage radio / sticker collage / receipt / lab notebook / graph paper / chalkboard / blackboard / cyberpunk / neon city / cartoon / hand-drawn animation / isometric / 2.5D / continuous line / one-line drawing / soft 3D / 3D render / puffy letters / ball pit / shape morph / morphing / newspaper collage / Dada / ransom note / halftone / glassmorphism / aurora gradient / Bauhaus / geometric poster / screen print / synthwave / retrowave / outrun / perler beads / hama beads / artkal / fuse beads / melty beads / pegboard beads / petroglyph / rock art / rock carving / desert varnish / Egyptian tomb painting / ancient Egypt / hieroglyphs / Theban tomb / Roman mosaic / floor mosaic / tesserae / opus vermiculatum / Pompeii mosaic / stained glass / leaded glass / church window / Gothic window / grisaille / illuminated manuscript / medieval manuscript / book of hours / gold leaf / illuminated initial / blackletter / vellum / astrolabe / da Vinci notebook / Leonardo codex / Renaissance sketchbook / mirror writing / iron-gall ink / red chalk / sanguine / ornithopter / exploded view / inventor's sketch / silhouette / silhouette portrait / cut-paper profile / shade portrait / Georgian portrait / Regency portrait / oval gilt frame / letterpress / wood type / playbill / circus poster / Victorian poster / two-colour misregistration / woodcut poster / constructivism / constructivist poster / Soviet avant-garde / Russian avant-garde / Rodchenko style / photomontage poster / art deco / streamline moderne / 1930s travel poster / railway poster / airbrush poster / sunburst rays / Gatsby style / golden age comic / vintage comic book / comic cover / Ben-Day dots / four-color printing / newsprint / speech balloon / pulp cover / pop art / Warhol-style / pop silkscreen / silkscreen portrait / repeated pop portrait grid / ASCII art / text art / typewriter art / line printer / greenbar / fanfold paper / tractor feed / overstrike / printer plot / low poly / low-poly / retro 3D / 90s 3D game / PS1 style / N64 style / software rasterizer / flat shading / affine texture mapping / vertex fog / game HUD / stencil / stencil graffiti / spray paint stencil / street art / drips and overspray / Banksy-style stencil / embroidered patch / embroidery patch / iron-on patch / sew-on patch / merit badge / camp badge / merrow border / rocker patch / denim jacket patches / blueprint / technical drawing / crayon / kid's drawing / CRT terminal / green screen / thermal camera / thermal imaging / Delft tiles / Delft blue / cave painting / ochre / Lascaux-style / 1-bit / MacPaint-style / black-figure / Greek vase / pencil drawing / graphite / X-ray / baggage scanner / rubber hose / 1930s cartoon / linocut / lino print / VHS / home video / flat vector / flat illustration / storybook animation / squash and stretch / ballpoint / biro / ballpoint doodle / margin doodles / hand-drawn board game / overlay sheets / tracing-paper overlays / light box / colour separations / registration marks / acetate overlay / pastel UI / Dot-style product film / launch-film interface / macOS window cards / exam grading / grading an answer sheet / red-pen marking / graded test paper / rubber-stamped answer sheet / shadow puppet / shadow puppetry / Chinese shadow play / leather shadow puppets / backlit puppet screen / pen and wash / pen & wash / line and wash / ink and watercolour / ink and watercolor / fineliner sketch / fineliner and watercolour / sketchbook characters / sketch cards / urban sketching / water brush / gouache / retro gouache / gouache portrait / gouache illustration / opaque gouache / matte acrylic / picture-book portrait / vintage picture book / retro children's book illustration / mid-century children's book / big-nosed character portrait / cable-knit sweater / knitted bobble hat without an image model" 时使用;也用于需要逐步画出(draw-on)动画的插画。单独说「剪纸」指剪纸拼贴、「刺绣」指十字绣、「丝网印刷 / screen print」指包豪斯几何;「打马赛克」是打码,不是马赛克画风;单说「蓝图」指蓝图工程图,「蓝晒 / 晒图」仍指蓝晒;「铅笔 / 素描」指铅笔素描,「彩铅」指韩国彩铅;「像素」仍指像素风,「1-bit / 黑白画图软件」指 1-bit 早期画图软件;「霓虹」仍指赛博朋克;「喷漆 / 街头涂鸦」仍指喷漆模板涂鸦,「圆珠笔 / 随手涂鸦 / 页边涂鸦」指圆珠笔涂鸦;「描图纸 / 硫酸纸 / 叠片 / 灯箱」指描图纸叠层(蓝图工程图那张描图布是晒成蓝图的,不是叠片);「Dot 风 / 粉彩界面 / 窗口卡片 / 发布会界面」指粉彩界面(纯色底 + 白色实心窗口卡片),要磨砂玻璃和弥散渐变仍用弥散玻璃;「阅卷 / 批改 / 答题卡 / 判卷 / 红笔打分」指阅卷批改,实验记录里的红笔圈和便利贴仍用实验笔记本,带「已付」橡皮章的小票拼贴仍用贴纸拼贴 · 小票;「皮影 / 皮影戏 / 影子戏」指皮影戏(透光的彩色驴皮人偶),黑纸剪出的侧影小像仍用剪影,彩纸剪贴仍用剪纸拼贴。「钢笔淡彩 / 淡彩速写 / 针管笔加水彩 / 线稿上色的速写小卡」指钢笔淡彩;单说「水彩」仍指水彩(风景、花卉的大片晕染),蓝铅笔稿 + 毛笔线 + 赛璐璐阴影的拟人小物仍用卡通手绘,「素描 / 铅笔」仍指铅笔素描。「水粉 / 复古水粉 / 绘本大头像 / 复古童书插画」指复古水粉(不透明水粉画的特写大头像);梵高式厚涂的风景、名画感仍用油画厚涂,扁平矢量、会挤压拉伸的小角色动画(「绘本动画」)仍用绘本角色动画,针管笔线稿加淡彩的速写小卡仍用钢笔淡彩,撞色多格的头像仍用波普丝网。
+description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型,由 Claude 用代码一笔一笔「画」出图片(程序化绘画)。内置六十六种画风:中国水墨、水彩、剪纸拼贴、韩国彩铅、日本动漫、编辑风手绘(Riso)、油画厚涂(梵高式流向笔触+颜料浮雕打光)、浮世绘木版画(晕色、木纹、墨线主版、青海波)、像素风(低分辨率+Bayer 抖动+像素字体)、黏土定格(高度图捏出的彩泥+影棚打光)、蓝晒(普鲁士蓝日光晒图,植物剪影透光)、十字绣(Aida 布十字绣+回针绣+缎面绣+法式结)、复古仪器面板(60 年代收音机/仪器正面:柚木、拉丝铝、旋钮、刻度窗、指示灯)、贴纸拼贴·小票(模切乙烯贴纸、热敏小票、和纸胶带、吊牌、橡皮章)、实验笔记本·贴纸(线圈方格本、铅笔图表、荧光笔、红笔圈、便利贴)、黑板板书(墨绿石板、粉笔颗粒、板擦残影、示意图与公式)、赛博朋克(雨夜霓虹街道、玻璃管霓虹招牌、全息广告、湿路面倒影)、卡通手绘(蓝铅笔稿、毛笔线、错位平涂、赛璐璐阴影、逐帧抖线)、等轴 2.5D(正等轴微缩模型、一个太阳照出三面明暗、悬浮数据卡)、单线画(一根不断开的线一笔画完、唯一点睛色)、柔光 3D(光线追踪的糖果色小球海和鼓鼓的软字、景深)、形变动画(一条轮廓依次变形、洋葱皮残影、缓动曲线)、报刊拼贴(牛皮纸、手撕旧报纸、网点老照片、勒索信拼贴字)、弥散玻璃(弥散渐变、磨砂玻璃卡片界面)、包豪斯几何(三原色几何、丝网印刷海报)、复古 Synthwave(切口落日、霓虹网格、镀铬字、录像带质感)、拼豆(钉板上的熔珠小管、熨烫熔合)、岩画(沙漠漆上凿出的凹坑图形、新旧凿痕、剥落)、古埃及墓室壁画(灰泥墙、红格起稿、分栏叙事、象形文字、剥落)、罗马马赛克(石子与玻璃沿轮廓一排排铺、灰缝、燕尾铭牌)、彩色玻璃花窗(哥特尖拱窗、通体着色玻璃、grisaille 彩绘与银染、铅条、透光)、泥金手抄本(羊皮纸、鹅毛笔哥特体、朱红标题、打磨金箔首字母)、达·芬奇手稿(铁胆墨水、左手排线、红粉笔、镜像手写、机械分解图)、剪影(黑纸剪出的侧影小像、薄金粉、椭圆金框)、凸版印刷海报(木活字、红黑双色错版、木刻插图)、苏联构成主义(红黑两版、斜条与楔形、西里尔大字、网点照片拼贴)、装饰艺术 Art Deco(1930 年代喷枪流线型海报、交替射线、阶梯高楼、金色 Deco 字)、黄金时代漫画(毛笔墨线、Ben-Day 网点、四色错版、新闻纸)、波普丝网(多格撞色平涂 + 错位的照相黑版)、ASCII 字符画(行式打印机、绿条连续纸、叠打)、低多边形(1999 年代 3D:平面着色、仿射贴图、逐顶点雾、15 位色抖动)、喷漆模板涂鸦(混凝土墙上多层卡纸模板喷绘、雾化与滴痕)、刺绣徽章(牛仔布上的机绣徽章:填充绣、缎面绣、锁边)、蓝图工程图(描图墨线晒成蓝底白线)、儿童蜡笔画(小孩在糙纸上的蜡笔涂抹)、绿屏终端 CRT(荧光字符画、扫描线、余辉)、热成像(先画温度场再上伪彩色)、代尔夫特蓝瓷砖(锡釉砖上的钴蓝手绘)、洞穴壁画(火光下的赭石、吹喷手印)、1-bit 早期画图软件(黑白整屏、8×8 图案填充)、古希腊黑绘陶瓶(黑釉剪影、刻线、饰带展开图)、铅笔素描(石墨排线、擦笔、边缘只剩线稿)、X 光片(安检透视、轮廓发亮、伪彩)、1930 年代黑白橡皮管动画(白手套、饼切眼、老胶片)、黑白麻胶版画(刻刀减法、手拓发花、套色错版)、VHS 家庭录像(钨丝灯偏色、色度渗色、REC)、扁平矢量(分层几何色块、七色、层间投影)、绘本角色动画(小角色挤压拉伸的真动画)、圆珠笔涂鸦(蓝红圆珠笔线稿、墨团、彩铅、页边涂鸦)、描图纸叠层(灯箱上的黑线底图 + 一张张单色描图纸叠片:正片叠底、套准十字、定位钉、绘图胶带)、粉彩界面 · Pastel UI(产品发布片式的界面画面:纯色粉彩底与大光斑、macOS 窗口卡片、胶囊与粗黑标题色条、状态标签与 ✓ / ✗ 徽章、放大镜、从卡片边探头的扁平小图标)、阅卷批改 · Exam Grading(绿毛毡桌上被红笔批改的答题卡:定位黑块、考号涂卡、得分格与阅卷栏、长尾夹夹住的标准答案卡、油墨不均的朱红印章、立体红笔、波浪线 / 圈 / 引线 / 批注 / 叉 / 圈起来的分数)、皮影戏 · Shadow Puppetry(油灯照亮的幕布上,雕空、透明染色的驴皮关节人偶:镂空纹样、阳刻空脸、雉翎盔头、线结与操纵杆、离幕时虚化的双影;雕花戏台、红漆金字牌匾、红灯笼)、钢笔淡彩 · Pen & Wash(速写小卡上的针管笔线稿 + 松散淡彩:线条抖、出头、不闭合,颜色错位出线、留白缝、干边与颗粒,不铺满的背景色块;大头、圆眼镜、点点眼、红鼻子的呆萌小人;卡片拍在木桌上,旁边放着针管笔和水笔)、复古水粉 · Retro Gouache(复古绘本风的水粉大头像:不透明水粉从暗到亮一层层盖上去,单色背景用干笔皴擦;大红鼻子、腮红、圆眼和大耳朵用几阶色值塑出来;看得见针脚的毛衣和毛线帽,一根根的头发和胡子,毛毡;最后是印刷书页的纸纹)、蓝调绘本 · Blue Picture Book(软蓝色调的现代绘本跨页:几乎只用粉蓝、矢车菊蓝、深青蓝三阶蓝加黑墨和纸白,只点一点珊瑚红、粉色腮红和芥末黄;毛笔 / 墨铅笔线干、抖、断,粗细不匀,线不闭合,暗部用快速来回的乱线排出来;颜色是干蜡笔、粉彩、干水粉,错位出线,纸纹的白点透出来;白粉笔痕压在蓝上,甩点和细尘;背景蓝块毛边、不到纸边;大圆脑袋、带高光的点点眼、点彩腮红和雀斑、火柴腿穿靴子的小人,乱线毛边的白色毛绒动物;最后印在书上:中缝和页码)。用户说「claude绘图」「用代码画」「你自己画」「不用生图模型画」「程序化绘画」,或点名以上任一画风(含黏土、彩泥、定格动画、蓝晒、晒图、十字绣、刺绣、复古面板、老式收音机、贴纸、小票、收据、手帐拼贴、实验笔记本、方格本、荧光笔、便利贴、黑板、板书、粉笔、赛博朋克、霓虹、雨夜街道、卡通、手绘卡通、逐帧手绘、抖线、等轴、2.5D、微缩模型、单线画、一笔画、线条动画、柔光 3D、3D 渲染、C4D 风、软糖字、小球海、形变、变形动画、报刊拼贴、剪报、达达、勒索信字、网点印刷、弥散渐变、玻璃拟态、毛玻璃、包豪斯、几何构成、丝网印刷、Synthwave、蒸汽波、合成器浪潮、80 年代复古、拼豆、拼拼豆、熔珠、熨豆、豆豆画、钉板、烫豆、岩画、岩刻、凿刻、石刻、沙漠漆、史前壁刻、大角羊、古埃及、埃及壁画、墓室壁画、法老时代、象形文字、尼罗河、底比斯、罗马马赛克、马赛克镶嵌、镶嵌画、石子拼画、地砖画、古罗马地板、彩色玻璃、彩绘玻璃、花窗、玻璃花窗、教堂花窗、哥特花窗、铅条玻璃、泥金手抄本、手抄本、彩饰手抄本、中世纪手稿、羊皮纸、哥特体、花体首字母、泥金、贴金、星盘、达芬奇、达·芬奇、达芬奇手稿、手稿风、文艺复兴手稿、发明手稿、镜像字、镜像书写、扑翼机、红粉笔、钢笔排线、机械草图、分解图、剪影、剪影肖像、侧影、侧面像、黑纸剪影、剪影小像、椭圆金框、乔治时代肖像、摄政时期肖像、凸版印刷、活版印刷、木活字、铅字海报、马戏团海报、复古海报、老海报、19 世纪海报、双色套印、错版、套色错位、木刻插图、构成主义、苏联海报、苏联构成主义、俄国先锋派、罗德琴科风、红黑海报、照片蒙太奇、照片拼贴海报、西里尔字、装饰艺术、装饰风、流线型、流线型海报、1930 年代海报、旅行海报、铁路海报、火车海报、喷枪画、喷笔画、阶梯高楼、射线背景、盖茨比风、黄金时代漫画、老漫画、复古漫画、美漫封面、漫画封面、Ben-Day 网点、本戴点、网点上色、四色印刷、四色错版、新闻纸、对白框、拟声字、1940 年代漫画、波普、波普艺术、波普丝网、沃霍尔风、丝网版画头像、撞色头像、多格重复头像、六宫格撞色头像、ASCII、字符画、字符艺术、文字画、行式打印机、绿条纸、连续打印纸、针孔打印纸、老电脑打印、叠打、低多边形、低面数、低模、多边形风、千禧年 3D、90 年代 3D、复古 3D 游戏、老游戏截图、PS1 风、N64 风、平面着色、线框、游戏 HUD、飞行游戏、穿环、喷漆、模板涂鸦、镂空模板、喷漆模板、模板喷绘、街头涂鸦、街头艺术、墙绘、滴漆、班克西风格、刺绣徽章、徽章、布章、臂章、刺绣贴、绣标、锁边、牛仔外套徽章、户外徽章、营地徽章、弧形条章、蓝图、工程图、施工图、蜡笔画、儿童画、绿屏终端、CRT、显像管、热成像、热像仪、温度图、代尔夫特、荷兰蓝瓷砖、洞穴壁画、史前壁画、赭石、1-bit、黑白画图软件、MacPaint 风、黑绘、古希腊陶瓶、希腊瓶画、铅笔素描、素描、铅笔画、X 光、X 光片、安检图像、橡皮管动画、黑白卡通、老动画、麻胶版画、黑白版画、藏书票、VHS、家庭录像、录像带、扁平插画、扁平风、矢量插画、绘本动画、角色动画、挤压拉伸、圆珠笔、圆珠笔涂鸦、原子笔、页边涂鸦、课本涂鸦、手画棋盘、描图纸、硫酸纸、叠片、叠层、分色片、灯箱、拷贝台、透光台、套准、定位钉、粉彩界面、粉彩 UI、Dot 风、Dot 那种风格、产品发布会界面、发布会质感、窗口卡片、macOS 窗口、界面卡片、讲解片界面页、小图标探头、阅卷、阅卷批改、批改、判卷、改卷、改作业、答题卡、试卷、考卷、测验卷、红笔批改、红笔打分、打分数、盖章批改、朱红印章、标准答案卡、长尾夹、讲解片评测 / 打分页、皮影、皮影戏、影子戏、驴皮影、灯影戏、皮影人偶、雕花戏台、戏台牌匾、亮相、钢笔淡彩、淡彩、淡彩速写、钢笔淡彩小人、针管笔、勾线笔、针管笔加水彩、线稿上色、速写卡片、速写本小人、水彩小卡、城市速写、街头速写、水笔、自来水笔、复古水粉、水粉、水粉画、不透明水粉、哑光丙烯、复古绘本、绘本插画、绘本大头像、童书插画、复古童书、大头像、大鼻子人物、针织毛衣、麻花毛衣、毛线帽、毛毡帽、卷发、胡子、蓝调绘本、蓝色绘本、软蓝绘本、蓝调童书、软蓝童书插画、蓝色童书插画、蓝色系绘本、限色绘本、蓝白绘本、现代绘本跨页、手绘绘本跨页、绘本跨页、绘本内页、干笔墨线、墨铅笔线、粉彩蜡笔质感绘本、白色毛绒动物、毛绒白熊、点彩腮红),或 "draw it yourself", "paint with code", "procedural painting", "watercolor / collage / colored pencil / anime / editorial / impasto oil / ukiyo-e / pixel art / clay / claymation / cyanotype / sun print / cross-stitch / embroidery / retro instrument panel / vintage radio / sticker collage / receipt / lab notebook / graph paper / chalkboard / blackboard / cyberpunk / neon city / cartoon / hand-drawn animation / isometric / 2.5D / continuous line / one-line drawing / soft 3D / 3D render / puffy letters / ball pit / shape morph / morphing / newspaper collage / Dada / ransom note / halftone / glassmorphism / aurora gradient / Bauhaus / geometric poster / screen print / synthwave / retrowave / outrun / perler beads / hama beads / artkal / fuse beads / melty beads / pegboard beads / petroglyph / rock art / rock carving / desert varnish / Egyptian tomb painting / ancient Egypt / hieroglyphs / Theban tomb / Roman mosaic / floor mosaic / tesserae / opus vermiculatum / Pompeii mosaic / stained glass / leaded glass / church window / Gothic window / grisaille / illuminated manuscript / medieval manuscript / book of hours / gold leaf / illuminated initial / blackletter / vellum / astrolabe / da Vinci notebook / Leonardo codex / Renaissance sketchbook / mirror writing / iron-gall ink / red chalk / sanguine / ornithopter / exploded view / inventor's sketch / silhouette / silhouette portrait / cut-paper profile / shade portrait / Georgian portrait / Regency portrait / oval gilt frame / letterpress / wood type / playbill / circus poster / Victorian poster / two-colour misregistration / woodcut poster / constructivism / constructivist poster / Soviet avant-garde / Russian avant-garde / Rodchenko style / photomontage poster / art deco / streamline moderne / 1930s travel poster / railway poster / airbrush poster / sunburst rays / Gatsby style / golden age comic / vintage comic book / comic cover / Ben-Day dots / four-color printing / newsprint / speech balloon / pulp cover / pop art / Warhol-style / pop silkscreen / silkscreen portrait / repeated pop portrait grid / ASCII art / text art / typewriter art / line printer / greenbar / fanfold paper / tractor feed / overstrike / printer plot / low poly / low-poly / retro 3D / 90s 3D game / PS1 style / N64 style / software rasterizer / flat shading / affine texture mapping / vertex fog / game HUD / stencil / stencil graffiti / spray paint stencil / street art / drips and overspray / Banksy-style stencil / embroidered patch / embroidery patch / iron-on patch / sew-on patch / merit badge / camp badge / merrow border / rocker patch / denim jacket patches / blueprint / technical drawing / crayon / kid's drawing / CRT terminal / green screen / thermal camera / thermal imaging / Delft tiles / Delft blue / cave painting / ochre / Lascaux-style / 1-bit / MacPaint-style / black-figure / Greek vase / pencil drawing / graphite / X-ray / baggage scanner / rubber hose / 1930s cartoon / linocut / lino print / VHS / home video / flat vector / flat illustration / storybook animation / squash and stretch / ballpoint / biro / ballpoint doodle / margin doodles / hand-drawn board game / overlay sheets / tracing-paper overlays / light box / colour separations / registration marks / acetate overlay / pastel UI / Dot-style product film / launch-film interface / macOS window cards / exam grading / grading an answer sheet / red-pen marking / graded test paper / rubber-stamped answer sheet / shadow puppet / shadow puppetry / Chinese shadow play / leather shadow puppets / backlit puppet screen / pen and wash / pen & wash / line and wash / ink and watercolour / ink and watercolor / fineliner sketch / fineliner and watercolour / sketchbook characters / sketch cards / urban sketching / water brush / gouache / retro gouache / gouache portrait / gouache illustration / opaque gouache / matte acrylic / picture-book portrait / vintage picture book / retro children's book illustration / mid-century children's book / big-nosed character portrait / cable-knit sweater / knitted bobble hat / blue picture book / soft blue picture book / soft-blue children's book illustration / modern picture book / limited-palette picture book / picture-book spread / scratchy ink line / dry-brush ink line / ink pencil line / crayon and pastel texture / chalky white marks / blue and coral palette / fluffy white bear without an image model" 时使用;也用于需要逐步画出(draw-on)动画的插画。单独说「剪纸」指剪纸拼贴、「刺绣」指十字绣、「丝网印刷 / screen print」指包豪斯几何;「打马赛克」是打码,不是马赛克画风;单说「蓝图」指蓝图工程图,「蓝晒 / 晒图」仍指蓝晒;「铅笔 / 素描」指铅笔素描,「彩铅」指韩国彩铅;「像素」仍指像素风,「1-bit / 黑白画图软件」指 1-bit 早期画图软件;「霓虹」仍指赛博朋克;「喷漆 / 街头涂鸦」仍指喷漆模板涂鸦,「圆珠笔 / 随手涂鸦 / 页边涂鸦」指圆珠笔涂鸦;「描图纸 / 硫酸纸 / 叠片 / 灯箱」指描图纸叠层(蓝图工程图那张描图布是晒成蓝图的,不是叠片);「Dot 风 / 粉彩界面 / 窗口卡片 / 发布会界面」指粉彩界面(纯色底 + 白色实心窗口卡片),要磨砂玻璃和弥散渐变仍用弥散玻璃;「阅卷 / 批改 / 答题卡 / 判卷 / 红笔打分」指阅卷批改,实验记录里的红笔圈和便利贴仍用实验笔记本,带「已付」橡皮章的小票拼贴仍用贴纸拼贴 · 小票;「皮影 / 皮影戏 / 影子戏」指皮影戏(透光的彩色驴皮人偶),黑纸剪出的侧影小像仍用剪影,彩纸剪贴仍用剪纸拼贴。「钢笔淡彩 / 淡彩速写 / 针管笔加水彩 / 线稿上色的速写小卡」指钢笔淡彩;单说「水彩」仍指水彩(风景、花卉的大片晕染),蓝铅笔稿 + 毛笔线 + 赛璐璐阴影的拟人小物仍用卡通手绘,「素描 / 铅笔」仍指铅笔素描。「水粉 / 复古水粉 / 绘本大头像 / 复古童书插画」指复古水粉(不透明水粉画的特写大头像);梵高式厚涂的风景、名画感仍用油画厚涂,扁平矢量、会挤压拉伸的小角色动画(「绘本动画」)仍用绘本角色动画,针管笔线稿加淡彩的速写小卡仍用钢笔淡彩,撞色多格的头像仍用波普丝网。「蓝调绘本 / 软蓝绘本 / 蓝色童书插画 / 绘本跨页」指蓝调绘本(软蓝限色的现代绘本跨页:干笔墨线 + 干蜡笔粉彩上色 + 白粉笔痕);单说「绘本」仍指绘本角色动画,「水粉 / 绘本大头像」仍指复古水粉,「编辑风 / Riso」仍指编辑风手绘,针管笔线稿加淡彩的速写小卡仍用钢笔淡彩,小孩自己画的蜡笔画仍用儿童蜡笔画。
---
# Claude 绘图
@@ -79,6 +79,7 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型
| 皮影戏 · Shadow Puppetry | `lib/shadowpuppet.py` · `ShadowPuppet` | `examples/shadowpuppet_cuju.py` 蹴鞠 · Cuju by Lamplight(油灯从背后照亮的琥珀色幕布,前面是雕花戏台:回纹浮雕横楣、红漆金字牌匾「蹴鞠」、透空回纹挂落、两角镂空花牙子、两盏红灯笼;幕上是雕空、透明染色的驴皮:牌楼式球门(瓦顶飞檐、鸱吻、窗棂网、红边风流眼)、底部回纹装饰带、四个关节人偶。红方球头刚起脚,一条腿踢得老高,同伴一手高一手低、提膝亮相;青方一个跳起扑球(离幕一点,边缘发软、成双影),一个指着球;鞠正卡在风流眼里;「球头」「骁色」两块小牌挂在线上。人偶是阳刻空脸或阴刻红脸、雉翎盔或三叉冠、云肩护心镜鱼鳞甲、厚底靴,皮叠在一起处更深,关节有线结,操纵杆从领口和手上垂下去;`--stages` 出 60 个阶段,全是真运动:点灯、横楣落下、灯笼晃着亮起、球门升起、人从侧幕滑进来由虚变实、传球、起脚、亮相、小牌落下) | 约 7 秒(成品)/ 约 27 秒(含阶段) |
| 钢笔淡彩 · Pen & Wash | `lib/penwash.py` · `PenWash` | `examples/penwash_neighbours.py` 街角速写 · Sketchbook Neighbours(橡木桌上并排四张冷压水彩小卡,一张一个街坊在做一件小事:吹着口哨的邮差,钴蓝帽子和外套,挎包塞得太满,两封信从背后逃出去扑扇着飞走;戴超大圆眼镜的奶奶给花盆浇水,猫却钻进了盆里,水滴正落在它两耳之间(眯眼、爪子扒着盆沿),真正的那朵红花在旁边干等;踩滑板车的小孩,钴蓝头盔大了两号、压到眉毛,吐着舌头,膝盖贴着创可贴,身后速度线和尘土;圆滚滚的面包师戴高高的白帽子,抱着一根比他还长的法棍,法棍从手绘边框里戳出去,一只麻雀落在尖上啄;针管笔线条抖、出头、不闭合、偶尔描两遍,淡彩错位出线、在线里留白缝、干边、颗粒,腮红湿中湿,不铺满的背景色块绕开人物留白边,白色水粉高光;卡片有阴影和受光的切边,旁边放着一支针管笔、一支水笔(透明杆里的水和气泡、染了颜色的尼龙笔尖)和水笔的笔帽;`--stages` 出 9 个阶段:空桌、白卡、两批墨线、两遍淡彩、背景色块、高光、放下笔) | 约 3 秒(成品)/ 约 6 秒(含阶段) |
| 复古水粉 · Retro Gouache | `lib/gouache.py` · `GouachePortrait` | `examples/gouache_rainy_day.py` 雨天三人像 · Rainy-Day Portraits(米色画板上并排三幅竖长的绘本大头像,每幅一块刷出来的单色背景:浅海玻璃绿底上的老渔夫,黄色防水雨帽上还挂着雨珠、帽檐尖上吊着一滴水,巨大的红鼻子、白色浓眉、大耳朵、一圈白色下巴胡子,藏青麻花毛衣配罗纹领,胸前毛毡口袋里探出一条银色小鱼、张着「O」字嘴,他眯着眼往下看它;绿底上被一顶巨大的芥末黄毛线帽和红白条纹围巾埋住的小孩,橙色大绒球,两只毛线手套捧着一杯冒热气的可可,杯里漂着两块棉花糖,他盯着棉花糖看成了斗鸡眼;蓝到黄渐变底上的高个女士,橙色小卷堆成一座高塔发型,蓝眼影、珍珠耳坠、红色高领、钴蓝大衣配青绿毛毡翻领,斜眼瞟着爬上她肩膀的蜗牛,蜗牛身后的大衣上还有一道发亮的黏液;不透明水粉从暗到亮:托底色、赭色起稿、背景干笔皴擦、平涂大块、几阶色值塑形(鼻子、脸颊、帽子)、帽檐和鼻子下的软投影、粉状腮红、V 字平针与麻花、罗纹、一根根发丝和胡子、毛毡、受光处的干笔高光,最后是印刷书页的纸纹;`--stages` 出 8 个阶段:托底色、起稿、背景、平涂、塑形、质感、五官与道具、高光) | 约 7 秒(成品)/ 约 8 秒(含阶段) |
+| 蓝调绘本 · Blue Picture Book | `lib/bluebook.py` · `BlueBook` | `examples/bluebook_shared_umbrella.py` 借伞 · The Shared Umbrella(软蓝雨天里的一张绘本跨页,背景蓝块毛边、不到纸边:左页是一个小小的公交站,玻璃候车亭里的长椅空着,只有一只蜗牛独占整条干燥的长椅,旁边是画着小巴士的圆站牌、亮着芥末黄灯的路灯,路灯下的大水洼里一只鸭妈妈带着两只小鸭玩得正欢;右页一个穿钴蓝雨衣、扎两个珊瑚红小揪揪的小女孩,双臂伸到最高,把一把珊瑚红小伞举向一只巨大、害羞、毛茸茸的白熊——伞只遮住了它的鼻子,雨落在它的耳朵和头顶,也落在小女孩自己的头发上,她一点也不在意,仰着头冲它笑;白熊低头看着自己并在一起的爪子,脸红了;水洼里映着一点红伞,蓝黑乱线的灌木里开着几朵珊瑚红小花;照绘本画家的顺序:空白纸、蓝色色块(天空块、雾里的远树、灌木、雨衣、候车亭、水洼)、松的墨线(线不闭合、偶尔描两遍)、乱线排出的暗部、珊瑚红点缀和点彩腮红、白粉笔(云、白毛、水纹、玻璃反光)、雨丝 / 水花 / 甩点 / 细尘,最后印在书上(中缝、页码、印刷的柔化);`--stages` 出 7 个阶段加成品:空白纸、蓝色色块、墨线、暗部、点缀色、粉笔白、雨) | 约 5 秒 |
各画风共用 `lib/core.py` 里的底层工具:噪声、模糊、样条曲线、多边形遮罩、有机轮廓 `blob_pts`、毛笔 `bristle_stroke`、中文字体查找;新四种还用到补零平移 `shift`、文字遮罩 `text_mask`、西文字体查找 `latin_font`/`load_font`,以及高度图打光 `height_normals`、`height_shadow`(沿光线步进的投影)、`ambient_occlusion`。
@@ -147,7 +148,8 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型
- 考试、作业、批改与打分,「对照标准答案逐条检查」的过程(评测、验收、审核、评分规则、哪里错了、为什么扣分),讲解片里的「怎么判对错 / 评分标准 / 检查结果」页 → 阅卷批改(要草稿纸上的随手推演用圆珠笔涂鸦;要实验记录、红笔圈和便利贴用实验笔记本;要明亮的产品界面里打 ✓ / ✗ 用粉彩界面);
- 中国传统与民间艺术、节庆(元宵、庙会、过年)、戏曲和民间故事、古代体育与游戏(蹴鞠、赛龙舟、舞狮)、「一场好戏」式的小叙事(登场—交手—亮相),讲解片里的「历史 / 传统 / 一场比赛的高光时刻」页,要人物有动作又不能用真人 → 皮影戏(要黑纸剪的侧影小像用剪影;要彩纸剪贴的童趣用剪纸拼贴;要山水留白用水墨);
- 人物小品、街坊邻居与日常小事(送信、浇花、骑车、买面包)、一组角色卡 / 人设卡、旅行和城市速写里「一个人在做一件小事」、轻松幽默的配图,讲解片里「一组用户 / 角色 / 团队成员」的介绍页 → 钢笔淡彩(要蓝铅笔稿、毛笔线和赛璐璐阴影的拟人小物用卡通手绘;要风景和花卉的大片晕染用水彩;要真的动起来的角色用绘本角色动画;要草稿纸上的随手涂鸦用圆珠笔涂鸦);
-- 人物大头像、角色特写、一组人设的「封面像」、温暖怀旧的复古童书 / 绘本插画,要有摸得着的手感(毛衣针脚、毛线帽、胡子和卷发、毛毡),讲解片里「这个人登场」的特写页 → 复古水粉(要线稿加淡彩、「一个人在做一件小事」的速写小卡用钢笔淡彩;要真的动起来的扁平小角色用绘本角色动画;要梵高式厚涂的风景用油画厚涂;要撞色多格的头像用波普丝网)。
+- 人物大头像、角色特写、一组人设的「封面像」、温暖怀旧的复古童书 / 绘本插画,要有摸得着的手感(毛衣针脚、毛线帽、胡子和卷发、毛毡),讲解片里「这个人登场」的特写页 → 复古水粉(要线稿加淡彩、「一个人在做一件小事」的速写小卡用钢笔淡彩;要真的动起来的扁平小角色用绘本角色动画;要梵高式厚涂的风景用油画厚涂;要撞色多格的头像用波普丝网);
+- 温柔又好笑的小故事、绘本跨页或内页、童书封面和插页、「一个小角色帮另一个」这类有情节的一幕,下雨、下雪、夜晚这类安静的天气,要一眼就是「手画的现代绘本」,颜色只要一种主色(软蓝)加一点点睛色 → 蓝调绘本(要单人特写大头像、看得见毛衣针脚用复古水粉;要速写小卡上的针管笔线稿加淡彩用钢笔淡彩;要真的动起来的扁平小角色用绘本角色动画;要小孩自己画的蜡笔画用儿童蜡笔画;要网点和套色的观点插画用编辑风手绘)。
每种画风一幅范例作为质量基准(范例都不用禅意主题);水墨另加一幅「月印万川」(留白托月、水面倒影)。
@@ -1070,6 +1072,47 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask
- `ramp(base, deep, shadow, light, pale, cool, warm)` 给五色阶;皮肤记得给暖的 `cool`。
- 常量 `PAINTS PAPER LIGHT`;`grain(amount)`、`render()`、`composite()`、`stage(name)`、`save(path, stages_dir)`;`save('x.jpg')` 默认 quality 88、4:4:4 色度。
+**蓝调绘本 `BlueBook`**:
+- 思路:照绘本画家的顺序画一页、再印出来(空白纸 → 蓝色色块 → 墨线 → 乱线暗部 → 点缀色和腮红 → 白粉笔 → 雨、水花、甩点 → 印刷)。
+ - 纸纹:一张直方图均衡过的纸纹高度场 `T`(0–1 均匀分布),所以「工具碰到纸纹高于 1 − 接触压力的地方」直接就是覆盖率。另外预先算好沿 8 个方向拖开的纸纹 `TD`,每一笔按自己的方向取,干的工具漏掉的白点会顺着笔拉成短道。
+ - 一笔(墨线、彩色蜡笔线、粉笔线、雨丝共用):路径先过样条、按 2 px 重采样,再加慢的手抖和细颤。Pillow 把每段的序号画进 32 位整数图,得到这一笔覆盖的像素和所属线段,再精确投影出每个像素的弧长和横向偏移。
+ - 落笔快、收笔慢(`taper`),沿途粗细起伏(`swell`)。
+ - 横向几根笔毛含墨不同,沿笔越用越干(`dry`);接触 × 含墨低于纸纹的地方断成顺着笔的白道。
+ - 边缘随纸纹游走,不是矢量边。
+ - 上色是干蜡笔、粉彩或干水粉:
+ - 区域先整体错开 1.5–3.5 px(`slip`),边缘在模糊过的遮罩上用游走的阈值重新找(`loose`),靠边的地方压力减小、断成干边(`edge`、`dry_edge`)。
+ - 覆盖率只由压力和纸纹决定(`pressure` 0.95 只留细白点);颜色深浅由低频斑驳和平行笔道决定(`mottle`、`lanes`)。
+ - 蜡和粉彩半透明:新 = 旧 + (色 × 旧^0.55 − 旧) × 覆盖。盖在白纸上就是本色,盖在墨上仍是黑,蓝上加蓝更深;`medium='gouache'` 和 `'chalk'` 不透明。
+ - 墨在上:墨的覆盖记在 `K` 里,之后再上的颜色在墨上几乎挂不住(`over_ink` 默认 0.1,粉笔 0.5,眼睛高光 1),所以线一直在颜色上面,像印出来的书。
+ - 最后 `printed()`:印刷的轻微柔化、只把黑抬到深墨色(白纸不变灰)、细纸点,可选中缝(柔和的阴影、一道细折痕和一线亮边)。
+- 构造:`BlueBook(W, H, seed, keep_stages=True, stages_dir=None)`(总像素不超过 4096²),先 `paper(tone='paper', tooth, drag)`。坐标是整张画布的像素。
+- 形状:返回画布大小的浮点遮罩,用 `np.maximum`、相乘、`1 −` 组合。
+ - `ellipse(cx, cy, rx, ry, rot)`、`poly(pts, smooth=True)`、`blob(cx, cy, rx, ry, rough, seed, rot)`、`band(path, w0, w1)`;`BlueBook.tube(path, w0, w1)` 给轮廓点。
+ - `cloud(cx, cy, w, h, bumps, seed)` 云;`rect(x0, y0, x1, y1, rough, corner, seed)` 手画的毛边矩形。
+- 颜色:
+ - `block(box 或遮罩, colour='powder', rough, corner, pressure, angle, edge, dry_edge, streaks, avoid, halo)` 背景大色块:毛边、不到纸边,边缘的笔道顺着边走、拖干,再贴着边拖几十笔干笔(限在边缘附近)。
+ - `fill(mask, colour, pressure=0.9, angle, slip, loose, edge, dry_edge, mottle, lanes, lane_var, passes, medium='crayon'|'gouache'|'chalk', avoid, halo, clip, streak, over_ink)` 涂一块,返回实际涂到的区域。`angle` 是数或画布大小的角度场;`avoid` + `halo` 绕开前面的东西、留一圈白缝;`slip=0` 不错位。
+ - `crayon(paths, colour, width, pressure, dry, medium)` 沿路径的彩色干笔(头发丝、远树干、湿地面、倒影)。
+- 墨:
+ - `ink(path, width=4, dry, taper, wobble, swell, overshoot, clip)` 一笔毛笔 / 墨铅笔线。
+ - `outline(pts, width, closed=True, open_=0.45, overshoot, strokes=(1, 3), twice=0.35)` 快速的轮廓:闭合形分 1–3 笔,在接头前停下留缺口,或冲过接头顺着切线出头;`twice` 是某一段再描一遍、偏开一两 px 的几率。
+ - `scribble(mask, width=5, spacing=4.5, angle=80, reach, overshoot, dry, colour, clip)` 暗部:沿一个方向来回不抬笔的之字乱线,转折处冲出或不到轮廓,一次一个手腕的范围。
+ - `hatch(mask, angle, spacing, length, width, colour, medium, density)` 一根根平行的快速短排线(衣服暗面、白毛的阴影)。
+ - `blades(x0, x1, y 或 f(x), n, height, lean, width, clip)` 从底线长出来的锥形草叶。
+ - `dot(x, y, r, ry, colour, medium)` 边缘不规则的实心小点(眼睛、鼻子、扣子)。
+- 白与天气:
+ - `chalk(遮罩 或 路径列表, width, pressure=0.62, angle, over_ink=0.5)` 不透明的白粉笔 / 白粉彩:给遮罩就涂(云、小巴士),给路径就画(高光、玻璃反光),只挂在纸纹凸起上,顺着笔拉成长道。
+ - `rain(region, n, angle=100, length, width, colour='deep', avoid)` 短的干笔雨丝。
+ - `splash(x, y, size, colour, n, up)` 雨点落下溅起的一圈小短线和水珠;`ripples(cx, cy, rx, ry, rings)` 水洼上断开的同心圈。
+ - `spatter(region, colour, n, size, satellites)` 甩出来的颜料点(幂律大小、略拉长、带小卫星点);`speckle(region, colour, n, size)` 更细的尘点和闪点。`region` 是遮罩或 (x0, y0, x1, y1)。
+- 角色:
+ - `head(cx, cy, rx, ry, width, ears=[(x, y, r)])` 大圆脑袋的开口轮廓,耳朵只画露出来的那段,返回头(含耳朵)的遮罩。
+ - `eyes(pts, r, look=(dx, dy), glint)` 带白高光的点点眼;`smile(x, y, w, depth, tilt)`;`blush(cx, cy, r)` 点彩腮红(一层很淡的蜡笔底 + 稀疏的粉点);`freckles(cx, cy, n, spread)`。
+ - `fluff(mask, 'ink' 或 'chalk', length, width, curl, avoid, gaps, curls, reach)` 毛绒。`'ink'` 把轮廓画成一串短的扇贝形小弧(不闭合,有缺口);`'chalk'` 是从里往外越过边缘、压在背景蓝上的白毛;`curls` 是里面的小卷。
+ - `flower(x, y, r, colour='coral')` 小花:不透明的花瓣加墨点花心。
+- 收尾:`printed(amount, gutter=x)` 印在书上;`folio(x, y, '14', size)` 小页码;`render()`、`composite()`、`stage(name)`、`save(path, stages_dir)`;`save('x.jpg')` 默认 quality 88、4:4:4 色度。
+- 颜色用 `COLOURS` 里的名字(paper chalk ink mist powder cornflower blue cobalt deep teal navy slate coral tomato cheek flesh freckle mustard butter)或 '#rrggbb';常量 `COLOURS`、`INK`。
+
**顺序**:都是先远后近、先大后小,文字最后叠加。水墨的雾要画在它该吞没的东西之后;水彩的叶梗要先画,并且只画在叶子外面。
## 三、毛病清单(都真实出现过)
@@ -2089,6 +2132,29 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask
| 帽子和外套大块干净,像塑料 | 少了最后的干笔高光:`dry_highlight` 只在受光 > 0.62–0.7 的地方拖半干的浅色;穹顶用 `angle='fall'`(顺坡),用 `'contour'` 会画成一个漩涡 |
| 动图里瞳孔和眼皮线发蓝 | 中值切分出来最深的一色是毛衣的藏青:强制放进三个深中性色,另外 9 色只从末帧误差最大(> 18 级)的像素里切 |
+**蓝调绘本**
+
+| 问题 | 改法 |
+|---|---|
+| 背景蓝块里白道太多,像刮花的粉笔 | 压力的斑驳和笔道直接改了覆盖率,压力掉到 0.7 就露出三成白纸:覆盖率只由 `pressure`(0.95 左右)和纸纹决定,斑驳和笔道只改颜料浓淡;纸纹只一半顺笔拖开(`streak` 0.45),里面只剩细白点 |
+| 白纸发灰发脏 | 纸纹在白纸上的明暗 0.022 → 0.012,印刷细点 0.016 → 0.009;纸色改成更白的 #fbfaf5 |
+| 墨点像带刺的墨团 | 点的半径每个顶点单独随机:改成沿一圈的低频起伏 |
+| 熊的毛边是碎碎的虚线 | 小弧太短太干:长 16–30 px,间隔为平均长度的 0.62 倍(相邻小弧叠一点),dry 0.12,12% 的位置留缺口 |
+| 珊瑚红小花、伞的倒影在深色上发褐 | 蜡的半透明混色(色 × 底^0.55)盖在深青、蓝上会变暗:深底上的点缀用不透明的 `medium='gouache'`(倒影 alpha 0.8);伞、头发这些大块在背景色块里先留白(`avoid`),蜡笔涂在白纸上 |
+| 后上的颜色把墨线盖掉,眼睛的白高光不见了 | 墨的覆盖记进 `K`,之后上的颜色乘 (1 − 0.9·K);高光 `over_ink=1`,粉笔 0.5 |
+| 举伞的胳膊从小孩脸上横穿过去 | 两只胳膊都从右肩出发,在头的右侧往上伸:先确认胳膊在头的高度上 x 大于头的右边缘 |
+| 草叶和乱线画到了熊腿和小孩身上,靴子是白的、只有几道灰线 | `blades`、`scribble` 加 `clip=1 − 前景遮罩`;小面积的靴子先用近黑的不透明水粉涂满,再在上面乱线 |
+| 熊整只发灰发蓝 | 暗面的淡蓝、排线和落在熊身上的雨都太多:暗面只留最右边一窄条,排线行距 14–16、density 0.6–0.7,熊身上只下 45 笔雨,用粉蓝 |
+| 熊的鼻子在伞边上,不像「只有鼻子是干的」 | 口鼻往左拉长(rx 80 → 92),鼻子挪到伞的雨影正中;雨按斜度留出伞下一条不下雨的柱子,熊的头顶、耳朵加水花和挂着的水珠 |
+| 乱线暗部是一把梳子、一条黑带横贯整页 | 暗部遮罩的上缘是一条直线,转折全排在一条线上:改成按「越往下越暗 + 低频噪声」取阈值的一团一团(深青灌木 0.66、蓝灌木 0.9),笔 5.2 px、行距 4.6 px 叠成一片;蓝灌木用藏青不用黑;灌木底线改成波浪 |
+| 蜗牛读成长椅靠背上的一个芥末黄圆盘 | 去掉靠背;候车亭里加一块淡蓝玻璃(不透明水粉,alpha 0.82),蜗牛坐在座板上,眼柄和小笑脸落在浅色玻璃前面才看得见 |
+| 远处的树是一个个平涂的气球 | 改小、颜色改成接近天色的 #a3c1e2、两团叠成不规则的树冠,加竖向的干笔树干;小孩身后那棵删掉,免得像她头后面的气球 |
+| 线条像马克笔,太细太匀 | 主要轮廓加粗约 20%(小孩头 5.2、熊毛边 4.2、伞 4.8),`swell` 0.3–0.35;`outline` 默认 35% 的几率把一段再描一遍、偏开 1.5–3 px |
+| 雨像数码雨,一样长、一样密 | 深蓝 560 笔(10–40 px)、矢车菊蓝 260 笔、粉笔白 240 笔,三种深浅、长短拉开 |
+| 鸭妈妈的头伸进天空色块,染成了蓝 | 鸭子放低,并加进背景色块的 `avoid` |
+| 背景块角上一道干笔斜着戳出纸外 | 贴边的干笔用 `clip` 限在块的边缘附近 |
+| 印刷一步把白纸压灰,动图最后一帧整体一暗 | 「黑色抬到墨色」原来是整体混进 5% 深墨:改成 c0 + 颜色 × (1 − c0),白纸不动,只抬黑 |
+
## 四、做成动画
- 各画风都有 `stage(name)` 和 `save(path, stages_dir)`,按阶段依次淡入叠化,就是「一幅画被逐步画出来」。README 里的动图就是这样做的。
@@ -2118,6 +2184,11 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask
- 调色板:56 色只从托底色那帧切;186 色从和它不同的像素切(饱和 ×3、末帧 ×3);再留 12 色,其中 3 个是强制的深中性色(不然最深的一色是毛衣藏青,瞳孔和眼皮线全变蓝),另外 9 色只从末帧误差最大(> 18 级)的像素里切。
- 固定 4×4 Bayer。和屏上已显示颜色差不到 7 级(叠化帧)或 4 级(关键帧)的像素沿用上一帧,末帧精确发送。
- 结果:49 帧、13.4 秒、约 1.79 MB,按解码结果逐帧自检,末帧 p99 误差 25。
+- 蓝调绘本的动图(脚本在 `claude_drawing/bluebook_work/make_gif_bluebook.py`):
+ - 阶段:空白纸 → 蓝色色块(不到纸边的天空块、远树、灌木、雨衣、候车亭、水洼)→ 墨线 → 乱线暗部、草叶、靴子 → 珊瑚红点缀、腮红、芥末黄 → 白粉笔(云、熊的白毛、水纹、玻璃反光、站牌上的小巴士)→ 雨丝、水花、甩点、细尘 → 印在书上(中缝、页码、印刷的柔化,成品)。每段 900 毫秒 + 5 帧叠化。
+ - 调色板:第一帧几乎只有纸白,只给它 12 色;230 色从和它不同的像素切(饱和 ×3、末帧 ×3);再留 12 色,其中 3 个是强制的深中性色(墨线和眼睛保持黑,不变藏青),另外 9 色只从末帧误差最大(> 18 级)的像素里切。
+ - 固定 4×4 Bayer。和屏上已显示颜色差不到 7 级(叠化帧)或 4 级(关键帧)的像素沿用上一帧,末帧精确发送。
+ - 结果:43 帧、12.05 秒、约 1.04 MB,按解码结果逐帧自检,末帧 p99 误差 18。
- 绘本角色动画的动图是真动画,不是阶段叠化:`Storybook.gif()` 按时间逐帧渲染,720×405、15 fps(GIF 延时只能写厘秒,按累计取整写成 7、7、6 厘秒交替),共用一张加权调色板 + 固定 4×4 Bayer,没变的像素记成品红透明,151 帧(动作 9.95 秒 + 末帧停 1.4 秒)约 0.56 MB;范例加 `--gif out.gif` 出这张,`--stages` 的关键帧仍可喂给上面的阶段动图工具。
- 形变动画可以直接出真动画:`Morph.at(keys, T)` 给出全局时间 T 的轮廓,逐帧渲染即可。
- 更细的逐笔动画:把一组笔画单独画到透明层上导出,再用 Motion Canvas 遮罩按顺序显现。这个还没做成现成接口。
@@ -2191,6 +2262,7 @@ lib/grading.py 阅卷批改(绿毛毡桌、带位姿和投影的纸与
lib/shadowpuppet.py 皮影戏(油灯照亮的幕布、两个灯芯;按光密度叠加的透明染色驴皮:剪、染、描边、打孔、九种镂空纹样;关节树人偶、线结、操纵杆;离幕虚化与双影;标准人偶(阳刻空脸 / 阴刻脸、雉翎盔 / 三叉冠);牌楼球门、鞠、底部回纹带、小牌;雕花戏台、红漆金字牌匾、灯笼)
lib/penwash.py 钢笔淡彩(冷压水彩小卡:受光纸纹、不直的切边;针管笔线:手抖、出头、不闭合、描两遍、按 z 遮挡断线;淡彩:错位出线与留白缝、游走的边、干边、颗粒、平刷条纹、湿中湿、起皱;不铺满的背景色块与白边;白色水粉;呆萌小人部件;橡木桌、卡片阴影、针管笔与透明水笔)
lib/gouache.py 复古水粉(托底色的画板与纸纹;不透明水粉:鬃毛条纹、越用越干、挂在纸纹上的干笔,湿笔带起底色;毛边;穹顶光照的几阶色值塑形与球体塑形;软投影、粉状腮红、干笔高光;圆眼、大鼻子、大耳朵;V 字平针、麻花、罗纹;顺着流向的发丝、胡子、绒球、卷发;毛毡;印刷书页的颗粒)
+lib/bluebook.py 蓝调绘本(直方图均衡的纸纹与 8 个方向拖开的纸纹;毛笔 / 墨铅笔线:手抖、落笔收笔、粗细起伏、笔毛含墨、越画越干、顺笔的干白道、不闭合的轮廓与再描一遍;之字乱线暗部、平行短排线、草叶;干蜡笔 / 粉彩 / 干水粉上色:错位、游走的边、干边、笔道、纸纹白点、半透明混色,墨线始终在上;毛边、不到纸边的背景色块;白粉笔;雨丝、水花、水纹、甩点、细尘;大圆脑袋、点点眼、点彩腮红、雀斑、扇贝形毛边和白毛;印刷:柔化、抬黑、中缝、页码)
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/bluebook_shared_umbrella.jpg b/examples/bluebook_shared_umbrella.jpg
new file mode 100644
index 0000000..c7c2f38
Binary files /dev/null and b/examples/bluebook_shared_umbrella.jpg differ
diff --git a/examples/bluebook_shared_umbrella.py b/examples/bluebook_shared_umbrella.py
new file mode 100644
index 0000000..0e2ebe1
--- /dev/null
+++ b/examples/bluebook_shared_umbrella.py
@@ -0,0 +1,466 @@
+"""Example (blue picture book): 借伞 · The Shared Umbrella -- one spread of a soft-blue modern picture book.
+
+Soft blue rain at a tiny bus stop. The shelter is far too small for a huge, shy, fluffy white bear, so a small
+girl in a blue raincoat stretches both arms as high as they will go and holds her coral-red umbrella over him.
+It covers exactly one thing: his nose. The rain runs off his ears and the top of his head, it lands on
+her own coral hair too, and she does not mind -- she is looking up at him, very pleased. He looks down at his paws,
+blushing. Under the empty shelter a snail has the whole dry bench to itself; in the big puddle by the lamppost a
+duck and two ducklings are having the best day of their lives.
+
+Drawn the way the illustrator works: blank paper -> blue colour blocks (sky block that stops short of the page edge,
+misty trees, bushes, coat, shelter, puddles) -> loose ink line -> dark scribbled masses -> coral accents and cheeks
+-> chalky whites -> rain, splashes and speckle -> printed on the page (gutter fold, page numbers).
+--stages writes those steps as snapshots for the draw-on. No image model.
+python3 bluebook_shared_umbrella.py [out.jpg] [--stages DIR]
+"""
+import os, sys, time
+sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'lib'))
+import numpy as np
+from bluebook import BlueBook, INK
+from core import blur, smoothstep, noise2d
+
+W, H = 1920, 1080
+GUTTER = 960
+RAIN_ANG = 80.0 # falling a little to the right
+SLANT = 1 / np.tan(np.deg2rad(RAIN_ANG))
+
+
+def base_y(x):
+ """the wavy line where the bushes meet the pavement"""
+ return 906 + 7 * np.sin(np.asarray(x, np.float32) / 53.0) + 4 * np.sin(np.asarray(x, np.float32) / 17.0 + 1)
+
+# ---------------------------------------------------------------- the umbrella, tilted toward the bear
+TILT = np.deg2rad(25)
+AX = np.array([np.sin(TILT), -np.cos(TILT)]) # shaft axis, handle -> tip
+PX = np.array([np.cos(TILT), np.sin(TILT)]) # across the canopy
+RC = np.array([1300.0, 420.0]) # centre of the rim
+CAN_R, CAN_H = 134.0, 94.0
+
+
+def at(u, w):
+ """umbrella frame -> canvas: u across the canopy, w up the shaft"""
+ return RC + PX * u + AX * w
+
+
+def canopy_pts():
+ th = np.linspace(0, np.pi, 40)
+ dome = [at(CAN_R * np.cos(t), CAN_H * np.sin(t) ** 0.9) for t in th] # right rim -> tip -> left rim
+ us = np.linspace(-CAN_R, CAN_R, 6)
+ rim = []
+ for a, b in zip(us[:-1], us[1:]):
+ for t in np.linspace(0, 1, 7)[1:]:
+ rim.append(at(a + (b - a) * t, -9 * np.sin(np.pi * t)))
+ return np.array(dome + rim, np.float32)
+
+
+def rib(ui):
+ t = np.linspace(0, 1, 12)
+ return np.array([at(ui * np.sin(x * np.pi / 2), CAN_H * np.cos(x * np.pi / 2) ** 0.9) for x in t], np.float32)
+
+
+class Spread:
+ def __init__(self, b):
+ self.b = b
+ self.YY, self.XX = np.mgrid[0:H, 0:W].astype(np.float32)
+ self.shapes()
+
+ # ============================================================ shapes
+ def shapes(self):
+ b, X, Y = self.b, self.XX, self.YY
+ S = self.S = {}
+ # --- the bear: sitting, head tipped down-left, nose under the umbrella
+ S['b_body'] = b.poly([(1430, 700), (1500, 600), (1640, 568), (1780, 610), (1858, 760), (1872, 900),
+ (1820, 975), (1640, 990), (1470, 975), (1410, 880)])
+ S['b_head'] = b.ellipse(1585, 492, 168, 146, rot=-8)
+ S['b_muz'] = b.ellipse(1416, 566, 92, 56, rot=-10)
+ S['b_earL'] = b.ellipse(1492, 370, 40, 38); S['b_earR'] = b.ellipse(1690, 384, 38, 36)
+ S['b_pawL'] = b.ellipse(1506, 742, 44, 34, rot=-25); S['b_pawR'] = b.ellipse(1556, 760, 40, 31, rot=18)
+ S['b_footL'] = b.ellipse(1522, 962, 64, 30, rot=-6); S['b_footR'] = b.ellipse(1772, 968, 56, 27, rot=8)
+ S['bear'] = np.maximum.reduce([S['b_body'], S['b_head'], S['b_muz'], S['b_earL'], S['b_earR'],
+ S['b_footL'], S['b_footR']])
+ # --- the kid
+ S['k_head'] = b.ellipse(1100, 652, 74, 70)
+ S['k_ear'] = b.ellipse(1028, 668, 14, 16)
+ S['k_hair'] = np.clip(S['k_head'] * smoothstep(636, 610, Y + 10 * np.sin((X - 1030) / 12.0)) +
+ b.ellipse(1032, 618, 24, 19, rot=-30) + b.ellipse(1170, 610, 23, 18, rot=25), 0, 1)
+ S['k_bunL'] = b.ellipse(1012, 596, 23, 17, rot=-35); S['k_bunR'] = b.ellipse(1190, 588, 22, 16, rot=30)
+ S['k_coat'] = b.poly([(1078, 728), (1134, 728), (1150, 760), (1180, 884), (1106, 892), (1030, 884), (1060, 760)])
+ S['k_armR'] = b.band([(1146, 752), (1186, 690), (1212, 622)], 24, 19) # far arm, lower hand
+ S['k_armL'] = b.band([(1128, 748), (1184, 664), (1226, 590)], 25, 19) # near arm, upper hand
+ S['k_bootL'] = b.poly([(1066, 920), (1086, 920), (1090, 948), (1094, 958), (1048, 960), (1046, 948), (1064, 940)])
+ S['k_bootR'] = b.poly([(1112, 918), (1132, 918), (1134, 946), (1150, 952), (1150, 962), (1110, 962)])
+ S['kid'] = np.maximum.reduce([S['k_head'], S['k_ear'], S['k_hair'], S['k_bunL'], S['k_bunR'], S['k_coat'],
+ S['k_armR'], S['k_armL'], b.band([(1080, 880), (1076, 930)], 12),
+ b.band([(1118, 884), (1124, 930)], 12), S['k_bootL'], S['k_bootR']])
+ # --- the umbrella
+ S['canopy'] = b.poly(canopy_pts(), smooth=False)
+ # --- the bus stop, the lamp, the sign
+ S['roof'] = b.poly([(512, 534), (908, 506), (914, 542), (508, 572)], smooth=False)
+ S['seat'] = b.poly([(584, 796), (838, 792), (840, 812), (582, 816)], smooth=False)
+ S['glass'] = b.poly([(572, 566), (864, 548), (866, 792), (570, 796)], smooth=False)
+ S['bench'] = S['seat']
+ S['sign'] = b.ellipse(455, 398, 46, 46)
+ S['lamp'] = b.poly([(152, 158), (198, 158), (206, 214), (144, 214)], smooth=False)
+ # --- snail and ducks
+ S['shell'] = b.ellipse(712, 762, 27, 25)
+ S['slug'] = b.band([(668, 788), (700, 789), (740, 787), (762, 776), (770, 766)], 13, 17)
+ S['snail'] = np.maximum(S['shell'], S['slug'])
+ self.ducks = [(290, 978, 1.3), (436, 988, 0.74), (522, 996, 0.66)] # (x, y, size)
+ S['ducks'] = np.zeros((H, W), np.float32)
+ S['duck_parts'] = []
+ for (x, y, s) in self.ducks:
+ body = b.poly([(x - 46 * s, y - 2 * s), (x - 30 * s, y - 24 * s), (x + 10 * s, y - 22 * s), (x + 36 * s, y - 10 * s),
+ (x + 52 * s, y - 30 * s), (x + 44 * s, y + 4 * s), (x + 20 * s, y + 14 * s), (x - 30 * s, y + 12 * s)])
+ head = b.ellipse(x - 34 * s, y - 40 * s, 19 * s, 18 * s)
+ bill = b.poly([(x - 50 * s, y - 42 * s), (x - 72 * s, y - 38 * s), (x - 70 * s, y - 31 * s), (x - 48 * s, y - 33 * s)])
+ S['duck_parts'].append((body, head, bill))
+ S['ducks'] = np.maximum.reduce([S['ducks'], body, head, bill])
+ # --- puddles
+ self.puddles = [(330, 990, 262, 40, 3), (1300, 1006, 250, 36, 4), (770, 948, 112, 17, 5), (1840, 1016, 70, 14, 6)]
+ S['puddles'] = np.maximum.reduce([b.blob(x, y, rx, ry, 0.06, sd) for x, y, rx, ry, sd in self.puddles])
+ # --- the rain shadow under the canopy (rain falls along RAIN_ANG)
+ E1, E2 = at(-CAN_R, 0), at(CAN_R, 0)
+ drop = lambda p: (p[0] + (975 - p[1]) * SLANT, 975)
+ S['dry'] = np.maximum(b.poly([tuple(E1), tuple(E2), drop(E2), drop(E1)], smooth=False), S['canopy'])
+ # --- bushes along the back
+ self.bush_list = [(150, 820, 150, 92, 'blue', 11), (360, 800, 170, 108, 'teal', 12), (560, 832, 140, 76, 'blue', 13),
+ (760, 812, 180, 100, 'teal', 14), (990, 826, 160, 90, 'blue', 15), (1190, 808, 190, 112, 'teal', 16),
+ (1420, 830, 160, 84, 'blue', 17), (1620, 806, 190, 112, 'teal', 18), (1790, 830, 120, 84, 'blue', 19),
+ (260, 868, 210, 56, 'teal', 20), (900, 872, 230, 52, 'teal', 21), (1500, 874, 260, 50, 'teal', 22)]
+ S['bushes'] = []
+ for (x, y, rx, ry, col, sd) in self.bush_list:
+ top = b.blob(x, y, rx, ry, 0.13, sd)
+ base = (Y < base_y(X)) * (Y > y - ry * 0.2) * (np.abs(X - x) < rx * 0.92)
+ S['bushes'].append((np.maximum(top, base.astype(np.float32)), col, sd))
+ S['front'] = np.maximum.reduce([S['bear'], S['kid'], S['canopy'], S['bench'], S['ducks'], S['snail'], S['glass']])
+ self.N = noise2d(H, W, 70, 3, 77)
+
+ # ============================================================ 2 blue colour blocks
+ def blue(self):
+ b, S, X, Y = self.b, self.S, self.XX, self.YY
+ keep_white = np.maximum.reduce([S['bear'], S['k_head'], S['k_hair'], S['k_bunL'], S['k_bunR'], S['k_ear'],
+ S['canopy'], S['lamp'], S['ducks']])
+ b.block((62, 50, 1860, 906), 'powder', rough=10, corner=30, avoid=keep_white, halo=3, seed=31)
+ # misty trees far behind
+ trees = [(262, 600, 92, 118), (370, 650, 62, 80), (800, 560, 96, 130), (905, 640, 58, 76), (1760, 600, 86, 110)]
+ far = np.zeros((H, W), np.float32)
+ for i, (x, y, rx, ry) in enumerate(trees):
+ far = np.maximum(far, b.blob(x, y, rx, ry, 0.22, 40 + i))
+ far = np.maximum(far, b.blob(x + rx * 0.35, y + ry * 0.25, rx * 0.6, ry * 0.55, 0.25, 60 + i))
+ far = np.maximum(far, b.band([(x + 4, y + ry * 0.5), (x - 2, 880)], 12, 20))
+ b.fill(far, '#a3c1e2', pressure=0.94, angle=-80, slip=0, loose=3, edge=9, dry_edge=0.65, mottle=0.12, streak=0.8,
+ avoid=keep_white, halo=3, seed=41)
+ for i, (x, y, rx, ry) in enumerate(trees):
+ b.crayon([[(x - rx * 0.5 + k * rx * 0.33, y - ry * 0.4 + 16 * (k % 2)), (x - rx * 0.46 + k * rx * 0.35, y + ry * 0.55)]
+ for k in range(4)], 'cornflower', width=7, pressure=0.55, dry=0.6, seed=50 + i)
+ b.crayon([[(x + 2, y + ry * 0.2), (x - 1, 880)]], 'slate', width=8, pressure=0.6, dry=0.4, seed=55 + i)
+ # bushes: one colour each, overlapping
+ front = S['front']
+ for (m, col, sd) in S['bushes']:
+ b.fill(m * (Y < base_y(X) + 4), col, pressure=0.95, angle=float(np.random.default_rng(sd).uniform(-75, -55)), loose=4,
+ edge=10, dry_edge=0.6, mottle=0.12, avoid=front, halo=3, seed=sd)
+ # shelter, sign, coat
+ b.fill(S['glass'], '#cfe0f0', pressure=0.95, angle=80, slip=0, loose=2, edge=6, medium='gouache', alpha=0.82,
+ seed=59)
+ b.fill(S['roof'], 'teal', pressure=0.95, angle=-4, seed=60)
+ b.fill(S['bench'] * (1 - S['snail']), 'cornflower', pressure=0.92, angle=-2, seed=61)
+ b.fill(S['sign'], 'cobalt', pressure=0.95, angle=-30, seed=62)
+ coat = np.maximum.reduce([S['k_coat'], S['k_armR'], S['k_armL']])
+ b.fill(coat, 'cobalt', pressure=0.95, angle=72, mottle=0.14, seed=63)
+ b.fill(coat * smoothstep(1110, 1160, X + (Y - 760) * 0.3), 'deep', pressure=0.85, angle=70, slip=0, seed=64)
+ # the bear's shadow side, pale and scratchy
+ shade = S['bear'] * smoothstep(1740, 1830, X + 0.25 * (Y - 500) + 30 * np.sin(Y / 50))
+ b.fill(shade, 'mist', pressure=0.7, angle=60, loose=6, edge=20, dry_edge=0.85, slip=0, seed=65)
+ under = S['bear'] * (blur(S['b_head'], 12) > 0.02) * (1 - S['b_head']) * (Y > 560) * (Y < 650)
+ b.fill(under, 'mist', pressure=0.75, angle=10, loose=6, edge=12, dry_edge=0.8, slip=0, seed=66)
+ b.fill(S['b_footL'] * (Y > 962) + S['b_footR'] * (Y > 966), 'mist', pressure=0.8, angle=0, seed=67)
+ # puddles and the wet pavement
+ b.fill(S['puddles'], 'blue', pressure=0.95, angle=4, loose=3, edge=10, dry_edge=0.6, avoid=S['ducks'], halo=2,
+ slip=0, seed=70)
+ for i, (x, y, rx, ry, sd) in enumerate(self.puddles):
+ b.fill(b.blob(x - rx * 0.1, y + ry * 0.25, rx * 0.75, ry * 0.45, 0.1, sd + 9) * (1 - S['ducks']), 'deep',
+ pressure=0.7, angle=2, slip=0, loose=3, seed=71 + i)
+ r = np.random.default_rng(9)
+ wet = []
+ for _ in range(26):
+ x, y = r.uniform(80, 1840), r.uniform(925, 1050)
+ L = r.uniform(40, 160)
+ wet.append([(x, y), (x + L, y + r.uniform(-3, 3))])
+ b.crayon(wet, 'powder', width=7, pressure=0.6, dry=0.6, seed=72)
+
+ # ============================================================ 3 the ink line
+ def ink(self):
+ b, S, X, Y = self.b, self.S, self.XX, self.YY
+ # bear: fur silhouette in scalloped tufts, muzzle smooth
+ b.fluff(S['b_head'] * (1 - S['b_muz']), 'ink', length=(18, 34), curl=0.55, width=4.2, seed=101)
+ b.fluff(S['b_body'], 'ink', length=(20, 38), curl=0.5, width=4.2,
+ avoid=np.maximum.reduce([blur(S['b_head'], 3) > 0.3, S['b_pawL'], S['b_pawR'],
+ S['b_footL'] > 0.5, S['b_footR'] > 0.5, S['kid'] > 0.5]).astype(np.float32), seed=102)
+ for e, (ex, ey, er) in ((S['b_earL'], (1492, 370, 40)), (S['b_earR'], (1690, 384, 38))):
+ t = np.linspace(np.deg2rad(150), np.deg2rad(400), 30)
+ b.ink(np.stack([ex + np.cos(t) * er, ey + np.sin(t) * er], 1), 4.4, seed=int(ex))
+ t = np.linspace(np.deg2rad(190), np.deg2rad(350), 14)
+ b.ink(np.stack([ex + np.cos(t) * er * 0.55, ey + 4 + np.sin(t) * er * 0.5], 1), 2.6, seed=int(ex) + 1)
+ t = np.linspace(np.deg2rad(95), np.deg2rad(335), 40)
+ mx = 1416 + np.cos(t) * 92 * np.cos(np.deg2rad(-10)) - np.sin(t) * 56 * np.sin(np.deg2rad(-10))
+ my = 566 + np.cos(t) * 92 * np.sin(np.deg2rad(-10)) + np.sin(t) * 56 * np.cos(np.deg2rad(-10))
+ b.ink(np.stack([mx, my], 1), 4.4, swell=0.35, seed=103)
+ b.dot(1340, 550, 21, 15, seed=104) # the dry nose
+ b.ink([(1350, 565), (1356, 584), (1378, 594), (1398, 584)], 2.8, seed=105)
+ b.eyes([(1474, 494), (1559, 489)], r=8.0, look=(-1.0, 1.0), seed=106)
+ b.ink([(1462, 466), (1476, 460), (1492, 463)], 2.6, seed=107) # worried little brows
+ b.ink([(1549, 459), (1564, 455), (1579, 459)], 2.6, seed=108)
+ b.fluff(S['b_pawL'], 'ink', length=(14, 22), curl=0.4, width=3.0, gaps=0.2, seed=109)
+ b.fluff(S['b_pawR'] * (1 - S['b_pawL']), 'ink', length=(14, 22), curl=0.4, width=3.0, gaps=0.2, seed=110)
+ b.ink([(1475, 610), (1462, 660), (1474, 712)], 3.0, seed=111) # arm against the chest
+ b.ink([(1610, 640), (1600, 700), (1580, 738)], 3.0, seed=112)
+ for f, sd in ((S['b_footL'], 113), (S['b_footR'], 114)):
+ b.fluff(f, 'ink', length=(16, 26), curl=0.4, width=3.0, gaps=0.15, seed=sd)
+ for (x, y) in ((1500, 960), (1520, 956), (1540, 958), (1752, 966), (1770, 962), (1788, 965)):
+ b.dot(x, y - 10, 4.5, 4.0, colour='slate', medium='crayon', seed=x)
+ # kid
+ b.head(1100, 652, 74, 70, width=5.2, ears=[(1028, 668, 14)], seed=120)
+ b.eyes([(1082, 660), (1126, 654)], r=7.2, look=(0.8, -0.6), seed=121)
+ b.smile(1108, 690, 18, 6, 2.8, tilt=-6, seed=122)
+ b.ink([(1101, 668), (1097, 677), (1104, 679)], 2.3, seed=123) # a little nose
+ b.outline([(1078, 728), (1134, 728), (1150, 760), (1180, 884), (1106, 892), (1030, 884), (1060, 760)], 4.6,
+ smooth=False, open_=0.6, seed=124)
+ b.ink([(1092, 730), (1102, 748), (1120, 730)], 3.0, seed=125) # collar
+ for (x, y) in ((1106, 776), (1110, 812), (1113, 848)):
+ b.dot(x, y, 3.6, seed=int(y))
+ b.ink([(1158, 764), (1198, 698), (1222, 630)], 4.2, swell=0.35, seed=127)
+ b.ink([(1116, 742), (1172, 662), (1214, 596)], 4.2, swell=0.35, seed=128)
+ b.ink([(1140, 760), (1176, 700)], 3.0, seed=129)
+ for (x, y) in ((1214, 618), (1228, 584)): # mitten hands on the shaft
+ b.outline(np.array([(x + 13 * np.cos(t), y + 11 * np.sin(t)) for t in np.linspace(0, 6.2, 12)]), 3.0,
+ open_=0.3, seed=int(x + y))
+ b.ink([(1084, 884), (1080, 922)], 6.0, dry=0.1, seed=130) # stick legs
+ b.ink([(1118, 888), (1124, 922)], 6.0, dry=0.1, seed=131)
+ # umbrella
+ b.outline(canopy_pts(), 4.8, smooth=False, open_=0.5, seed=140)
+ for ui in (-66, 0, 66):
+ b.ink(rib(ui), 2.8, seed=141 + ui)
+ tip = at(0, CAN_H + 18)
+ b.ink([at(0, CAN_H - 2), tip], 4.4, seed=142)
+ hook = [at(0, -10), at(0, -150), at(0, -232), at(-6, -250), at(-20, -254), at(-30, -244)]
+ b.ink(hook, 5.0, dry=0.15, seed=143)
+ # bus stop
+ b.outline([(512, 534), (908, 506), (914, 542), (508, 572)], 4.6, smooth=False, seed=150)
+ b.ink([(560, 566), (556, 930)], 6.4, swell=0.3, seed=151); b.ink([(872, 540), (876, 930)], 6.4, swell=0.3, seed=152)
+ b.outline([(584, 796), (838, 792), (840, 812), (582, 816)], 3.2, smooth=False, seed=153)
+ b.ink([(574, 568), (570, 796)], 2.4, seed=154); b.ink([(862, 550), (866, 792)], 2.4, seed=155)
+ for x in (604, 816):
+ b.ink([(x, 816), (x + 4, 912)], 3.6, seed=x + 1)
+ b.outline([(455 + 46 * np.cos(t), 398 + 46 * np.sin(t)) for t in np.linspace(0, 6.1, 24)], 3.6, seed=155)
+ b.ink([(455, 444), (458, 930)], 5.0, seed=156)
+ # snail, content on its dry bench
+ t = np.linspace(0.3, 4.6 * np.pi, 60)
+ rr = 26 * (1 - t / (5.2 * np.pi))
+ b.ink(np.stack([712 + rr * np.cos(t), 766 + rr * np.sin(t)], 1), 2.8, seed=157)
+ b.ink([(664, 792), (690, 795), (736, 794), (764, 786), (778, 770), (772, 758), (760, 760)], 3.0, seed=158)
+ b.ink([(768, 760), (760, 734)], 2.2, seed=159); b.ink([(776, 762), (786, 738)], 2.2, seed=160)
+ b.dot(759, 731, 3.2); b.dot(787, 735, 3.2)
+ b.smile(772, 774, 8, 3, 2.0, tilt=-20, seed=161)
+ # lamppost
+ b.outline([(152, 158), (198, 158), (206, 214), (144, 214)], 3.4, smooth=False, seed=161)
+ b.ink([(140, 160), (175, 136), (210, 160)], 3.6, seed=162)
+ b.ink([(175, 214), (173, 560), (176, 920)], 10.0, dry=0.35, swell=0.35, seed=163)
+ b.ink([(160, 920), (192, 920)], 8.0, seed=164)
+ # ducks
+ for (x, y, s) in self.ducks:
+ b.outline([(x - 46 * s, y - 2 * s), (x - 30 * s, y - 24 * s), (x + 10 * s, y - 22 * s), (x + 36 * s, y - 10 * s),
+ (x + 52 * s, y - 30 * s), (x + 44 * s, y + 4 * s), (x + 20 * s, y + 14 * s), (x - 30 * s, y + 12 * s)],
+ 3.0 * max(s, 0.7), open_=0.5, seed=int(x))
+ t = np.linspace(np.deg2rad(-30), np.deg2rad(250), 24)
+ b.ink(np.stack([x - 34 * s + np.cos(t) * 19 * s, y - 40 * s + np.sin(t) * 18 * s], 1), 2.8 * max(s, 0.7), seed=int(x) + 1)
+ b.dot(x - 38 * s, y - 44 * s, 3.2 * max(s, 0.6))
+ b.ink([(x - 6 * s, y - 8 * s), (x + 12 * s, y - 2 * s), (x + 24 * s, y - 10 * s)], 2.4 * max(s, 0.7), seed=int(x) + 2)
+ # puddle lips and the ground line
+ for (x, y, rx, ry, sd) in self.puddles:
+ t = np.linspace(np.deg2rad(10), np.deg2rad(170), 30)
+ b.ink(np.stack([x + np.cos(t) * rx * 0.98, y + np.sin(t) * ry * 0.95], 1), 3.0, dry=0.3, seed=sd + 200)
+ r = np.random.default_rng(5)
+ for _ in range(40):
+ x, y = r.uniform(80, 1840), r.uniform(915, 1060)
+ if S['puddles'][int(y), int(x)] > 0.3 or S['front'][int(y), int(x)] > 0.3: continue
+ L = r.uniform(8, 26)
+ b.ink([(x, y), (x + L, y + r.uniform(-2, 2))], r.uniform(1.8, 3.2), dry=0.4, seed=int(x * 7))
+
+ # ============================================================ 4 dark scribbled masses
+ def dark(self):
+ b, S, X, Y = self.b, self.S, self.XX, self.YY
+ front = S['front']
+ for i, (m, col, sd) in enumerate(S['bushes']):
+ r = np.random.default_rng(sd + 500)
+ rows = np.flatnonzero(m.max(1) > 0.5)
+ y0, y1 = rows[0], rows[-1]
+ g = (Y - y0) / max(1, y1 - y0) + 0.9 * (self.N - 0.5) + 0.06 * np.sin(X / 9.0 + sd)
+ dark = m * (g > (0.66 if col == 'teal' else 0.9)) * (1 - front) * (Y < base_y(X) + 4)
+ b.scribble(dark.astype(np.float32), width=5.2, spacing=4.6 if col == 'teal' else 6.0,
+ angle=r.uniform(68, 82) * r.choice([-1, 1]) % 180, colour=INK if col == 'teal' else 'navy',
+ dry=0.5, overshoot=10, clip=1 - front, seed=sd + 1)
+ xs = np.flatnonzero(m.max(0) > 0.5)
+ b.blades(xs[0] + 10, xs[-1] - 10, lambda x: float(base_y(x)) + 8, n=int(len(xs) / 24), height=(40, 120 if col == 'teal' else 80),
+ lean=r.uniform(-8, 8), width=4.6, dry=0.3, clip=1 - front, seed=sd + 2)
+ b.blades(70, 1850, lambda x: float(base_y(x)) + 6, n=24, height=(20, 60), width=3.4, clip=1 - front, seed=520)
+ # shelter roof underside, boots
+ b.scribble(S['roof'] * (Y > 542 - (X - 508) * 0.07), width=3.6, spacing=4.0, angle=-6, dry=0.4, seed=530)
+ for k in ('k_bootL', 'k_bootR'):
+ b.fill(S[k], '#22232b', pressure=0.95, angle=10, slip=0, loose=1.5, edge=3, lanes=0, medium='gouache', seed=533)
+ b.scribble(S[k], width=4.0, spacing=3.6, angle=20, dry=0.5, overshoot=2, seed=531 if k[-1] == 'L' else 532)
+ # hatch: coat shadow, bench shadow, bear fur shadow
+ b.hatch(S['k_coat'] * smoothstep(1120, 1150, X + (Y - 760) * 0.25), angle=74, spacing=7, length=(16, 34),
+ width=2.2, dry=0.4, seed=540)
+ b.hatch(S['seat'] * (X > 700) * (1 - S['snail']), angle=-80, spacing=9, length=(8, 12), width=2.0, seed=541)
+ fur = S['bear'] * smoothstep(1730, 1800, X + 0.3 * (Y - 600)) * (1 - S['b_footR'])
+ b.hatch(fur, angle=-70, spacing=16, length=(16, 30), width=3.0, colour='cornflower', medium='crayon',
+ dry=0.55, bend=0.25, density=0.7, seed=542)
+ b.hatch(S['b_body'] * (Y > 900) * (1 - np.maximum(S['b_footL'], S['b_footR'])), angle=-20, spacing=16,
+ length=(16, 28), width=3.0, colour='cornflower', medium='crayon', dry=0.55, bend=0.25, density=0.6, seed=543)
+ b.hatch(S['b_head'] * smoothstep(1700, 1745, X), angle=-60, spacing=14, length=(12, 22), width=2.6,
+ colour='cornflower', medium='crayon', dry=0.55, bend=0.3, density=0.7, seed=544)
+
+ # ============================================================ 5 coral accents and cheeks
+ def accents(self):
+ b, S, X, Y = self.b, self.S, self.XX, self.YY
+ b.fill(S['canopy'], 'coral', pressure=0.96, angle=-30, loose=3, mottle=0.12, medium='crayon', seed=600)
+ rshade = S['canopy'] * smoothstep(40, 110, (X - RC[0]) * PX[0] + (Y - RC[1]) * PX[1])
+ b.hatch(rshade, angle=60, spacing=6, length=(14, 30), width=3.0, colour='tomato', medium='crayon', dry=0.4, seed=601)
+ hair = np.maximum.reduce([S['k_hair'], S['k_bunL'], S['k_bunR']])
+ b.fill(hair, 'coral', pressure=0.95, angle=20, loose=2.5, seed=602)
+ b.crayon([[(1036 + k * 15, 596 + 6 * (k % 3)), (1042 + k * 15, 626 + 4 * (k % 2))] for k in range(10)],
+ 'tomato', width=4, pressure=0.85, dry=0.3, seed=603)
+ for (x, y) in ((1012, 596), (1190, 588)): # the bunches
+ b.crayon([[(x - 12, y - 6 + k * 5), (x + 12, y - 4 + k * 5)] for k in range(3)], 'tomato', width=3,
+ pressure=0.8, seed=int(x))
+ b.ink([(1036, 626), (1052, 612), (1080, 604), (1110, 598), (1140, 600), (1166, 614)], 2.6, dry=0.3, seed=604)
+ b.ink([(1012, 584), (996, 594), (1004, 610)], 2.4, seed=605); b.ink([(1188, 576), (1206, 588), (1196, 602)], 2.4, seed=606)
+ b.fill(S['k_head'] * (1 - hair) * (Y > 612), 'flesh', pressure=0.5, angle=30, loose=2, edge=6, dry_edge=0.5,
+ lanes=0, seed=607)
+ b.blush(1060, 686, 16, seed=608); b.blush(1144, 678, 15, seed=609)
+ b.freckles(1101, 672, 4, 13, seed=610)
+ b.blush(1503, 533, 24, seed=611); b.blush(1636, 522, 22, seed=612)
+ b.blush(1336, 598, 9, seed=613, density=0.6)
+ # flowers in the bushes, duck bills, snail shell, lamp glow
+ r = np.random.default_rng(620)
+ for (fx, fy, k) in ((120, 812, 3), (395, 770, 2), (690, 842, 2), (1000, 800, 3), (1340, 836, 2)):
+ for j in range(k):
+ x, y = fx + r.uniform(-28, 28), fy + r.uniform(-18, 18)
+ if S['front'][int(y), int(x)] > 0.2: continue
+ b.ink([(x, y + 4), (x + r.uniform(-6, 6), y + r.uniform(30, 50))], 2.2, seed=int(x) + j)
+ b.flower(x, y, r.uniform(7.5, 10.5), 'coral', seed=int(x * 3) + j)
+ for (body, head, bill) in S['duck_parts']:
+ b.fill(bill, 'mustard', pressure=0.95, slip=0, loose=1, edge=3, lanes=0, medium='gouache', seed=630)
+ b.fill(S['shell'], 'mustard', pressure=0.9, angle=40, loose=2, seed=631)
+ b.fill(S['lamp'], 'butter', pressure=0.9, angle=0, loose=2, seed=632)
+ b.crayon([[(175 + np.cos(a) * 44, 186 + np.sin(a) * 44), (175 + np.cos(a) * 64, 186 + np.sin(a) * 64)]
+ for a in np.deg2rad([200, 235, 270, 305, 340])], 'mustard', width=5, pressure=0.8, seed=633)
+
+ # ============================================================ 6 chalky whites
+ def chalk(self):
+ b, S, X, Y = self.b, self.S, self.XX, self.YY
+ for i, (x, y, w, h) in enumerate([(380, 160, 300, 110), (1120, 128, 250, 92), (1690, 178, 240, 92)]):
+ b.chalk(b.cloud(x, y, w, h, 5, seed=700 + i), pressure=0.82, angle=-6, seed=700 + i)
+ b.chalk([[(x - w * 0.35, y + h * 0.3), (x + w * 0.3, y + h * 0.32)]], width=8, pressure=0.6, seed=710 + i)
+ b.fluff(S['bear'] * (1 - S['kid']) * (1 - S['canopy']), 'chalk', length=(18, 30), width=5.5, reach=(0.35, 0.75),
+ seed=720)
+ b.chalk([[(1222, 380), (1262, 352), (1300, 338)], [(1240, 404), (1272, 384)]], width=6, pressure=0.75, seed=721)
+ b.chalk([[(1384, 600), (1410, 596)]], width=4, pressure=0.8, seed=722)
+ for (x, y, rx, ry, sd) in self.puddles:
+ r = np.random.default_rng(sd)
+ for k in range(2 if rx < 120 else 4):
+ cx, cy = x + r.uniform(-0.6, 0.6) * rx, y + r.uniform(-0.3, 0.2) * ry
+ if S['ducks'][int(cy), int(cx)] > 0.3: continue
+ b.ripples(cx, cy, r.uniform(14, 30), r.uniform(4, 6), rings=2, width=2.6, seed=sd * 10 + k)
+ for (x, y, s) in self.ducks:
+ b.ripples(x, y + 14 * s, 60 * s, 9 * s, rings=2, width=2.6, seed=int(x) + 3)
+ b.chalk([[(620, 600), (660, 560)], [(640, 640), (700, 580)], [(780, 620), (820, 580)]], width=5,
+ pressure=0.55, seed=730) # glass glints in the shelter
+ # a tiny white bus on the round sign
+ b.chalk(b.poly([(428, 382), (478, 382), (484, 408), (426, 410)], smooth=False), pressure=0.95, angle=0,
+ edge=2, dry_edge=0.3, loose=1, seed=731)
+ b.dot(440, 412, 4.6, colour='navy', medium='gouache'); b.dot(470, 412, 4.6, colour='navy', medium='gouache')
+ for x in (436, 452, 468):
+ b.dot(x, 391, 4.0, 3.4, colour='cobalt', medium='gouache')
+ b.chalk([[(1092, 762), (1088, 860)]], width=6, pressure=0.6, seed=732) # coat sheen
+ b.chalk([[(1200, 960), (1260, 962)], [(1330, 1000), (1420, 1002)]], width=5, pressure=0.6, seed=733)
+
+ # ============================================================ 7 rain, splashes, speckle
+ def rain(self):
+ b, S, X, Y = self.b, self.S, self.XX, self.YY
+ sky = (b.rect(70, 60, 1850, 1060, rough=6, seed=31) > 0.5).astype(np.float32)
+ dry = np.maximum(S['dry'], S['canopy'])
+ b.rain(sky * (Y < 905), n=560, angle=RAIN_ANG, length=(10, 40), width=(1.6, 3.0), colour='deep', avoid=dry, seed=800)
+ b.rain(sky * (Y < 905), n=260, angle=RAIN_ANG, length=(10, 30), width=(1.6, 2.6), colour='cornflower', avoid=dry, seed=804)
+ b.rain(sky * (Y < 905), n=240, angle=RAIN_ANG, length=(12, 28), width=(1.8, 3.0), colour='chalk', avoid=dry, seed=801)
+ b.rain(S['bear'] * (1 - S['dry']), n=45, angle=RAIN_ANG, length=(12, 24), width=(1.6, 2.4), colour='powder',
+ avoid=dry, seed=802)
+ b.rain((80, 905, 1840, 1050), n=140, angle=RAIN_ANG, length=(10, 22), width=(1.5, 2.4), colour='cornflower',
+ avoid=dry, seed=803)
+ r = np.random.default_rng(810)
+ for (x, y) in [(1060, 592), (1100, 584), (1140, 590), (1010, 580), (1192, 572), (1080, 588)]: # on her hair
+ b.splash(x, y, 15, 'chalk', n=5, width=2.6, seed=int(x))
+ for (x, y) in [(1004, 612), (1200, 604), (1036, 640)]: # drips off her bunches
+ b.ink([(x, y), (x + 1, y + 12)], 3.0, colour='deep', dry=0.2, seed=int(x) + 3)
+ b.dot(x + 2, y + 24, 2.6, 3.5, colour='deep', medium='crayon')
+ for (x, y) in [(1520, 352), (1600, 344), (1680, 360), (1470, 360), (1700, 372), (1750, 420)]: # bear's head
+ b.splash(x, y, 13, 'deep', n=4, width=2.2, seed=int(x) + 1)
+ for u in (-110, -60, -10, 40, 90): # on the canopy
+ p = at(u, CAN_H * np.sqrt(max(0.05, 1 - (u / CAN_R) ** 2)) + 2)
+ b.splash(p[0], p[1], 12, 'chalk', n=4, width=2.4, up=-90 + np.degrees(TILT) * 0.6, seed=int(u) + 900)
+ for u in (-130, -80, 30, 82, 130): # drips off the rim
+ p = at(u, -10)
+ b.ink([(p[0], p[1] + 6), (p[0] + 1.5, p[1] + 16)], 3.2, colour='deep', dry=0.2, seed=int(u) + 950)
+ b.dot(p[0] + 3, p[1] + 28, 2.6, 3.4, colour='deep', medium='crayon')
+ for (x, y) in [(1692, 336), (1500, 335), (1066, 668), (1150, 696)]: # drops on ear tips and cheeks
+ b.dot(x, y + 18, 3.0, 4.2, colour='deep', medium='crayon')
+ b.dot(x - 1, y + 16, 1.0, colour='chalk', medium='chalk')
+ for (x, y, rx, ry, sd) in self.puddles:
+ for k in range(3):
+ xx = x + r.uniform(-0.7, 0.7) * rx
+ b.splash(xx, y + r.uniform(-0.3, 0.3) * ry, 9, 'chalk', n=3, width=2.0, seed=sd * 7 + k)
+ # coral reflection of the umbrella in the puddle
+ refl = []
+ for j, (y, x0, x1) in enumerate([(990, 1222, 1392), (998, 1236, 1380), (1006, 1258, 1362), (1014, 1282, 1338)]):
+ cuts = np.sort(r.uniform(x0, x1, 2))
+ for a, c in ((x0, cuts[0] - 5), (cuts[0] + 4, cuts[1] - 5), (cuts[1] + 4, x1)):
+ if c - a > 8: refl.append([(a, y + r.uniform(-1, 1)), (c, y + r.uniform(-1, 1))])
+ b.crayon(refl, 'coral', width=6, pressure=0.8, dry=0.45, alpha=0.8, medium='gouache', seed=820)
+ b.crayon([[(1300, 1016), (1300, 1034)]], 'ink', width=3, pressure=0.6, dry=0.5, seed=821)
+ b.spatter(sky, 'ink', n=55, size=(0.8, 3.6), avoid=np.maximum(S['bear'], S['kid']), seed=830)
+ b.spatter(sky, 'chalk', n=160, size=(0.8, 3.2), avoid=np.maximum(S['bear'], S['canopy']), seed=831)
+ b.speckle(sky, 'chalk', n=1400, size=(0.5, 1.4), seed=832)
+ b.speckle((60, 900, 1860, 1070), 'cornflower', n=500, size=(0.5, 1.5), seed=833)
+ b.speckle(sky * (Y > 700), 'navy', n=500, size=(0.5, 1.3), seed=834)
+
+ def finish(self):
+ b = self.b
+ b.folio(104, 1046, '14', 19); b.folio(1816, 1046, '15', 19)
+ b.printed(1.0, gutter=GUTTER)
+
+
+PHASES = ('blue', 'ink', 'dark', 'accents', 'chalk', 'rain')
+
+
+def main():
+ out = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith('--') else 'bluebook_shared_umbrella.jpg'
+ stages = sys.argv[sys.argv.index('--stages') + 1] if '--stages' in sys.argv else None
+ T0 = time.time()
+ tick = (lambda name: print(f'{name:10s} {time.time() - T0:5.1f}s')) if os.environ.get('BB_TIMING') else (lambda n: None)
+ b = BlueBook(W, H, seed=21, keep_stages=bool(stages), stages_dir=stages)
+ b.paper()
+ b.stage('paper')
+ sp = Spread(b)
+ tick('setup')
+ for ph in PHASES:
+ getattr(sp, ph)()
+ tick(ph)
+ b.stage(ph)
+ sp.finish()
+ b.save(out, stages_dir=stages)
+ tick('saved')
+ print('saved', out)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/examples/drawing_bluebook_shared_umbrella.gif b/examples/drawing_bluebook_shared_umbrella.gif
new file mode 100644
index 0000000..10e42a6
Binary files /dev/null and b/examples/drawing_bluebook_shared_umbrella.gif differ
diff --git a/lib/bluebook.py b/lib/bluebook.py
new file mode 100644
index 0000000..21dc35f
--- /dev/null
+++ b/lib/bluebook.py
@@ -0,0 +1,992 @@
+"""bluebook — 蓝调绘本 / Blue Picture Book: a soft-blue, limited-palette modern picture-book page (numpy + Pillow only).
+
+The look of a contemporary children's picture book drawn by hand and printed: a mostly blue world (powder blue,
+cornflower, a deep teal-blue) on white paper, a loose black ink line that is scratchy, broken and dry, flat-ish
+colour laid with dry crayon / pastel / gouache so the tooth of the paper shows through, chalky white marks over the
+blue, speckle and spatter, a few small accents (coral, a flesh-pink cheek, a touch of mustard) and charming round
+characters. Nothing here is a filter on flat shapes: every mark is laid by a modelled tool on a modelled paper, in
+the order an illustrator works (colour blocks, ink line, dark scribbled masses, accents, chalk, weather, print).
+
+Physical model
+ paper Cartridge / pastel paper. Its tooth is a height field (1 px grain, 2-5 px bumps and a softer 9 px
+ undulation) histogram-equalised to a uniform 0..1, so "the tool reaches the tooth where tooth >
+ 1 - contact" turns a contact pressure straight into a coverage fraction. A dry tool dragged across
+ the sheet rides from peak to peak, so the bare pits it skips are drawn out into short streaks along
+ the stroke: the tooth is pre-averaged along 8 directions (`TD`) and every mark reads the version that
+ matches its own direction. The bare paper is a warm white with a faint tooth.
+ ink line A brush / ink-pencil line. The drawn path is re-sampled and pushed sideways by a slow hand wobble and
+ a small tremor. Pressure lands fast and lifts slower (taper), and swells and thins along the way
+ (thick-thin). The tip is a bundle of hairs that carry different loads, so across the line there are
+ lanes; the load runs out along the stroke (`dry`), and where contact x load falls below the tooth the
+ ink breaks into dry white streaks that run along the stroke. The edge of the line wanders with the
+ tooth, so it is never vector-clean. Closed shapes are not closed: `outline()` draws a contour as one
+ to three strokes that stop short or run past the join on their tangent, and now and then goes over
+ part of a stroke again a couple of px off (a sketchy double line). Every pixel of a mark knows
+ its arc length and its offset across the mark (segment indices are rasterised by Pillow, then
+ projected exactly), so taper, swell, lanes and drying are per pixel.
+ scribble Dark masses (bush shadows, trunks, boots, hair shadow) are quick back-and-forth scribbles: zigzag
+ polylines inside the mask along one direction, sharp V turns that over- or under-shoot the outline,
+ a wrist-sized patch at a time, the same dry ink model, so white tooth and gaps between passes stay
+ in the black. `hatch()` lays separate quick parallel flicks; `blades()` draws tapered leaf / grass
+ blades.
+ colour Dry media (crayon, pastel, dry gouache) laid AFTER a rough idea of the shape, not inside the line:
+ the region slips 1.5-3.5 px one way (misregistration), its edge is re-found on a blurred copy with a
+ threshold that wanders, contact pressure is mottled at low frequency, the area is laid in parallel
+ stroke lanes of slightly different pressure, and near the edge the pressure falls so the border
+ breaks up dry. Coverage comes from the directional tooth, so white specks of paper show through and
+ streak along the stroke. Wax / pastel is semi-opaque: new = lerp(under, colour * under^0.55,
+ coverage) -- over white it is the colour, over the ink it stays dark, a second blue over a blue goes
+ deeper. `block()` is the big background colour field: a rough-sided block that does not reach the
+ edge of the page, whose borders are brushed along their own direction and dragged dry.
+ chalk White pastel / chalk / white gouache is opaque and dry: it is laid only on the tooth peaks, with
+ long streaks, over the blue (clouds, fur on the silhouette, ripples, highlights, snow-like specks).
+ spatter Flicked paint: drops with a power-law size distribution, slightly elongated, with satellite
+ droplets (`spatter()`); `speckle()` is finer dust; `rain()` is short dry strokes; `splash()` is the
+ little crown where a drop hits; `ripples()` are broken rings on a puddle.
+ characters Round-headed picture-book people and animals: `head()` an open contour with optional ears,
+ `eyes()` ink dots with a white glint, `smile()`, `blush()` a stippled cheek of pink dots, `freckles()`,
+ `fluff()` scribbly fur -- the silhouette drawn as short scalloped ink tufts, or white chalk tufts that
+ cross the edge into the background, plus little curls inside.
+ print The page is reproduced in a book (`printed()`): a slight print softness, blacks that lift to a deep
+ ink, a fine paper speck, an optional centre gutter (the fold of a spread: a soft shadow, a fine crease
+ and a hairline of light), and tiny page numbers (`folio()`).
+
+API (canvas px; angles in degrees, 0 = to the right, 90 = down; colours are names in COLOURS or '#rrggbb')
+ paper BlueBook(W, H, seed, keep_stages, stages_dir); paper(tone, tooth, drag)
+ shapes ellipse(cx, cy, rx, ry, rot), poly(pts, smooth), blob(cx, cy, rx, ry, rough, seed, rot), band(path, w0, w1),
+ cloud(cx, cy, w, h, bumps, seed), rect(x0, y0, x1, y1, rough, corner, seed) -> canvas-size float masks
+ colour block(mask | box, colour, ...); fill(mask, colour, pressure, angle, slip, loose, edge, dry_edge, medium,
+ avoid, halo, passes, clip); crayon(paths, colour, width, pressure)
+ ink ink(path, width, dry, taper, wobble, ...); outline(pts, width, closed, open_, overshoot, twice);
+ scribble(mask, width, spacing, angle, reach, dry); hatch(mask, angle, spacing, length, width);
+ blades(x0, x1, y, n, height, lean, width); dot(x, y, r)
+ white chalk(mask | paths, width, pressure, angle); ripples(cx, cy, rx, ry, rings, medium)
+ weather rain(region, n, angle, length, colour, medium, avoid); splash(x, y, size, colour, medium);
+ spatter(region, colour, n, size, medium); speckle(region, colour, n, size)
+ figures head(cx, cy, rx, ry, ears); eyes(pts, r, look); smile(x, y, w, depth); blush(cx, cy, r); freckles(cx, cy, n);
+ fluff(mask, medium, every, length, curls, avoid); flower(x, y, r, colour)
+ finish printed(amount, gutter); folio(x, y, text, size); render(); composite(); stage(name); save(path, stages_dir)
+
+ import sys; sys.path.insert(0, 'lib')
+ from bluebook import BlueBook
+ b = BlueBook(1920, 1080, seed=4)
+ b.paper()
+ bear = b.ellipse(1200, 620, 220, 240)
+ b.block((60, 50, 1860, 900), 'powder', avoid=bear) # the blue field, painted round the bear
+ b.stage('blue')
+ b.fluff(bear, 'ink') # scalloped fur line
+ b.eyes([(1150, 560), (1250, 556)], r=7)
+ b.blush(1120, 610, 22); b.blush(1290, 604, 22)
+ b.fluff(bear, 'chalk') # white tufts across the edge
+ b.rain((60, 50, 1860, 900), n=400, avoid=bear)
+ b.printed(gutter=960); b.save('bluebook.jpg')
+"""
+import io
+import os
+import numpy as np
+from PIL import Image, ImageDraw
+from core import blur, fbm1d, noise2d, smoothstep, spline, polygon_mask, blob_pts, load_font, text_mask
+from core import shift as _shift
+
+
+COLOURS = {
+ 'paper': '#fbfaf5', 'chalk': '#fbfbf6', 'ink': '#17181e',
+ 'mist': '#d6e4f1', 'powder': '#b9d2ea', 'cornflower': '#8fb3dc', 'blue': '#5b8fcb', 'cobalt': '#3e6fb0',
+ 'deep': '#2f5c91', 'teal': '#2b5d72', 'navy': '#1d3450', 'slate': '#6f8fae',
+ 'coral': '#e8574a', 'tomato': '#d9483c', 'cheek': '#ee7f78', 'flesh': '#f7dfd3', 'freckle': '#9a5446',
+ 'mustard': '#e7b34c', 'butter': '#f2d488',
+}
+INK = COLOURS['ink']
+NB = 8 # directions of the dragged tooth
+
+
+def hexc(c):
+ """'#rrggbb', a COLOURS name or an RGB triple -> float32 RGB 0..1"""
+ if not isinstance(c, str): return np.asarray(c, np.float32)
+ h = COLOURS.get(c, c).lstrip('#')
+ return np.array([int(h[i:i + 2], 16) for i in (0, 2, 4)], np.float32) / 255
+
+
+def _closed_spline(P, per=8):
+ P = np.asarray(P, np.float32)
+ n = len(P)
+ ext = np.vstack([P[-1:], P, P[:2]])
+ out = []
+ for i in range(1, n + 1):
+ p0, p1, p2, p3 = ext[i - 1], ext[i], ext[i + 1], ext[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(out[0])
+ return np.array(out, np.float32)
+
+
+def _resample(P, step):
+ P = np.asarray(P, np.float32)
+ 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(np.ceil(s[-1] / step)) + 1)
+ ss = np.linspace(0, s[-1], n)
+ return np.stack([np.interp(ss, s, P[:, 0]), np.interp(ss, s, P[:, 1])], 1).astype(np.float32)
+
+
+def _equalise(t, bins=1024):
+ hist, edges = np.histogram(t, bins)
+ cdf = np.cumsum(hist).astype(np.float32); cdf /= cdf[-1]
+ return np.interp(t, edges[1:], cdf).astype(np.float32)
+
+
+class BlueBook:
+ COLOURS = COLOURS
+
+ def __init__(self, W=1920, H=1080, seed=0, keep_stages=True, stages_dir=None):
+ if W * H > 4096 * 4096: raise ValueError('canvas larger than 4096 x 4096')
+ self.W, self.H, self.seed = W, H, seed
+ self.rng = np.random.default_rng(seed)
+ self.keep_stages, self.stages_dir = keep_stages, stages_dir
+ self.stages, self._n_stages = [], 0
+ self.C = np.empty((H, W, 3), np.float32)
+ self.C[:] = hexc('paper')
+ self.K = np.zeros((H, W), np.float32) # ink already on the page
+ self.T = None
+ self.TD = None
+ self.print_amt, self.gutter_x = 0.0, None
+
+ def _r(self, seed=None):
+ return np.random.default_rng(int(self.rng.integers(1 << 30)) if seed is None else seed)
+
+ # ================================================================== paper
+ def paper(self, tone='paper', tooth=1.0, drag=7):
+ """cartridge paper: an equalised tooth (grain, bumps, undulation) and its 8 dragged versions"""
+ H, W = self.H, self.W
+ r = np.random.default_rng(self.seed + 101)
+ z = lambda a: (a - a.mean()) / (a.std() + 1e-6)
+ g1 = blur(r.random((H, W)).astype(np.float32), 0.7)
+ g2 = noise2d(H, W, 2.6, 2, self.seed + 102)
+ g3 = noise2d(H, W, 9.0, 2, self.seed + 103)
+ T = _equalise(0.52 * z(g1) + 0.36 * z(g2) + 0.22 * z(g3))
+ T = T * tooth + 0.5 * (1 - tooth)
+ self.T = T
+ TD = np.empty((NB, H, W), np.float32)
+ ks = np.arange(-drag, drag + 1)
+ wk = 1.0 - np.abs(ks) / (drag + 1.0)
+ for b in range(NB):
+ a = np.pi * b / NB
+ acc = np.zeros((H, W), np.float32)
+ for k, w in zip(ks, wk):
+ acc += w * np.roll(T, (int(round(k * np.sin(a))), int(round(k * np.cos(a)))), axis=(0, 1))
+ TD[b] = _equalise(0.32 * T + 0.68 * acc / wk.sum())
+ self.TD = TD
+ mot = noise2d(H, W, 260, 2, self.seed + 104) - 0.5
+ self.C[:] = hexc(tone) * (1 - 0.012 * (T[..., None] - 0.5) + 0.008 * mot[..., None])
+
+ def _need(self):
+ if self.T is None: self.paper()
+
+ def _bin(self, ang_rad):
+ return (np.round((np.mod(ang_rad, np.pi)) / np.pi * NB).astype(np.int32)) % NB
+
+ def _tooth_region(self, sl, angle):
+ """dragged tooth for a region: angle (deg) a number or a canvas-size field"""
+ if np.ndim(angle) == 0:
+ return self.TD[int(self._bin(np.deg2rad(angle)))][sl]
+ bins = self._bin(np.deg2rad(angle[sl]))
+ sub = self.TD[:, sl[0], sl[1]]
+ return np.take_along_axis(sub, bins[None], 0)[0]
+
+ # ================================================================== shapes (canvas-size masks)
+ def _grid(self, sl):
+ ys = np.arange(sl[0].start, sl[0].stop, dtype=np.float32)[:, None]
+ xs = np.arange(sl[1].start, sl[1].stop, dtype=np.float32)[None, :]
+ return xs, ys
+
+ def _clip_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))), min(self.H, int(np.ceil(y1)))
+ if x1 <= x0 or y1 <= y0: return None
+ return (slice(y0, y1), slice(x0, x1))
+
+ def ellipse(self, cx, cy, rx, ry=None, rot=0.0):
+ ry = rx if ry is None else ry
+ R = max(rx, ry) + 3
+ out = np.zeros((self.H, self.W), np.float32)
+ sl = self._clip_box(cx - R, cy - R, cx + R + 1, cy + R + 1)
+ if sl is None: return out
+ X, Y = self._grid(sl)
+ X, Y = X - cx, Y - cy
+ if rot:
+ a = np.deg2rad(rot); c, s = np.cos(a), np.sin(a)
+ X, Y = X * c + Y * s, -X * s + Y * c
+ d = np.sqrt((X / rx) ** 2 + (Y / ry) ** 2)
+ e = 1.0 / max(2.0, min(rx, ry))
+ out[sl] = smoothstep(1 + e, 1 - e, d)
+ return out
+
+ def poly(self, pts, smooth=True, per=8):
+ pts = np.asarray(pts, np.float32)
+ if smooth and len(pts) > 2: pts = _closed_spline(pts, per)
+ return polygon_mask(self.H, self.W, pts, ss=2)
+
+ def blob(self, cx, cy, rx, ry=None, rough=0.08, seed=0, rot=0.0):
+ return self.poly(blob_pts(cx, cy, rx, rx if ry is None else ry, rough, 120, seed, np.deg2rad(rot)), smooth=False)
+
+ @staticmethod
+ def tube(path, w0, w1=None, per=8):
+ """outline polygon of a thick path (width w0 -> w1), rounded ends"""
+ Q = spline(np.asarray(path, np.float32), per) if len(path) > 2 else np.asarray(path, np.float32)
+ w1 = w0 if w1 is None else w1
+ d = np.gradient(Q, axis=0); d /= np.linalg.norm(d, axis=1, keepdims=True) + 1e-6
+ nrm = np.stack([-d[:, 1], d[:, 0]], 1)
+ hw = np.linspace(w0, w1, len(Q))[:, None] / 2
+ L, R = Q + nrm * hw, Q - nrm * hw
+ a0 = np.arctan2(nrm[0, 1], nrm[0, 0]); a1 = np.arctan2(nrm[-1, 1], nrm[-1, 0])
+ cap1 = [Q[-1] + hw[-1] * np.array([np.cos(a1 - t), np.sin(a1 - t)]) for t in np.linspace(0, np.pi, 9)[1:-1]]
+ cap0 = [Q[0] + hw[0] * np.array([np.cos(a0 + np.pi - t), np.sin(a0 + np.pi - t)]) for t in np.linspace(0, np.pi, 9)[1:-1]]
+ return np.vstack([L, np.array(cap1).reshape(-1, 2), R[::-1], np.array(cap0).reshape(-1, 2)]).astype(np.float32)
+
+ def band(self, path, w0, w1=None):
+ return self.poly(self.tube(path, w0, w1), smooth=False)
+
+ def cloud(self, cx, cy, w, h, bumps=5, seed=0):
+ """a cumulus outline: a flat-ish bottom and a row of rounded bumps on top"""
+ r = np.random.default_rng(seed)
+ m = self.ellipse(cx, cy + h * 0.18, w * 0.5, h * 0.32)
+ xs = np.linspace(cx - w * 0.36, cx + w * 0.36, bumps)
+ for i, x in enumerate(xs):
+ k = 1 - abs(i - (bumps - 1) / 2) / ((bumps - 1) / 2 + 1e-6)
+ rr = h * (0.26 + 0.24 * k) * r.uniform(0.85, 1.15)
+ m = np.maximum(m, self.ellipse(x, cy + h * 0.12 - rr * 0.55, rr, rr * 0.92))
+ return m
+
+ def rect(self, x0, y0, x1, y1, rough=8.0, corner=24.0, seed=0):
+ """a hand-cut / brushed rectangle: wobbly sides, softly rounded corners"""
+ r = np.random.default_rng(seed)
+ pts = []
+ sides = [((x0 + corner, y0), (x1 - corner, y0)), ((x1, y0 + corner), (x1, y1 - corner)),
+ ((x1 - corner, y1), (x0 + corner, y1)), ((x0, y1 - corner), (x0, y0 + corner))]
+ for (a, b) in sides:
+ a, b = np.array(a, np.float32), np.array(b, np.float32)
+ L = float(np.hypot(*(b - a)))
+ n = max(8, int(L / 6))
+ t = np.linspace(0, 1, n)[:, None]
+ d = (b - a) / max(L, 1e-3); nrm = np.array([d[1], -d[0]], np.float32) # outward
+ off = fbm1d(n, max(4, n / 7), 4, int(r.integers(1 << 30)))[:, None] * rough
+ pts.append(a + (b - a) * t + nrm * off)
+ return polygon_mask(self.H, self.W, _closed_spline(np.vstack(pts)[::3], 6), ss=2)
+
+ def _bbox(self, m, pad=0, thr=0.004):
+ rows = np.flatnonzero(m.max(1) > thr)
+ if not len(rows): return None
+ cols = np.flatnonzero(m.max(0) > thr)
+ pad = int(np.ceil(pad))
+ return (slice(max(0, rows[0] - pad), min(self.H, rows[-1] + 1 + pad)),
+ slice(max(0, cols[0] - pad), min(self.W, cols[-1] + 1 + pad)))
+
+ # ================================================================== laying media
+ def _lay(self, idx, dep, colour, medium, over_ink=0.1):
+ """put pigment on the page at idx (a region slice or (ys, xs)) with coverage dep. Ink is remembered in K;
+ colour laid later barely takes on it (over_ink), so the line stays on top as in the printed book."""
+ if medium == 'ink':
+ self.K[idx] = 1 - (1 - self.K[idx]) * (1 - dep)
+ elif over_ink < 1:
+ dep = dep * (1 - (1 - over_ink) * self.K[idx])
+ C = self.C[idx]
+ col = hexc(colour) if np.ndim(colour) <= 1 else colour
+ if medium == 'crayon':
+ tgt = col * np.clip(C, 0, 1) ** 0.55 # semi-opaque wax / pastel
+ else:
+ tgt = col if np.ndim(col) > 1 else np.broadcast_to(col, C.shape) # ink, chalk, gouache: cover
+ self.C[idx] = C + (tgt - C) * dep[..., None]
+
+ def _hand(self, path, wobble=1.0, smooth=True, closed=False, r=None, step=2.0):
+ """the drawn path: smoothed, re-sampled every `step` px, pushed sideways by hand wobble and tremor"""
+ r = r if r is not None else self._r()
+ P = np.asarray(path, np.float32).reshape(-1, 2)
+ if len(P) < 2: return P
+ if smooth and len(P) > 2:
+ P = _closed_spline(P) if closed else spline(P, 8)
+ elif closed:
+ P = np.vstack([P, P[:1]])
+ Q = _resample(P, step)
+ n = len(Q)
+ if wobble and n > 3:
+ d = np.gradient(Q, axis=0); d /= np.linalg.norm(d, axis=1, keepdims=True) + 1e-6
+ nrm = np.stack([-d[:, 1], d[:, 0]], 1)
+ w = fbm1d(n, 30, 3, int(r.integers(1 << 30))) * 1.4 * wobble \
+ + fbm1d(n, 3.5, 2, int(r.integers(1 << 30))) * 0.32 * wobble
+ Q = Q + nrm * w[:, None]
+ return Q
+
+ def _footprint(self, Q, reach):
+ """pixels within `reach` of polyline Q, with the index of the segment they belong to (Pillow rasterises
+ the segment ids into an int image; round caps at both ends)"""
+ x0 = max(0, int(np.floor(Q[:, 0].min() - reach - 2))); x1 = min(self.W, int(np.ceil(Q[:, 0].max() + reach + 3)))
+ y0 = max(0, int(np.floor(Q[:, 1].min() - reach - 2))); y1 = min(self.H, int(np.ceil(Q[:, 1].max() + reach + 3)))
+ if x1 <= x0 or y1 <= y0: return None
+ im = Image.new('I', (x1 - x0, y1 - y0), 0)
+ d = ImageDraw.Draw(im)
+ q = (Q - [x0 - 0.5, y0 - 0.5]).tolist()
+ wpx = max(1, int(np.ceil(2 * reach + 1)))
+ n = len(q)
+ rr = reach + 0.5
+ d.ellipse([q[0][0] - rr, q[0][1] - rr, q[0][0] + rr, q[0][1] + rr], fill=1)
+ for k in range(n - 1):
+ d.line([tuple(q[k]), tuple(q[k + 1])], fill=k + 1, width=wpx)
+ d.ellipse([q[-1][0] - rr, q[-1][1] - rr, q[-1][0] + rr, q[-1][1] + rr], fill=n - 1)
+ a = np.asarray(im, np.int32)
+ yy, xx = np.nonzero(a)
+ if not len(yy): return None
+ return yy + y0, xx + x0, a[yy, xx] - 1
+
+ def _mark(self, path, width, colour, medium='ink', pressure=1.0, dry=0.2, taper=(0.12, 0.3), wobble=1.0,
+ smooth=True, closed=False, streak=0.45, rough=1.0, alpha=0.97, swell=0.18, clip=None, seed=None,
+ Q=None, over_ink=0.1):
+ """one mark of a dry tool along a path: thick-thin, tapered, bristle lanes, drying out, toothy edge"""
+ self._need()
+ r = self._r(seed)
+ if Q is None: Q = self._hand(path, wobble, smooth, closed, r)
+ if len(Q) < 2: return
+ seg = Q[1:] - Q[:-1]
+ sL = np.hypot(seg[:, 0], seg[:, 1]) + 1e-6
+ cum = np.concatenate([[0], np.cumsum(sL)])
+ L = float(cum[-1])
+ if L < 1.0: return
+ reach = width * 0.5 * (1 + abs(swell)) + 1.5 + rough * 0.6
+ fp = self._footprint(Q, reach)
+ if fp is None: return
+ ys, xs, k = fp
+ k = np.clip(k, 0, len(seg) - 1)
+ dx, dy = seg[k, 0] / sL[k], seg[k, 1] / sL[k]
+ rx, ry = xs - Q[k, 0], ys - Q[k, 1]
+ u = np.clip(rx * dx + ry * dy, 0, sL[k])
+ px, py = rx - u * dx, ry - u * dy
+ dist = np.hypot(px, py)
+ side = np.sign(-rx * dy + ry * dx)
+ s01 = (cum[k] + u) / L
+ prof = np.clip(np.minimum(s01 / max(taper[0], 1e-3), (1 - s01) / max(taper[1], 1e-3)), 0, 1) ** 0.6
+ nn = max(4, int(L / 7))
+ sw = np.interp(s01, np.linspace(0, 1, nn), fbm1d(nn, max(2.0, nn / 3), 2, int(r.integers(1 << 30))))
+ hw = 0.5 * width * (0.2 + 0.8 * prof) * (1 + swell * sw)
+ Td = self.TD[self._bin(np.arctan2(dy, dx)), ys, xs]
+ e = dist - hw - rough * 0.9 * (Td - 0.5) * min(1.0, width / 3.0)
+ body = smoothstep(0.7, -0.7, e)
+ nbr = max(3, int(width / 1.6))
+ tn = np.clip(side * dist / (hw + 1e-3), -1, 1)
+ B = np.interp(tn, np.linspace(-1, 1, nbr), r.uniform(0.4, 1.0, nbr))
+ load = 1.0 - dry * 1.35 * s01 ** 1.25 * r.uniform(0.8, 1.2)
+ c = pressure * (0.55 + 0.45 * prof) * load * (1 - streak * (1 - B)) * (1 - 0.3 * streak * smoothstep(0.55, 1.0, np.abs(tn)))
+ dep = body * smoothstep(-0.1, 0.1, Td - (1 - 1.12 * c)) * alpha
+ if clip is not None: dep = dep * clip[ys, xs]
+ keep = dep > 0.003
+ if not keep.any(): return
+ self._lay((ys[keep], xs[keep]), dep[keep], colour, medium, over_ink)
+
+ # ================================================================== colour
+ def fill(self, mask, colour, pressure=0.9, angle=None, slip=None, loose=3.0, edge=8.0, dry_edge=0.55,
+ mottle=0.1, lanes=24.0, lane_var=0.08, passes=1, medium='crayon', alpha=1.0, avoid=None, halo=3.0,
+ clip=None, tint=0.05, streak=0.45, over_ink=0.1, seed=None):
+ """colour an area in dry media, loose against the line. Returns the region actually coloured.
+ pressure: contact (0..1 = coverage fraction on the tooth; 0.95 leaves fine specks of paper); mottle /
+ lanes / lane_var: how much the pigment density varies (blotches, parallel passes); streak: how much the
+ bare specks are drawn out along the stroke; angle: stroke direction (deg, or a canvas-size
+ field); slip: misregistration (dx, dy), None = random 1.5-3.5 px, 0 = none; loose: edge wander px;
+ edge / dry_edge: width and strength of the dry-out at the border; lanes: stroke width of the parallel passes;
+ medium: 'crayon' (semi-opaque) | 'gouache' | 'chalk' (opaque); avoid / halo: a mask to colour round"""
+ self._need()
+ r = self._r(seed)
+ if slip is None:
+ a = r.uniform(0, 2 * np.pi); mg = r.uniform(1.5, 3.5)
+ slip = (np.cos(a) * mg, np.sin(a) * mg)
+ elif np.ndim(slip) == 0:
+ slip = (0.0, 0.0)
+ pad = loose * 3 + edge + 8 + abs(slip[0]) + abs(slip[1])
+ sl = self._bbox(mask, pad)
+ if sl is None: return np.zeros((self.H, self.W), np.float32)
+ m = mask[sl].astype(np.float32)
+ if slip[0] or slip[1]: m = _shift(m, slip[0], slip[1])
+ if avoid is not None:
+ av = avoid[sl]
+ if halo: av = smoothstep(0.08, 0.4, blur(av, halo * 0.6))
+ m = m * (1 - av)
+ h, w = m.shape
+ if loose:
+ mb = blur(m, max(0.8, loose * 0.5))
+ wob = noise2d(h, w, max(14.0, loose * 9), 2, int(r.integers(1 << 30))) - 0.5
+ R = smoothstep(0.40, 0.60, mb + wob * 0.55)
+ else:
+ R = m
+ Pc = pressure + 0.04 * (noise2d(h, w, 40, 2, int(r.integers(1 << 30))) - 0.5)
+ if dry_edge and edge:
+ ed = blur(R, edge * 0.5)
+ Pc = Pc * ((1 - dry_edge) + dry_edge * smoothstep(0.5, 0.92, ed))
+ dens = 1 - mottle * 2 * np.abs(noise2d(h, w, 110, 3, int(r.integers(1 << 30))) - 0.5)
+ ang = r.uniform(-40, 40) if angle is None else angle
+ a0 = np.deg2rad(ang if np.ndim(ang) == 0 else float(np.median(ang[sl])))
+ if lanes:
+ X, Y = self._grid(sl)
+ v = -X * np.sin(a0) + Y * np.cos(a0) + 7 * (noise2d(h, w, 70, 2, int(r.integers(1 << 30))) - 0.5) * 2
+ v = v - v.min()
+ nl = int(v.max() / lanes) + 3
+ dens = dens * np.interp(v / lanes, np.arange(nl), 1 - lane_var * np.abs(r.normal(0, 1, nl)))
+ Td = self._tooth_region(sl, ang)
+ Tf = Td * streak + self.T[sl] * (1 - streak)
+ dep = R * smoothstep(-0.06, 0.06, Tf - (1 - Pc))
+ for i in range(1, passes):
+ Td2 = self._tooth_region(sl, (ang if np.ndim(ang) == 0 else float(np.degrees(a0))) + r.choice([-1, 1]) * r.uniform(45, 75))
+ d2 = R * smoothstep(-0.06, 0.06, Td2 - (1 - Pc * 0.85))
+ dep = 1 - (1 - dep) * (1 - d2)
+ dep = dep * np.clip(dens, 0, 1)
+ dep = dep * alpha
+ if clip is not None: dep = dep * clip[sl]
+ col = hexc(colour)
+ if tint:
+ nt = noise2d(h, w, 60, 2, int(r.integers(1 << 30)))[..., None] - 0.5
+ col = np.clip(col * (1 + tint * 2 * nt), 0, 1)
+ else:
+ col = np.broadcast_to(col, (h, w, 3))
+ self._lay(sl, dep, col, medium, over_ink)
+ out = np.zeros((self.H, self.W), np.float32)
+ out[sl] = R
+ return out
+
+ def block(self, box, colour='powder', rough=9.0, corner=28.0, pressure=0.96, angle=-12.0, edge=16.0,
+ dry_edge=0.7, streaks=90, avoid=None, halo=3.0, seed=None, **kw):
+ """the big background colour field: a rough-sided block on white (box = (x0, y0, x1, y1) or a mask);
+ its borders are brushed along their own direction and drag out dry"""
+ r = self._r(seed)
+ mask = self.rect(*box, rough=rough, corner=corner, seed=int(r.integers(1 << 30))) if np.ndim(box) == 1 else box
+ mb = blur(mask, 16)
+ gy, gx = np.gradient(mb)
+ mag = np.hypot(gx, gy)
+ along = np.degrees(np.arctan2(gx, -gy)) # direction of the border
+ wgt = smoothstep(0.004, 0.02, mag)
+ field = np.where(wgt > 0.5, along, angle).astype(np.float32)
+ R = self.fill(mask, colour, pressure, angle=field, slip=0, loose=rough * 0.45, edge=edge, dry_edge=dry_edge,
+ lanes=46, avoid=avoid, halo=halo, seed=int(r.integers(1 << 30)), **kw)
+ # dry strokes dragged along the border, some running a little off the block (kept near the border)
+ ys, xs = np.nonzero((mag > 0.012) & (mask > 0.15) & (mask < 0.85))
+ near = smoothstep(0.02, 0.12, blur(mask, 6))
+ if streaks and len(ys):
+ for i in r.choice(len(ys), min(streaks, len(ys)), replace=False):
+ x, y = float(xs[i]), float(ys[i])
+ a = np.deg2rad(along[ys[i], xs[i]])
+ nx, ny = -gx[ys[i], xs[i]] / (mag[ys[i], xs[i]] + 1e-6), -gy[ys[i], xs[i]] / (mag[ys[i], xs[i]] + 1e-6)
+ off = r.uniform(-9, 3)
+ Lh = r.uniform(25, 110)
+ c0 = (x + nx * off, y + ny * off)
+ p0 = (c0[0] - np.cos(a) * Lh, c0[1] - np.sin(a) * Lh)
+ p1 = (c0[0] + np.cos(a) * Lh, c0[1] + np.sin(a) * Lh)
+ if avoid is not None:
+ if avoid[int(np.clip(c0[1], 0, self.H - 1)), int(np.clip(c0[0], 0, self.W - 1))] > 0.3: continue
+ self._mark([p0, c0, p1], r.uniform(8, 20), colour, 'crayon', pressure=r.uniform(0.7, 0.9),
+ dry=r.uniform(0.3, 0.7), taper=(0.2, 0.4), wobble=1.5, streak=0.7, rough=2.0, alpha=0.95,
+ clip=near if avoid is None else near * (1 - avoid))
+ return R
+
+ def crayon(self, paths, colour, width=8.0, pressure=0.8, dry=0.35, taper=(0.15, 0.35), wobble=1.0, streak=0.6,
+ alpha=0.95, medium='crayon', clip=None, seed=None):
+ """coloured dry strokes along paths (hair, blades, wet streaks, reflections)"""
+ r = self._r(seed)
+ for p in paths:
+ self._mark(p, width * r.uniform(0.85, 1.15), colour, medium, pressure, dry * r.uniform(0.7, 1.3), taper,
+ wobble, streak=streak, rough=1.6, alpha=alpha, clip=clip, seed=int(r.integers(1 << 30)))
+
+ # ================================================================== ink
+ def ink(self, path, width=4.0, colour=INK, dry=0.2, taper=(0.12, 0.32), wobble=1.0, smooth=True, pressure=1.0,
+ streak=0.45, rough=1.0, alpha=0.97, swell=0.18, overshoot=0.0, clip=None, seed=None):
+ """one brush / ink-pencil stroke along a path"""
+ r = self._r(seed)
+ Q = self._hand(path, wobble, smooth, False, r)
+ if overshoot and len(Q) > 2:
+ d = Q[-1] - Q[-3]; d /= np.linalg.norm(d) + 1e-6
+ Q = np.vstack([Q, Q[-1] + d * overshoot * 0.5, Q[-1] + d * overshoot])
+ self._mark(None, width, colour, 'ink', pressure, dry, taper, wobble, streak=streak, rough=rough, alpha=alpha,
+ swell=swell, clip=clip, seed=int(r.integers(1 << 30)), Q=Q)
+
+ def outline(self, pts, width=4.0, closed=True, open_=0.45, overshoot=(4, 12), strokes=(1, 3), colour=INK,
+ dry=0.2, wobble=1.0, smooth=True, taper=(0.1, 0.3), alpha=0.97, twice=0.35, clip=None, seed=None):
+ """a quick contour: closed shapes are drawn as 1-3 strokes that stop short (a gap) or run past the
+ join and leave the curve on its tangent; open_ = chance of a gap; twice = chance that part of a stroke
+ is gone over again a little off the first line (a sketchy double line)"""
+ r = self._r(seed)
+ P = np.asarray(pts, np.float32)
+ if not closed:
+ self.ink(P, width, colour, dry, taper, wobble, smooth, alpha=alpha, clip=clip, seed=int(r.integers(1 << 30)))
+ return
+ P = _closed_spline(P, 6) if smooth else np.vstack([P, P[:1]])
+ P = _resample(P, 2.0)
+ seg = np.hypot(*np.diff(P, axis=0).T)
+ s = np.concatenate([[0], np.cumsum(seg)])
+ Lp = float(s[-1])
+ ns = int(r.integers(strokes[0], strokes[1] + 1))
+ start = r.uniform(0, Lp)
+ cuts = np.sort(r.uniform(0.2, 0.8, ns - 1)) * Lp if ns > 1 else np.array([])
+ bounds = np.concatenate([[0], cuts, [Lp]]) + start
+
+ def at(u):
+ u = np.mod(u, Lp)
+ return np.stack([np.interp(u, s, P[:, 0]), np.interp(u, s, P[:, 1])], 1)
+ for i in range(ns):
+ a, b = bounds[i], bounds[i + 1]
+ gap = r.random() < open_
+ if gap: b -= r.uniform(5, 14)
+ else: b += r.uniform(*overshoot) * 0.3
+ a -= 0 if i == 0 else r.uniform(2, 6)
+ Q = at(np.arange(a, b, 2.0))
+ if len(Q) < 3: continue
+ if not gap:
+ d = Q[-1] - Q[-3]; d /= np.linalg.norm(d) + 1e-6
+ e = r.uniform(*overshoot)
+ Q = np.vstack([Q, Q[-1] + d * e * 0.5, Q[-1] + d * e])
+ self.ink(Q, width, colour, dry, taper, wobble, smooth=False, alpha=alpha, clip=clip, seed=int(r.integers(1 << 30)))
+ if r.random() < twice and len(Q) > 12:
+ n = len(Q); a_ = int(r.uniform(0, 0.5) * n); b_ = min(n, a_ + int(r.uniform(0.25, 0.5) * n))
+ d = np.gradient(Q[a_:b_], axis=0); d /= np.linalg.norm(d, axis=1, keepdims=True) + 1e-6
+ off = r.uniform(1.5, 3.2) * r.choice([-1, 1])
+ Q2 = Q[a_:b_] + np.stack([-d[:, 1], d[:, 0]], 1) * off * np.sin(np.linspace(0, np.pi, b_ - a_))[:, None] ** 0.5
+ self.ink(Q2, width * 0.6, colour, dry + 0.2, (0.3, 0.4), wobble, smooth=False, alpha=alpha * 0.9, clip=clip,
+ seed=int(r.integers(1 << 30)))
+
+ def _runs(self, mask, angle, spacing, step=3.0, r=None):
+ """rows across `angle`, each with the [u0, u1] runs where the row lies in the mask"""
+ sl = self._bbox(mask, 2)
+ if sl is None: return [], None
+ a = np.deg2rad(angle)
+ dv, nv = np.array([np.cos(a), np.sin(a)]), np.array([-np.sin(a), np.cos(a)])
+ cx, cy = (sl[1].start + sl[1].stop) / 2, (sl[0].start + sl[0].stop) / 2
+ R = 0.5 * np.hypot(sl[1].stop - sl[1].start, sl[0].stop - sl[0].start) + 4
+ vs = np.arange(-R, R, spacing) + r.uniform(0, spacing)
+ vs = vs + r.normal(0, spacing * 0.18, len(vs))
+ us = np.arange(-R, R, step)
+ X = cx + dv[0] * us[None, :] + nv[0] * vs[:, None]
+ Y = cy + dv[1] * us[None, :] + nv[1] * vs[:, None]
+ ok = (X >= 0) & (X < self.W) & (Y >= 0) & (Y < self.H)
+ ins = np.zeros(X.shape, bool)
+ ins[ok] = mask[Y[ok].astype(int), X[ok].astype(int)] > 0.5
+ rows = []
+ for i in range(len(vs)):
+ d = np.diff(np.concatenate([[0], ins[i].astype(np.int8), [0]]))
+ st, en = np.flatnonzero(d == 1), np.flatnonzero(d == -1) - 1
+ rows.append([[us[a_], us[b_], False] for a_, b_ in zip(st, en) if b_ > a_])
+ return rows, (cx, cy, dv, nv, vs)
+
+ def scribble(self, mask, width=5.0, spacing=4.5, angle=80.0, reach=900.0, overshoot=7.0, dry=0.45,
+ colour=INK, medium='ink', alpha=0.95, wobble=0.6, piece=260.0, clip=None, seed=None):
+ """a dark mass scribbled back and forth: zigzag passes along `angle`, sharp turns past (or short of)
+ the outline, one wrist-sized patch at a time"""
+ r = self._r(seed)
+ rows, geo = self._runs(mask, angle, spacing, r=r)
+ if geo is None: return
+ cx, cy, dv, nv, vs = geo
+ # cut long runs into wrist-sized pieces
+ for row in rows:
+ out = []
+ for a, b, _ in row:
+ while b - a > piece * 1.3:
+ m = a + piece * r.uniform(0.6, 1.0)
+ out.append([a, m, False]); a = m - r.uniform(4, 12)
+ out.append([a, b, False])
+ row[:] = out
+
+ def xy(u, v):
+ return (cx + dv[0] * u + nv[0] * v, cy + dv[1] * u + nv[1] * v)
+ for i in range(len(rows)):
+ for run in rows[i]:
+ if run[2]: continue
+ pts, total, row, cur, fwd = [], 0.0, i, run, bool(r.random() < 0.5)
+ while cur is not None and total < reach:
+ cur[2] = True
+ a = cur[0] - r.uniform(-0.4, 1.0) * overshoot
+ b = cur[1] + r.uniform(-0.4, 1.0) * overshoot
+ v = vs[row]
+ pts += [xy(a, v), xy(b, v)] if fwd else [xy(b, v), xy(a, v)]
+ total += b - a
+ nxt, best = None, 0.0
+ if row + 1 < len(rows):
+ for cand in rows[row + 1]:
+ if cand[2]: continue
+ ov = min(cand[1], cur[1]) - max(cand[0], cur[0])
+ if ov > best: nxt, best = cand, ov
+ if nxt is None or best < 6: break
+ row += 1; fwd = not fwd; cur = nxt
+ if len(pts) >= 2:
+ self._mark(None, width * r.uniform(0.85, 1.15), colour, medium, 1.0, dry * r.uniform(0.7, 1.3),
+ (0.04, 0.12), wobble, streak=0.6, rough=1.3, alpha=alpha, swell=0.25, clip=clip,
+ Q=self._hand(np.array(pts, np.float32), wobble, False, False, r))
+
+ def hatch(self, mask, angle=70.0, spacing=8.0, length=(18, 40), width=2.2, colour=INK, medium='ink', dry=0.35,
+ bend=0.1, jitter=0.35, density=1.0, alpha=0.95, pressure=1.0, seed=None):
+ """quick parallel flicks inside a mask (shading, rain-darkened cloth, fur shadow)"""
+ r = self._r(seed)
+ sl = self._bbox(mask, 2)
+ if sl is None: return
+ a = np.deg2rad(angle)
+ dv, nv = np.array([np.cos(a), np.sin(a)]), np.array([-np.sin(a), np.cos(a)])
+ cx, cy = (sl[1].start + sl[1].stop) / 2, (sl[0].start + sl[0].stop) / 2
+ R = 0.5 * np.hypot(sl[1].stop - sl[1].start, sl[0].stop - sl[0].start) + 4
+ Lm = float(np.mean(length))
+ for v in np.arange(-R, R, spacing):
+ for u in np.arange(-R, R, Lm * 0.9) + r.uniform(0, Lm):
+ if r.random() > density: continue
+ uu = u + r.normal(0, Lm * jitter); vv = v + r.normal(0, spacing * jitter)
+ x, y = cx + dv[0] * uu + nv[0] * vv, cy + dv[1] * uu + nv[1] * vv
+ if not (0 <= x < self.W and 0 <= y < self.H) or mask[int(y), int(x)] < 0.5: continue
+ L = r.uniform(*length); aa = a + r.normal(0, 0.06)
+ d = np.array([np.cos(aa), np.sin(aa)]); nrm = np.array([-d[1], d[0]])
+ b = r.uniform(-bend, bend) * L
+ p = [(x - d[0] * L / 2, y - d[1] * L / 2), (x + nrm[0] * b, y + nrm[1] * b), (x + d[0] * L / 2, y + d[1] * L / 2)]
+ self._mark(p, width * r.uniform(0.8, 1.2), colour, medium, pressure, dry, (0.08, 0.45), 0.5,
+ streak=0.5, rough=1.2, alpha=alpha, seed=int(r.integers(1 << 30)))
+
+ def blades(self, x0, x1, y, n=20, height=(30, 90), lean=0.0, width=4.0, colour=INK, medium='ink', dry=0.3,
+ curl=0.25, alpha=0.95, clip=None, seed=None):
+ """tapered leaf / grass blades growing up from a base line y (or a function of x)"""
+ r = self._r(seed)
+ for _ in range(n):
+ x = r.uniform(x0, x1)
+ yb = y(x) if callable(y) else y
+ h = r.uniform(*height)
+ a = np.deg2rad(-90 + lean + r.normal(0, 16))
+ c = r.normal(0, curl)
+ p0 = np.array([x, yb + r.uniform(0, 6)])
+ d = np.array([np.cos(a), np.sin(a)]); nrm = np.array([-d[1], d[0]])
+ pts = [p0, p0 + d * h * 0.5 + nrm * c * h * 0.3, p0 + d * h + nrm * c * h * 0.8]
+ self._mark(pts, width * r.uniform(0.7, 1.25), colour, medium, 1.0, dry, (0.04, 0.85), 0.7, streak=0.4,
+ rough=1.0, alpha=alpha, swell=0.1, clip=clip, seed=int(r.integers(1 << 30)))
+
+ # ================================================================== dots, spatter, speckle
+ def _dots(self, xs, ys, rs, colour, medium='ink', alpha=0.95, elong=None, angle=None, rough=0.0, tooth=0.35,
+ ss=3, over_ink=0.1, seed=None):
+ """many small dots at once (rendered at ss x, then laid through the tooth)"""
+ xs, ys, rs = (np.asarray(v, np.float32).ravel() for v in (xs, ys, rs))
+ if not len(xs): return
+ r = self._r(seed)
+ pad = float(rs.max() * (1 + (0 if elong is None else np.max(elong))) + 3)
+ sl = self._clip_box(xs.min() - pad, ys.min() - pad, xs.max() + pad + 1, ys.max() + pad + 1)
+ if sl is None: return
+ x0, y0 = sl[1].start, sl[0].start
+ h, w = sl[0].stop - y0, sl[1].stop - x0
+ im = Image.new('L', (w * ss, h * ss), 0)
+ d = ImageDraw.Draw(im)
+ el = np.ones(len(xs)) if elong is None else np.asarray(elong, np.float32) * np.ones(len(xs))
+ an = r.uniform(0, np.pi, len(xs)) if angle is None else np.deg2rad(np.asarray(angle, np.float32)) * np.ones(len(xs))
+ for x, y, rr, e, a in zip(xs, ys, rs, el, an):
+ cx, cy = (x - x0) * ss, (y - y0) * ss
+ m = max(10, int(rr * ss * 2.2))
+ t = np.linspace(0, 2 * np.pi, m, endpoint=False)
+ rad = rr * ss * (1 + rough * 0.5 * fbm1d(m, max(2.0, m / 5), 2, int(r.integers(1 << 30))) if rough else 1)
+ px, py = np.cos(t) * rad * e, np.sin(t) * rad
+ c, s_ = np.cos(a), np.sin(a)
+ d.polygon(list(zip((cx + px * c - py * s_).tolist(), (cy + px * s_ + py * c).tolist())), fill=255)
+ cov = np.asarray(im.resize((w, h), Image.BOX), np.float32) / 255
+ if tooth:
+ cov = cov * smoothstep(-0.2, 0.25, self.T[sl] - 0.5 + (1 - tooth) + cov * 0.6 - 0.35)
+ self._lay(sl, cov * alpha, colour, medium, over_ink)
+
+ def dot(self, x, y, r=4.0, ry=None, colour=INK, medium='ink', alpha=0.97, rough=0.18, seed=None):
+ """a solid little ink dot (an eye, a nose, a button) with an irregular edge"""
+ ry = r if ry is None else ry
+ self._dots([x], [y], [ry], colour, medium, alpha, elong=[r / ry], angle=[0.0], rough=rough, tooth=0.15, seed=seed)
+
+ def _region_points(self, region, n, r, avoid=None):
+ if np.ndim(region) == 1:
+ x0, y0, x1, y1 = region
+ xs, ys = r.uniform(x0, x1, n * 2), r.uniform(y0, y1, n * 2)
+ else:
+ yy, xx = np.nonzero(region > 0.5)
+ if not len(yy): return np.zeros(0), np.zeros(0)
+ i = r.integers(0, len(yy), n * 2)
+ xs, ys = xx[i] + r.random(n * 2), yy[i] + r.random(n * 2)
+ if avoid is not None:
+ ok = avoid[np.clip(ys.astype(int), 0, self.H - 1), np.clip(xs.astype(int), 0, self.W - 1)] < 0.5
+ xs, ys = xs[ok], ys[ok]
+ return xs[:n], ys[:n]
+
+ def spatter(self, region, colour=INK, n=60, size=(0.7, 4.5), alpha=0.92, satellites=0.6, medium=None,
+ avoid=None, seed=None):
+ """flicked paint: power-law drop sizes, slightly elongated, with satellite droplets"""
+ r = self._r(seed)
+ medium = medium or ('ink' if hexc(colour).mean() < 0.3 else 'chalk')
+ xs, ys = self._region_points(region, n, r, avoid)
+ if not len(xs): return
+ rs = size[0] + (size[1] - size[0]) * r.random(len(xs)) ** 3.2
+ an = r.uniform(0, 180, len(xs))
+ X, Y, R_, E, A = [xs], [ys], [rs], [r.uniform(1.0, 1.6, len(xs))], [an]
+ k = r.random(len(xs)) < satellites
+ if k.any():
+ m = int(k.sum())
+ dd = rs[k] * r.uniform(1.8, 4.0, m)
+ X.append(xs[k] + np.cos(np.deg2rad(an[k])) * dd); Y.append(ys[k] + np.sin(np.deg2rad(an[k])) * dd)
+ R_.append(np.maximum(0.45, rs[k] * r.uniform(0.2, 0.45, m))); E.append(np.ones(m)); A.append(an[k])
+ self._dots(np.concatenate(X), np.concatenate(Y), np.concatenate(R_), colour, medium, alpha,
+ np.concatenate(E), np.concatenate(A), rough=0.2, tooth=0.25, seed=int(r.integers(1 << 30)))
+
+ def speckle(self, region, colour='chalk', n=400, size=(0.45, 1.3), alpha=0.85, medium=None, avoid=None, seed=None):
+ """fine dust / sparkle specks"""
+ r = self._r(seed)
+ medium = medium or ('ink' if hexc(colour).mean() < 0.3 else ('chalk' if hexc(colour).mean() > 0.85 else 'crayon'))
+ xs, ys = self._region_points(region, n, r, avoid)
+ if not len(xs): return
+ rs = size[0] + (size[1] - size[0]) * r.random(len(xs)) ** 2
+ self._dots(xs, ys, rs, colour, medium, alpha, r.uniform(1.0, 1.8, len(xs)), None, rough=0.3, tooth=0.4,
+ seed=int(r.integers(1 << 30)))
+
+ # ================================================================== chalk, weather
+ def chalk(self, target, width=10.0, pressure=0.62, angle=None, dry=0.45, colour='chalk', alpha=0.95, taper=(0.2, 0.4),
+ wobble=1.2, over_ink=0.5, seed=None, **fill_kw):
+ """opaque white chalk / pastel / white gouache over the colour: a mask is coloured in, paths are stroked"""
+ r = self._r(seed)
+ if isinstance(target, np.ndarray) and target.ndim == 2 and target.shape == (self.H, self.W):
+ kw = dict(slip=0, loose=3.0, edge=10.0, dry_edge=0.7, mottle=0.2, lanes=16.0, lane_var=0.2, streak=0.85,
+ over_ink=over_ink)
+ kw.update(fill_kw)
+ return self.fill(target, colour, pressure, angle, medium='chalk', alpha=alpha, tint=0,
+ seed=int(r.integers(1 << 30)), **kw)
+ for p in target:
+ self._mark(p, width * r.uniform(0.8, 1.2), colour, 'chalk', pressure * r.uniform(0.85, 1.1),
+ dry * r.uniform(0.7, 1.3), taper, wobble, streak=0.7, rough=2.0, alpha=alpha,
+ seed=int(r.integers(1 << 30)), over_ink=over_ink)
+
+ def rain(self, region, n=400, angle=100.0, length=(12, 30), width=(1.5, 2.8), colour='deep', medium=None,
+ dry=0.5, pressure=0.95, alpha=0.9, avoid=None, seed=None):
+ """rain as short dry strokes"""
+ r = self._r(seed)
+ medium = medium or ('chalk' if hexc(colour).mean() > 0.85 else 'crayon')
+ xs, ys = self._region_points(region, n, r, avoid)
+ for x, y in zip(xs, ys):
+ L = r.uniform(*length); a = np.deg2rad(angle + r.normal(0, 3))
+ d = np.array([np.cos(a), np.sin(a)])
+ self._mark([(x - d[0] * L / 2, y - d[1] * L / 2), (x + d[0] * L / 2, y + d[1] * L / 2)],
+ r.uniform(*width), colour, medium, pressure, dry, (0.05, 0.6), 0.3, smooth=False,
+ streak=0.5, rough=1.2, alpha=alpha, swell=0.1, seed=int(r.integers(1 << 30)))
+
+ def splash(self, x, y, size=10.0, colour='chalk', medium=None, n=5, width=2.0, up=-90.0, seed=None):
+ """the little crown where a drop hits: a fan of short ticks and a couple of droplets"""
+ r = self._r(seed)
+ medium = medium or ('chalk' if hexc(colour).mean() > 0.85 else ('ink' if hexc(colour).mean() < 0.3 else 'crayon'))
+ for a in np.linspace(up - 70, up + 70, n) + r.normal(0, 8, n):
+ d = np.array([np.cos(np.deg2rad(a)), np.sin(np.deg2rad(a))])
+ s0, s1 = size * r.uniform(0.25, 0.45), size * r.uniform(0.7, 1.1)
+ self._mark([(x + d[0] * s0, y + d[1] * s0), (x + d[0] * s1, y + d[1] * s1)], width * r.uniform(0.7, 1.2),
+ colour, medium, 1.0, 0.2, (0.1, 0.6), 0.2, smooth=False, streak=0.3, alpha=0.95,
+ seed=int(r.integers(1 << 30)))
+ k = int(r.integers(1, 3))
+ aa = np.deg2rad(up + r.uniform(-50, 50, k))
+ self._dots(x + np.cos(aa) * size * 1.4, y + np.sin(aa) * size * 1.4, r.uniform(0.8, 1.5, k) * width * 0.6,
+ colour, medium, 0.95, tooth=0.2)
+
+ def ripples(self, cx, cy, rx, ry, rings=2, colour='chalk', medium=None, width=2.4, gap=0.55, seed=None):
+ """broken concentric rings on a puddle"""
+ r = self._r(seed)
+ medium = medium or ('chalk' if hexc(colour).mean() > 0.85 else ('ink' if hexc(colour).mean() < 0.3 else 'crayon'))
+ for k in range(rings):
+ s = 1 + k * gap
+ n_arc = int(r.integers(2, 4))
+ starts = np.sort(r.uniform(0, 2 * np.pi, n_arc))
+ for a0 in starts:
+ span = r.uniform(0.6, 1.5)
+ t = np.linspace(a0, a0 + span, 14)
+ pts = np.stack([cx + np.cos(t) * rx * s, cy + np.sin(t) * ry * s], 1)
+ self._mark(pts, width * (1 - 0.15 * k), colour, medium, 0.9, 0.3, (0.25, 0.4), 0.6, streak=0.5,
+ rough=1.4, alpha=0.95 - 0.15 * k, seed=int(r.integers(1 << 30)))
+
+ # ================================================================== characters
+ def head(self, cx, cy, rx, ry=None, width=4.6, rot=0.0, ears=(), lumpy=0.025, colour=INK, open_=0.6, seed=None):
+ """a big round head as an open ink contour; ears = [(x, y, r)] drawn only where they stick out.
+ Returns the head mask (ears included)."""
+ r = self._r(seed)
+ ry = rx if ry is None else ry
+ pts = blob_pts(cx, cy, rx, ry, lumpy, 120, int(r.integers(1 << 30)), np.deg2rad(rot))
+ self.outline(pts, width, open_=open_, strokes=(1, 2), colour=colour, seed=int(r.integers(1 << 30)))
+ m = self.ellipse(cx, cy, rx, ry, rot)
+ for ex, ey, er in ears:
+ t = np.linspace(0, 2 * np.pi, 90, endpoint=False)
+ E = np.stack([ex + np.cos(t) * er, ey + np.sin(t) * er], 1)
+ X, Y = E[:, 0] - cx, E[:, 1] - cy
+ a = np.deg2rad(rot); c, s = np.cos(a), np.sin(a)
+ X, Y = X * c + Y * s, -X * s + Y * c
+ out = (X / rx) ** 2 + (Y / ry) ** 2 > 0.98
+ if out.any():
+ i0 = int(np.argmin(out)) if not out.all() else 0
+ E2, o2 = np.roll(E, -i0, 0), np.roll(out, -i0)
+ idx = np.flatnonzero(o2)
+ arc = E2[idx[0]:idx[-1] + 1]
+ if len(arc) > 2:
+ self.ink(arc, width * 0.9, colour, 0.2, (0.1, 0.25), smooth=False, seed=int(r.integers(1 << 30)))
+ m = np.maximum(m, self.ellipse(ex, ey, er))
+ return m
+
+ def eyes(self, pts, r=6.0, look=(0.0, 0.0), glint=0.36, ry=1.12, colour=INK, seed=None):
+ """dot eyes with a white glint"""
+ rr = self._r(seed)
+ for (x, y) in pts:
+ x2, y2 = x + look[0] * r * 0.3, y + look[1] * r * 0.3
+ self.dot(x2, y2, r, r * ry, colour, seed=int(rr.integers(1 << 30)))
+ if glint:
+ self._dots([x2 - r * 0.32], [y2 - r * 0.38], [max(0.9, r * glint)], 'chalk', 'chalk', 0.97, tooth=0.05,
+ over_ink=1.0)
+
+ def smile(self, x, y, w=14.0, depth=5.0, width=2.6, tilt=0.0, colour=INK, seed=None):
+ a = np.deg2rad(tilt); c, s = np.cos(a), np.sin(a)
+ P = np.array([(-w / 2, 0), (-w / 4, depth * 0.8), (0, depth), (w / 4, depth * 0.8), (w / 2, -depth * 0.1)], np.float32)
+ P = np.stack([x + P[:, 0] * c - P[:, 1] * s, y + P[:, 0] * s + P[:, 1] * c], 1)
+ self.ink(P, width, colour, 0.1, (0.2, 0.35), wobble=0.4, seed=seed)
+
+ def blush(self, cx, cy, r=18.0, colour='cheek', density=1.0, ry=None, soft=0.18, seed=None):
+ """a stippled cheek: separate little pink dots over a faint crayon disc"""
+ rr = self._r(seed)
+ ry = r * 0.82 if ry is None else ry
+ if soft:
+ self.fill(self.ellipse(cx, cy, r * 0.95, ry * 0.95), colour, pressure=soft, slip=0, loose=2.0, edge=4,
+ dry_edge=0.6, lanes=0, mottle=0.3, seed=int(rr.integers(1 << 30)))
+ n = int(r * ry * 0.55 * density)
+ a = rr.uniform(0, 2 * np.pi, n); d = np.sqrt(rr.random(n)) ** 0.8
+ xs, ys = cx + np.cos(a) * d * r, cy + np.sin(a) * d * ry
+ keep = rr.random(n) < 1.15 - d ** 2
+ k = int(keep.sum())
+ self._dots(xs[keep], ys[keep], rr.uniform(0.8, 1.9, k) * max(1.0, r / 22), colour, 'gouache', 0.92,
+ rr.uniform(1, 1.4, k), rough=0.3, tooth=0.25)
+
+ def freckles(self, cx, cy, n=4, spread=9.0, r=1.2, colour='freckle', seed=None):
+ rr = self._r(seed)
+ self._dots(cx + rr.normal(0, spread * 0.5, n), cy + rr.normal(0, spread * 0.3, n), rr.uniform(0.7, 1.15, n) * r,
+ colour, 'crayon', 0.9, rough=0.2, tooth=0.1)
+
+ def _edge_points(self, mask, every, r, avoid=None, inset=0.0):
+ """points on the silhouette of a mask, about `every` px apart, with outward normals"""
+ sl = self._bbox(mask, 6)
+ if sl is None: return []
+ mb = blur(mask[sl], 1.6)
+ gy, gx = np.gradient(mb)
+ band = (mb > 0.3) & (mb < 0.7)
+ yy, xx = np.nonzero(band)
+ if not len(yy): return []
+ cell = (yy // every) * 100000 + (xx // every)
+ order = r.permutation(len(yy))
+ _, first = np.unique(cell[order], return_index=True)
+ pick = order[first]
+ out = []
+ for i in pick:
+ y, x = yy[i], xx[i]
+ g = np.hypot(gx[y, x], gy[y, x]) + 1e-6
+ nx, ny = -gx[y, x] / g, -gy[y, x] / g
+ X, Y = x + sl[1].start + r.uniform(-every / 3, every / 3) * -ny, y + sl[0].start + r.uniform(-every / 3, every / 3) * nx
+ if avoid is not None and avoid[int(np.clip(Y, 0, self.H - 1)), int(np.clip(X, 0, self.W - 1))] > 0.5: continue
+ out.append((X - nx * inset, Y - ny * inset, nx, ny))
+ return out
+
+ def fluff(self, mask, medium='ink', every=None, length=(16, 30), width=None, curl=0.5, colour=None, avoid=None,
+ curls=0, alpha=None, reach=(0.6, 0.45), gaps=0.12, seed=None):
+ """scribbly fur. medium='ink': the silhouette as short scalloped tufts (a line that is all little
+ bumps, never closed); medium='chalk': white tufts that start inside and cross the edge into the background;
+ curls = little c-shaped marks inside (in `colour`)."""
+ r = self._r(seed)
+ ink_ = medium == 'ink'
+ colour = colour or (INK if ink_ else 'chalk')
+ width = width or (3.2 if ink_ else 5.0)
+ alpha = alpha or (0.96 if ink_ else 0.92)
+ every = every or (0.62 * float(np.mean(length)) if ink_ else 0.5 * float(np.mean(length)))
+ for (x, y, nx, ny) in self._edge_points(mask, every, r, avoid):
+ tx, ty = -ny, nx
+ L = r.uniform(*length)
+ if ink_:
+ if r.random() < gaps: continue
+ sgn = r.choice([-1, 1])
+ bulge = L * curl * r.uniform(0.35, 1.0)
+ sink = L * r.uniform(0.04, 0.16)
+ p0 = (x - tx * L / 2 * sgn - nx * sink, y - ty * L / 2 * sgn - ny * sink)
+ pm = (x + nx * bulge * 0.6, y + ny * bulge * 0.6)
+ p1 = (x + tx * L / 2 * sgn - nx * sink * 0.5, y + ty * L / 2 * sgn - ny * sink * 0.5)
+ self._mark([p0, pm, p1], width * r.uniform(0.75, 1.25), colour, 'ink', 1.0, 0.12, (0.18, 0.4), 0.4,
+ streak=0.35, rough=1.0, alpha=alpha, swell=0.25, seed=int(r.integers(1 << 30)))
+ else:
+ a = r.normal(0, 0.45)
+ dx, dy = nx * np.cos(a) - ny * np.sin(a), nx * np.sin(a) + ny * np.cos(a)
+ b = r.normal(0, 0.25) * L
+ p0 = (x - dx * L * reach[0], y - dy * L * reach[0])
+ p1 = (x + dx * L * reach[1] + tx * b, y + dy * L * reach[1] + ty * b)
+ self._mark([p0, ((p0[0] + p1[0]) / 2 + tx * b * 0.4, (p0[1] + p1[1]) / 2 + ty * b * 0.4), p1],
+ width * r.uniform(0.7, 1.3), colour, 'chalk', r.uniform(0.7, 0.95), 0.4, (0.15, 0.6), 0.5,
+ streak=0.6, rough=1.8, alpha=alpha, seed=int(r.integers(1 << 30)))
+ if curls:
+ yy, xx = np.nonzero(mask > 0.9)
+ if len(yy):
+ for i in r.integers(0, len(yy), curls):
+ x, y = xx[i], yy[i]
+ rr_ = r.uniform(4, 8); a0 = r.uniform(0, 2 * np.pi)
+ t = np.linspace(a0, a0 + r.uniform(2.6, 4.2), 9)
+ pts = np.stack([x + np.cos(t) * rr_, y + np.sin(t) * rr_ * 0.8], 1)
+ self._mark(pts, (width or 2.4) * 0.7, colour if colour else 'slate', 'ink' if ink_ else 'crayon',
+ 0.9, 0.3, (0.2, 0.5), 0.4, streak=0.4, alpha=0.85, seed=int(r.integers(1 << 30)))
+
+ def flower(self, x, y, r=7.0, colour='coral', petals=5, centre=INK, seed=None):
+ """a tiny flower: crayon petals and an ink centre"""
+ rr = self._r(seed)
+ a0 = rr.uniform(0, 2 * np.pi)
+ a = a0 + np.arange(petals) * 2 * np.pi / petals + rr.normal(0, 0.15, petals)
+ self._dots(x + np.cos(a) * r * 0.62, y + np.sin(a) * r * 0.62, rr.uniform(0.5, 0.62, petals) * r, colour,
+ 'gouache', 0.95, rr.uniform(1.1, 1.4, petals), np.degrees(a), rough=0.25, tooth=0.45)
+ self._dots([x], [y], [max(1.0, r * 0.22)], centre, 'ink' if hexc(centre).mean() < 0.3 else 'crayon', 0.95, tooth=0.1)
+
+ # ================================================================== finish
+ def printed(self, amount=1.0, gutter=None):
+ """reproduce the page in a book: print softness, lifted blacks, paper speck; gutter = x of the fold"""
+ self.print_amt = float(amount)
+ self.gutter_x = gutter
+
+ def folio(self, x, y, text, size=20, colour=INK, anchor='mm'):
+ """a tiny page number"""
+ self._need()
+ f = load_font('serif', size)
+ m = text_mask(self.H, self.W, str(text), f, (x, y), anchor=anchor)
+ sl = self._bbox(m, 2)
+ if sl is None: return
+ dep = m[sl] * smoothstep(0.05, 0.35, self.T[sl] + m[sl] * 0.5 - 0.2) * 0.9
+ self._lay(sl, dep, colour, 'ink')
+
+ def render(self):
+ out = self.C.copy()
+ p = self.print_amt
+ if p:
+ soft = np.stack([blur(out[..., i], 0.7) for i in range(3)], -1)
+ out = out * (1 - 0.3 * p) + soft * 0.3 * p
+ c0 = 0.07 * p * hexc('#262833') # blacks lift to a deep ink, white stays white
+ out = c0 + out * (1 - c0)
+ if not hasattr(self, '_speck'):
+ r = np.random.default_rng(self.seed + 7)
+ sp = r.normal(0, 1, (self.H, self.W)).astype(np.float32)
+ self._speck = 0.6 * sp + 0.4 * blur(sp, 1.1) * 2.2
+ out = out * (1 + 0.009 * p * self._speck[..., None])
+ if self.gutter_x is not None:
+ X = np.arange(self.W, dtype=np.float32) - self.gutter_x
+ sh = 0.075 * np.exp(-(X / 9) ** 2) + 0.045 * np.exp(-(X / 60) ** 2) + 0.02 * np.exp(-((X + 2) / 1.2) ** 2)
+ hi = 0.025 * np.exp(-((X - 4) / 1.5) ** 2)
+ out = out * (1 - p * sh)[None, :, None] + p * hi[None, :, None]
+ return np.clip(out, 0, 1)
+
+ def composite(self):
+ return Image.fromarray((self.render() * 255 + 0.5).astype(np.uint8))
+
+ def stage(self, name):
+ if not self.keep_stages: return
+ im = self.composite()
+ if self.stages_dir:
+ os.makedirs(self.stages_dir, exist_ok=True)
+ im.save(f'{self.stages_dir}/{self._n_stages:02d}_{name}.png', compress_level=1)
+ else:
+ b = io.BytesIO(); im.save(b, 'PNG', compress_level=1)
+ self.stages.append((name, b.getvalue()))
+ self._n_stages += 1
+
+ def save(self, path, stages_dir=None, quality=88):
+ img = self.composite()
+ if str(path).lower().endswith(('.jpg', '.jpeg')): img.save(path, quality=quality, subsampling=0)
+ else: img.save(path)
+ sd = stages_dir or self.stages_dir
+ if sd and self.keep_stages:
+ os.makedirs(sd, exist_ok=True)
+ for i, (name, b) in enumerate(self.stages):
+ with open(f'{sd}/{i:02d}_{name}.png', 'wb') as f: f.write(b)
+ img.save(f'{sd}/{self._n_stages:02d}_final.png', compress_level=1)
+ return img