Claude paints with code: a Claude Code skill for procedural illustration in 83 styles, from ink wash (水墨), watercolour and ukiyo-e to stained glass, Roman mosaic, Art Deco, shadow puppets, pastel UI, sketchbook doodles, spot illustrations, grainy picture books, dreamy hills, sunlit greenery. No image model: numpy + Pillow on a CPU, draw-on GIFs.
Python agent-skillsanimechinese-paintingclaudeclaude-codeclaude-skillscolored-pencilcreative-codingcross-stitcheditorial-illustrationgenerative-artink-wash-paintingoil-paintingpaper-collagepixel-artprocedural-generationrisographshanshuiukiyo-ewatercolor
Add retro gouache style (65 total): picture-book portraits in opaque gouache
clovericaccb5d8f3df9
diff --git a/README.md b/README.mdindex f3dfc64..9367452 100644--- a/README.md+++ b/README.md@@ -1,7 +1,7 @@# Claude Drawing · Claude 绘图-**Claude paints with code — no image model.** Sixty-four 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 and pen-and-wash sketch cards.-**不用生图模型,Claude 用代码一笔一笔作画。** 六十四种画风,从水墨、油画到黏土、蓝晒、彩色玻璃花窗、罗马马赛克、代尔夫特蓝瓷砖、赛博朋克、光线追踪的小球海、低多边形 3D、热成像、X 光片、VHS 录像带、Synthwave 落日、产品发布片式的粉彩界面、红笔批改的答题卡、油灯下的皮影戏和钢笔淡彩的速写小卡。+**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 落日、产品发布片式的粉彩界面、红笔批改的答题卡、油灯下的皮影戏、钢笔淡彩的速写小卡和复古水粉的绘本大头像。[English](#english) · [中文](#中文)@@ -50,6 +50,8 @@|  |  |  || **Exam grading · 阅卷批改** | **Shadow puppetry · 皮影戏** | **Pen & wash · 钢笔淡彩** ||  |  |  |+| **Retro gouache · 复古水粉** | **Ink wash · 水墨(月印万川)** | **Watercolour washes · 水彩底纹** |+|  |  |  |### Gallery · 画廊@@ -57,72 +59,72 @@|---|---|| **八万四千法门** · *Many Paths, One Summit*<br><sub>Ink wash · 水墨</sub> | **月印万川** · *One Moon in Ten Thousand Rivers*<br><sub>Ink wash · 水墨</sub> || <img src="examples/bawansiqian.jpg" width="100%"> | <img src="examples/moon_river.jpg" width="100%"> |-| **秋日湖畔** · *Autumn Lake*<br><sub>Watercolour · 水彩</sub> | **水彩底纹** · *Watercolour Washes*<br><sub>Watercolour · 水彩 — a background for explainer videos · 讲解视频的背景</sub> |-| <img src="examples/watercolor_autumn.jpg" width="100%"> | <img src="examples/watercolor_washes.jpg" width="100%"> |-| **热气球小镇** · *Balloon Day*<br><sub>Paper collage · 剪纸拼贴</sub> | **午后甜点** · *Afternoon Dessert*<br><sub>Coloured pencil · 韩国彩铅</sub> |-| <img src="examples/papercut_balloons.jpg" width="100%"> | <img src="examples/colorpencil_dessert.jpg" width="100%"> |-| **夏空** · *Summer Sky*<br><sub>Anime · 日本动漫</sub> | **灵感生长** · *Growing Ideas*<br><sub>Editorial · 编辑风手绘</sub> |-| <img src="examples/anime_summer.jpg" width="100%"> | <img src="examples/editorial_ideas.jpg" width="100%"> |-| **麦田星空** · *Swirling Sky over the Wheat Field*<br><sub>Impasto oil · 油画厚涂</sub> | **富士曙** · *Fuji at Dawn*<br><sub>Ukiyo-e · 浮世绘</sub> |-| <img src="examples/oil_wheatfield.jpg" width="100%"> | <img src="examples/ukiyoe_fuji.jpg" width="100%"> |-| **雨夜咖啡店** · *Rainy Night Cafe*<br><sub>Pixel art · 像素风</sub> | **灯塔岛** · *Lighthouse Island*<br><sub>Stop-motion clay · 黏土定格</sub> |-| <img src="examples/pixel_rainy_cafe.png" width="100%"> | <img src="examples/clay_lighthouse.jpg" width="100%"> |-| **蓝晒植物** · *Sun-Print Botanicals*<br><sub>Cyanotype · 蓝晒</sub> | **家** · *Home Sampler*<br><sub>Cross-stitch · 十字绣</sub> |-| <img src="examples/cyanotype_botanicals.jpg" width="100%"> | <img src="examples/stitch_sampler.jpg" width="100%"> |-| **Aurora 64 收音机** · *Aurora 64 Radio*<br><sub>Vintage instrument panel · 复古仪器面板</sub> | **周末市集** · *Weekend Market*<br><sub>Sticker collage × receipt · 贴纸拼贴 · 小票</sub> |-| <img src="examples/panel_radio.jpg" width="100%"> | <img src="examples/sticker_market.jpg" width="100%"> |-| **咖啡萃取实验** · *Coffee Brewing Experiment*<br><sub>Lab notebook × stickers · 实验笔记本 · 贴纸</sub> | **为什么天空是蓝的** · *Why Is the Sky Blue?*<br><sub>Chalkboard · 黑板板书</sub> |-| <img src="examples/notebook_brewing.jpg" width="100%"> | <img src="examples/chalk_lesson.jpg" width="100%"> |-| **霓虹不夜城** · *Neon District*<br><sub>Cyberpunk · 赛博朋克</sub> | **早安吐司** · *Good Morning, Toast*<br><sub>Hand-drawn cartoon · 卡通手绘</sub> |-| <img src="examples/cyberpunk_neon_street.jpg" width="100%"> | <img src="examples/cartoon_toaster.jpg" width="100%"> |-| **岛上的气象站** · *Island Weather Station*<br><sub>Isometric 2.5D · 等轴 2.5D</sub> | **从这扇窗到那扇窗** · *From Window to Window*<br><sub>Continuous line art · 单线画</sub> |-| <img src="examples/isometric_weather_island.jpg" width="100%"> | <img src="examples/lineart_paper_plane.jpg" width="100%"> |-| **浮出** · *Rise*<br><sub>Soft 3D · 柔光 3D</sub> | **一滴水的旅程** · *A Drop's Round Trip*<br><sub>Shape morph · 形变动画</sub> |-| <img src="examples/soft3d_rise.jpg" width="100%"> | <img src="examples/morph_water_cycle.jpg" width="100%"> |-| **好奇心周刊 · 拆开看看** · *Curiosity Weekly · Take It Apart*<br><sub>Newspaper collage · 报刊拼贴</sub> | **晨间计划** · *Morning Plan*<br><sub>Aurora glassmorphism · 弥散玻璃</sub> |-| <img src="examples/newscollage_curiosity.jpg" width="100%"> | <img src="examples/aurora_morning.jpg" width="100%"> |-| **形与色** · *Form & Colour*<br><sub>Bauhaus geometric · 包豪斯几何</sub> | **海岸线 1987** · *Coastline 1987*<br><sub>Retro synthwave · 复古 Synthwave</sub> |-| <img src="examples/bauhaus_form_colour.jpg" width="100%"> | <img src="examples/synthwave_coastline.jpg" width="100%"> |-| **草莓杯垫** · *Strawberry Coaster*<br><sub>Perler beads · 拼豆</sub> | **迁徙季** · *Migration Season*<br><sub>Petroglyph · 岩画</sub> |-| <img src="examples/perler_strawberry_coaster.jpg" width="100%"> | <img src="examples/petroglyph_migration.jpg" width="100%"> |-| **尼罗河丰收** · *Harvest on the Nile*<br><sub>Egyptian tomb painting · 古埃及墓室壁画</sub> | **港口渔获** · *The Day's Catch*<br><sub>Roman mosaic · 罗马马赛克</sub> |-| <img src="examples/tomb_harvest.jpg" width="100%"> | <img src="examples/mosaic_harbor.jpg" width="100%"> |-| **四季之窗** · *Window of the Seasons*<br><sub>Stained glass · 彩色玻璃花窗</sub> | **星辰之书** · *Liber Stellarum*<br><sub>Illuminated manuscript · 泥金手抄本</sub> |-| <img src="examples/stainedglass_seasons.jpg" width="100%"> | <img src="examples/illuminated_starchart.jpg" width="100%"> |-| **扑翼机** · *The Ornithopter*<br><sub>Leonardo codex · 达·芬奇手稿</sub> | **剪影小像** · *Shades of the Wren Household*<br><sub>Silhouette · 剪影</sub> |-| <img src="examples/codex_ornithopter.jpg" width="100%"> | <img src="examples/silhouette_family.jpg" width="100%"> |-| **马戏团来了** · *The Circus Is Coming*<br><sub>Letterpress poster · 凸版印刷海报</sub> | **无线电** · *Radio*<br><sub>Soviet constructivism · 苏联构成主义</sub> |-| <img src="examples/letterpress_circus.jpg" width="100%"> | <img src="examples/constructivism_radio.jpg" width="100%"> |-| **夜行快车** · *Night Express*<br><sub>Art Deco · 装饰艺术</sub> | **火箭小队** · *Rocket Squad*<br><sub>Golden-age comic · 黄金时代漫画</sub> |-| <img src="examples/artdeco_express.jpg" width="100%"> | <img src="examples/comic_rocket.jpg" width="100%"> |-| **猫的六种心情** · *Six Moods of a Cat*<br><sub>Pop silkscreen · 波普丝网</sub> | **发射记录** · *Liftoff Trace*<br><sub>ASCII art (line printer) · ASCII 字符画(行式打印机)</sub> |-| <img src="examples/popart_cat_moods.jpg" width="100%"> | <img src="examples/lineprinter_launch.jpg" width="100%"> |-| **峡谷飞行** · *Canyon Run*<br><sub>Low poly · 低多边形</sub> | **放风筝** · *Hold On*<br><sub>Stencil graffiti · 喷漆模板涂鸦</sub> |-| <img src="examples/lowpoly_canyon.jpg" width="100%"> | <img src="examples/stencil_kite.jpg" width="100%"> |-| **三晚露营** · *Three Nights Out*<br><sub>Embroidered patches · 刺绣徽章</sub> | **灯塔剖面** · *Halvard Rock Light*<br><sub>Blueprint · 蓝图工程图</sub> |-| <img src="examples/patch_camping.jpg" width="100%"> | <img src="examples/blueprint_lighthouse.jpg" width="100%"> |-| **我的周末** · *My Weekend*<br><sub>Children's crayon · 儿童蜡笔画</sub> | **今天带伞吗** · *Bring an Umbrella?*<br><sub>Green-screen CRT terminal · 绿屏终端(荧光字符画)</sub> |-| <img src="examples/crayon_picnic.jpg" width="100%"> | <img src="examples/crt_weather.jpg" width="100%"> |-| **厨房里的温度** · *Kitchen Heat Map*<br><sub>Thermal camera · 热成像</sub> | **一阵风** · *The Gust*<br><sub>Delft tiles · 代尔夫特蓝瓷砖</sub> |-| <img src="examples/thermal_kitchen.jpg" width="100%"> | <img src="examples/delft_canal.jpg" width="100%"> |-| **篝火旁的岩洞** · *The Hunt by the Fire*<br><sub>Cave painting · 洞穴壁画</sub> | **窗台花园** · *Windowsill Garden*<br><sub>1-bit paint program · 1-bit 早期画图软件</sub> |-| <img src="examples/cave_hunt.jpg" width="100%"> | <img src="examples/macpaint_garden.jpg" width="100%"> |-| **赛跑与赛车** · *Games on a Vase*<br><sub>Greek black-figure vase · 古希腊黑绘陶瓶</sub> | **老街角的自行车** · *The Bread Run*<br><sub>Graphite pencil · 铅笔素描</sub> |-| <img src="examples/blackfigure_games.jpg" width="100%"> | <img src="examples/graphite_bicycle.jpg" width="100%"> |-| **行李安检** · *Security Check*<br><sub>X-ray · X 光片</sub> | **早晨的闹钟** · *Seven O'Clock*<br><sub>1930s rubber hose · 1930 年代黑白橡皮管动画</sub> |-| <img src="examples/xray_luggage.jpg" width="100%"> | <img src="examples/rubberhose_morning.jpg" width="100%"> |-| **雪夜归途** · *Homeward, First Snow*<br><sub>Linocut · 黑白麻胶版画</sub> | **吹蜡烛** · *Blow Out the Candles*<br><sub>VHS home video · VHS 家庭录像</sub> |-| <img src="examples/linocut_snowy_village.jpg" width="100%"> | <img src="examples/vhs_birthday.jpg" width="100%"> |-| **山间夜营** · *Night Camp*<br><sub>Flat vector · 扁平矢量</sub> | **小橡果的秋天** · *An Acorn's Autumn*<br><sub>Storybook animation · 绘本角色动画</sub> |-| <img src="examples/flatvector_night_camp.jpg" width="100%"> | <img src="examples/storybook_acorn.jpg" width="100%"> |-| **蛇梯棋大冒险** · *Snakes & Ladders, Round 7*<br><sub>Ballpoint doodle · 圆珠笔涂鸦</sub> | **海港步行图** · *Larkhaven on Foot*<br><sub>Overlay sheets · 描图纸叠层</sub> |-| <img src="examples/ballpoint_board_game.jpg" width="100%"> | <img src="examples/overlay_city_map.jpg" width="100%"> |-| **出发前,再查一遍行李** · *Pack Check*<br><sub>Pastel UI · 粉彩界面</sub> | **数学单元测验** · *Unit Test, Graded*<br><sub>Exam grading · 阅卷批改</sub> |-| <img src="examples/pastelui_packing.jpg" width="100%"> | <img src="examples/grading_math_quiz.jpg" width="100%"> |-| **蹴鞠** · *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%"> |--Every mark above is computed: paper fibres, ink washes and mist, dry-brush strokes, pigment granulation and blooms, torn-paper edges, pencil wax on paper tooth, cel-shaded clouds, risograph grain and halftones, lit impasto relief, woodblock grain and bokashi, dithered pixels, plasticine lit like a film set, sunlight through leaves on Prussian blue, twisted thread on Aida cloth, machined knobs behind a backlit dial, die-cut vinyl with a laminate gloss, streaky thermal print, graphite catching the tooth of graph paper, highlighter pooling at the start of a swipe, chalk dust settling under half-erased lessons, rain-lit neon glass mirrored in a wet street, a blue-pencil rough under boiling brush ink, an island ray-traced under one soft sun, a single unbroken gold line, candy balls with softbox glints, one outline morphing through six shapes, halftone photos cut out with scissors, frosted glass blurring the real pixels behind it, screen-printed primaries out of register, a slit sun sinking behind a neon grid played off tape, hollow fuse beads on a pegboard melting together under an iron, pits knocked through desert varnish, a red grid showing through flaking plaster, stones laid row by row along an outline, daylight through leaded glass, burnished gold that mirrors the room, left-handed hatching in iron-gall ink, black paper cut with scissors, wood type printed a hair out of register, red and black plates slipping apart, airbrush fades inside knife-cut friskets, Ben-Day dots on yellowed newsprint, one photo key pulled across hand-painted colour, characters struck through a fading ribbon, flat-shaded triangles dithered to 15 bits, spray drifting past cut card, satin stitches catching the light by their angle, ink lines printed white on Prussian blue, wax scribbles skipping the paper's pits, phosphor glowing behind curved glass, heat leaking out of a kitchen, cobalt fired into tin glaze tile by tile, ochre blown onto rock lit by a fire, 1-bit patterns in an old paint program, slip silhouettes incised to the clay, graphite that never quite reaches black, X-rays adding up through a suitcase, grey cels shot on scratched film, gouge marks in a rolled-up block, a birthday smeared onto tape, seven flat colours lifting off each other, an acorn squashing and stretching through a world drawn as it goes, ballpoint ink blobbing at every corner of a hand-drawn game, inks multiplying through tracing paper on a light box, window cards floating on a pastel field over shadows tinted by it, a vermilion stamp running dry at one end, red ink pooling where the pen slowed down and dyed donkey hide glowing on a lamp-lit screen. No diffusion model, no API, no stock art. It is just Python with **numpy + Pillow** on a CPU: from 0.1 s (pixel art) to about 45 s (the soft 3D ray tracer) per 1920×1080 image.+| **秋日湖畔** · *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.---@@ -130,7 +132,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-four styles:+A [Claude Code](https://claude.com/claude-code) skill and a small painting library with sixty-five styles:| Style | Module | What makes it read as the real medium ||---|---|---|@@ -198,6 +200,7 @@ A [Claude Code](https://claude.com/claude-code) skill and a small painting libra| **Exam grading (an answer sheet marked in red)** | `lib/grading.py` · `Grading` | an answer sheet on a green felt desk, printed like the real form — timing marks down the edge, a heavy title, fields, a ticket number with its bubbles filled, a score / grader table, numbered sections, ruled answer lines and a hatched grading column — with an answer key held by a black binder clip beside it; every paper has its own frame and pose, so a sheet can come down onto the desk (a little larger with a wide soft shadow while lifted, a thin contact shadow once down); everything written after printing keeps a progress value and a time map, so a stage can show a stroke half drawn: the candidate's blue-black answers, vermilion rubber stamps (ragged edges, clustered pin-holes, one end pressed dry so the thin border breaks, ink pooled at the rims, a wet bleed, a slight tilt, the paper dented round the rubber) and the red pen — a wavy underline, a ring that overshoots its start, a bowed leader, a note set in a bold sans and inked like the pen (no handwriting font), crosses, ticks and a score written stroke by stroke and circled; ink is Beer–Lambert density, so the red deepens where the pen slowed down and where it crosses print; a red pen shaded as a cylinder whose shadow spreads from the tip, and a varnished wooden stamp that comes down, presses and lifts || **Shadow puppetry (皮影戏)** | `lib/shadowpuppet.py` · `ShadowPuppet` | a shadow play seen from the audience, where everything on the screen is lamp light that came through it: a cloth screen lit by an oil lamp behind the middle (pale gold at the hot spot, deep amber toward the rim, thread slubs, a fold or two); puppets of scraped donkey hide kept as coverage plus an optical density per channel, so vermilion, teal, ochre and green glow, black dye is almost opaque and pieces darken where they overlap, in any order; pieces are cut, dyed in fields, inked along every cut edge and punched with the craft's hollow patterns (dots, rings, plum blossoms, coins, fish scales, ruyi cloud heads, lattice, ice cracks, stripes), and the hide's uneven thickness leaves no dye flat; a figure is a tree of jointed pieces with thread knots and an angle per joint (a hollow-carved or solid face in profile with one long eye and a long brow, a helmet with barred pheasant plumes or a crown with pompoms, cloud collar, breastplate mirror, scale armour, cuffs, thick-soled boots), with control rods tied to the collar and the hands; a puppet off the cloth grows, blurs and splits into two shadows (the lamp has two wicks), the soft double edge of a figure not quite pressed, and rods are sharp where they are tied and soft lower down; props come from the same leather (a pailou goal with a lattice net and a round eye, a stitched ball, a key-fret floor band, hanging name plaques); in front, a carved proscenium (key-fret lintel, a red lacquer plaque with raised gilt characters, an openwork valance and corner brackets the screen glows through) lit only by the light the screen spills onto its edges, and red paper lanterns lit from inside, with tassels and a warm halo || **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 |Ask Claude to *"draw it yourself"*, *"paint this with code"*, or *"claude绘图"*, and name a style if you like. Claude then:@@ -315,6 +318,13 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages- **Exam grading**: tell one grading story on one sheet — a few answers, one mistake, and every red mark pointing at it: a wave under it, a ring round it, a leader out to the grading column, and the note and the cross on the same row as the error (put that row first in the column so the leader stays short). Keep the words few and large and let the form itself (bubbles, timing marks, hatching) carry the texture. Give a ring room: it needs ~8 px of clear paper on each side, so leave the candidate a wider gap before the wrong figure. Stamps should be uneven but still legible (pressure ~0.64 at the light end). Red ink is Beer–Lambert density and only darkens a little above ~0.8, so light and dark passages come from the density range (about 0.4–1.2), not from the colour. In the GIF, give the pen and the stamps real in-between frames (`~` motion stages) instead of cross-fades.- **Shadow puppetry**: keep the screen dark at the rim and pale gold only round the lamp, so dyed leather glows instead of looking printed. Leave big fields of solid dye and put the hollow patterns in bands; a pattern cell under ~12 px on the canvas turns a robe into fishnet. In profile the shoulder sits right under the head, so a near arm raised past ~140° crosses the face: raise the far arm up and back and keep the near one forward (130–147°). The classic 亮相 is one arm high behind, one low in front and a knee up. Give each figure room for its plumes, and keep the shoulder guard on the near arm only. A puppet slightly off the cloth (d ≈ 0.05) should read as a sharp shadow with a soft double edge, not as out of focus. In the GIF, everything that moves gets real in-between frames (`~` motion stages): the lamp glow spreading, players sliding in from the wings blurred and doubled until they are pressed sharp, the kick, the 亮相 snap.- **Pen & wash**: ink first, paint second, and let the paint miss: slip each wash a few px off its line so one side spills and the other leaves white paper — but shrink the slip for tiny shapes, or a nose or a crumb becomes a white ring. Keep tooth and granulation quiet; at full strength the card looks like stucco and the washes like coloured pencil. Give parts a depth so outlines break where something is in front, and keep the features inside the head (only the nose may bulge past it). Watch for accidental reads: a small circle under a moustache becomes a letter, a red dome with white spots a toadstool, a white oval belly a snowman, and a scooter stem must not cross a face. Paint the background block around the figure with a halo, never out to the card edge. Draw the tools at real scale (a fineliner is longer than the card is tall). In the GIF, give the bare table a small palette share of its own and cut the rest only from pixels that change, or the oak eats the colours of the pale blocks.+- **Retro gouache**: paint dark to light and let every coat cover the one before. The dry brush is what makes it gouache: lay the background solid with loaded strokes, then scumble it with a brush that is already half dry (`load` ≈ 0.7) in a lighter and a darker mix; strokes that start fully loaded read as sausages. Model forms in three or four soft value steps on a dome, with the light partly frontal, or hats and faces turn into flat discs with a bright rim. Give skin a warm shadow ramp, because the default cool ramp goes violet on skin. Model big noses with small, semi-opaque strokes, or they look like camouflage. Every texture works on the paint already under its mask, so subtract whatever lies in front before you call `knit`, `rib` or `dry_highlight`. Watch for accidental reads:+ - oilskin beads in a row become rivets;+ - a scarf with round ends becomes a neck pillow;+ - steam that touches the nose becomes a runny nose;+ - 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.### Roadmap@@ -326,7 +336,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,加上一个小巧的绘图库,内置六十五种画风:| 画风 | 模块 | 为什么看起来像真的 ||---|---|---|@@ -394,6 +404,7 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages| **阅卷批改** | `lib/grading.py` · `Grading` | 绿毛毡桌上的一张答题卡,照真表格印:左边一排定位黑块、粗黑标题、姓名班级栏、考号格和涂好的圆泡、得分 / 阅卷人表格、分节、作答横线、斜纹阅卷栏;旁边是长尾夹夹住的标准答案卡。每张纸有自己的坐标和位姿,能从空中落到桌上(抬着时略大、投一片宽软的影,放下后只剩贴边细影);印刷之后写上去的东西都带「写到第几成」的进度和时间图,阶段快照能画出写到一半的笔画:考生的蓝黑作答、朱红橡皮章(毛边、成簇针孔、一头压得轻而细框断开飞白、边缘积墨、刚盖下的湿晕、轻微歪斜、纸面压出的凹痕),以及红笔的波浪线、越过起点的手画圈、弧形引线、用粗黑体按红墨处理的批注(不用手写字体)、叉、勾、一笔笔写出再圈起来的分数;墨按比尔定律算密度,笔走慢的拐弯处、压在印刷上都会更深;红笔按圆柱打光、投影从笔尖散开,上漆木章落下、压一下、再抬起 || **皮影戏** | `lib/shadowpuppet.py` · `ShadowPuppet` | 观众这边看到的一场皮影,幕布上的一切都是透过来的灯光。幕布由一盏油灯从背后照亮:灯后面淡金,往外深琥珀,带纱线粗节和一两道折痕。人偶是刮薄的驴皮,按覆盖率加每个通道的光密度来算,所以朱红、青绿、赭黄、绿色透亮,黑色几乎不透,两块皮相叠处更深,和先后顺序无关;每块皮可以剪、分区染色、沿剪边描黑,打出皮影的各种镂空纹样(圆点、圆环、梅花、铜钱、鱼鳞、如意云头、方格、冰裂、条孔),皮厚不匀让染色不会死平。关节人偶是一棵带线结、每个关节一个角度的皮件树(阳刻空脸或阴刻脸的侧面像,一只长眼一道长眉;带黑横斑的雉翎盔或绒球三叉冠;云肩、护心镜、鱼鳞甲、袖口、厚底靴),操纵杆绑在领口和手上。离开幕布的人偶会变大、变虚,又因为灯有两个灯芯分成两个影,就是没贴紧时那种软的双边;操纵杆绑的地方清楚,往下越来越虚。同一套皮还做道具:牌楼式球门(窗棂网和风流眼)、缝线的鞠、回纹底带、挂在线上的小牌。幕前是雕花戏台(回纹横楣、红漆凸起金字牌匾、透空挂落和花牙子,幕布的光从镂空处透出来),只被幕布溢出的光照亮边缘;还有内有烛光的红纸灯笼,带穗子和一圈暖光 || **钢笔淡彩** | `lib/penwash.py` · `PenWash` | 照速写人的顺序画在冷压水彩小卡上:先针管笔线稿,再松散淡彩,最后把卡片放在桌上拍下来。每张卡是独立的一张纸(窗光照出的纸纹、略不直的切边),不转着画,放下时才带一个小角度。墨线几乎等宽但是手画的:低频手抖加颤动、线宽漂几个百分点、落笔一个小墨点、有的收尾一甩;闭合形状由一到三笔组成,接口停早留缺口或冲过头沿切线出头,方框的角相互出头,偶尔一段描两遍;部件分前后,被前面部件盖住的轮廓线自动断开。淡彩先算「本来要涂的区域」,再像手快那样涂:整块错位 2–5 px(一边出线、另一边在线里留白缝),边缘用游走的阈值重新取、顺着纸纹,干边更深,颗粒沉在纸纹的谷里,淡淡的平刷条纹,浓淡斑驳,腮红和面包烤色湿中湿滴进去,打湿处纸面起皱;小形状错位缩小,鼻子不会变成白圈。不铺满卡片的背景色块绕开人物、留一圈白边;白色水粉高光最后上。墨和颜料都按光密度叠加,相叠变深、混色。带画呆萌小人的部件:大圆眼镜、点点眼、翘头发、简单的手、四肢、手绘边框、地线。照片:带「山纹」年轮和拼接缝的橡木桌、卡片的软阴影和受光的切边、按圆柱打光的针管笔和水笔(透明水杆折射下面的东西)、窗光衰减、暗角和颗粒 |+| **复古水粉** | `lib/gouache.py` · `GouachePortrait` | 用不透明水粉画复古绘本里的大头像,照水粉画家的顺序从暗到亮、从大到小:画板上先刷一层暖色托底,用赭色起稿;背景先满载铺平,再用半干的笔蘸亮一点、暗一点的同色皴擦;然后平涂大块,用几阶色值塑形,再上质感、五官和干笔高光,最后是印刷书页的颗粒。每一层都不透明(盖住下面),湿笔会带起一点底色。一笔是扁笔沿短弧拖过去:鬃毛含色不同,所以顺着笔有条纹;颜料越拖越少,笔尾只在纸纹凸起上留下断续的丝和点;两侧毛边,落笔处圆头。边缘利落,但会游走、在纸纹上断开。形体先鼓成穹顶(鼻子、绒球、珍珠用精确的椭球),左上方一盏灯,受光分成几个软台阶、映射到五个调出来的颜色,再用顺着形体的短笔一笔笔盖上去,台阶之间是带笔触的接缝;帽檐、鼻子、胡子下面的暗部是一层薄薄的正片叠底,腮红是粉状的。毛衣一针一针地算:V 字两条带捻股的纱线、交替在前的麻花、凹下去的反针罗纹,乘到已有的颜料上,大的明暗不丢。头发、眉毛、胡子、卷发、绒球是成千上万根锥形细线,沿流向场走、按受光分档。毛毡是斑驳、短纤维和毛茸茸的轮廓。呆萌五官:带眼皮和高光的圆眼(`look` 可以对成斗鸡眼)、带鼻孔和亮点的大鼻子、大耳朵 |对 Claude 说「claude绘图」「你自己画」「用代码画」,也可以指定画风。它会:1. **先定构图**:层次、焦点、留白,而且画面要图解内容本身;@@ -487,6 +498,7 @@ python3 examples/pastelui_packing.py out.jpg --stages stages/ # 粉彩界python3 examples/grading_math_quiz.py out.jpg --stages stages/ # 阅卷批改:数学单元测验python3 examples/shadowpuppet_cuju.py out.jpg --stages stages/ # 皮影戏:蹴鞠python3 examples/penwash_neighbours.py out.jpg --stages stages/ # 钢笔淡彩:街角速写+python3 examples/gouache_rainy_day.py out.jpg --stages stages/ # 复古水粉:雨天三人像```### 作画要点(Claude 交图前逐条自查)@@ -553,6 +565,13 @@ python3 examples/penwash_neighbours.py out.jpg --stages stages/ # 钢笔淡- **阅卷批改**:一张卷子讲一件批改的事——几道作答、一处错,所有红笔都指向它:下面波浪线、外面一个圈、一道引线拉到阅卷栏,批注和叉跟出错那行同高(把批注行排在阅卷栏第一行,引线才短)。字少而大,纹理交给表格本身(涂卡圆泡、定位黑块、斜纹)。圈要有地方:两边各要约 8 px 空白,所以让考生在写错的那个数前多空一格。印章要不匀但认得出(轻的那头压力约 0.64)。红墨按比尔定律算密度,0.8 以上只是略微变深,浓淡要靠密度范围(约 0.4–1.2)拉开,而不是换颜色。做动图时,笔和章给真正的中间帧(`~` 运动阶段),不要叠化。- **皮影戏**:幕布边缘要暗,只在灯后面那一块发淡金,染色的皮才会「透亮」,而不是像印上去的。大面积留实色,镂空纹样只放在一段里:画布上一个纹样单元小于约 12 px,袍子就成了渔网。侧身时肩就在头的正下方,近侧手臂抬过约 140° 会从脸前过:要高举就举远侧那只往后上方,近侧手臂斜向前上(130–147°);亮相就是一手高(远侧向后上)、一手低(近侧向前下),再提膝。给翎子留地方;护肩花只放在近侧手臂上。离幕一点(d ≈ 0.05)的人应该是一个清楚的影加一条软的双边,不是失焦。做动图时,会动的都给真正的中间帧(`~` 运动阶段):光晕铺开,人从侧幕滑进来由虚变实,起脚,亮相定住。- **钢笔淡彩**:先墨后彩,让颜色「涂歪」:每块淡彩错开线条几 px,一边出线、另一边留白缝;但小形状要把错位缩小,否则鼻子、面包屑会变成白圈。纸纹和颗粒要收着,开满了卡片像拉毛墙、淡彩像彩铅。部件要分前后,被挡住的轮廓线才会断开;五官收在头的轮廓里(只有鼻子可以鼓出去)。小心看错:胡子下面的小圆圈会读成字母,红圆顶加白点是毒蘑菇,白色椭圆肚子是雪人,滑板车立杆不能穿过脸。背景色块绕开人物留白边,不要铺到卡边。桌上的笔按真实比例画(针管笔比卡片还长)。做动图时空桌面单独分少量色位,其余只从变化的像素里切,否则橡木会吃掉淡色背景块的色位。+- **复古水粉**:从暗到亮,每层盖住上一层。让它像水粉的是干笔:背景先用满载的笔铺平,再用一落笔就半干(`load` 约 0.7)的笔蘸亮一点、暗一点的同色皴擦;每笔都满载落笔,就成了一根根香肠。形体在穹顶上分三四个软台阶,光要带正面分量,否则帽子和脸是扁盘子、亮的是轮廓边。皮肤给暖的暗部,默认的冷色在皮肤上发紫。大鼻子用小的半透明笔触,否则像迷彩。所有质感都是对遮罩里已有的颜料做乘法或加笔,调 `knit`、`rib`、`dry_highlight` 前先把前面的部件从遮罩里减掉。小心看错:+ - 排成一排的雨珠像铆钉;+ - 两端圆头的围巾像颈枕;+ - 热气碰到鼻子像鼻涕;+ - 同心的卷发像肉桂卷(让每个卷是绕着暗色空洞的环);+ - 两片鼓鼓的衣领像靠垫。+ 最后在受光面拖干笔高光,穹顶要顺坡拖。做动图时强制放几个深中性色,否则瞳孔会被量化成藏青。### 计划diff --git a/SKILL.md b/SKILL.mdindex 95d5c8a..46895f9 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(速写小卡上的针管笔线稿 + 松散淡彩:线条抖、出头、不闭合,颜色错位出线、留白缝、干边与颗粒,不铺满的背景色块;大头、圆眼镜、点点眼、红鼻子的呆萌小人;卡片拍在木桌上,旁边放着针管笔和水笔)。用户说「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 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(复古绘本风的水粉大头像:不透明水粉从暗到亮一层层盖上去,单色背景用干笔皴擦;大红鼻子、腮红、圆眼和大耳朵用几阶色值塑出来;看得见针脚的毛衣和毛线帽,一根根的头发和胡子,毛毡;最后是印刷书页的纸纹)。用户说「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 风 / 粉彩界面 / 窗口卡片 / 发布会界面」指粉彩界面(纯色底 + 白色实心窗口卡片),要磨砂玻璃和弥散渐变仍用弥散玻璃;「阅卷 / 批改 / 答题卡 / 判卷 / 红笔打分」指阅卷批改,实验记录里的红笔圈和便利贴仍用实验笔记本,带「已付」橡皮章的小票拼贴仍用贴纸拼贴 · 小票;「皮影 / 皮影戏 / 影子戏」指皮影戏(透光的彩色驴皮人偶),黑纸剪出的侧影小像仍用剪影,彩纸剪贴仍用剪纸拼贴。「钢笔淡彩 / 淡彩速写 / 针管笔加水彩 / 线稿上色的速写小卡」指钢笔淡彩;单说「水彩」仍指水彩(风景、花卉的大片晕染),蓝铅笔稿 + 毛笔线 + 赛璐璐阴影的拟人小物仍用卡通手绘,「素描 / 铅笔」仍指铅笔素描。「水粉 / 复古水粉 / 绘本大头像 / 复古童书插画」指复古水粉(不透明水粉画的特写大头像);梵高式厚涂的风景、名画感仍用油画厚涂,扁平矢量、会挤压拉伸的小角色动画(「绘本动画」)仍用绘本角色动画,针管笔线稿加淡彩的速写小卡仍用钢笔淡彩,撞色多格的头像仍用波普丝网。---# Claude 绘图@@ -78,6 +78,7 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型| 阅卷批改 · Exam Grading | `lib/grading.py` · `Grading` | `examples/grading_math_quiz.py` 数学单元测验 · Unit Test, Graded(深绿毛毡桌上一张米色答题卡,下面还压着两张:左边一排定位黑块、角标、粗黑标题、姓名班级栏、考号格和涂好的涂卡圆泡、得分 / 阅卷人表格、填涂示例;一题三道计算,二题应用题(灰底题目框 + 浅方格横线作答区 + 斜纹阅卷栏);左边长尾夹夹着深蓝页眉的标准答案卡,下面一张评分小纸条。考生用蓝黑墨水逐行作答;两个朱红橡皮章盖进阅卷栏(书写工整 ✓、列式正确 ✓);红笔给三道计算打勾,在 128 ÷ 16 = 6(天)下画波浪线、圈出「6(天)」、引线拉到阅卷栏写「应为 8 天」再打叉,答句里的 6 划一道,标准答案卡上 ① 打勾、② 打叉,最后在得分格写 75 并圈起来,笔放在得分格旁;印章一头发干、边缘飞白、轻微歪斜,红墨有浓淡和晕染,纸纹和灯光不均;`--stages` 出 113 个阶段,含纸落下、章落下压一下抬起、红笔边走边写的中间帧) | 约 1 秒(成品)/ 约 35 秒(含阶段) || 皮影戏 · Shadow Puppetry | `lib/shadowpuppet.py` · `ShadowPuppet` | `examples/shadowpuppet_cuju.py` 蹴鞠 · Cuju by Lamplight(油灯从背后照亮的琥珀色幕布,前面是雕花戏台:回纹浮雕横楣、红漆金字牌匾「蹴鞠」、透空回纹挂落、两角镂空花牙子、两盏红灯笼;幕上是雕空、透明染色的驴皮:牌楼式球门(瓦顶飞檐、鸱吻、窗棂网、红边风流眼)、底部回纹装饰带、四个关节人偶。红方球头刚起脚,一条腿踢得老高,同伴一手高一手低、提膝亮相;青方一个跳起扑球(离幕一点,边缘发软、成双影),一个指着球;鞠正卡在风流眼里;「球头」「骁色」两块小牌挂在线上。人偶是阳刻空脸或阴刻红脸、雉翎盔或三叉冠、云肩护心镜鱼鳞甲、厚底靴,皮叠在一起处更深,关节有线结,操纵杆从领口和手上垂下去;`--stages` 出 60 个阶段,全是真运动:点灯、横楣落下、灯笼晃着亮起、球门升起、人从侧幕滑进来由虚变实、传球、起脚、亮相、小牌落下) | 约 7 秒(成品)/ 约 27 秒(含阶段) || 钢笔淡彩 · 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 秒(含阶段) |各画风共用 `lib/core.py` 里的底层工具:噪声、模糊、样条曲线、多边形遮罩、有机轮廓 `blob_pts`、毛笔 `bristle_stroke`、中文字体查找;新四种还用到补零平移 `shift`、文字遮罩 `text_mask`、西文字体查找 `latin_font`/`load_font`,以及高度图打光 `height_normals`、`height_shadow`(沿光线步进的投影)、`ambient_occlusion`。@@ -145,7 +146,8 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型- 产品发布片 / 科技讲解片的「界面 / 流程 / 检查结果」页,要明亮干净、像真产品截图的窗口卡片,一屏讲一件事(大标题 + 一个主窗口 + 一个侧面板 + 状态),一整部讲解片统一的主画面(每节换一种粉彩底、圆形擦除转场)→ 粉彩界面(要磨砂玻璃和弥散渐变用弥散玻璃;要等轴微缩模型用等轴 2.5D;要黑白早期界面用 1-bit 早期画图软件);- 考试、作业、批改与打分,「对照标准答案逐条检查」的过程(评测、验收、审核、评分规则、哪里错了、为什么扣分),讲解片里的「怎么判对错 / 评分标准 / 检查结果」页 → 阅卷批改(要草稿纸上的随手推演用圆珠笔涂鸦;要实验记录、红笔圈和便利贴用实验笔记本;要明亮的产品界面里打 ✓ / ✗ 用粉彩界面);- 中国传统与民间艺术、节庆(元宵、庙会、过年)、戏曲和民间故事、古代体育与游戏(蹴鞠、赛龙舟、舞狮)、「一场好戏」式的小叙事(登场—交手—亮相),讲解片里的「历史 / 传统 / 一场比赛的高光时刻」页,要人物有动作又不能用真人 → 皮影戏(要黑纸剪的侧影小像用剪影;要彩纸剪贴的童趣用剪纸拼贴;要山水留白用水墨);-- 人物小品、街坊邻居与日常小事(送信、浇花、骑车、买面包)、一组角色卡 / 人设卡、旅行和城市速写里「一个人在做一件小事」、轻松幽默的配图,讲解片里「一组用户 / 角色 / 团队成员」的介绍页 → 钢笔淡彩(要蓝铅笔稿、毛笔线和赛璐璐阴影的拟人小物用卡通手绘;要风景和花卉的大片晕染用水彩;要真的动起来的角色用绘本角色动画;要草稿纸上的随手涂鸦用圆珠笔涂鸦)。+- 人物小品、街坊邻居与日常小事(送信、浇花、骑车、买面包)、一组角色卡 / 人设卡、旅行和城市速写里「一个人在做一件小事」、轻松幽默的配图,讲解片里「一组用户 / 角色 / 团队成员」的介绍页 → 钢笔淡彩(要蓝铅笔稿、毛笔线和赛璐璐阴影的拟人小物用卡通手绘;要风景和花卉的大片晕染用水彩;要真的动起来的角色用绘本角色动画;要草稿纸上的随手涂鸦用圆珠笔涂鸦);+- 人物大头像、角色特写、一组人设的「封面像」、温暖怀旧的复古童书 / 绘本插画,要有摸得着的手感(毛衣针脚、毛线帽、胡子和卷发、毛毡),讲解片里「这个人登场」的特写页 → 复古水粉(要线稿加淡彩、「一个人在做一件小事」的速写小卡用钢笔淡彩;要真的动起来的扁平小角色用绘本角色动画;要梵高式厚涂的风景用油画厚涂;要撞色多格的头像用波普丝网)。每种画风一幅范例作为质量基准(范例都不用禅意主题);水墨另加一幅「月印万川」(留白托月、水面倒影)。@@ -1018,6 +1020,56 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask- 桌上的道具:`pen(x, y, angle, length=430, r=10.5, cap=True)` 针管笔(笔尖在 (x, y)、笔身朝 angle 度:纤维笔尖、金属套管、灰色锥头、哑光笔杆上印着线宽、套在尾部的亮面笔帽和笔夹);`water_brush(x, y, angle, length=320, r=12, stain='teal', cap=(x, y, angle))` 水笔(尼龙笔尖、尖上染一点颜料、螺纹握把、微雾的透明水杆按圆柱折射下面的东西、尾部气泡;`cap` 另放一个透明笔帽);都按圆柱打光、带投影(透明部分影子浅、有一点焦散)。比例:卡片约 9 cm 宽时,针管笔比卡片还长(范例 640 px、r 16),水笔 600 px、r 24- 常量 `PAINTS INK PAPER WOODS LINEN SHADOW`;`render()`、`composite()`、`stage(name)`、`save(path, stages_dir)`;`save('x.jpg')` 默认 quality 88、4:4:4 色度;笔杆上的字用 core 的 sans_bold(可用 `INKPAINT_FONT_SANS_BOLD` 指定)+**复古水粉 `GouachePortrait`**:+- 思路:不透明水粉一层盖一层,从暗到亮、从大到小(托底色 → 赭色起稿 → 背景 → 平涂 → 色值塑形 → 质感 → 五官 → 高光 → 印刷颗粒)。+ - 颜料:每一笔都替换下面的颜色(C ← C + (色 − C)·A),湿笔会带起一点底层的颜色(`pickup`)。+ - 纸纹:画板有一张纸纹高度场 `G`。+ - 一笔:扁笔沿短弧拖过去。横向每根鬃毛含色不同,所以顺着笔有条纹、颜色略有深浅;纵向颜料越用越少。含色高时全覆盖,变少后只落在含色多的鬃毛经过纸纹凸起的地方,所以笔尾断成干笔丝和点;两侧毛边,落笔处圆头。+ - 边缘:形状先模糊一像素,再按低频摆动和纸纹重新取阈值,利落但不是矢量边。+ - 塑形:遮罩模糊后按内缘归一化、再开方当穹顶高度(也可以给 `height`;球体用精确椭球)。一盏左上偏正面的光,受光量化成 3–5 个软台阶,映射到五色阶(暗部偏紫红,亮部偏暖白)。先湿铺一遍,再用顺着形体的短笔(等高线方向、顺坡或绕球心)按落点取色盖上去。+ - 针织:每针一个 V(两条斜椭圆、圆柱截面的纱线,带捻股斜纹,相邻行交叠,谷底遮蔽),按光照乘到已有颜料上,大的明暗保留。行可以拱、垂、旋转或沿路径走;麻花是两股交替在前的圆管;罗纹是凸起的正针列和凹下的反针列,每列上有小的人字针。+ - 头发:先画暗色的发团,再沿流向场画成百上千根锥形细线,按受光场从暗到亮分档,暗的先画,少数飞出轮廓。+ - 毛毡:两种尺度的斑驳,加短纤维和轮廓外的绒毛。+ - 最后 `grain()` 叠印刷书页的感觉:纸纹颗粒、亮部的暖纸色、墨色到不了纯黑、饱和度略收。+- 构造:`GouachePortrait(W, H, seed, keep_stages=True, stages_dir=None)`(总像素不超过 4096²)。+ - `panel(x0, y0, w, h)` 新建一块画面并设为当前;之后的坐标都是这块画面里的局部像素。`use(p)` 切换。+ - `ground(tone='#c88f5a', paper, alpha=0.5)` 画米色画板,每块画面刷一层薄的暖色托底。+ - `sketch(mask, colour, width=2.2, alpha=0.8, breaks)` 用稀释的赭色勾出遮罩轮廓,即起稿,会被后面的颜色盖住。+- 形状:返回画面大小的浮点遮罩,用 `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)` 粗路径;`GouachePortrait.tube(path, w0, w1)` 给轮廓点。+ - `rough(mask, amount)` 画出来的毛边。+- 笔:角度一律是度,0 向右,90 向下。+ - `stroke(x, y, angle, length, width, colour, bend, dry, alpha)` 一笔。+ - `strokes(mask, colour 或颜色场, angle 或角度场或 f(x, y), length, width, density, dry, alpha, clip, load)` 在遮罩里撒很多笔,每笔在落点取颜色和方向。`load` < 1 是落笔就半干的皴擦。+ - `dry_brush(path, width, colour, dry, alpha, taper)` 沿折线拖一长笔(热气、长扫)。+- 画:+ - `scumble_background(colour, bottom=None, avoid=人物遮罩, angle, light, dark, scratches, flecks, blend)` 单色或上下渐变的背景:满载的长笔铺底,再用半干的亮、暗两遍皴擦,加短的浅色刮痕和溅点,绕开人物。+ - `block_in(mask, colour, angle)` 平涂一块,返回毛边遮罩。+ - `model_form(mask, colours 五色阶, steps=4, height=None, angle='contour'|'fall'|数|场|函数, relief=0.55, round_=0.5, bias, ambient=0.08)` 几阶色值塑形,返回受光场。+ - `form_light(mask, height, relief)` → (受光 0–1, 高度, 梯度)。+ - `sphere_shade(cx, cy, rx, ry, colours, mask, rot)` 球形塑形:笔触绕球心,下缘有反光。+ - `glaze(mask, colour, alpha, mode='multiply'|'screen'|'normal', soft)` 罩一层。+ - `cast_shadow(caster, dx, dy, soft, alpha, colour, on)` 帽檐、鼻子、胡子下的软投影,只落在 `on` 上。+ - `dry_highlight(mask, colour, above=0.62, angle)` 受光处的干笔高光,穹顶用 `'fall'`。+ - `blush(cx, cy, rx, ry, colour, strength)` 粉状腮红。+ - `dab(x, y, r, colour)` 一小点(高光、扣子)。+ - `line(path, width, colour, alpha, taper, dry)` 小圆笔画线。+ - `spatter(mask, colour, n, size)` 溅点。+- 脸:+ - `eye(cx, cy, r, ry, iris, iris_r, look=(dx, dy), lid, lid_colour, lashes, lash_dir, ring, lower, iris_light)` 圆眼:米白眼球、眼皮下的阴影、深色或青色虹膜(下半亮)、黑瞳孔、白色高光、眼皮和眼皮线、细的暖色外框。`look` 取 1 是贴边,两只眼往里、往下就是斗鸡眼。+ - `nose(cx, cy, rx, ry, colour, on, cast)` 大鼻子:脸上的软投影、球体塑形、下缘反光、鼻孔、柔和的粉白高光加一点白。+ - `ear(cx, cy, rx, ry, colour, side)` 大耳朵。+- 质感:+ - `knit(mask, stitch=(宽, 高), origin, curve, angle, path, cables=[(x, 宽)], strength, highlight)` V 字平针。`curve` > 0 行往下垂,< 0 往上拱;给 `path` 时沿围巾走。+ - `rib(mask, path, period)` 罗纹(领口、袖口、帽檐翻边)。+ - `hair_strands(mask, flow, colours 暗→亮, n, length, width, shade, curl, jitter, roots, clip)` 发丝、眉毛、胡子、绒球、卷发。+ - `felt(mask, strength, fibres, fuzz)` 毛毡。+- 颜色与常量:+ - 颜色用 `PAINTS` 里的名字(vermilion red orange mustard yellow ochre cobalt cerulean navy teal seaglass green olive peach skin ruddy nose rose blush pink umber sienna cream white grey ink brown cocoa)或 '#rrggbb'。+ - `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 色度。+**顺序**:都是先远后近、先大后小,文字最后叠加。水墨的雾要画在它该吞没的东西之后;水彩的叶梗要先画,并且只画在叶子外面。## 三、毛病清单(都真实出现过)@@ -2020,6 +2072,23 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask| 笔太小,下面三分之一桌面空着 | 按真实比例:卡片约 9 cm 宽时,针管笔比卡片还长(640 px、r 16),水笔 600 px、r 24 || 动图里淡蓝、灰绿背景块变成灰青和米色,黄衣服发橙 | 橡木桌本身就是饱和色,「饱和像素 ×5」把色位都给了木头:56 色只从空桌面切,198 色只从和空桌面不同的像素切;末帧 p99 误差 35 → 23 |+**复古水粉**++| 问题 | 改法 |+|---|---|+| 背景像一根根香肠,圆头,颜色一块一块地跳 | 每笔都满载落笔才会这样:底层的长笔触几乎同色(vj 0.012),只在笔尾变干;上面亮、暗两遍落笔就半干(load 0.72–0.74,dry 约 0.5),只挂在纸纹凸起上,断成一道道;托底色先薄铺一层平的,再加笔触 |+| 帽子和脸像扁盘子,亮的是轮廓边而不是面 | 「模糊遮罩开方」的枕头中间平、边缘陡,光又太偏侧:高度改成按遮罩内缘的值归一化、再开方的穹顶,光加正面分量 (-0.44, -0.56, 0.70),relief 默认 0.55(脸 0.45–0.5) |+| 皮肤暗部发紫发灰,一块一块的 | `ramp()` 默认的冷色偏紫,只适合衣服:皮肤用暖的五阶(#c0705d → #fbe3cc)或 `ramp(..., cool='#a02a3a')`;`model_form` 默认 ambient 0.08,遮罩边缘就不会取到最深一阶,同色的袖子边上也不再冒出孤立的深色短笔 |+| 大红鼻子像迷彩 | 大笔触不透明地铺几阶颜色造成的:`sphere_shade` 改用小笔触、alpha 0.55、密度 3.2、湿底 0.9、色阶交界 soft 0.3 |+| 防水雨帽读成遮阳盔,帽檐像游泳圈,雨珠像铆钉和珍珠,系带像两根筷子 | 去掉冠上的缝线和系带,冠压低变圆;帽檐不按枕头塑形,height 全 0 平涂,下垂的两侧罩暗,底下一条深边,顶面一道亮边;雨珠是透明的:比帽子更饱和的黄、右下一块琥珀色投影、反侧一小块焦散亮斑、很小的白高光,位置打散,不排成一行 |+| 小鱼读成鸟头 | 嘴画在头外面成了一个黑球,眼珠贴边像翻白眼:嘴放进吻端、加一圈浅色唇,眼珠只略偏;鱼身放大,用亮银色压在藏青毛衣上 |+| 围巾像颈枕或香肠,热气从鼻子连到杯子像鼻涕 | 一个 U 形环、两端圆头悬在肩外:改成绕两圈,下卷压在肩上,上卷在下卷上投影,垂下的那一端先画(在两卷后面);热气两缕从杯口往两边歪,停在围巾上,不碰鼻子 |+| 一塔卷发像一盘肉桂卷 | 每个卷中心最亮、笔触同心:卷改成「环」,中心是暗的空洞,鼓起在 0.5 r 处;卷减到约 30 个,半径 34–60 不等;再加几百根往上梳的长发和少量飞丝,把卷连成一个发型(这一遍不用最深的颜色,深色长线像划痕) |+| 衣领两片像两个靠垫 | 两片圆鼓鼓的领子改成带缺口的平西装领(relief 0.25),领口下露出红高领的 V 区 |+| 质感跑到前面的部件上(高领的罗纹画到翻领上,外套的高光画到杯子上) | `knit`、`rib`、`dry_highlight` 是对遮罩里已有的颜料做乘法或加笔:遮罩先乘 (1 − 前面的部件) |+| 帽子和外套大块干净,像塑料 | 少了最后的干笔高光:`dry_highlight` 只在受光 > 0.62–0.7 的地方拖半干的浅色;穹顶用 `angle='fall'`(顺坡),用 `'contour'` 会画成一个漩涡 |+| 动图里瞳孔和眼皮线发蓝 | 中值切分出来最深的一色是毛衣的藏青:强制放进三个深中性色,另外 9 色只从末帧误差最大(> 18 级)的像素里切 |+## 四、做成动画- 各画风都有 `stage(name)` 和 `save(path, stages_dir)`,按阶段依次淡入叠化,就是「一幅画被逐步画出来」。README 里的动图就是这样做的。@@ -2044,6 +2113,11 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask- 阅卷批改的动图(脚本在 `claude_drawing/grading_work/make_gif_grading.py`):阶段是 桌面 → 答题卡抬着淡入、两帧落下 → 标准答案卡和纸条同样落下 → 夹上长尾夹 → 五行作答逐字出现 → 两个章各「落下两帧 → 压下停 360 毫秒 → 抬起 → 拿走」→ 红笔从右下角进来,给三道计算打勾,画波浪线、圈、引线、批注、叉,划答句,在标准答案卡上打勾打叉,写分数再圈起来,每一笔之间抬笔移过去 → 笔放回得分格旁。阶段名里带时间:带 `~` 的是运动帧(硬切、不叠化),`@毫秒` 是停留时间,其余是关键阶段(停 900 毫秒,相邻两个关键阶段之间 5 帧叠化),所以章和笔是真的在动。重发规则沿用描图纸叠层的平滑分量 / 细节残差阈值;帧一张张算、不全留在内存里;调色板 180 色中值切分(饱和像素 ×5、亮色 ×2)+ 75 色只从饱和像素里切(红笔、朱红印、深蓝页眉、木章),固定 4×4 Bayer。133 帧、21.4 秒、约 1.17 MB,按解码结果逐帧自检,末帧误差和单纯调色板量化相同。- 皮影戏的动图(脚本在 `claude_drawing/shadowpuppet_work/make_gif_shadowpuppet.py`):阶段是 黑场 → 灯点着、光晕一圈圈铺开、闪动 → 横楣带着灯笼从上面落下,灯笼晃着亮起来 → 底带和球门从下面升上来,边升边贴紧幕布(由虚变实)→ 四个人从两边侧幕滑进来,离幕远时又虚又是双影,边走边贴上幕布 → 站定 → 同伴挑球传过去 → 球头收腿、起脚,球画一道弧穿过风流眼,青方一个跳起扑空、一个指着球,同伴摆出亮相 → 全体带一点过冲定住 → 两块小牌顺着线落下 → 灯暗一下 → 成品。全部是真运动(`~` 运动帧),一个叠化都没有;阶段名的约定和阅卷批改一样(`~` 运动帧、`@毫秒` 停留)。重发规则同阅卷批改;调色板 150 色中值切分(成品取样 ×8、饱和像素 ×5、亮色 ×2)+ 105 色只从最后几帧的饱和色和冷色里切,再做 6 轮 k-means 收短误差尾巴;固定 4×4 Bayer。61 帧、10.8 秒、约 1.75 MB,按解码结果逐帧自检,末帧误差(p99 16)和单纯调色板量化相同。点灯那几帧和结尾灯暗一下要整帧重发,是最贵的几帧(各 75–130 KB)。- 钢笔淡彩的动图(脚本在 `claude_drawing/penwash_work/make_gif_penwash.py`):阶段是 空桌面 → 四张白卡放下 → 第 1、2 张上墨线 → 第 3、4 张上墨线 → 第一遍淡彩 → 第二遍(鼻子、鞋、细部)→ 背景色块 → 白色水粉高光 → 放下针管笔和水笔,都是 900 毫秒 + 5 帧叠化。橡木桌本身就是饱和色,「饱和像素 ×5」会把色位都给木头,淡蓝 / 灰绿背景块被量化成灰青和米色:调色板改成 56 色只从空桌面切、198 色只从和空桌面不同的像素(卡片、墨线、颜料、笔)切(饱和 ×3、末帧 ×3),固定 4×4 Bayer,和屏上已显示颜色差不到 7 级(叠化帧)/ 4 级(关键帧)的像素沿用上一帧,末帧精确发送。49 帧、13.4 秒、约 0.77 MB,按解码结果逐帧自检,末帧 p99 误差 23。+- 复古水粉的动图(脚本在 `claude_drawing/gouache_work/make_gif_gouache.py`):+ - 阶段:托底色 → 赭色起稿 → 背景绕开人物皴擦 → 平涂大块 → 几阶色值塑形 → 针织、罗纹、发丝、毛毡 → 腮红、鼻子、眼睛和道具(鱼、可可杯、蜗牛)→ 雨珠、热气、干笔高光 → 印刷颗粒(成品)。每段 900 毫秒 + 5 帧叠化。+ - 调色板:56 色只从托底色那帧切;186 色从和它不同的像素切(饱和 ×3、末帧 ×3);再留 12 色,其中 3 个是强制的深中性色(不然最深的一色是毛衣藏青,瞳孔和眼皮线全变蓝),另外 9 色只从末帧误差最大(> 18 级)的像素里切。+ - 固定 4×4 Bayer。和屏上已显示颜色差不到 7 级(叠化帧)或 4 级(关键帧)的像素沿用上一帧,末帧精确发送。+ - 结果:49 帧、13.4 秒、约 1.79 MB,按解码结果逐帧自检,末帧 p99 误差 25。- 绘本角色动画的动图是真动画,不是阶段叠化:`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 遮罩按顺序显现。这个还没做成现成接口。@@ -2116,6 +2190,7 @@ lib/pastelui.py 粉彩界面(纯色粉彩底与光斑、距离场抗锯lib/grading.py 阅卷批改(绿毛毡桌、带位姿和投影的纸与卡片、答题卡部件与装订齿孔、长尾夹、带进度和时间图的红笔 / 批注 / 作答 / 印章、比尔定律红墨、立体红笔与木章道具)lib/shadowpuppet.py 皮影戏(油灯照亮的幕布、两个灯芯;按光密度叠加的透明染色驴皮:剪、染、描边、打孔、九种镂空纹样;关节树人偶、线结、操纵杆;离幕虚化与双影;标准人偶(阳刻空脸 / 阴刻脸、雉翎盔 / 三叉冠);牌楼球门、鞠、底部回纹带、小牌;雕花戏台、红漆金字牌匾、灯笼)lib/penwash.py 钢笔淡彩(冷压水彩小卡:受光纸纹、不直的切边;针管笔线:手抖、出头、不闭合、描两遍、按 z 遮挡断线;淡彩:错位出线与留白缝、游走的边、干边、颗粒、平刷条纹、湿中湿、起皱;不铺满的背景色块与白边;白色水粉;呆萌小人部件;橡木桌、卡片阴影、针管笔与透明水笔)+lib/gouache.py 复古水粉(托底色的画板与纸纹;不透明水粉:鬃毛条纹、越用越干、挂在纸纹上的干笔,湿笔带起底色;毛边;穹顶光照的几阶色值塑形与球体塑形;软投影、粉状腮红、干笔高光;圆眼、大鼻子、大耳朵;V 字平针、麻花、罗纹;顺着流向的发丝、胡子、绒球、卷发;毛毡;印刷书页的颗粒)examples/*.py 范例脚本;*.jpg 成品;drawing_*.gif 逐步画出的动图中文字体:自动找 Kaiti/Songti(macOS)、Noto CJK(Linux)、KaiTi/SimSun(Windows),或设 INKPAINT_FONT西文字体(后来新增的画风用):core.latin_font(style) 按 sans / sans_bold / rounded / script / hand / typewriter 等找系统字体,可用 INKPAINT_FONT_<STYLE> 指定;字体文件不要放进仓库diff --git a/examples/drawing_gouache_rainy_day.gif b/examples/drawing_gouache_rainy_day.gifnew file mode 100644index 0000000..2ca0382Binary files /dev/null and b/examples/drawing_gouache_rainy_day.gif differdiff --git a/examples/gouache_rainy_day.jpg b/examples/gouache_rainy_day.jpgnew file mode 100644index 0000000..af88cd1Binary files /dev/null and b/examples/gouache_rainy_day.jpg differdiff --git a/examples/gouache_rainy_day.py b/examples/gouache_rainy_day.pynew file mode 100644index 0000000..27ccb7f--- /dev/null+++ b/examples/gouache_rainy_day.py@@ -0,0 +1,632 @@+"""Example (retro gouache): 雨天三人像 · Rainy-Day Portraits — a picture-book triptych of three close-up portraits+painted in opaque gouache, side by side on a cream board, each with its own scumbled background.++ 1 an old sea-fisherman in a yellow sou'wester still beaded with rain (one drop about to fall off the brim): an+ enormous red nose, white bushy brows,+ big ears, a white chin-curtain beard and a navy cable-knit sweater -- and a small fish poking its head out of+ his felt chest pocket, which he is squinting down at (pale sea-glass background);+ 2 a little kid buried in a huge mustard bobble hat and a striped scarf, holding a steaming cocoa mug in two+ mittens, going cross-eyed at the marshmallow floating in it (green background);+ 3 a tall lady with a towering orange updo of ringlets, blue eyeshadow, pearl drops, a vermilion turtleneck and a+ cobalt coat with wide teal felt lapels, side-eyeing the snail that has climbed onto her shoulder, its slime+ trail still shining on the coat behind it (blue-to-yellow background).++The painting order is the gouache one, dark to light, big to small: toned ground, umber underdrawing, background+scrubbed round the figures, flat masses, value steps that model each form, textures (cable knit, ribbing, hair and+brow strands, beard, felt, curls), features (blush, noses, eyes, pocket and fish, mug, snail), highlights (rain+drops, steam, catchlights), then the printed-page grain.+--stages writes those steps as snapshots for the draw-on.+No image model.+python3 gouache_rainy_day.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 gouache import GouachePortrait, ramp+from core import blur, shift, smoothstep, spline++PW, PH = 620, 1050+PANELS = [(15, 15), (650, 15), (1285, 15)]+SKIN = ['#c0705d', '#d98d76', '#efbb98', '#f6d0b2', '#fbe3cc']+RUDDY = ['#b8604f', '#d27c66', '#e9a888', '#f2c3a6', '#f8dcc6']+++def rrect(cx, cy, w, h, r=10.0, rot=0.0, n=5):+ pts = []+ for qx, qy, a0 in ((1, 1, 0), (-1, 1, 90), (-1, -1, 180), (1, -1, 270)):+ ox, oy = cx + qx * (w / 2 - r), cy + qy * (h / 2 - r)+ for a in np.linspace(a0, a0 + 90, n):+ pts.append((ox + r * np.cos(np.deg2rad(a)), oy + r * np.sin(np.deg2rad(a))))+ P = np.array(pts, np.float32)+ if rot:+ a = np.deg2rad(rot); c, s = np.cos(a), np.sin(a)+ d = P - [cx, cy]+ P = np.stack([cx + d[:, 0] * c - d[:, 1] * s, cy + d[:, 0] * s + d[:, 1] * c], 1)+ return P+++def dashes(g, pts, colour, width=2.2, dash=9, gap=7, alpha=0.85):+ """running stitches along a closed outline"""+ P = np.vstack([pts, pts[:1]])+ seg = np.hypot(*np.diff(P, axis=0).T)+ s = np.concatenate([[0], np.cumsum(seg)])+ t = 0.0+ while t + dash < s[-1]:+ u = np.linspace(t, t + dash, 4)+ q = np.stack([np.interp(u, s, P[:, 0]), np.interp(u, s, P[:, 1])], 1)+ g.line(q, width, colour, alpha, taper=(0.3, 0.3), smooth=False)+ t += dash + gap+++def raindrop(g, x, y, r):+ """a bead of water on yellow oilskin: a soft amber shadow under it, the yellow seen through it a little+ brighter, a darker amber rim at the top (refraction) and a sharp white highlight"""+ drop = g.ellipse(x, y, r, r * 0.92)+ g.glaze(g.ellipse(x + r * 0.4, y + r * 0.6, r * 1.05, r * 0.8) * (1 - drop), '#a86a12', 0.55, soft=r * 0.3)+ g.glaze(drop, '#e8a020', 0.45)+ g.glaze(g.ellipse(x + r * 0.15, y + r * 0.42, r * 0.6, r * 0.32) * drop, '#fff3b0', 0.65, mode='screen', soft=1)+ g.dab(x - r * 0.38, y - r * 0.38, max(1.2, r * 0.17), '#fffdf6', 0.95, dry=0.0)+++# ================================================================== 1: the sea-fisherman+class Fisherman:+ def __init__(self, g, p):+ self.g, self.p = g, p+ g.use(p)+ S = self.S = {}+ S['sweater'] = g.poly([(14, 1062), (22, 950), (60, 872), (140, 812), (220, 786), (400, 786), (480, 812),+ (560, 872), (598, 950), (606, 1062)])+ self.collar_path = [(150, 806), (230, 830), (310, 838), (390, 830), (470, 806)]+ S['collar'] = g.band(self.collar_path, 46) * S['sweater']+ S['earL'] = g.blob(100, 512, 46, 64, 0.04, 1, -8)+ S['earR'] = g.blob(520, 512, 46, 64, 0.04, 2, 8)+ S['face'] = g.poly([(150, 330), (310, 316), (470, 330), (512, 430), (520, 540), (502, 640), (452, 712),+ (380, 752), (310, 762), (240, 752), (168, 712), (118, 640), (100, 540), (108, 430)])+ S['beard'] = g.poly([(104, 548), (106, 640), (146, 728), (226, 786), (310, 806), (394, 786), (474, 728),+ (514, 640), (516, 548), (486, 600), (456, 666), (392, 702), (310, 712), (228, 702),+ (164, 666), (134, 600)])+ S['crown'] = g.poly([(158, 372), (160, 300), (188, 236), (240, 194), (310, 180), (380, 194), (432, 236),+ (460, 300), (462, 372)])+ S['brim'] = g.poly([(20, 496), (30, 432), (96, 376), (200, 348), (310, 342), (420, 348), (524, 376),+ (590, 432), (600, 496), (572, 500), (540, 470), (500, 446), (412, 422), (310, 414),+ (208, 422), (120, 446), (80, 470), (48, 500)])++ S['hat'] = np.maximum(S['crown'], S['brim'])+ S['browL'] = g.blob(220, 438, 74, 27, 0.14, 11, -9)+ S['browR'] = g.blob(400, 438, 74, 27, 0.14, 12, 9)+ S['pocket'] = g.poly(rrect(186, 952, 146, 128, 16, -4), smooth=False)+ S['fish'] = g.blob(176, 842, 92, 34, 0.03, 21, 62)+ self.fig = np.maximum.reduce([S['sweater'], S['earL'], S['earR'], S['face'], S['beard'], S['hat'],+ S['browL'], S['browR']])++ def sketch(self):+ g, S = self.g, self.S+ for k in ('sweater', 'collar', 'earL', 'earR', 'face', 'beard', 'crown', 'brim', 'browL', 'browR', 'pocket'):+ g.sketch(S[k])+ g.sketch(g.ellipse(312, 540, 92, 80))+ g.sketch(g.ellipse(226, 474, 17, 16)); g.sketch(g.ellipse(394, 474, 17, 16))++ def background(self):+ self.g.scumble_background('#74b6b1', bottom='#93c9bf', avoid=self.fig, angle=-32, seed=101)++ def block_in(self):+ g, S = self.g, self.S+ g.block_in(S['sweater'], 'navy', angle=80)+ g.block_in(S['collar'], '#2b4278', angle=0, length=(20, 40), width=(8, 14))+ for k in ('earL', 'earR'): g.block_in(S[k], '#e49c7e', length=(14, 30), width=(7, 12))+ g.block_in(S['face'], '#e9a888', length=(24, 56), width=(10, 20))+ g.block_in(S['beard'], '#c9c6c0', angle=90, length=(20, 46), width=(8, 16))+ g.block_in(S['crown'], 'yellow', angle=95)+ g.block_in(S['brim'], 'yellow', angle=0)++ def form(self):+ g, S = self.g, self.S+ g.model_form(S['sweater'], ramp('navy', deep=0.55, shadow=0.75, light=0.22, pale=0.4), steps=3,+ length=(24, 54), width=(9, 18), alpha=0.85)+ g.model_form(S['collar'], ramp('#2b4278', light=0.2, pale=0.35), steps=3, round_=0.5, length=(10, 20), width=(5, 9))+ for k in ('earL', 'earR'):+ g.model_form(S[k], ramp('#e49c7e', cool='#7a1d2a'), steps=3, length=(10, 22), width=(5, 10))+ g.model_form(S['face'], RUDDY, steps=4, length=(18, 40), width=(8, 15), relief=0.5)+ # the brim's core shadow across the forehead and the ears; the beard's shadow on the collar and sweater+ g.cast_shadow(S['hat'], 4, 26, soft=10, alpha=0.5, colour='#8d4d4a', on=np.maximum(S['face'], np.maximum(S['earL'], S['earR'])))+ g.cast_shadow(S['beard'], 6, 22, soft=12, alpha=0.55, colour='#3a3550', on=S['sweater'])+ g.model_form(S['beard'], ['#7f7d84', '#a9a6a6', '#d6d2ca', '#ece7dd', '#faf6ee'], steps=4, angle=90,+ length=(16, 34), width=(6, 12), relief=0.5)+ yr = ramp('yellow', deep=0.5, shadow=0.72, cool='#6a3a10', light=0.3, pale=0.6)+ g.model_form(S['crown'], yr, steps=4, length=(26, 54), width=(10, 20), relief=0.6)+ # the brim is a flat sheet: lit evenly on top, turning away at the drooping sides, its underside a dark rim+ X = self.p.XX+ tilt = np.abs(X - 310) / 300+ g.model_form(S['brim'], yr, steps=3, height=np.zeros_like(X), angle=lambda x, y: 8 * np.sign(x - 310),+ length=(40, 90), width=(10, 18), bias=-0.05)+ g.glaze(S['brim'] * smoothstep(0.35, 1.0, tilt), '#c8892a', 0.45)+ under = S['brim'] * (1 - shift(S['brim'], 0, -16))+ g.glaze(blur(under, 2), '#9a6418', 0.7)+ g.cast_shadow(S['crown'], 0, 14, soft=8, alpha=0.3, colour='#a77a2a', on=S['brim'])+ rimline = [(30, 440), (96, 380), (200, 351), (310, 345), (420, 351), (524, 380), (590, 440)]+ g.line(rimline, 4.0, '#fde89a', 0.7, dry=0.35)++ def texture(self):+ g, S = self.g, self.S+ g.knit(S['sweater'], stitch=(14, 10), origin=(310, 0), curve=0.5,+ cables=[(310, 66), (196, 46), (424, 46), (88, 40), (532, 40)], strength=0.8, highlight=0.3, seed=7)+ g.rib(S['collar'], self.collar_path, period=8.5, strength=0.8, seed=8)+ # a soft crease where the crown meets the brim, and a row of stitching round the brim+ g.line([(170, 366), (240, 352), (310, 348), (380, 352), (450, 366)], 3.0, '#b07a18', 0.55, dry=0.3)+ brim_line = [(46, 484), (90, 456), (130, 436), (210, 412), (310, 405), (410, 412), (490, 436), (530, 456), (574, 484)]+ q = spline(np.array(brim_line, np.float32), 12)+ for i in range(0, len(q) - 3, 5):+ g.line(q[i:i + 3], 2.0, '#9e6c12', 0.75, taper=(0.3, 0.3))+ # brows and beard: dark mass first, then strands, dark to light, following the hair's growth+ for k, sgn, cx in (('browL', -1, 220), ('browR', 1, 400)):+ m = S[k]+ g.block_in(m, '#b9b5ae', length=(10, 22), width=(5, 9))+ lam = g.form_light(m, relief=0.6)[0]+ g.hair_strands(m, (lambda x, y, sgn=sgn, cx=cx: (180 if sgn < 0 else 0) - sgn * 14 + (y - 438) * 0.9 * sgn+ + (x - cx) * 0.08), ['#77736f', '#a8a39d', '#d4cec4', '#ece6db', '#fffbf2'], n=520,+ length=(14, 42), width=(1.0, 2.4), shade=lam, curl=1.2, spread=0.28, seed=40 + sgn)+ lam = g.form_light(S['beard'], relief=0.5)[0]++ def beard_flow(x, y):+ a = np.degrees(np.arctan2(y - 600, x - 310))+ return 90 + (a - 90) * 0.55+ g.hair_strands(S['beard'], beard_flow, ['#6f6c73', '#9c9a9c', '#c9c5be', '#e6e1d7', '#fbf8f0'], n=2600,+ length=(16, 46), width=(1.0, 2.3), shade=lam, curl=1.5, spread=0.25, pad=6, seed=44)++ def features(self):+ g, S = self.g, self.S+ face = S['face']+ g.blush(170, 584, 60, 54, 'blush', 0.5, mask=face)+ g.blush(452, 584, 60, 54, 'blush', 0.5, mask=face)+ # little smile under the nose, and crow's feet+ g.line([(278, 650), (296, 660), (318, 662), (340, 654)], 4.2, '#8a3a32', 0.85, taper=(0.3, 0.3))+ g.line([(286, 667), (312, 672), (334, 667)], 2.0, '#c97764', 0.5, taper=(0.4, 0.4))+ for sgn, cx in ((-1, 226), (1, 394)):+ for dy, ln in ((-6, 16), (4, 18), (14, 13)):+ x0 = cx + sgn * 26+ g.line([(x0, 474 + dy * 0.5), (x0 + sgn * ln, 474 + dy)], 1.8, '#b0634f', 0.55, taper=(0.2, 0.8))+ # eyes: small and squinting down at the fish+ for cx in (226, 394):+ g.eye(cx, 476, 17, 15, iris='#1b2226', iris_r=0.62, look=(-0.45, 0.5), lid=0.36, lid_colour='#d98c72',+ lower=0.3)+ g.nose(312, 544, 94, 82, 'nose', on=np.maximum(face, S['beard']))++ # the fish, then the felt pocket over its tail+ fish = S['fish']+ g.cast_shadow(fish, 7, 10, soft=7, alpha=0.5, colour='#141830', on=S['sweater'])+ fin = g.poly([(196, 806), (226, 792), (224, 830), (204, 846)])+ g.block_in(fin, '#ef8040', length=(6, 14), width=(3, 6))+ g.line([(204, 812), (220, 800)], 1.4, '#a8401a', 0.6); g.line([(206, 826), (222, 818)], 1.4, '#a8401a', 0.6)+ g.block_in(fish, '#a9c9d9', length=(12, 28), width=(5, 10))+ g.model_form(fish, ['#3d6688', '#5f8db0', '#a9c9d9', '#d6e7ee', '#f4f9f8'], steps=4, length=(10, 24),+ width=(4, 8), relief=0.7, bias=0.05)+ for t in np.linspace(0.42, 0.8, 4): # scales: little arcs down the body+ cx, cy = 140 + (214 - 140) * t, 776 + (916 - 776) * t+ for k in (-1, 0, 1):+ ox, oy = cx + k * 11 * 0.88, cy - k * 11 * 0.47+ g.line([(ox - 5, oy - 4), (ox + 1, oy + 1), (ox + 6, oy - 2)], 1.5, '#4f7899', 0.55, taper=(0.3, 0.3))+ g.line([(140, 812), (154, 818), (164, 834)], 2.6, '#33587a', 0.75) # gill+ g.eye(154, 800, 12, iris='#141418', iris_r=0.6, look=(0.3, -0.3), lid=0.0, lower=0, catch=(-0.4, -0.45))+ # a gasping 'o' at the tip of the snout, with a pale lip round it+ g.glaze(g.ellipse(139, 772, 9.5, 8.5, 62), '#e9eef0', 0.9, mode='normal')+ mouth = g.ellipse(139, 772, 6.5, 5.5, 62)+ g.block_in(mouth, '#4a1a24', length=(4, 8), width=(3, 5), edge=0.3)+ g.dab(137, 769, 1.4, '#c0707a', 0.7)+ pk = S['pocket']+ g.cast_shadow(pk, 5, 7, soft=5, alpha=0.45, colour='#1a1d34', on=S['sweater'])+ g.block_in(pk, '#d9532e', length=(20, 40), width=(8, 14))+ g.model_form(pk, ramp('#d9532e', cool='#4a1020'), steps=3, round_=0.4, relief=0.35, length=(16, 30), width=(6, 10))+ g.felt(pk, 0.8, seed=12)+ g.glaze(g.poly(rrect(186, 896, 134, 16, 6, -4), smooth=False) * pk, '#5a1a12', 0.55, soft=2)+ dashes(g, rrect(186, 952, 124, 106, 11, -4), '#f6dfb0', 2.2, 8, 6)++ def highlights(self):+ g, S = self.g, self.S+ g.dry_highlight(S['crown'], '#fff0a8', above=0.7, angle='fall', length=(26, 56), width=(5, 12), density=0.45,+ relief=0.6, seed=61)+ g.dry_highlight(S['brim'], '#fff0a8', above=0.0, height=np.zeros_like(self.p.XX),+ angle=lambda x, y: 8 * np.sign(x - 310), length=(40, 90), width=(5, 10), density=0.25,+ alpha=0.55, seed=62)+ g.dry_highlight(S['face'] * (self.p.YY < 520), '#fbe0c8', above=0.72, length=(20, 44), width=(5, 10),+ density=0.4, alpha=0.45, relief=0.5, seed=63)+ for (x, y), r in zip(((252, 378), (152, 420), (494, 404), (352, 228), (204, 280), (420, 262), (318, 312),+ (566, 448), (262, 206)), (8, 6, 9, 7, 6, 8, 5, 5, 4)):+ raindrop(g, x, y, r)+ g.line([(214, 214), (196, 250), (188, 300)], 6, '#fff3c4', 0.5, dry=0.4)+ # a drop about to fall off the tip of the brim+ for x, y, r in ((30, 518, 6.5),):+ m = g.poly([(x, y - r * 2.2), (x + r, y - r * 0.2), (x + r * 0.7, y + r * 0.8), (x, y + r),+ (x - r * 0.7, y + r * 0.8), (x - r, y - r * 0.2)])+ g.glaze(m, '#e9f3f0', 0.75, mode='normal')+ g.glaze(m * g.ellipse(x + r * 0.2, y + r * 0.3, r * 0.7, r * 0.6), '#5f9e98', 0.45)+ g.dab(x - r * 0.3, y - r * 0.4, max(1.2, r * 0.22), '#ffffff', 0.95, dry=0.0)+++# ================================================================== 2: the kid with cocoa+class Kid:+ def __init__(self, g, p):+ self.g, self.p = g, p+ g.use(p)+ S = self.S = {}+ S['coat'] = g.poly([(28, 1062), (40, 960), (84, 885), (170, 842), (250, 828), (370, 828), (450, 842),+ (536, 885), (580, 960), (592, 1062)])+ S['sleeveL'] = g.band([(52, 1080), (104, 1004), (162, 930)], 112, 96)+ S['sleeveR'] = g.band([(568, 1080), (516, 1004), (458, 930)], 112, 96)+ S['face'] = g.ellipse(310, 590, 186, 162)+ S['dome'] = g.poly([(62, 452), (58, 350), (84, 252), (150, 178), (240, 136), (310, 128), (380, 136),+ (470, 178), (536, 252), (562, 350), (558, 452)])+ S['pom'] = g.blob(312, 112, 98, 92, 0.12, 31)+ self.brim_path = [(34, 466), (170, 456), (310, 451), (450, 456), (586, 466)]+ S['brim'] = g.poly([(38, 420), (120, 406), (310, 398), (500, 406), (582, 420), (592, 468), (582, 520),+ (500, 506), (310, 500), (120, 506), (38, 520), (28, 468)])+ S['hat'] = np.maximum(S['dome'], S['brim'])+ # the scarf is wound twice: an upper roll over the chin and a lower roll on the collarbone+ self.roll1_path = [(132, 712), (220, 694), (310, 690), (400, 694), (488, 712)]+ self.roll2_path = [(112, 800), (210, 786), (310, 782), (410, 786), (508, 800)]+ S['roll1'] = g.poly([(128, 690), (180, 662), (250, 648), (310, 650), (370, 648), (440, 662), (492, 690),+ (500, 730), (470, 756), (400, 744), (310, 740), (220, 744), (150, 756), (120, 730)])+ S['roll2'] = g.poly([(104, 772), (170, 748), (250, 740), (310, 742), (370, 740), (450, 748), (516, 772),+ (524, 820), (490, 850), (400, 834), (310, 830), (220, 834), (130, 850), (96, 820)])+ S['wrap'] = np.maximum(S['roll1'], S['roll2'])+ self.tail_path = [(190, 800), (180, 900), (168, 1004)]+ S['tail'] = g.band(self.tail_path, 108, 100)+ S['mug'] = g.poly(rrect(310, 880, 178, 176, 30), smooth=False)+ S['cocoa'] = g.ellipse(310, 796, 80, 17)+ S['rim'] = g.ellipse(310, 794, 89, 21)+ S['mitL'] = np.maximum(g.blob(212, 892, 54, 66, 0.05, 41, 14), g.blob(248, 852, 19, 30, 0.05, 42, 28))+ S['mitR'] = np.maximum(g.blob(408, 892, 54, 66, 0.05, 43, -14), g.blob(372, 852, 19, 30, 0.05, 44, -28))+ S['mallow'] = g.poly(rrect(334, 784, 50, 38, 11, 12), smooth=False)+ S['mallow2'] = g.poly(rrect(284, 792, 36, 28, 9, -18), smooth=False)+ self.fig = np.maximum.reduce([S['coat'], S['face'], S['hat'], S['pom'], S['wrap'], S['tail'],+ S['sleeveL'], S['sleeveR']])++ def sketch(self):+ g, S = self.g, self.S+ for k in ('coat', 'sleeveL', 'sleeveR', 'face', 'dome', 'pom', 'brim', 'roll1', 'roll2', 'tail', 'mug', 'mitL', 'mitR'):+ g.sketch(S[k])+ g.sketch(g.ellipse(236, 556, 40)); g.sketch(g.ellipse(384, 556, 40))++ def background(self):+ self.g.scumble_background('#4f9a5c', bottom='#5aa565', avoid=self.fig, angle=-40, seed=202)++ def block_in(self):+ g, S = self.g, self.S+ g.block_in(S['coat'], 'cobalt', angle=80)+ for k in ('sleeveL', 'sleeveR'): g.block_in(S[k], 'cobalt', angle=60)+ g.block_in(S['face'], 'peach', length=(24, 50), width=(10, 18))+ g.block_in(S['tail'], 'vermilion', angle=95)+ g.block_in(S['roll2'], 'vermilion', angle=0)+ g.block_in(S['roll1'], 'vermilion', angle=0)+ g.block_in(S['dome'], 'mustard', angle=90)+ g.block_in(S['brim'], 'mustard', angle=0)+ g.block_in(S['pom'], '#e05a2a', length=(16, 34), width=(8, 14))++ def form(self):+ g, S = self.g, self.S+ coat_r = ramp('cobalt', deep=0.5, shadow=0.72, light=0.2, pale=0.38)+ g.model_form(S['coat'], coat_r, steps=3, length=(26, 56), width=(9, 18))+ for k in ('sleeveL', 'sleeveR'):+ g.model_form(S[k], coat_r, steps=3, angle='fall', length=(20, 44), width=(8, 14), relief=0.3, bias=0.08)+ g.cast_shadow(np.maximum(S['sleeveL'], S['sleeveR']), 8, 10, soft=10, alpha=0.4, colour='#1a1a40', on=S['coat'])+ g.model_form(S['face'], SKIN, steps=4, length=(18, 40), width=(8, 15), relief=0.45)+ g.cast_shadow(S['hat'], 2, 24, soft=10, alpha=0.5, colour='#9a5048', on=S['face'])+ g.cast_shadow(S['wrap'], 0, -10, soft=8, alpha=0.3, colour='#9a5048', on=S['face'])+ stripe = lambda m, ph, per, along: m * (np.cos((along + ph) * 2 * np.pi / per) > 0.55)+ red = ramp('vermilion', cool='#3a0a20', light=0.24, pale=0.45)+ cream = ramp('cream', deep=0.55, shadow=0.8, cool='#5a3020', light=0.2, pale=0.4)+ lamt, Ht, _ = g.form_light(S['tail'], relief=0.6)+ st_ = stripe(S['tail'], 30, 92, self.p.YY)+ g.model_form(S['tail'] * (1 - st_), red, steps=4, height=Ht, angle=90, length=(18, 40), width=(7, 13))+ g.model_form(st_, cream, steps=4, height=Ht, angle=90, length=(14, 30), width=(6, 11))+ g.cast_shadow(S['tail'], 10, 8, soft=10, alpha=0.45, colour='#1a1a40', on=S['coat'])+ g.cast_shadow(S['wrap'], 4, 18, soft=12, alpha=0.5, colour='#1a1a40', on=S['coat'])+ g.cast_shadow(S['roll2'], 0, 22, soft=10, alpha=0.5, colour='#3a1a20', on=S['tail'])+ for k, ph in (('roll2', 52), ('roll1', 20)):+ lamw, Hw, _ = g.form_light(S[k], relief=0.75, round_=0.45)+ sw_ = stripe(S[k], ph, 84, self.p.XX)+ g.model_form(S[k] * (1 - sw_), red, steps=4, height=Hw, angle=0, length=(18, 40), width=(7, 13))+ g.model_form(sw_, cream, steps=4, height=Hw, angle=0, length=(14, 30), width=(6, 11))+ if k == 'roll2':+ g.cast_shadow(S['roll1'], 0, 16, soft=8, alpha=0.55, colour='#3a1020', on=S['roll2'])+ hat_r = ramp('mustard', deep=0.5, shadow=0.72, cool='#5a2a10', light=0.28, pale=0.55)+ g.model_form(S['dome'], hat_r, steps=4, length=(26, 56), width=(10, 20), relief=0.65)+ g.cast_shadow(S['brim'], 0, -16, soft=8, alpha=0.4, colour='#7a4a20', on=S['dome'])+ g.model_form(S['brim'], hat_r, steps=3, round_=0.45, relief=0.45, angle=0, length=(30, 60), width=(10, 18))+ g.cast_shadow(S['pom'], 10, 22, soft=12, alpha=0.5, colour='#6a3a10', on=S['dome'])+ g.sphere_shade(312, 112, 98, 92, ramp('#e05a2a', cool='#3a0a1a', light=0.26, pale=0.5), steps=4, mask=S['pom'],+ length=(12, 30), width=(6, 12))++ def texture(self):+ g, S = self.g, self.S+ g.knit(S['dome'], stitch=(17, 12), origin=(310, 0), curve=-0.9, strength=0.75, seed=9)+ g.rib(S['brim'], self.brim_path, period=10, strength=0.8, seed=10)+ g.knit(S['roll2'], stitch=(14, 11), path=self.roll2_path, strength=0.65, seed=11)+ g.knit(S['roll1'], stitch=(14, 11), path=self.roll1_path, strength=0.65, seed=16)+ g.knit(S['tail'], stitch=(14, 11), path=self.tail_path, strength=0.65, seed=12)+ # fringe at the end of the scarf+ for x in np.linspace(126, 220, 13):+ g.line([(x, 1046), (x - 2, 1062), (x - 3, 1080)], 5.0, '#f0e0c0' if int(x) % 2 else '#d84a2a', 0.95, taper=(0.1, 0.6))+ lam = g.form_light(S['pom'], relief=0.9)[0]+ g.hair_strands(S['pom'], lambda x, y: np.degrees(np.arctan2(y - 112, x - 312)),+ ['#7a2412', '#b8401c', '#e2622c', '#f2884a', '#fbb47a'], n=1700, length=(10, 30), width=(1.2, 2.6),+ shade=lam, curl=4, jitter=22, spread=0.22, pad=8, seed=45)+ g.felt(S['coat'], 0.6, fibres=0.4, fuzz=0.0, seed=13)+ for k in ('sleeveL', 'sleeveR'): g.felt(S[k], 0.6, fibres=0.4, fuzz=0.0)++ def features(self):+ g, S = self.g, self.S+ face = S['face']+ g.blush(176, 622, 60, 52, 'blush', 0.55, mask=face)+ g.blush(444, 622, 60, 52, 'blush', 0.55, mask=face)+ for cx, lk in ((236, (0.72, 0.62)), (384, (-0.72, 0.62))):+ g.eye(cx, 556, 40, iris='#18343a', iris_r=0.5, look=lk, lid=0.1, lid_colour='#e8a48a', ring='#6e9d52',+ lower=0.35, iris_light='#3f8f8a')+ g.nose(310, 612, 34, 29, 'rose', on=face)+ # the mug: a cream cylinder with vermilion dots, cocoa, a marshmallow; mittens round it+ mug = S['mug']+ g.cast_shadow(mug, 10, 16, soft=12, alpha=0.5, colour='#141436', on=np.maximum(S['coat'], S['tail']))+ g.block_in(mug, 'cream', angle=90, length=(20, 44), width=(8, 16))+ cyl = np.sqrt(np.clip(1 - ((self.p.XX - 310) / 89) ** 2, 0, 1)) * 60+ g.model_form(mug, ramp('cream', deep=0.55, shadow=0.78, cool='#40305a', light=0.2, pale=0.4), steps=4,+ height=cyl, angle=90, length=(16, 40), width=(6, 12))+ for (x, y, r) in ((262, 852, 13), (318, 838, 12), (356, 884, 13), (292, 912, 12), (340, 940, 10), (248, 936, 9),+ (380, 836, 9)):+ sq = np.cos(np.arcsin(np.clip((x - 310) / 89, -0.95, 0.95)))+ g.block_in(g.ellipse(x, y, r * sq, r) * mug, '#d9482c', length=(4, 10), width=(3, 6), edge=0.5)+ g.glaze(g.ellipse(310, 800, 84, 20) * (1 - g.ellipse(310, 798, 80, 17)), '#7a6a6a', 0.4)+ g.block_in(S['rim'], '#efe4cf', length=(10, 20), width=(4, 8))+ g.block_in(S['cocoa'], 'cocoa', angle=0, length=(10, 30), width=(4, 8))+ g.glaze(g.ellipse(298, 800, 64, 11) * S['cocoa'], '#a06a46', 0.6, mode='normal', soft=2)+ for k in ('mallow2', 'mallow'):+ g.cast_shadow(S[k], 4, 7, soft=3, alpha=0.6, colour='#2a1408', on=S['cocoa'])+ g.block_in(S[k], '#f7e8e6', length=(8, 18), width=(4, 8))+ g.model_form(S[k], ['#b58a96', '#d9b2b8', '#f5e4e2', '#fbf1ee', '#fffaf6'], steps=3, round_=0.4,+ relief=0.6, length=(6, 14), width=(3, 6))+ for k, sgn in (('mitL', -1), ('mitR', 1)):+ m = S[k]+ g.cast_shadow(m, 6, 10, soft=8, alpha=0.45, colour='#2a2040', on=mug)+ g.block_in(m, 'mustard', length=(14, 30), width=(6, 12))+ g.model_form(m, ramp('mustard', cool='#5a2a10', light=0.28, pale=0.5), steps=3, relief=0.7,+ length=(12, 26), width=(5, 10))+ g.knit(m, stitch=(10, 8), origin=(212 if sgn < 0 else 408, 0), angle=-14 * sgn, strength=0.6)++ def highlights(self):+ g, S = self.g, self.S+ # steam: two soft curls leaning away from the face, fading out over the scarf+ for x0, lean, top, w in ((268, -1, 690, 22), (358, 1, 700, 20)):+ ys = np.linspace(774, top, 14)+ u = (774 - ys) / (774 - top)+ xs = x0 + lean * 40 * u ** 1.4 + 13 * np.sin(u * 2.4 * np.pi) * (0.4 + u)+ path = np.stack([xs, ys], 1)+ g.dry_brush(path, w, '#fbf6ec', dry=0.45, alpha=0.4, streak=0.4, pickup=0.25, taper=(0.35, 0.6))+ g.dry_brush(path + [lean * 3, 4], w * 0.32, '#ffffff', dry=0.55, alpha=0.4, streak=0.6, taper=(0.3, 0.7))+ g.dab(258, 834, 5, '#fff7e8', 0.8)+ front = np.maximum.reduce([S['tail'], S['wrap'], S['mug'], S['mitL'], S['mitR'], S['sleeveL'], S['sleeveR']])+ g.dry_highlight(S['coat'] * (1 - front), '#6f9be0', above=0.66, length=(30, 70), width=(7, 14), density=0.5,+ alpha=0.6, seed=64)+ g.dry_highlight(S['face'] * (self.p.YY < 600), '#fbe4cf', above=0.74, length=(18, 40), width=(5, 9),+ density=0.4, alpha=0.4, seed=65)+ g.dab(312, 777, 3, '#ffffff', 0.9)+ g.line([(240, 820), (238, 870), (242, 918)], 5, '#fffaf0', 0.55, dry=0.35)+++# ================================================================== 3: the lady and the snail+class Lady:+ def __init__(self, g, p):+ self.g, self.p = g, p+ g.use(p)+ S = self.S = {}+ r = np.random.default_rng(77)+ S['coat'] = g.poly([(20, 1062), (32, 968), (80, 904), (170, 866), (244, 856), (376, 856), (450, 866),+ (540, 904), (588, 968), (600, 1062)])+ S['neck'] = g.poly([(228, 690), (392, 690), (396, 872), (224, 872)], smooth=False)+ self.turtle_path = [(214, 838), (310, 852), (406, 838)]+ S['neckband'] = g.poly([(214, 800), (310, 812), (406, 800), (414, 878), (310, 892), (206, 878)])+ S['vee'] = g.poly([(236, 860), (384, 860), (350, 1070), (270, 1070)], smooth=False)+ S['turtle'] = np.maximum(S['neckband'], S['vee'])+ # wide notched lapels of the coat collar, felt+ lap = [(232, 846), (164, 866), (118, 902), (150, 928), (100, 972), (214, 1070), (290, 1070), (300, 980),+ (296, 900), (268, 860)]+ S['collarL'] = g.poly(lap, smooth=False)+ S['collarR'] = g.poly([(620 - x, y) for x, y in lap], smooth=False)+ S['earL'] = g.blob(164, 606, 30, 44, 0.04, 51, -6)+ S['earR'] = g.blob(456, 606, 30, 44, 0.04, 52, 6)+ S['face'] = g.poly([(310, 412), (412, 440), (456, 530), (452, 640), (418, 716), (360, 760), (310, 770),+ (260, 760), (202, 716), (168, 640), (164, 530), (208, 440)])+ # the updo: a hair cap over the head, side swoops, and a tower of curls+ cap = g.poly([(150, 560), (148, 470), (186, 400), (250, 362), (310, 352), (370, 362), (434, 400), (472, 470),+ (470, 560), (446, 520), (420, 480), (360, 452), (310, 448), (260, 452), (200, 480), (174, 520)])+ swL = g.blob(160, 520, 48, 78, 0.08, 53, 8)+ swR = g.blob(460, 520, 48, 78, 0.08, 54, -8)+ tower = [(310, 366, 138), (292, 270, 120), (330, 186, 104), (300, 112, 88), (326, 52, 64)]+ S['tower'] = np.maximum.reduce([g.blob(x, y, rr, rr * 0.92, 0.10, 60 + i) for i, (x, y, rr) in enumerate(tower)])+ S['hair'] = np.maximum.reduce([cap, swL, swR, S['tower']])+ # curl centres scattered over the mass+ cs = []+ hm = S['hair']+ for _ in range(6000):+ x, y = r.uniform(110, 510), r.uniform(10, 560)+ if hm[int(y), int(x)] > 0.5 and all((x - a) ** 2 + (y - b) ** 2 > 60 ** 2 for a, b, _ in cs):+ cs.append((x, y, r.uniform(34, 60)))+ self.curls = np.array(cs, np.float32)+ S['shell'] = g.ellipse(472, 852, 50, 47)+ S['snail'] = g.poly([(366, 902), (374, 878), (398, 864), (430, 870), (500, 884), (556, 900), (574, 918),+ (538, 924), (450, 920), (388, 916)])+ self.fig = np.maximum.reduce([S['coat'], S['neck'], S['face'], S['hair'], S['earL'], S['earR'],+ S['collarL'], S['collarR'], S['turtle']])++ def curl_fields(self):+ """nearest curl centre for every pixel -> a flow round it and a little bump of height"""+ P = self.p+ X, Y = P.XX, P.YY+ best = np.full(X.shape, 1e9, np.float32); flow = np.zeros_like(X); bump = np.zeros_like(X)+ for x, y, rr in self.curls:+ d2 = (X - x) ** 2 + (Y - y) ** 2+ m = d2 < best+ best = np.where(m, d2, best)+ d = np.sqrt(d2)+ flow = np.where(m, np.degrees(np.arctan2(Y - y, X - x)) + 90 + 14, flow)+ # a ringlet seen end-on: a rolled loop of hair round a dark hollow+ ring = np.sqrt(np.clip(1 - ((d - 0.5 * rr) / (0.62 * rr)) ** 2, 0, 1))+ bump = np.where(m, ring * rr * 0.75, bump)+ return flow, bump++ def sketch(self):+ g, S = self.g, self.S+ for k in ('coat', 'neck', 'turtle', 'collarL', 'collarR', 'face', 'hair', 'earL', 'earR', 'shell', 'snail'):+ g.sketch(S[k])++ def background(self):+ self.g.scumble_background('#4a95cc', bottom='#f2c84a', avoid=self.fig, angle=-25, blend=(0.3, 0.92), seed=303)++ def block_in(self):+ g, S = self.g, self.S+ g.block_in(S['coat'], 'cobalt', angle=80)+ g.block_in(S['neck'], '#ecb592', angle=90, length=(20, 40), width=(8, 14))+ g.block_in(S['turtle'], '#d8452e', angle=0, length=(16, 36), width=(6, 12))+ for k in ('collarL', 'collarR'): g.block_in(S[k], 'teal', length=(20, 44), width=(8, 16))+ for k in ('earL', 'earR'): g.block_in(S[k], '#eaa98a', length=(10, 22), width=(5, 10))+ g.block_in(S['face'], '#f2c3a0', length=(24, 50), width=(10, 18))+ g.block_in(S['hair'], '#c9561c', length=(20, 44), width=(8, 16))++ def form(self):+ g, S = self.g, self.S+ g.model_form(S['coat'], ramp('cobalt', deep=0.5, shadow=0.72, light=0.2, pale=0.38), steps=3,+ length=(26, 56), width=(9, 18))+ neck_r = ['#b46553', '#cf8670', '#ecb592', '#f3cba9', '#f8dcc2']+ g.model_form(S['neck'], neck_r, steps=3, angle=90, length=(16, 34), width=(6, 12), relief=0.5, bias=-0.1)+ g.cast_shadow(S['face'], 0, 26, soft=10, alpha=0.55, colour='#8a4048', on=S['neck'])+ g.model_form(S['turtle'], ramp('#d8452e', cool='#3a0a20', light=0.2, pale=0.4), steps=3,+ angle=0, length=(14, 30), width=(5, 10))+ for k in ('collarL', 'collarR'):+ g.cast_shadow(S[k], 6, 12, soft=10, alpha=0.5, colour='#141436', on=np.maximum(S['coat'], S['turtle']))+ g.model_form(S[k], ramp('teal', deep=0.5, shadow=0.72, cool='#10203a', light=0.24, pale=0.45), steps=3,+ length=(18, 40), width=(7, 14), relief=0.25, round_=0.25)+ for k in ('earL', 'earR'):+ g.model_form(S[k], ramp('#eaa98a', cool='#7a1d2a'), steps=3, length=(8, 18), width=(4, 8))+ g.model_form(S['face'], SKIN, steps=4, length=(18, 40), width=(8, 15), relief=0.45)+ g.cast_shadow(S['hair'], 4, 20, soft=10, alpha=0.5, colour='#9a4a40', on=np.maximum(S['face'], np.maximum(S['earL'], S['earR'])))+ flow, bump = self.curl_fields()+ lam0, H0, _ = g.form_light(S['hair'], relief=0.6, round_=0.35)+ g.model_form(S['hair'], ramp('#e2702a', deep=0.42, shadow=0.68, cool='#3a0a10', light=0.26, pale=0.5),+ steps=4, height=H0 * 0.6 + bump, angle=flow, length=(14, 30), width=(6, 11))++ def texture(self):+ g, S = self.g, self.S+ lapels = np.maximum(S['collarL'], S['collarR'])+ g.rib(S['neckband'] * (1 - lapels), self.turtle_path, period=8, strength=0.7, highlight=0.25)+ for k in ('collarL', 'collarR'): # the pressed edge of the lapel+ g.sketch(S[k], colour='#0f4a44', width=1.6, alpha=0.7, breaks=0.12)+ g.knit(S['vee'] * (1 - S['neckband']) * (1 - lapels), stitch=(11, 8), origin=(310, 0), curve=0.4, strength=0.55)+ flow, bump = self.curl_fields()+ lam_t, H0, _ = g.form_light(S['hair'], relief=0.6, round_=0.35)+ lam = g.form_light(S['hair'], height=H0 * 0.6 + bump)[0]+ g.hair_strands(S['hair'], flow, ['#5e1a08', '#9a3510', '#d0581c', '#ec7d32', '#f8a85a', '#fdd08e'], n=4600,+ length=(24, 64), width=(1.0, 2.4), shade=lam, curl=1.6, jitter=7, spread=0.18, pad=5, seed=46)+ # long locks swept up the tower over the curls, so they read as one hairdo, and a few flyaways+ sweep = lambda x, y: -90 + np.clip((310 - x) * 0.35, -40, 40) + 12 * np.sin(y / 40.0)+ g.hair_strands(S['tower'], sweep, ['#d0601e', '#ee8538', '#f8a85a', '#fcc77e'], n=300, length=(50, 120),+ width=(0.9, 1.8), shade=lam_t, curl=1.0, jitter=6, spread=0.22, alpha=0.6, seed=47)+ edge = S['hair'] * (blur(S['hair'], 6) < 0.85) # a band just inside the silhouette+ g.hair_strands(S['hair'], sweep, ['#c24e18', '#f2a050'], n=90, roots=edge, length=(20, 46), width=(0.8, 1.4),+ curl=4, jitter=25, alpha=0.8, clip=False, seed=48)+ for k in ('collarL', 'collarR'): g.felt(S[k], 0.55, seed=14)+ g.felt(S['coat'], 0.6, fibres=0.4, fuzz=0.0, seed=15)++ def features(self):+ g, S = self.g, self.S+ face = S['face']+ g.blush(226, 652, 46, 40, 'blush', 0.5, mask=face)+ g.blush(398, 652, 46, 40, 'blush', 0.5, mask=face)+ # thin arched brows+ g.line([(214, 520), (238, 506), (268, 506), (288, 516)], 4.2, '#a2401a', 0.9, taper=(0.3, 0.6))+ g.line([(334, 514), (356, 503), (386, 504), (410, 518)], 4.2, '#a2401a', 0.9, taper=(0.6, 0.3))+ for cx, ld in ((252, -1), (370, 1)):+ g.eye(cx, 566, 30, 27, iris='#1c5f62', iris_r=0.56, look=(0.62, 0.45), lid=0.5, lid_colour='#6d9bd6',+ lashes=3, lash_dir=ld, lower=0.25, iris_light='#4aa39a')+ g.nose(318, 634, 36, 46, 'rose', on=face, cast=(0.3, 0.46, 0.38))+ lips = g.poly([(290, 698), (302, 690), (314, 694), (326, 690), (338, 698), (326, 710), (302, 710)])+ g.block_in(lips, '#cf3b2c', length=(6, 14), width=(3, 6), edge=0.4)+ g.model_form(lips, ramp('#cf3b2c', cool='#3a0a1a'), steps=3, relief=0.7, length=(6, 12), width=(3, 5))+ g.line([(292, 699), (314, 700), (336, 699)], 1.8, '#6a1218', 0.85, taper=(0.3, 0.3))+ g.dab(305, 693, 2.2, '#ffd9c8', 0.8)+ # pearl drops+ for x in (162, 458):+ g.cast_shadow(g.ellipse(x, 664, 12), 3, 5, soft=3, alpha=0.4, colour='#7a3a40')+ g.line([(x, 640), (x, 652)], 2.0, '#d9b45a', 0.9)+ g.sphere_shade(x, 664, 12, 12, ['#8a8a9a', '#b8b6bf', '#ece6dc', '#f8f4ec', '#ffffff'], steps=4,+ length=(4, 8), width=(2, 4))+ # the snail on her shoulder+ g.cast_shadow(np.maximum(S['snail'], S['shell']), 6, 10, soft=7, alpha=0.5, colour='#0c2030',+ on=np.maximum(S['collarR'], S['coat']))+ g.block_in(S['snail'], '#9da36e', angle=0, length=(10, 24), width=(4, 9))+ g.model_form(S['snail'], ['#56603a', '#7a8452', '#a7ad78', '#c8cc9c', '#e6e8c6'], steps=3, relief=0.7,+ length=(8, 18), width=(3, 7))+ for (x0, y0), (x1, y1) in (((386, 874), (360, 822)), ((400, 868), (394, 818))):+ g.line([(x0, y0), ((x0 + x1) / 2 - 3, (y0 + y1) / 2), (x1, y1)], 5.0, '#8f9860', 0.95, taper=(0.05, 0.05))+ g.dab(x1, y1, 6.0, '#8f9860', 0.95)+ g.dab(x1 + 1.5, y1 + 1, 3.2, '#22240f', 0.95, dry=0.0)+ g.dab(x1, y1 - 0.5, 1.2, '#fffff0', 0.95, dry=0.0)+ g.line([(372, 896), (381, 902), (392, 899)], 2.2, '#3a4224', 0.85, taper=(0.3, 0.3)) # a contented smile+ g.blush(380, 890, 7, 5, '#e08a70', 0.45, grain=0.3)+ g.block_in(S['shell'], '#e79a4a', length=(10, 22), width=(5, 9))+ g.sphere_shade(472, 852, 50, 47, ramp('#e79a4a', cool='#5a1020', light=0.3, pale=0.55), steps=4, mask=S['shell'],+ length=(8, 20), width=(4, 9))+ th = np.linspace(0, 3.3 * np.pi, 70)+ rr = 43 * (1 - th / (3.6 * np.pi))+ spiral = np.stack([477 + rr * np.cos(th + 2.6), 855 + rr * 0.95 * np.sin(th + 2.6)], 1)+ g.line(spiral, 3.6, '#8a3a1c', 0.85, taper=(0.1, 0.6))+ g.line(spiral + [-2.5, -2.5], 1.6, '#ffd09a', 0.5, taper=(0.1, 0.6), dry=0.3)++ def highlights(self):+ g, S = self.g, self.S+ # the slime trail: a wet sheen on the felt behind the snail -- darker where the felt is wet, a broken+ # white gloss along it+ trail = [(566, 918), (580, 934), (588, 954), (592, 976), (602, 1000), (612, 1022)]+ wet = g.band(trail, 20, 14) * S['coat']+ g.glaze(wet, '#14205a', 0.4, soft=2)+ g.dry_brush(trail, 15, '#c9d8ea', dry=0.45, alpha=0.6, streak=0.8, taper=(0.05, 0.3))+ g.line(np.array(trail) + [-3, -1], 2.4, '#ffffff', 0.85, taper=(0.1, 0.4), dry=0.5)+ for x, y in ((582, 938), (594, 972), (606, 1006)):+ g.dab(x - 2, y, 2.2, '#ffffff', 0.9, dry=0.0)+ g.dab(450, 828, 7, '#fff3dc', 0.85)+ front = np.maximum.reduce([S['collarL'], S['collarR'], S['turtle'], S['snail'], S['shell'], S['neck']])+ g.dry_highlight(S['coat'] * (1 - g.rough(front, 0.3)), '#6f9be0', above=0.66, length=(30, 70), width=(7, 14),+ density=0.5, alpha=0.6, seed=66)+ for k in ('collarL', 'collarR'):+ g.dry_highlight(S[k], '#5fc0b0', above=0.6, length=(24, 50), width=(5, 10), density=0.5, alpha=0.5,+ relief=0.25, seed=67)+ g.dry_highlight(S['face'] * (self.p.YY < 600), '#fbe4cf', above=0.74, length=(18, 40), width=(5, 9),+ density=0.4, alpha=0.4, seed=68)+ g.dab(330, 602, 4, '#fff6ea', 0.7)+ g.line([(326, 40), (304, 84), (300, 120)], 4.5, '#ffe0a8', 0.5, dry=0.4)+++PHASES = ('sketch', 'background', 'block_in', 'form', 'texture', 'features', 'highlights')+++def main():+ out = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith('--') else 'gouache_rainy_day.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:12s} {time.time() - T0:5.1f}s')) if os.environ.get('GP_TIMING') else (lambda n: None)+ g = GouachePortrait(1920, 1080, seed=11, keep_stages=bool(stages), stages_dir=stages)+ ps = [g.panel(x, y, PW, PH) for x, y in PANELS]+ g.ground('#c88f5a', alpha=0.5)+ g.stage('ground')+ chars = [Fisherman(g, ps[0]), Kid(g, ps[1]), Lady(g, ps[2])]+ tick('setup')+ for ph in PHASES:+ for c in chars:+ g.use(c.p)+ getattr(c, ph)()+ tick(ph)+ g.stage(ph)+ g.grain(1.0)+ g.save(out, stages_dir=stages)+ tick('saved')+ print('saved', out)+++if __name__ == '__main__':+ main()diff --git a/lib/gouache.py b/lib/gouache.pynew file mode 100644index 0000000..6c3a9e2--- /dev/null+++ b/lib/gouache.py@@ -0,0 +1,1091 @@+"""gouache — 复古水粉 / Retro Gouache: picture-book character portraits in opaque gouache (numpy + Pillow only).++The look of a mid-century picture book painted in gouache (or matte acrylic used the same way): tight head-and-+shoulders portraits of goofy characters with huge rosy noses, round eyes, blush circles, big ears, bushy brows and+beards, wide necks and small shoulders, in a bold retro palette (vermilion, cobalt, cerulean, teal, mustard, warm+peach) against one scumbled background colour; knit sweaters, strand-y hair and felt hats you can almost touch, and+the grain of the board and of the printed page over everything. Nothing here is a filter on flat shapes: every+coloured pixel was laid by a brush stroke, a painted line or a texture model, in the order a painter works.++Physical model+ ground Gouache is painted on a board or heavy paper. The board has a tooth: fine bumps (a blurred white noise+ at ~1 px), a softer undulation and a very faint canvas-like weave, kept as one height field `G` in 0..1.+ The tooth decides where a dry brush catches. Before any colour each panel gets a thin warm imprimatura+ (toned ground) scrubbed on with big low-alpha strokes; it glows through wherever later coats break.+ paint Gouache is opaque and dries matte: a coat REPLACES what is under it (C <- C + (paint - C) * A), it does+ not glaze over it like watercolour. A wet brush picks up a little of the layer below (`pickup`), so+ neighbouring strokes blend at their seams. Each stroke also leaves a little body (`T`), and the final+ picture is lit very gently from the upper left, so stroke ridges and the tooth read as a matte relief,+ not as gloss. Layers go on dark to light and big to small: toned ground, underdrawing in thinned umber,+ background, flat masses, value steps, textures, features, highlights.+ dry brush One stroke is a flat brush dragged along a short arc. Across it the hairs carry different loads+ (a random bristle profile, so streaks run along the stroke and the colour varies slightly per hair);+ along it the paint runs out (load falls with distance, faster for a drier brush). Where the load is+ high the paint covers everything under the brush; as it falls, paint is deposited only where a loaded+ bristle passes over a high point of the tooth, so the tail of the stroke breaks into streaks and+ specks -- the scumbled, dragged look of a gouache background. The sides of the stroke are ragged+ (the half-width wobbles along it) and the ends are rounded where the brush lands. `dry_brush()` does+ the same along any polyline (long sweeps, steam), `strokes()` scatters many strokes over a region+ with an orientation field (so they follow a form) and a colour field (so they pick their colour from+ where they land).+ edges A shape's edge is crisp but never vector-clean: the mask is blurred by a pixel and re-thresholded+ against a low-frequency wobble and the tooth (`rough()`), so the edge wanders a little and is+ broken where the brush skipped.+ modelling Forms are modelled in a few value steps, as a picture-book painter does: the shape is inflated into a+ soft pillow (a blurred mask taken as a height field; `sphere_shade()` uses an exact ellipsoid), lit+ by one light from the upper left, the light quantised into 3-5 soft steps, and each step mapped onto a+ ramp of mixed colours (deep shadow -> shadow -> local colour -> light -> pale light, shadows shifted+ toward violet / red, lights toward warm white). The ramp is laid first as a wet blend (soft) and then+ brushed over with short strokes that run ALONG the form (along the contour lines of the height, or+ around the centre of a sphere), each stroke taking its colour from the step it lands in, so the steps+ meet in brushy, slightly blended seams. Core shadows under a hat brim, a nose, a beard or a chin are+ thin multiply glazes of a shifted copy of the caster (`cast_shadow()`); cheeks are soft, powdery+ blush glazes broken by the tooth (`blush()`).+ knit A stockinette stitch is a V: two yarn legs leaning in from the top corners of a cell to its bottom+ centre. Each leg is a rotated ellipse with a cylinder profile (a raised yarn), twisted plies cut faint+ diagonal grooves across it, neighbouring rows overlap a little, and the valleys between legs are dark+ (occlusion). The height is lit with the same light, normalised and multiplied onto the paint that is+ already there, so the large-scale value steps of the garment survive and the stitches ride on top.+ Rows can bow (above eye level they arch, below they sag), follow a rotation, or follow a path (a scarf).+ Cables are two tubes twisting round each other in a column, one in front then the other, with a groove+ at each side. Every stitch gets a small hash-based value jitter and the lit tops get dry-brush+ highlights that only catch on the tooth. `rib()` is ribbing: raised knit columns and sunken purl+ columns across a band (collars, cuffs, a hat brim), with tiny chevrons of stitches along each column.+ hair Hair, brows, beards, curls, pompoms and fur are many fine painted strands over a darker mass. Each+ strand starts inside the mass (or on a root line), follows a flow field (an angle per pixel or a+ function: combed, radiating, curling round centres) with its own small bend and jitter, is drawn as a+ tapered line with a round brush (3x supersampled), and picks its value from a light field over the+ mass (dark strands in the shadow, light ones on the lit side) with some randomness, so the mass keeps+ its volume and still reads as hundreds of hairs; strays run a little past the silhouette.+ felt Felt is matted fibre: a fine two-scale mottle multiplied onto the paint, short random fibres in a+ lighter and a darker tone, and fibres sticking out across the silhouette so the edge is fuzzy.+ grain The finished painting is reproduced in a book: `grain()` adds the printed-page feel -- a fine paper+ speckle, a warm paper tone in the lights, ink that never reaches black and a slight softening of the+ most saturated colours -- over the matte relief of tooth and paint body.++API (panel-local coordinates in px; angles in degrees, 0 = to the right, 90 = down; colours are names in PAINTS+or '#rrggbb')+ surface GouachePortrait(W, H, seed, keep_stages, stages_dir); panel(x0, y0, w, h) -> panel (current), use(p);+ ground(tone, paper, alpha) gutters + toned imprimatura; sketch(mask, colour, width, alpha) underdrawing+ shapes ellipse(cx, cy, rx, ry, rot), poly(pts, smooth), blob(cx, cy, rx, ry, rough, seed, rot),+ band(path, w0, w1) a thick path; all return panel-size float masks (combine with np.maximum, *, 1 -)+ brush stroke(x, y, angle, length, width, colour, bend, dry, alpha); dry_brush(path, width, colour, dry, alpha);+ strokes(mask, colour|field, angle|field|callable, length, width, density, dry, alpha, clip);+ rough(mask, amount) a broken painted edge+ painting scumble_background(colour, bottom, avoid); block_in(mask, colour); form_light(mask, height) -> 0..1;+ model_form(mask, colours, steps, height, angle); sphere_shade(cx, cy, rx, ry, colours, mask);+ dry_highlight(mask, colour, above) broken light strokes on the lit side; glaze(mask, colour, alpha, mode);+ cast_shadow(caster, dx, dy, soft, alpha, on); blush(cx, cy, rx);+ dab(x, y, r, colour); line(path, width, colour, taper); spatter(mask, colour, n, size)+ features eye(cx, cy, r, iris, look, lid, lid_colour, lashes); nose(cx, cy, rx, ry, colour); ear(cx, cy, rx, ry,+ colour, side)+ textures knit(mask, stitch, origin, curve, angle, path, cables); rib(mask, path, period);+ hair_strands(mask, flow, colours, n, length, width, shade, curl); felt(mask, strength)+ finish grain(amount); render(); composite(); stage(name); save(path, stages_dir)+ helpers hexc(c), mix(a, b, t), ramp(base, ...) -> 5 colours dark -> light, PAINTS, LIGHT++ import sys; sys.path.insert(0, 'lib')+ import numpy as np+ from gouache import GouachePortrait, ramp+ g = GouachePortrait(1920, 1080, seed=5)+ p = g.panel(650, 15, 620, 1050)+ g.ground('#c88f5a')+ face = g.ellipse(310, 540, 190, 210)+ g.scumble_background('green', avoid=face)+ g.block_in(face, 'skin')+ g.model_form(face, ramp('skin', cool='#a02a3a'), steps=4) # skin shadows go warm, not violet+ g.blush(200, 600, 60); g.blush(420, 600, 60)+ g.nose(310, 580, 80, 70, 'nose')+ g.eye(230, 500, 26, look=(0.2, 0.1)); g.eye(390, 500, 26, look=(0.2, 0.1))+ g.grain(); g.save('portrait.jpg')+"""+import io+import os+from types import SimpleNamespace+import numpy as np+from PIL import Image, ImageDraw+from core import blur, noise2d, smoothstep, spline, polygon_mask, blob_pts+from core import shift as _shift+++PAINTS = {+ 'vermilion': '#e2512c', 'red': '#d33a2c', 'orange': '#ee7a22', 'mustard': '#e0a52b', 'yellow': '#f0c43c',+ 'ochre': '#c98a3a', 'cobalt': '#2c5bb0', 'cerulean': '#4d9bd0', 'navy': '#20325f', 'teal': '#1d877f',+ 'seaglass': '#7fbcb6', 'green': '#4d9a5c', 'olive': '#8d9a52', 'peach': '#f2c3a0', 'skin': '#efbb98',+ 'ruddy': '#e7a585', 'nose': '#e0563f', 'rose': '#e06d5c', 'blush': '#e9604c', 'pink': '#f0a59a',+ 'umber': '#5c3b28', 'sienna': '#b0603a', 'cream': '#f3ead6', 'white': '#f6f1e6', 'grey': '#9a9a98',+ 'ink': '#1c1a20', 'brown': '#6b4228', 'cocoa': '#5a3322',+}+PAPER = '#f2ead9' # the board / gutters+LIGHT = (-0.44, -0.56, 0.70) # one light from the upper left and in front+++def hexc(c):+ """'#rrggbb', a PAINTS name, or an RGB triple -> float32 RGB in 0..1"""+ if not isinstance(c, str): return np.asarray(c, np.float32)+ h = PAINTS.get(c, c).lstrip('#')+ return np.array([int(h[i:i + 2], 16) for i in (0, 2, 4)], np.float32) / 255+++def mix(a, b, t):+ a, b = hexc(a), hexc(b)+ return (a + (b - a) * t).astype(np.float32)+++def ramp(base, deep=0.50, shadow=0.74, light=0.26, pale=0.52, cool='#3b2450', warm='#fff2d8'):+ """five mixed colours, dark -> light, for modelling a form painted in `base`: shadows deepen and drift toward+ a violet-red, lights toward warm white (the way gouache is mixed, not a grey scale)"""+ b = hexc(base)+ return [mix(b * deep, cool, 0.20), mix(b * shadow, cool, 0.07), b, mix(b, warm, light), mix(b, warm, pale)]+++def _closed_spline(P, per=8):+ P = np.asarray(P, np.float32)+ n = len(P)+ t = np.linspace(0, 1, per, endpoint=False, dtype=np.float32)[:, None]+ t2, t3 = t * t, t * t * t+ out = []+ for i in range(n):+ p0, p1, p2, p3 = P[(i - 1) % n], P[i], P[(i + 1) % n], P[(i + 2) % n]+ out.append(0.5 * ((2 * p1) + (-p0 + p2) * t + (2 * p0 - 5 * p1 + 4 * p2 - p3) * t2 + (-p0 + 3 * p1 - 3 * p2 + p3) * t3))+ return np.concatenate(out).astype(np.float32)+++def _hash(a, b):+ h = np.sin(a * 12.9898 + b * 78.233) * 43758.5453+ return (h - np.floor(h)).astype(np.float32)+++def _steps(q, n, soft):+ """soft staircase: q in 0..1 -> n value steps with blended seams (soft 0.5 = no steps)"""+ x = np.clip(q, 0, 1) * n+ k = np.floor(np.minimum(x, n - 1e-4))+ f = x - k+ return np.clip((k + smoothstep(0.5 - soft, 0.5 + soft, f)) / n, 0, 1)+++def _ramp_field(q, colours):+ cols = np.stack([hexc(c) for c in colours])+ pos = np.linspace(0, 1, len(cols))+ out = np.empty(q.shape + (3,), np.float32)+ for ch in range(3):+ out[..., ch] = np.interp(q, pos, cols[:, ch])+ return out+++class GouachePortrait:+ PAINTS = PAINTS+ LIGHT = LIGHT++ 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.T = np.zeros((H, W), np.float32) # paint body left by the strokes+ r = np.random.default_rng(seed + 101)+ g1 = blur(r.random((H, W)).astype(np.float32), 0.7)+ g1 = (g1 - g1.mean()) / (g1.std() + 1e-6)+ g2 = noise2d(H, W, 7, 3, seed + 102)+ g2 = (g2 - g2.mean()) / (g2.std() + 1e-6)+ yy = np.arange(H, dtype=np.float32)[:, None]; xx = np.arange(W, dtype=np.float32)[None, :]+ weave = np.sin(xx * 2.07 + 0.6 * np.sin(yy * 0.05)) * np.sin(yy * 1.93)+ self.G = np.clip(0.5 + 0.16 * (0.66 * g1 + 0.30 * g2 + 0.22 * weave), 0, 1).astype(np.float32)+ L = np.asarray(LIGHT, np.float32)+ self.light = L / np.linalg.norm(L)+ self.print_amt = 0.0+ self.panels, self.P = [], None++ def _r(self, seed=None):+ return np.random.default_rng(int(self.rng.integers(1 << 30)) if seed is None else seed)++ # ================================================================== board and panels+ def panel(self, x0, y0, w, h):+ """a picture area on the board; becomes current. Drawing coordinates are local to it."""+ x0, y0, w, h = int(x0), int(y0), int(w), int(h)+ p = SimpleNamespace(x0=x0, y0=y0, w=w, h=h)+ p.YY, p.XX = np.mgrid[0:h, 0:w].astype(np.float32)+ p.C = self.C[y0:y0 + h, x0:x0 + w] # views: painting a panel paints the board+ p.T = self.T[y0:y0 + h, x0:x0 + w]+ p.G = self.G[y0:y0 + h, x0:x0 + w]+ self.panels.append(p)+ self.P = p+ return p++ def use(self, p):+ self.P = p+ return p++ def ground(self, tone='#c88f5a', paper=PAPER, alpha=0.5):+ """cream board in the gutters, and a thin warm imprimatura scrubbed over every panel with big loose strokes"""+ self.C[:] = hexc(paper) * (0.975 + 0.05 * (self.G[..., None] - 0.5))+ cur = self.P+ for p in self.panels:+ self.use(p)+ full = np.ones((p.h, p.w), np.float32)+ mot = noise2d(p.h, p.w, 140, 3, int(self.rng.integers(1 << 30))) - 0.5+ self._put((slice(None), slice(None)), full * alpha * (0.8 + 0.5 * mot), hexc(tone))+ self.strokes(full, tone, angle=-35, jitter=25, length=(240, 480), width=(60, 120), density=2.6,+ dry=0.6, alpha=alpha * 0.7, vj=0.06, pickup=0.0, bend=0.15, streak=1.0, load=0.82)+ self.P = cur++ # ================================================================== shapes (panel-size masks)+ def ellipse(self, cx, cy, rx, ry=None, rot=0.0):+ P = self.P+ ry = rx if ry is None else ry+ X, Y = P.XX - cx, P.YY - 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))+ return smoothstep(1 + e, 1 - e, d).astype(np.float32)++ def poly(self, pts, smooth=True, per=8):+ P = self.P+ pts = np.asarray(pts, np.float32)+ if smooth and len(pts) > 2: pts = _closed_spline(pts, per)+ return polygon_mask(P.h, P.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 at the start -> w1 at the end), 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 _bbox(self, m, pad=0, thr=0.004):+ P = self.P+ 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(P.h, rows[-1] + 1 + pad)),+ slice(max(0, cols[0] - pad), min(P.w, cols[-1] + 1 + pad)))++ def _put(self, sl, A, col):+ """opaque paint over what is there: C <- C + (col - C) * A"""+ Cs = self.P.C[sl]+ col = col if np.ndim(col) == 3 else np.asarray(col, np.float32)+ Cs += (col - Cs) * A[..., None]++ def rough(self, mask, amount=1.0, wobble=1.0, seed=None):+ """the painted edge of a shape: crisp, but wandering a little and broken by the tooth"""+ P = self.P+ sl = self._bbox(mask, 4)+ out = np.zeros_like(mask)+ if sl is None: return out+ m = blur(mask[sl], 0.9)+ h, w = m.shape+ lo = noise2d(h, w, 16, 2, int(self._r(seed).integers(1 << 30))) - 0.5+ out[sl] = smoothstep(0.40, 0.60, m + amount * (0.16 * wobble * lo + 0.20 * (P.G[sl] - 0.5)))+ return out++ # ================================================================== the brush+ def _stroke(self, cx, cy, ang, L, w, col, bend=0.0, dry=0.3, alpha=1.0, clip=None, pickup=0.1, streak=0.5,+ soft=0.8, r=None, thick=0.6, vjit=0.09, load0=1.0):+ """one flat-brush stroke centred at (cx, cy), angle in radians, bowing sideways by `bend` x half-length;+ load0 < 1 is a brush that is already nearly dry when it touches down (a scumble)"""+ P = self.P+ r = r if r is not None else self._r()+ ca, sa = np.cos(ang), np.sin(ang)+ hl, hw = max(L, 1.0) / 2, max(w, 1.0) / 2+ ex = abs(ca) * hl + abs(sa) * hw + abs(bend) * hl + 2+ ey = abs(sa) * hl + abs(ca) * hw + abs(bend) * hl + 2+ x0, x1 = max(0, int(cx - ex)), min(P.w, int(cx + ex) + 2)+ y0, y1 = max(0, int(cy - ey)), min(P.h, int(cy + ey) + 2)+ if x1 <= x0 or y1 <= y0: return+ sl = (slice(y0, y1), slice(x0, x1))+ X = P.XX[sl] - cx; Y = P.YY[sl] - cy+ u = X * ca + Y * sa+ v = -X * sa + Y * ca+ un = u / hl+ t = (v - bend * hl * (1 - np.clip(un, -1, 1) ** 2)) / hw+ k = 7+ wob = 1 + 0.11 * np.interp(un, np.linspace(-1.05, 1.05, k), r.normal(0, 1, k))+ c = min(0.45, hw / hl)+ a_ = np.maximum(np.abs(un) - (1 - c), 0) / c+ dist = np.sqrt(a_ * a_ + t * t) / wob+ body = smoothstep(1.0, 0.92 - 0.3 * soft, dist)+ if body.max() <= 0: return+ nb = max(5, int(w / 2.2))+ loads = r.uniform(0.3, 1.0, nb)+ B = np.interp(t, np.linspace(-1, 1, nb), loads)+ s = np.clip((un + 1) * 0.5, 0, 1)+ load = load0 - dry * 1.25 * r.uniform(0.8, 1.2) * s ** 1.4+ edge = smoothstep(0.55, 1.0, np.abs(t)) # outer hairs run dry first+ paint = load * (1 - 0.45 * streak + 0.45 * streak * B) * (1 - 0.35 * edge * streak) + (P.G[sl] - 0.5) * 0.6+ A = body * smoothstep(0.38, 0.58, paint) * alpha+ if clip is not None: A = A * clip[sl]+ Cs = P.C[sl]+ colv = np.asarray(col, np.float32) * (1 + vjit * streak * (B - 0.65))[..., None]+ if pickup: colv = colv * (1 - pickup) + Cs * pickup+ Cs += (colv - Cs) * A[..., None]+ P.T[sl] += A * thick * np.clip(load, 0, 1)++ def stroke(self, x, y, angle, length, width, colour, bend=0.0, dry=0.3, alpha=1.0, clip=None, pickup=0.1, streak=0.5):+ """one brush stroke (angle in degrees)"""+ self._stroke(x, y, np.deg2rad(angle), length, width, hexc(colour), bend, dry, alpha, clip, pickup, streak)++ def _angles(self, angle, xs, ys, r):+ n = len(xs)+ if angle is None: return r.uniform(0, 360, n)+ if callable(angle): return np.asarray(angle(xs, ys), np.float32) * np.ones(n)+ if np.ndim(angle) == 2:+ P = self.P+ return angle[np.clip(ys.astype(int), 0, P.h - 1), np.clip(xs.astype(int), 0, P.w - 1)]+ return np.full(n, float(angle))++ def strokes(self, mask, colour, angle=None, length=(30, 60), width=(10, 18), density=1.0, dry=0.3, alpha=1.0,+ bend=0.15, jitter=12.0, vj=0.03, clip=None, pickup=0.1, streak=0.5, soft=0.8, n=None, seed=None,+ thick=0.6, vjit=0.09, load=1.0):+ """lay many strokes with centres inside `mask` (> 0.5). colour: one colour or a panel-size colour field+ (each stroke takes the colour where it lands); angle (degrees): None = random, a number, a panel-size+ field, or f(x, y) -> degrees; clip: a mask the paint is confined to (default: none)"""+ P = self.P+ r = self._r(seed)+ sl = self._bbox(mask)+ if sl is None: return+ sub = mask[sl] > 0.5+ idx = np.flatnonzero(sub)+ if not len(idx): return+ if n is None:+ n = int(len(idx) / (np.mean(length) * np.mean(width)) * density) + 1+ pick = r.choice(idx, n)+ ys = (pick // sub.shape[1] + sl[0].start).astype(np.float32) + r.random(n)+ xs = (pick % sub.shape[1] + sl[1].start).astype(np.float32) + r.random(n)+ ang = np.deg2rad(self._angles(angle, xs, ys, r) + r.normal(0, jitter, n))+ if np.ndim(colour) == 3:+ cols = colour[np.clip(ys.astype(int), 0, P.h - 1), np.clip(xs.astype(int), 0, P.w - 1)]+ else:+ cols = np.broadcast_to(hexc(colour), (n, 3))+ cols = np.clip(cols * (1 + r.normal(0, vj, (n, 1))) + r.normal(0, vj * 0.35, (n, 3)), 0, 1)+ Ls = r.uniform(*length, n); Ws = r.uniform(*width, n)+ bends = r.uniform(-bend, bend, n); drys = np.clip(dry * r.uniform(0.6, 1.35, n), 0, 1)+ for i in range(n):+ self._stroke(xs[i], ys[i], ang[i], Ls[i], Ws[i], cols[i], bends[i], drys[i], alpha, clip, pickup,+ streak, soft, r, thick, vjit, load * r.uniform(0.85, 1.12))++ def _path_st(self, Q, sl):+ """for every pixel in sl: arc length of the nearest point on polyline Q, signed offset, squared distance"""+ P = self.P+ X = P.XX[sl]; Y = P.YY[sl]+ seg = Q[1:] - Q[:-1]+ Ls = np.hypot(seg[:, 0], seg[:, 1]) + 1e-6+ cum = np.concatenate([[0], np.cumsum(Ls)])+ best = np.full(X.shape, 1e12, np.float32); S = np.zeros_like(X); Tt = np.zeros_like(X)+ for k in range(len(seg)):+ dx, dy = seg[k] / Ls[k]+ rx, ry = X - Q[k, 0], Y - Q[k, 1]+ a = np.clip(rx * dx + ry * dy, 0, Ls[k])+ px, py = rx - a * dx, ry - a * dy+ d2 = px * px + py * py+ m = d2 < best+ best = np.where(m, d2, best)+ S = np.where(m, cum[k] + a, S)+ Tt = np.where(m, -rx * dy + ry * dx, Tt)+ return S, Tt, best, float(cum[-1])++ def dry_brush(self, path, width, colour, dry=0.35, alpha=1.0, clip=None, streak=0.6, pickup=0.08,+ taper=(0.12, 0.3), smooth=True, seed=None):+ """one long stroke along a polyline: bristle streaks, paint running out toward the end, tapered ends"""+ P = self.P+ r = self._r(seed)+ Q = np.asarray(path, np.float32)+ if smooth and len(Q) > 2: Q = spline(Q, 8)+ pad = width / 2 + 3+ x0, x1 = max(0, int(Q[:, 0].min() - pad)), min(P.w, int(Q[:, 0].max() + pad) + 1)+ y0, y1 = max(0, int(Q[:, 1].min() - pad)), min(P.h, int(Q[:, 1].max() + pad) + 1)+ if x1 <= x0 or y1 <= y0: return+ sl = (slice(y0, y1), slice(x0, x1))+ S, Tt, d2, L = self._path_st(Q, sl)+ s = S / max(L, 1e-3)+ prof = 0.25 + 0.75 * np.clip(np.minimum(s / max(taper[0], 1e-3), (1 - s) / max(taper[1], 1e-3)), 0, 1) ** 0.6+ hw = width / 2 * prof+ k = 9+ wob = 1 + 0.10 * np.interp(s, np.linspace(0, 1, k), r.normal(0, 1, k))+ dist = np.sqrt(d2) / (hw * wob + 1e-3)+ body = smoothstep(1.0, 0.7, dist)+ nb = max(5, int(width / 2.2))+ B = np.interp(np.clip(Tt / (hw + 1e-3), -1, 1), np.linspace(-1, 1, nb), r.uniform(0.3, 1.0, nb))+ load = 1.0 - dry * 1.25 * s ** 1.3+ paint = load * (1 - 0.45 * streak + 0.45 * streak * B) + (P.G[sl] - 0.5) * 0.6+ A = body * smoothstep(0.38, 0.58, paint) * alpha+ if clip is not None: A = A * clip[sl]+ Cs = P.C[sl]+ colv = hexc(colour) * (1 + 0.05 * streak * (B - 0.65))[..., None]+ if pickup: colv = colv * (1 - pickup) + Cs * pickup+ Cs += (colv - Cs) * A[..., None]+ P.T[sl] += A * 0.6 * np.clip(load, 0, 1)++ # ================================================================== painting+ def sketch(self, mask, colour='#8a4426', width=2.2, alpha=0.8, breaks=0.3, seed=None):+ """underdrawing: the contour of a shape in thinned paint with a small round brush, broken here and there"""+ P = self.P+ sl = self._bbox(mask, width * 3 + 4)+ if sl is None: return+ m = blur(mask[sl], width * 0.7)+ e = np.exp(-((m - 0.5) / 0.16) ** 2)+ h, w = m.shape+ brk = smoothstep(breaks - 0.15, breaks + 0.1, noise2d(h, w, 40, 2, int(self._r(seed).integers(1 << 30))))+ A = e * brk * alpha * smoothstep(0.25, 0.6, P.G[sl] + 0.2)+ Cs = P.C[sl]+ Cs *= 1 - A[..., None] * (1 - hexc(colour))++ def scumble_background(self, colour, bottom=None, avoid=None, light=0.15, dark=0.12, angle=-30, spread=40,+ dry=0.8, scratches=120, flecks=900, blend=(0.12, 0.92), seed=None):+ """the backdrop: one colour (or a top -> bottom blend) laid solid with long loaded strokes, then scrubbed+ over with an almost dry brush in lighter and darker mixes of the same colour, so the strokes break into+ streaks on the tooth and earlier coats show through; then short light scratches and a sprinkle of flecks.+ `avoid` (a mask) is painted around, a few px into it."""+ P = self.P+ r = self._r(seed)+ top = hexc(colour); bot = top if bottom is None else hexc(bottom)+ wob = (noise2d(P.h, P.w, 260, 2, int(r.integers(1 << 30))) - 0.5) * 0.25+ t = smoothstep(blend[0], blend[1], P.YY / P.h + wob)[..., None]+ field = top + (bot - top) * t+ mot = noise2d(P.h, P.w, 120, 3, int(r.integers(1 << 30))) - 0.5+ field = np.clip(field * (1 + 0.06 * mot[..., None]), 0, 1)+ if avoid is not None:+ clipm = 1 - smoothstep(0.55, 0.85, blur(avoid, 2.5))+ else:+ clipm = np.ones((P.h, P.w), np.float32)+ where = (clipm > 0.5).astype(np.float32)+ self._put((slice(None), slice(None)), clipm * 0.9, field)+ sd = lambda: int(r.integers(1 << 30))+ self.strokes(where, field, angle=angle, jitter=spread, length=(220, 420), width=(60, 110), density=1.3,+ dry=0.42, alpha=0.95, vj=0.012, clip=clipm, pickup=0.15, streak=1.0, seed=sd(), vjit=0.07)+ lite = field + (hexc('#fff6e2') - field) * light+ dk = field * (1 - dark) + hexc('#2a2440') * dark * 0.2+ self.strokes(where, lite, angle=angle + 60, jitter=spread, length=(140, 360), width=(22, 60), density=1.1,+ dry=dry * 0.6, alpha=0.75, vj=0.02, clip=clipm, pickup=0.0, streak=1.0, seed=sd(), vjit=0.1,+ load=0.74)+ self.strokes(where, dk, angle=angle, jitter=spread, length=(140, 340), width=(22, 56), density=0.6,+ dry=dry * 0.6, alpha=0.6, vj=0.02, clip=clipm, pickup=0.0, streak=1.0, seed=sd(), vjit=0.1,+ load=0.72)+ lite2 = field + (hexc('#fffaf0') - field) * (light * 2.4)+ if scratches:+ self.strokes(where, lite2, angle=angle + 25, jitter=spread * 1.2, length=(18, 70), width=(1.5, 3.5),+ n=scratches, dry=0.7, alpha=0.6, vj=0.03, clip=clipm, pickup=0.0, streak=1.0, seed=sd())+ if flecks:+ self.spatter(where * clipm, lite2, n=flecks // 2, size=(0.5, 1.4), alpha=0.5, seed=sd())+ self.spatter(where * clipm, dk * 0.92, n=flecks // 2, size=(0.5, 1.3), alpha=0.4, seed=sd())++ def block_in(self, mask, colour, angle=None, length=(34, 80), width=(14, 28), density=1.3, dry=0.15, edge=1.0,+ vj=0.03, alpha=0.97, flat=0.92, seed=None):+ """lay a shape in as a flat opaque mass: a near-solid coat with a broken edge, then brushed over in the same+ colour so the coat has direction and a little value drift. Returns the painted (rough) mask."""+ P = self.P+ r = self._r(seed)+ clip = self.rough(mask, edge, seed=int(r.integers(1 << 30)))+ sl = self._bbox(clip)+ if sl is None: return clip+ h, w = clip[sl].shape+ mot = (noise2d(h, w, 50, 3, int(r.integers(1 << 30))) - 0.5) * 0.05+ col = hexc(colour)+ self._put(sl, clip[sl] * flat, col * (1 + mot[..., None]))+ self.strokes(mask, colour, angle, length, width, density, dry, alpha, clip=clip, vj=vj, pickup=0.1,+ seed=int(r.integers(1 << 30)))+ return clip++ def form_light(self, mask, height=None, light=None, round_=0.5, ambient=0.0, relief=0.55):+ """light falling on a soft-modelled form, 0 (turned away) .. 1 (facing the light). The mask is inflated+ into a pillow unless `height` (panel-size, px) is given. Also returns the height and its gradient."""+ P = self.P+ Lv = self.light if light is None else np.asarray(light, np.float32) / np.linalg.norm(light)+ sl0 = self._bbox(mask)+ out = np.zeros_like(mask)+ if sl0 is None: return out, None, None+ if height is None:+ m0 = mask[sl0]+ re = float(np.sqrt(m0.sum() / np.pi)) + 1+ sig = max(2.0, re * round_)+ sl = self._bbox(mask, sig * 2.5)+ b = blur(mask[sl], sig)+ bm = float(b.max())+ inside = mask[sl] > 0.5+ b0 = float(np.percentile(b[inside], 0.5)) if inside.any() else 0.5+ hn = np.clip((b - b0) / max(bm - b0, 1e-3), 0, 1) * smoothstep(0.3, 0.6, mask[sl])+ hh = np.sqrt(hn) * re * relief+ else:+ sl = sl0+ hh = height[sl]+ gy, gx = np.gradient(hh)+ nz = 1 / np.sqrt(gx * gx + gy * gy + 1)+ lam = np.clip((-gx * Lv[0] - gy * Lv[1] + Lv[2]) * nz, 0, 1)+ out[sl] = ambient + (1 - ambient) * lam+ H = np.zeros_like(mask); H[sl] = hh+ GX = np.zeros_like(mask); GY = np.zeros_like(mask); GX[sl] = gx; GY[sl] = gy+ return out, H, (GX, GY)++ def _paint_field(self, mask, field, ang, clip, wet, length, width, density, dry, alpha, pickup, streak, vj, r,+ soft=0.8):+ sl = self._bbox(clip)+ if sl is None: return+ if wet:+ fb = np.stack([blur(field[sl][..., c], 2.0) for c in range(3)], -1)+ self._put(sl, clip[sl] * wet, fb)+ self.strokes(mask, field, ang, length, width, density, dry, alpha, bend=0.25, jitter=9, vj=vj, clip=clip,+ pickup=pickup, streak=streak, soft=soft, seed=int(r.integers(1 << 30)))++ def model_form(self, mask, colours, steps=4, soft=0.22, height=None, light=None, angle='contour', round_=0.5, relief=0.55,+ ambient=0.08, wet=0.75, length=(18, 44), width=(7, 15), density=2.2, dry=0.18, alpha=0.8,+ pickup=0.18, streak=0.45, vj=0.02, clip=None, bias=0.0, gamma=1.0, seed=None):+ """model a form in a few value steps (dark -> light ramp `colours`), wet-blended and then brushed ALONG the+ form. angle: 'contour' (strokes follow the contour lines of the height), 'fall' (down the slope), a number,+ a field or a function. bias / gamma shift the light (bias > 0 lighter). Returns the light field."""+ r = self._r(seed)+ lam, H, grad = self.form_light(mask, height, light, round_, ambient, relief)+ if H is None: return lam+ q = _steps(np.clip(lam ** gamma + bias, 0, 1), steps, soft)+ field = _ramp_field(q, colours)+ if isinstance(angle, str):+ GX, GY = grad+ base = np.degrees(np.arctan2(GY, GX + 1e-6))+ ang = base + 90 if angle == 'contour' else base+ else:+ ang = angle+ clip = self.rough(mask, 0.8, seed=int(r.integers(1 << 30))) if clip is None else clip+ self._paint_field(mask, field, ang, clip, wet, length, width, density, dry, alpha, pickup, streak, vj, r)+ return lam++ def sphere_shade(self, cx, cy, rx, ry=None, colours=None, steps=4, soft=0.3, mask=None, light=None, rot=0.0,+ reflect=0.18, wet=0.9, length=(10, 26), width=(5, 10), density=3.2, dry=0.1, alpha=0.55,+ pickup=0.25, streak=0.35, vj=0.008, clip=None, bias=0.0, seed=None):+ """model a round form (an ellipsoid) in value steps, strokes curving round its centre; a little reflected+ light comes back into the lower rim. Returns the light field."""+ P = self.P+ r = self._r(seed)+ ry = rx if ry is None else ry+ Lv = self.light if light is None else np.asarray(light, np.float32) / np.linalg.norm(light)+ X, Y = P.XX - cx, P.YY - 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+ nx, ny = X / rx, Y / ry+ r2 = nx * nx + ny * ny+ nz = np.sqrt(np.clip(1 - r2, 0, 1))+ lam = np.clip(nx * Lv[0] + ny * Lv[1] + nz * Lv[2], 0, 1)+ lam = lam + reflect * smoothstep(0.55, 1.0, r2) * np.clip(ny, 0, 1) * (r2 < 1.2)+ lam = np.clip(lam + bias, 0, 1)+ m = self.ellipse(cx, cy, rx, ry, rot) if mask is None else mask+ field = _ramp_field(_steps(lam, steps, soft), colours if colours is not None else ramp('nose'))+ ang = np.degrees(np.arctan2(ny, nx)) + 90 + rot+ clip = self.rough(m, 0.6, seed=int(r.integers(1 << 30))) if clip is None else clip+ self._paint_field(m, field, ang, clip, wet, length, width, density, dry, alpha, pickup, streak, vj, r)+ return lam++ def dry_highlight(self, mask, colour, above=0.62, height=None, angle='contour', length=(24, 60), width=(6, 14),+ density=0.6, alpha=0.7, load=0.7, dry=0.6, relief=0.55, seed=None):+ """the last touches on the lit side of a form: a nearly dry brush of a lighter mix dragged along the form,+ only where the light is strong, so it catches on the tooth and leaves broken streaks"""+ lam, H, grad = self.form_light(mask, height, relief=relief)+ if H is None: return+ where = mask * (lam > above)+ if isinstance(angle, str):+ ang = np.degrees(np.arctan2(grad[1], grad[0] + 1e-6)) + (90 if angle == 'contour' else 0)+ else:+ ang = angle+ clip = self.rough(mask, 0.5)+ self.strokes(where, colour, ang, length, width, density, dry, alpha, bend=0.2, jitter=10, vj=0.02,+ clip=clip, pickup=0.0, streak=1.0, seed=seed, load=load)++ def glaze(self, mask, colour, alpha=0.5, mode='multiply', soft=0.0):+ """a thin layer over what is there: 'multiply' (shadows), 'screen' (lights) or 'normal'"""+ m = blur(mask, soft) if soft else mask+ sl = self._bbox(m)+ if sl is None: return+ A = m[sl] * alpha+ Cs = self.P.C[sl]+ col = hexc(colour)+ if mode == 'multiply': tgt = Cs * col+ elif mode == 'screen': tgt = 1 - (1 - Cs) * (1 - col)+ else: tgt = np.broadcast_to(col, Cs.shape)+ Cs += (tgt - Cs) * A[..., None]++ def cast_shadow(self, caster, dx, dy, soft=8.0, alpha=0.4, colour='#7a4a52', on=None):+ """soft core / cast shadow of `caster` shifted by (dx, dy), only on `on` (default: anywhere), not on itself"""+ sh = blur(_shift(caster, dx, dy), soft) * (1 - caster)+ if on is not None: sh = sh * on+ self.glaze(sh, colour, alpha, 'multiply')++ def blush(self, cx, cy, rx, ry=None, colour='blush', strength=0.55, grain=0.6, mask=None, solid=0.45):+ """a round cheek of thinned colour: solid-ish in the middle, powdery toward the rim where only the tooth takes it"""+ P = self.P+ ry = rx if ry is None else ry+ d = np.sqrt(((P.XX - cx) / rx) ** 2 + ((P.YY - cy) / ry) ** 2)+ a = smoothstep(1.0, solid, d)+ sl = self._bbox(a)+ if sl is None: return+ a = a[sl]+ a = a * (1 - grain * 0.75 * (1 - smoothstep(0.25, 0.75, P.G[sl] + a * 0.45)))+ A = a * strength+ if mask is not None: A = A * mask[sl]+ self._put(sl, A, hexc(colour))++ def dab(self, x, y, r, colour='white', alpha=0.95, angle=-30, dry=0.15, clip=None):+ """a small round touch of paint (highlights, catchlights, buttons)"""+ self._stroke(x, y, np.deg2rad(angle), r * 2.2, r * 2.0, hexc(colour), 0.0, dry, alpha, clip, 0.0, 0.3, 0.6)++ # ------------------------------------------------------------------ painted lines (round brush)+ def _strands_mask(self, paths, widths, taper=(0.15, 0.5), fills=None, ss=3):+ """anti-aliased coverage of many tapered polylines (panel coords) -> (slice, crop)"""+ P = self.P+ allp = np.concatenate(paths)+ pad = float(np.max(widths)) + 3+ x0, x1 = max(0, int(allp[:, 0].min() - pad)), min(P.w, int(allp[:, 0].max() + pad) + 1)+ y0, y1 = max(0, int(allp[:, 1].min() - pad)), min(P.h, int(allp[:, 1].max() + pad) + 1)+ if x1 <= x0 or y1 <= y0: return None, None+ bw, bh = x1 - x0, y1 - y0+ ss = max(1, min(ss, 4096 // max(bw, bh))) # never draw larger than 4096 px a side+ im = Image.new('L', (bw * ss, bh * ss), 0)+ d = ImageDraw.Draw(im)+ o = np.array([x0, y0], np.float32)+ for i, Q in enumerate(paths):+ q = (np.asarray(Q, np.float32) - o) * ss+ n = len(q)+ f = 255 if fills is None else int(fills[i])+ if n < 2:+ rr = widths[i] * ss / 2+ d.ellipse([q[0, 0] - rr, q[0, 1] - rr, q[0, 0] + rr, q[0, 1] + rr], fill=f); continue+ tt = np.linspace(0, 1, n)+ prof = 0.2 + 0.8 * np.clip(np.minimum(tt / max(taper[0], 1e-3), (1 - tt) / max(taper[1], 1e-3)), 0, 1)+ ww = np.maximum(1, np.round(widths[i] * ss * prof)).astype(int)+ ql = [tuple(p) for p in q.tolist()]+ a = 0+ while a < n - 1:+ b = a + 1+ while b < n - 1 and ww[b] == ww[a]: b += 1+ d.line(ql[a:b + 1], fill=f, width=int(ww[a]), joint='curve' if ww[a] > 2 else None)+ a = b+ if widths[i] * ss > 4:+ for k in (0, n - 1):+ rr = ww[k] / 2+ d.ellipse([q[k, 0] - rr, q[k, 1] - rr, q[k, 0] + rr, q[k, 1] + rr], fill=f)+ cov = np.asarray(im.resize((bw, bh), Image.BOX), np.float32) / 255+ return (slice(y0, y1), slice(x0, x1)), cov++ def line(self, path, width, colour, alpha=1.0, taper=(0.2, 0.35), smooth=True, dry=0.0, clip=None):+ """a line painted with a small round brush, tapering in and out"""+ Q = np.asarray(path, np.float32)+ if smooth and len(Q) > 2: Q = spline(Q, 10)+ sl, m = self._strands_mask([Q], [width], taper)+ if sl is None: return+ A = m * alpha+ if dry: A = A * smoothstep(0.2, 0.55, self.P.G[sl] + (1 - dry) * 0.45)+ if clip is not None: A = A * clip[sl]+ self._put(sl, A, hexc(colour))++ def spatter(self, mask, colour, n=300, size=(0.6, 2.0), alpha=0.8, seed=None):+ """flecks of paint (a flicked brush or a sponge): tiny dots inside mask"""+ P = self.P+ r = self._r(seed)+ sl = self._bbox(mask)+ if sl is None: return+ sub = mask[sl] > 0.5+ idx = np.flatnonzero(sub)+ if not len(idx): return+ pick = r.choice(idx, n)+ ys = pick // sub.shape[1] + sl[0].start + r.random(n)+ xs = pick % sub.shape[1] + sl[1].start + r.random(n)+ paths = [np.array([[x, y]], np.float32) for x, y in zip(xs, ys)]+ s2, m = self._strands_mask(paths, r.uniform(*size, n) * 2, fills=r.uniform(120, 255, n))+ if s2 is None: return+ col = colour if np.ndim(colour) != 3 else colour[s2]+ self._put(s2, m * alpha * mask[s2], col if np.ndim(col) == 3 else hexc(col))++ # ================================================================== faces+ def eye(self, cx, cy, r, ry=None, iris='#1d2b2e', iris_r=0.58, look=(0.0, 0.0), lid=0.22, lid_colour=None,+ white='#f4efe3', outline='#4a2a22', ring=None, catch=(-0.38, -0.42), lashes=0, lash_dir=1, rot=0.0,+ lower=0.35, iris_light=None):+ """a round picture-book eye: an off-white ball shaded under the lid, a dark (or teal) iris with a lighter+ lower half, a black pupil, a white catchlight, a small lid with a dark lid line, and a thin warm outline.+ look = (dx, dy) in -1..1 moves the iris (1 = touching the rim); lid = how far the upper lid comes down (0..1)."""+ P = self.P+ ry = r if ry is None else ry+ ball = self.ellipse(cx, cy, r, ry, rot)+ clip = self.rough(ball, 0.35)+ wh = hexc(white)+ sh = mix(white, '#8d93a8', 0.55)+ q = np.clip((P.YY - (cy - ry)) / (2 * ry), 0, 1)+ field = wh + (sh - wh) * (0.9 * (1 - smoothstep(0.0, 0.62, q)))[..., None]+ sl = self._bbox(clip)+ self._put(sl, clip[sl], field[sl])+ self.strokes(ball, field, angle=0, length=(r * 0.5, r * 1.1), width=(r * 0.2, r * 0.38), density=1.6,+ dry=0.1, alpha=0.6, clip=clip, pickup=0.2, vj=0.01)+ # iris and pupil+ ir = r * iris_r+ ix, iy = cx + look[0] * (r - ir * 0.92), cy + look[1] * (ry - ir * 0.92)+ im = self.ellipse(ix, iy, ir, ir * 1.02) * clip+ ic = hexc(iris)+ il = hexc(iris_light) if iris_light is not None else mix(ic, '#7fb3a8', 0.35)+ qq = np.clip((P.YY - (iy - ir)) / (2 * ir), 0, 1)+ dd = np.sqrt((P.XX - ix) ** 2 + (P.YY - iy) ** 2) / ir+ ifield = ic + (il - ic) * (smoothstep(0.45, 1.0, qq) * smoothstep(1.0, 0.55, dd) * 0.8)[..., None]+ ifield = ifield * (1 - 0.35 * smoothstep(0.78, 1.0, dd))[..., None]+ s2 = self._bbox(im)+ if s2 is not None:+ self._put(s2, im[s2], ifield[s2])+ if ring is not None:+ rg = (smoothstep(0.42, 0.62, dd) * smoothstep(0.92, 0.7, dd))+ self._put(s2, (rg * im)[s2] * 0.75 * smoothstep(0.3, 0.7, P.G[s2] + 0.2), hexc(ring))+ pm = self.ellipse(ix, iy, ir * 0.55, ir * 0.56) * clip+ self._put(s2, pm[s2] * 0.95, hexc('#0d0c10'))+ # the lid and its shadow on the ball+ if lid > 0:+ yl = cy - ry + 2 * ry * lid+ arc = yl + (ry * 0.18) * ((P.XX - cx) / r) ** 2+ lm = ball * smoothstep(arc + 1.2, arc - 1.2, P.YY)+ self.glaze(ball * smoothstep(arc + ry * 0.45, arc, P.YY), '#6c6a86', 0.45, 'multiply')+ lc = lid_colour if lid_colour is not None else '#e2a688'+ sl3 = self._bbox(lm)+ if sl3 is not None:+ self._put(sl3, self.rough(lm, 0.3)[sl3], hexc(lc))+ xs = np.linspace(cx - r * 1.04, cx + r * 1.04, 24)+ ys = yl + (ry * 0.18) * ((xs - cx) / r) ** 2+ ys = np.minimum(ys, cy + ry * np.sqrt(np.clip(1 - ((xs - cx) / (r * 1.04)) ** 2, 0, 1)))+ self.line(np.stack([xs, ys], 1), max(1.6, r * 0.13), outline, 0.92, taper=(0.25, 0.25))+ for k in range(lashes):+ t = 0.62 + 0.36 * k / max(1, lashes - 1)+ sgn = lash_dir+ x0 = cx + sgn * (t - 0.5) * 2 * r * 0.98+ y0 = yl + (ry * 0.18) * ((x0 - cx) / r) ** 2+ self.line([(x0, y0), (x0 + sgn * r * 0.28, y0 - r * 0.22), (x0 + sgn * r * 0.48, y0 - r * 0.28)],+ max(1.2, r * 0.07), outline, 0.9, taper=(0.1, 0.9))+ # thin warm outline round the lower part of the ball, and a soft lower lid+ tt = np.linspace(0.08 * np.pi, 0.92 * np.pi, 30)+ a = np.deg2rad(rot)+ ox, oy = np.cos(tt) * r * 1.02, np.sin(tt) * ry * 1.02+ pts = np.stack([cx + ox * np.cos(a) - oy * np.sin(a), cy + ox * np.sin(a) + oy * np.cos(a)], 1)+ self.line(pts, max(1.0, r * 0.07), outline, 0.55, taper=(0.4, 0.4), dry=0.4)+ if lower:+ tt = np.linspace(0.22 * np.pi, 0.78 * np.pi, 20)+ pts = np.stack([cx + np.cos(tt) * r * 1.18, cy + np.sin(tt) * ry * 1.22], 1)+ self.line(pts, max(1.0, r * 0.08), '#b46a58', lower, taper=(0.5, 0.5), dry=0.5)+ # catchlights+ if catch is not None:+ self.dab(ix + catch[0] * ir, iy + catch[1] * ir, max(1.6, ir * 0.24), '#fbf8f0', 0.97, dry=0.0)+ self.dab(ix + catch[0] * ir * -0.7, iy + catch[1] * ir * -0.8, max(0.9, ir * 0.09), '#fbf8f0', 0.75, dry=0.0)+ return ball++ def nose(self, cx, cy, rx, ry=None, colour='nose', mask=None, cast=(0.22, 0.48, 0.42), nostrils=0.9,+ highlight=0.9, steps=4, shadow_colour='#8a3f3a', on=None, rot=0.0):+ """a big bulbous nose: a soft core shadow on the face below it, the bulb modelled as a sphere in value steps+ with strokes curving round it, warm reflected light in the lower rim, two dark nostril marks and a soft+ pinkish highlight with a sharp white glint"""+ ry = rx * 0.9 if ry is None else ry+ m = self.ellipse(cx, cy, rx, ry, rot) if mask is None else mask+ if cast:+ sh = blur(_shift(m, rx * cast[0], ry * cast[1]), max(3, rx * 0.22)) * (1 - m)+ if on is not None: sh = sh * on+ self.glaze(sh, shadow_colour, cast[2], 'multiply')+ cols = ramp(colour, deep=0.52, shadow=0.76, light=0.22, pale=0.5, cool='#4a1830')+ self.sphere_shade(cx, cy, rx, ry, cols, steps=steps, mask=m, rot=rot, reflect=0.22,+ length=(rx * 0.25, rx * 0.6), width=(rx * 0.1, rx * 0.2))+ if nostrils:+ for sgn in (-1, 1):+ x0 = cx + sgn * rx * 0.38; y0 = cy + ry * 0.62+ self.line([(x0 - sgn * rx * 0.13, y0 - ry * 0.05), (x0, y0 + ry * 0.07), (x0 + sgn * rx * 0.12, y0 + ry * 0.02)],+ max(1.6, rx * 0.085), mix(colour, '#3a0f1a', 0.6), nostrils, taper=(0.3, 0.6))+ if highlight:+ hx, hy = cx - rx * 0.36, cy - ry * 0.4+ self.blush(hx, hy, rx * 0.34, ry * 0.3, mix(colour, '#fff1e0', 0.62), 0.7 * highlight, grain=0.4,+ mask=m, solid=0.3)+ self.dab(hx - rx * 0.04, hy - ry * 0.04, max(1.5, rx * 0.075), '#fffaf2', 0.9 * highlight, dry=0.05)+ return m++ def ear(self, cx, cy, rx, ry, colour='ruddy', side=-1, rot=0.0, steps=3):+ """a big ear: modelled as a soft disc, the inner fold as a darker C-curve with a lit rim"""+ m = self.blob(cx, cy, rx, ry, 0.05, int(self.rng.integers(1 << 20)), rot)+ self.block_in(m, colour, length=(10, 26), width=(6, 12))+ self.model_form(m, ramp(colour), steps=steps, round_=0.4, length=(10, 24), width=(5, 10))+ k = -side+ tt = np.linspace(-0.85, 0.8, 18) * np.pi / 2+ pts = np.stack([cx + k * (np.cos(tt) * rx * 0.42 - rx * 0.05), cy + np.sin(tt) * ry * 0.58], 1)+ self.line(pts, max(2.0, rx * 0.16), mix(colour, '#5a1e28', 0.45), 0.6, taper=(0.4, 0.5), dry=0.2)+ self.line(pts + np.array([-k * rx * 0.12, -ry * 0.04]), max(1.5, rx * 0.08), mix(colour, '#fff0dc', 0.4),+ 0.5, taper=(0.4, 0.5), dry=0.3)+ return m++ # ================================================================== textures+ def knit(self, mask, stitch=(15, 11), origin=None, curve=0.0, angle=0.0, path=None, cables=(), cable_period=None,+ strength=0.75, highlight=0.3, fuzz=0.5, depth=0.45, seed=None):+ """stockinette (rows of V stitches) multiplied onto the paint that is already there. origin: the centre+ of the garment (rows bow away from it by `curve` rows at the sides: > 0 sag, < 0 arch); angle rotates+ the rows; path: the stitch columns follow a polyline (a scarf). cables: [(x, width)] columns (in the+ rotated frame) where two strands twist round each other instead."""+ P = self.P+ r = self._r(seed)+ sl = self._bbox(mask, 1)+ if sl is None: return+ sw, sh = stitch+ X, Y = P.XX[sl], P.YY[sl]+ if path is not None:+ S, Tt, _, _ = self._path_st(np.asarray(spline(np.asarray(path, np.float32), 8) if len(path) > 2 else path, np.float32), sl)+ Xr, Yr = Tt, S+ ox, hw = 0.0, max(1.0, float(np.abs(Tt[mask[sl] > 0.5]).max()) if (mask[sl] > 0.5).any() else 1.0)+ else:+ if angle:+ a = np.deg2rad(angle); c, s = np.cos(a), np.sin(a)+ Xr, Yr = X * c + Y * s, -X * s + Y * c+ else:+ Xr, Yr = X, Y+ ox = origin[0] if origin is not None else (sl[1].start + sl[1].stop) / 2+ hw = (sl[1].stop - sl[1].start) / 2+ U = (Xr - ox) / sw + 0.5+ V = Yr / sh + curve * ((Xr - ox) / hw) ** 2+ iu = np.floor(U); fu = U - iu - 0.5+ Hh = np.zeros_like(U); win_v = np.zeros_like(U)+ legd = np.array([0.44 * sw, 1.1 * sh]); legl = float(np.linalg.norm(legd))+ a_ = 0.5 * legl * 1.0; b_ = 0.215 * sw+ for dv in (-1, 0, 1):+ iv = np.floor(V) + dv+ hj1 = _hash(iu + 0.37, iv) - 0.5; hj2 = _hash(iu, iv + 0.71) - 0.5; hj3 = _hash(iu + 0.13, iv + 0.29)+ fv = V - iv - 0.5 - hj2 * 0.12+ px, py = (fu - hj1 * 0.10) * sw, fv * sh+ sc = 0.9 + 0.2 * hj3+ for side in (-1, 1):+ dx, dy = -side * legd[0] / legl, legd[1] / legl+ rx_, ry_ = px - side * 0.235 * sw, py+ al = rx_ * dx + ry_ * dy+ ac = -rx_ * dy + ry_ * dx+ e = (al / (a_ * sc)) ** 2 + (ac / (b_ * sc)) ** 2+ hl = np.sqrt(np.clip(1 - e, 0, 1))+ hl = hl * (0.86 + 0.14 * np.sin((al / a_ * 2.6 + ac / b_ * 0.9) * np.pi + hj3 * 3))+ # the leg of the row below sits over the bottom of this one: favour the lower row a little+ hl = hl * (1.0 + 0.06 * dv)+ win = hl > Hh+ Hh = np.where(win, hl, Hh); win_v = np.where(win, iv, win_v)+ jit = _hash(iu, win_v) - 0.5+ if cables:+ per = cable_period or sh * 7+ for xc, cw in cables:+ d = Xr - xc+ inside = smoothstep(cw / 2 + 1.5, cw / 2 - 1.5, np.abs(d))+ if not inside.any(): continue+ ph = Yr / per * 2 * np.pi+ off = 0.21 * cw * np.cos(ph)+ rs = 0.27 * cw+ hA = np.sqrt(np.clip(1 - ((d - off) / rs) ** 2, 0, 1))+ hB = np.sqrt(np.clip(1 - ((d + off) / rs) ** 2, 0, 1))+ front = np.sin(ph) > 0+ hc = np.where(front, np.maximum(hA * 1.1, hB * 0.75), np.maximum(hB * 1.1, hA * 0.75))+ hc = hc * (0.84 + 0.16 * np.abs(np.cos(Yr / (sh * 0.95) * np.pi + np.abs(d) * 0.25)))+ groove = smoothstep(cw / 2 - 1, cw / 2 - 3.5, np.abs(d))+ hc = hc * groove+ Hh = Hh * (1 - inside) + hc * inside+ hh = Hh * depth * sw+ gy, gx = np.gradient(hh)+ Lv = self.light+ nz = 1 / np.sqrt(gx * gx + gy * gy + 1)+ lam = np.clip((-gx * Lv[0] - gy * Lv[1] + Lv[2]) * nz, 0, 1)+ ao = 0.42 + 0.58 * smoothstep(0.0, 0.55, Hh)+ k = ao * (0.55 + 0.75 * lam) * (1 + 0.16 * jit)+ h, w = k.shape+ k = blur(k, 0.55)+ if fuzz:+ k = k * (1 + fuzz * 0.10 * (noise2d(h, w, 1.6, 2, int(r.integers(1 << 30))) - 0.5))+ m = mask[sl]+ mk = float((k * m).sum() / (m.sum() + 1e-6))+ k = k / mk+ Cs = P.C[sl]+ loose = 0.6 + 0.4 * smoothstep(0.25, 0.7, noise2d(h, w, 60, 2, int(r.integers(1 << 30))))+ f = 1 + strength * loose * (k - 1) * m+ Cs *= f[..., None]+ if highlight:+ hl = smoothstep(0.62, 0.9, lam * Hh) * smoothstep(0.45, 0.65, P.G[sl] + 0.1) * m+ tgt = np.clip(Cs * 1.22 + 0.06, 0, 1)+ Cs += (tgt - Cs) * (hl * highlight)[..., None]+ np.clip(Cs, 0, 1, out=Cs)++ def rib(self, mask, path, period=8.0, strength=0.75, highlight=0.25, rows=0.85, seed=None):+ """ribbing across a band (collar, cuff, hat brim): raised knit columns and sunken purl columns at right+ angles to `path` (the band's centre line), with small chevrons of stitches along each column"""+ P = self.P+ sl = self._bbox(mask, 1)+ if sl is None: return+ Q = np.asarray(path, np.float32)+ if len(Q) > 2: Q = spline(Q, 8)+ S, Tt, _, _ = self._path_st(Q, sl)+ ph = S / period+ f = ph - np.floor(ph) - 0.5+ Hh = np.sqrt(np.clip(1 - (f / 0.34) ** 2, 0, 1))+ if rows:+ g = Tt / (period * 0.62) + np.abs(f) * 1.4+ Hh = Hh * (1 - 0.22 * rows + 0.22 * rows * np.abs(np.cos(g * np.pi)))+ hh = Hh * period * 0.45+ gy, gx = np.gradient(hh)+ Lv = self.light+ nz = 1 / np.sqrt(gx * gx + gy * gy + 1)+ lam = np.clip((-gx * Lv[0] - gy * Lv[1] + Lv[2]) * nz, 0, 1)+ k = (0.42 + 0.58 * smoothstep(0, 0.5, Hh)) * (0.55 + 0.75 * lam)+ m = mask[sl]+ k = k / float((k * m).sum() / (m.sum() + 1e-6))+ Cs = P.C[sl]+ Cs *= (1 + strength * (k - 1) * m)[..., None]+ if highlight:+ hl = smoothstep(0.6, 0.92, lam * Hh) * smoothstep(0.45, 0.65, P.G[sl] + 0.1) * m+ tgt = np.clip(Cs * 1.2 + 0.05, 0, 1)+ Cs += (tgt - Cs) * (hl * highlight)[..., None]+ np.clip(Cs, 0, 1, out=Cs)++ def _flow_at(self, flow, x, y):+ P = self.P+ if callable(flow): return np.asarray(flow(x, y), np.float32)+ if np.ndim(flow) == 2:+ return flow[np.clip(y.astype(int), 0, P.h - 1), np.clip(x.astype(int), 0, P.w - 1)]+ return np.full(len(x), float(flow), np.float32)++ def hair_strands(self, mask, flow, colours, n=600, length=(18, 50), width=(0.9, 2.0), shade=None, spread=0.22,+ curl=0.0, jitter=8.0, step=3.0, alpha=0.95, clip=True, pad=4.0, roots=None,+ taper=(0.08, 0.6), opacity=(0.75, 1.0), seed=None):+ """many fine painted hairs over a mass: each starts inside `mask` (or `roots`), follows `flow` (degrees:+ a number, a panel-size field, or f(x, y)) with its own jitter and steady bend (`curl` degrees per step),+ and is drawn as a tapered round-brush line. Each picks a colour from `colours` (dark -> light) by the+ light field `shade` (0..1 panel-size) plus noise, and they are painted dark first, light last."""+ P = self.P+ r = self._r(seed)+ src = roots if roots is not None else mask+ sl = self._bbox(src)+ if sl is None: return+ sub = src[sl] > 0.5+ idx = np.flatnonzero(sub)+ if not len(idx): return+ pick = r.choice(idx, n)+ y = (pick // sub.shape[1] + sl[0].start).astype(np.float32) + r.random(n)+ x = (pick % sub.shape[1] + sl[1].start).astype(np.float32) + r.random(n)+ lens = r.uniform(*length, n)+ ns = max(2, int(lens.max() / step) + 1)+ jit = r.normal(0, jitter, n) if flow is not None else r.uniform(0, 360, n)+ if flow is None: flow = 0.0+ bend = r.normal(0, 1, n) * curl+ Xs = np.zeros((n, ns + 1), np.float32); Ys = np.zeros((n, ns + 1), np.float32)+ Xs[:, 0], Ys[:, 0] = x, y+ for k in range(ns):+ a = np.deg2rad(self._flow_at(flow, Xs[:, k], Ys[:, k]) + jit + bend * k)+ Xs[:, k + 1] = Xs[:, k] + np.cos(a) * step+ Ys[:, k + 1] = Ys[:, k] + np.sin(a) * step+ npts = np.clip((lens / step).astype(int) + 1, 2, ns + 1)+ nc = len(colours)+ base = shade[np.clip(y.astype(int), 0, P.h - 1), np.clip(x.astype(int), 0, P.w - 1)] if shade is not None else np.full(n, 0.5)+ cls = np.clip(np.floor((base + r.normal(0, spread, n)) * nc), 0, nc - 1).astype(int)+ widths = r.uniform(*width, n)+ fills = r.uniform(opacity[0], opacity[1], n) * 255+ cm = None+ if clip is True:+ cm = smoothstep(0.03, 0.3, blur(mask, pad))+ elif clip is not None and clip is not False:+ cm = clip+ for c in range(nc):+ sel = np.flatnonzero(cls == c)+ if not len(sel): continue+ paths = [np.stack([Xs[i, :npts[i]], Ys[i, :npts[i]]], 1) for i in sel]+ s2, m = self._strands_mask(paths, widths[sel], taper, fills[sel])+ if s2 is None: continue+ A = m * alpha+ if cm is not None: A = A * cm[s2]+ self._put(s2, A, hexc(colours[c]))++ def felt(self, mask, strength=0.7, fibres=1.0, fuzz=1.0, seed=None):+ """matted fibre: a fine two-scale mottle, short random fibres a little lighter and darker than the paint+ under them, and fibres sticking out across the silhouette"""+ P = self.P+ r = self._r(seed)+ sl = self._bbox(mask, 6)+ if sl is None: return+ h, w = sl[0].stop - sl[0].start, sl[1].stop - sl[1].start+ n1 = noise2d(h, w, 1.8, 2, int(r.integers(1 << 30))) - 0.5+ n2 = noise2d(h, w, 9, 3, int(r.integers(1 << 30))) - 0.5+ m = mask[sl]+ Cs = P.C[sl]+ Cs *= (1 + strength * (0.16 * n1 + 0.14 * n2) * m)[..., None]+ np.clip(Cs, 0, 1, out=Cs)+ if fibres:+ area = float(m.sum())+ mean = (Cs * m[..., None]).sum((0, 1)) / (area + 1e-6)+ nfib = int(area / 55 * fibres)+ if nfib > 0:+ self.hair_strands(mask, None, [mean * 0.8, np.clip(mean * 1.18 + 0.03, 0, 1)], n=nfib,+ length=(3, 8), width=(0.6, 1.0), step=1.5, jitter=60, curl=12, alpha=0.4,+ clip=mask, seed=int(r.integers(1 << 30)))+ if fuzz:+ b = blur(mask, 1.5)+ edge = (smoothstep(0.15, 0.5, b) * smoothstep(0.95, 0.6, b) > 0.5).astype(np.float32)+ if edge.any():+ Cs2 = P.C[sl]+ mean = (Cs2 * m[..., None]).sum((0, 1)) / (m.sum() + 1e-6)+ gy, gx = np.gradient(blur(mask, 3))+ out_ang = np.degrees(np.arctan2(-gy, -gx))+ ne = int(edge.sum() / 3 * fuzz)+ if ne > 0:+ self.hair_strands(mask, out_ang, [mean * 0.9, mean], n=ne, roots=edge, length=(3, 7),+ width=(0.6, 1.0), step=1.5, jitter=35, alpha=0.6, clip=False,+ seed=int(r.integers(1 << 30)))++ # ================================================================== finish+ def grain(self, amount=1.0):+ """reproduce the painting in a book: paper speckle, warm paper in the lights, ink that never reaches black"""+ self.print_amt = float(amount)++ def render(self):+ C = self.C+ Lv = self.light+ h = self.G * 1.1 + np.minimum(blur(self.T, 0.8), 3.0) * 0.55+ gy, gx = np.gradient(h)+ lit = 1 + (-gx * Lv[0] - gy * Lv[1]) * 0.09+ out = C * lit[..., None]+ p = self.print_amt+ if p:+ 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.65 * sp + 0.35 * blur(sp, 1.2) * 2.0+ lum = out.mean(-1, keepdims=True)+ out = lum + (out - lum) * (1 - 0.05 * p) # ink saturation a touch lower+ paper = hexc('#f7f0e2')+ out = out * (1 - 0.06 * p * smoothstep(0.6, 1.0, lum)) + paper * 0.06 * p * smoothstep(0.6, 1.0, lum)+ out = 0.045 * p * hexc('#2a1f2a') + out * (1 - 0.045 * p) # blacks lift to the darkest ink+ out = out * (1 + 0.022 * p * self._speck[..., 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