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 Jiangnan garden style (67 total): a lush spring water garden
clovericff15c1e23763
diff --git a/README.md b/README.mdindex 6317877..3226009 100644--- a/README.md+++ b/README.md@@ -1,7 +1,7 @@# Claude Drawing · Claude 绘图-**Claude paints with code — no image model.** Sixty-six styles, from ink wash and impasto oil to clay, cyanotype, stained glass, a Roman mosaic, Delft tiles, a cyberpunk street, a ray-traced ball pit, low-poly 3D, a thermal camera, an X-ray, a VHS tape, a synthwave sunset, a pastel product-film UI, an answer sheet marked in red, a lamp-lit shadow-puppet play, pen-and-wash sketch cards, retro gouache picture-book portraits and a soft-blue picture-book spread.-**不用生图模型,Claude 用代码一笔一笔作画。** 六十六种画风,从水墨、油画到黏土、蓝晒、彩色玻璃花窗、罗马马赛克、代尔夫特蓝瓷砖、赛博朋克、光线追踪的小球海、低多边形 3D、热成像、X 光片、VHS 录像带、Synthwave 落日、产品发布片式的粉彩界面、红笔批改的答题卡、油灯下的皮影戏、钢笔淡彩的速写小卡、复古水粉的绘本大头像和蓝调绘本的雨天跨页。+**Claude paints with code — no image model.** Sixty-seven styles, from ink wash and impasto oil to clay, cyanotype, stained glass, a Roman mosaic, Delft tiles, a cyberpunk street, a ray-traced ball pit, low-poly 3D, a thermal camera, an X-ray, a VHS tape, a synthwave sunset, a pastel product-film UI, an answer sheet marked in red, a lamp-lit shadow-puppet play, pen-and-wash sketch cards, retro gouache picture-book portraits, a soft-blue picture-book spread and a Jiangnan water garden in spring.+**不用生图模型,Claude 用代码一笔一笔作画。** 六十七种画风,从水墨、油画到黏土、蓝晒、彩色玻璃花窗、罗马马赛克、代尔夫特蓝瓷砖、赛博朋克、光线追踪的小球海、低多边形 3D、热成像、X 光片、VHS 录像带、Synthwave 落日、产品发布片式的粉彩界面、红笔批改的答题卡、油灯下的皮影戏、钢笔淡彩的速写小卡、复古水粉的绘本大头像、蓝调绘本的雨天跨页和江南园林的春水园景。[English](#english) · [中文](#中文)@@ -50,8 +50,8 @@|  |  |  || **Exam grading · 阅卷批改** | **Shadow puppetry · 皮影戏** | **Pen & wash · 钢笔淡彩** ||  |  |  |-| **Retro gouache · 复古水粉** | **Blue picture book · 蓝调绘本** | **Ink wash · 水墨(月印万川)** |-|  |  |  |+| **Retro gouache · 复古水粉** | **Blue picture book · 蓝调绘本** | **Jiangnan garden · 江南园林** |+|  |  |  |### Gallery · 画廊@@ -59,74 +59,74 @@|---|---|| **八万四千法门** · *Many Paths, One Summit*<br><sub>Ink wash · 水墨</sub> | **月印万川** · *One Moon in Ten Thousand Rivers*<br><sub>Ink wash · 水墨</sub> || <img src="examples/bawansiqian.jpg" width="100%"> | <img src="examples/moon_river.jpg" width="100%"> |-| **秋日湖畔** · *Autumn Lake*<br><sub>Watercolour · 水彩</sub> | **水彩底纹** · *Watercolour Washes*<br><sub>Watercolour · 水彩 — a background for explainer videos · 讲解视频的背景</sub> |-| <img src="examples/watercolor_autumn.jpg" width="100%"> | <img src="examples/watercolor_washes.jpg" width="100%"> |-| **热气球小镇** · *Balloon Day*<br><sub>Paper collage · 剪纸拼贴</sub> | **午后甜点** · *Afternoon Dessert*<br><sub>Coloured pencil · 韩国彩铅</sub> |-| <img src="examples/papercut_balloons.jpg" width="100%"> | <img src="examples/colorpencil_dessert.jpg" width="100%"> |-| **夏空** · *Summer Sky*<br><sub>Anime · 日本动漫</sub> | **灵感生长** · *Growing Ideas*<br><sub>Editorial · 编辑风手绘</sub> |-| <img src="examples/anime_summer.jpg" width="100%"> | <img src="examples/editorial_ideas.jpg" width="100%"> |-| **麦田星空** · *Swirling Sky over the Wheat Field*<br><sub>Impasto oil · 油画厚涂</sub> | **富士曙** · *Fuji at Dawn*<br><sub>Ukiyo-e · 浮世绘</sub> |-| <img src="examples/oil_wheatfield.jpg" width="100%"> | <img src="examples/ukiyoe_fuji.jpg" width="100%"> |-| **雨夜咖啡店** · *Rainy Night Cafe*<br><sub>Pixel art · 像素风</sub> | **灯塔岛** · *Lighthouse Island*<br><sub>Stop-motion clay · 黏土定格</sub> |-| <img src="examples/pixel_rainy_cafe.png" width="100%"> | <img src="examples/clay_lighthouse.jpg" width="100%"> |-| **蓝晒植物** · *Sun-Print Botanicals*<br><sub>Cyanotype · 蓝晒</sub> | **家** · *Home Sampler*<br><sub>Cross-stitch · 十字绣</sub> |-| <img src="examples/cyanotype_botanicals.jpg" width="100%"> | <img src="examples/stitch_sampler.jpg" width="100%"> |-| **Aurora 64 收音机** · *Aurora 64 Radio*<br><sub>Vintage instrument panel · 复古仪器面板</sub> | **周末市集** · *Weekend Market*<br><sub>Sticker collage × receipt · 贴纸拼贴 · 小票</sub> |-| <img src="examples/panel_radio.jpg" width="100%"> | <img src="examples/sticker_market.jpg" width="100%"> |-| **咖啡萃取实验** · *Coffee Brewing Experiment*<br><sub>Lab notebook × stickers · 实验笔记本 · 贴纸</sub> | **为什么天空是蓝的** · *Why Is the Sky Blue?*<br><sub>Chalkboard · 黑板板书</sub> |-| <img src="examples/notebook_brewing.jpg" width="100%"> | <img src="examples/chalk_lesson.jpg" width="100%"> |-| **霓虹不夜城** · *Neon District*<br><sub>Cyberpunk · 赛博朋克</sub> | **早安吐司** · *Good Morning, Toast*<br><sub>Hand-drawn cartoon · 卡通手绘</sub> |-| <img src="examples/cyberpunk_neon_street.jpg" width="100%"> | <img src="examples/cartoon_toaster.jpg" width="100%"> |-| **岛上的气象站** · *Island Weather Station*<br><sub>Isometric 2.5D · 等轴 2.5D</sub> | **从这扇窗到那扇窗** · *From Window to Window*<br><sub>Continuous line art · 单线画</sub> |-| <img src="examples/isometric_weather_island.jpg" width="100%"> | <img src="examples/lineart_paper_plane.jpg" width="100%"> |-| **浮出** · *Rise*<br><sub>Soft 3D · 柔光 3D</sub> | **一滴水的旅程** · *A Drop's Round Trip*<br><sub>Shape morph · 形变动画</sub> |-| <img src="examples/soft3d_rise.jpg" width="100%"> | <img src="examples/morph_water_cycle.jpg" width="100%"> |-| **好奇心周刊 · 拆开看看** · *Curiosity Weekly · Take It Apart*<br><sub>Newspaper collage · 报刊拼贴</sub> | **晨间计划** · *Morning Plan*<br><sub>Aurora glassmorphism · 弥散玻璃</sub> |-| <img src="examples/newscollage_curiosity.jpg" width="100%"> | <img src="examples/aurora_morning.jpg" width="100%"> |-| **形与色** · *Form & Colour*<br><sub>Bauhaus geometric · 包豪斯几何</sub> | **海岸线 1987** · *Coastline 1987*<br><sub>Retro synthwave · 复古 Synthwave</sub> |-| <img src="examples/bauhaus_form_colour.jpg" width="100%"> | <img src="examples/synthwave_coastline.jpg" width="100%"> |-| **草莓杯垫** · *Strawberry Coaster*<br><sub>Perler beads · 拼豆</sub> | **迁徙季** · *Migration Season*<br><sub>Petroglyph · 岩画</sub> |-| <img src="examples/perler_strawberry_coaster.jpg" width="100%"> | <img src="examples/petroglyph_migration.jpg" width="100%"> |-| **尼罗河丰收** · *Harvest on the Nile*<br><sub>Egyptian tomb painting · 古埃及墓室壁画</sub> | **港口渔获** · *The Day's Catch*<br><sub>Roman mosaic · 罗马马赛克</sub> |-| <img src="examples/tomb_harvest.jpg" width="100%"> | <img src="examples/mosaic_harbor.jpg" width="100%"> |-| **四季之窗** · *Window of the Seasons*<br><sub>Stained glass · 彩色玻璃花窗</sub> | **星辰之书** · *Liber Stellarum*<br><sub>Illuminated manuscript · 泥金手抄本</sub> |-| <img src="examples/stainedglass_seasons.jpg" width="100%"> | <img src="examples/illuminated_starchart.jpg" width="100%"> |-| **扑翼机** · *The Ornithopter*<br><sub>Leonardo codex · 达·芬奇手稿</sub> | **剪影小像** · *Shades of the Wren Household*<br><sub>Silhouette · 剪影</sub> |-| <img src="examples/codex_ornithopter.jpg" width="100%"> | <img src="examples/silhouette_family.jpg" width="100%"> |-| **马戏团来了** · *The Circus Is Coming*<br><sub>Letterpress poster · 凸版印刷海报</sub> | **无线电** · *Radio*<br><sub>Soviet constructivism · 苏联构成主义</sub> |-| <img src="examples/letterpress_circus.jpg" width="100%"> | <img src="examples/constructivism_radio.jpg" width="100%"> |-| **夜行快车** · *Night Express*<br><sub>Art Deco · 装饰艺术</sub> | **火箭小队** · *Rocket Squad*<br><sub>Golden-age comic · 黄金时代漫画</sub> |-| <img src="examples/artdeco_express.jpg" width="100%"> | <img src="examples/comic_rocket.jpg" width="100%"> |-| **猫的六种心情** · *Six Moods of a Cat*<br><sub>Pop silkscreen · 波普丝网</sub> | **发射记录** · *Liftoff Trace*<br><sub>ASCII art (line printer) · ASCII 字符画(行式打印机)</sub> |-| <img src="examples/popart_cat_moods.jpg" width="100%"> | <img src="examples/lineprinter_launch.jpg" width="100%"> |-| **峡谷飞行** · *Canyon Run*<br><sub>Low poly · 低多边形</sub> | **放风筝** · *Hold On*<br><sub>Stencil graffiti · 喷漆模板涂鸦</sub> |-| <img src="examples/lowpoly_canyon.jpg" width="100%"> | <img src="examples/stencil_kite.jpg" width="100%"> |-| **三晚露营** · *Three Nights Out*<br><sub>Embroidered patches · 刺绣徽章</sub> | **灯塔剖面** · *Halvard Rock Light*<br><sub>Blueprint · 蓝图工程图</sub> |-| <img src="examples/patch_camping.jpg" width="100%"> | <img src="examples/blueprint_lighthouse.jpg" width="100%"> |-| **我的周末** · *My Weekend*<br><sub>Children's crayon · 儿童蜡笔画</sub> | **今天带伞吗** · *Bring an Umbrella?*<br><sub>Green-screen CRT terminal · 绿屏终端(荧光字符画)</sub> |-| <img src="examples/crayon_picnic.jpg" width="100%"> | <img src="examples/crt_weather.jpg" width="100%"> |-| **厨房里的温度** · *Kitchen Heat Map*<br><sub>Thermal camera · 热成像</sub> | **一阵风** · *The Gust*<br><sub>Delft tiles · 代尔夫特蓝瓷砖</sub> |-| <img src="examples/thermal_kitchen.jpg" width="100%"> | <img src="examples/delft_canal.jpg" width="100%"> |-| **篝火旁的岩洞** · *The Hunt by the Fire*<br><sub>Cave painting · 洞穴壁画</sub> | **窗台花园** · *Windowsill Garden*<br><sub>1-bit paint program · 1-bit 早期画图软件</sub> |-| <img src="examples/cave_hunt.jpg" width="100%"> | <img src="examples/macpaint_garden.jpg" width="100%"> |-| **赛跑与赛车** · *Games on a Vase*<br><sub>Greek black-figure vase · 古希腊黑绘陶瓶</sub> | **老街角的自行车** · *The Bread Run*<br><sub>Graphite pencil · 铅笔素描</sub> |-| <img src="examples/blackfigure_games.jpg" width="100%"> | <img src="examples/graphite_bicycle.jpg" width="100%"> |-| **行李安检** · *Security Check*<br><sub>X-ray · X 光片</sub> | **早晨的闹钟** · *Seven O'Clock*<br><sub>1930s rubber hose · 1930 年代黑白橡皮管动画</sub> |-| <img src="examples/xray_luggage.jpg" width="100%"> | <img src="examples/rubberhose_morning.jpg" width="100%"> |-| **雪夜归途** · *Homeward, First Snow*<br><sub>Linocut · 黑白麻胶版画</sub> | **吹蜡烛** · *Blow Out the Candles*<br><sub>VHS home video · VHS 家庭录像</sub> |-| <img src="examples/linocut_snowy_village.jpg" width="100%"> | <img src="examples/vhs_birthday.jpg" width="100%"> |-| **山间夜营** · *Night Camp*<br><sub>Flat vector · 扁平矢量</sub> | **小橡果的秋天** · *An Acorn's Autumn*<br><sub>Storybook animation · 绘本角色动画</sub> |-| <img src="examples/flatvector_night_camp.jpg" width="100%"> | <img src="examples/storybook_acorn.jpg" width="100%"> |-| **蛇梯棋大冒险** · *Snakes & Ladders, Round 7*<br><sub>Ballpoint doodle · 圆珠笔涂鸦</sub> | **海港步行图** · *Larkhaven on Foot*<br><sub>Overlay sheets · 描图纸叠层</sub> |-| <img src="examples/ballpoint_board_game.jpg" width="100%"> | <img src="examples/overlay_city_map.jpg" width="100%"> |-| **出发前,再查一遍行李** · *Pack Check*<br><sub>Pastel UI · 粉彩界面</sub> | **数学单元测验** · *Unit Test, Graded*<br><sub>Exam grading · 阅卷批改</sub> |-| <img src="examples/pastelui_packing.jpg" width="100%"> | <img src="examples/grading_math_quiz.jpg" width="100%"> |-| **蹴鞠** · *Cuju by Lamplight*<br><sub>Shadow puppetry · 皮影戏</sub> | **街角速写** · *Sketchbook Neighbours*<br><sub>Pen & wash · 钢笔淡彩</sub> |-| <img src="examples/shadowpuppet_cuju.jpg" width="100%"> | <img src="examples/penwash_neighbours.jpg" width="100%"> |-| **雨天三人像** · *Rainy-Day Portraits*<br><sub>Retro gouache · 复古水粉</sub> | **借伞** · *The Shared Umbrella*<br><sub>Blue picture book · 蓝调绘本</sub> |-| <img src="examples/gouache_rainy_day.jpg" width="100%"> | <img src="examples/bluebook_shared_umbrella.jpg" width="100%"> |--Every mark above is computed: paper fibres, ink washes and mist, dry-brush strokes, pigment granulation and blooms, torn-paper edges, pencil wax on paper tooth, cel-shaded clouds, risograph grain and halftones, lit impasto relief, woodblock grain and bokashi, dithered pixels, plasticine lit like a film set, sunlight through leaves on Prussian blue, twisted thread on Aida cloth, machined knobs behind a backlit dial, die-cut vinyl with a laminate gloss, streaky thermal print, graphite catching the tooth of graph paper, highlighter pooling at the start of a swipe, chalk dust settling under half-erased lessons, rain-lit neon glass mirrored in a wet street, a blue-pencil rough under boiling brush ink, an island ray-traced under one soft sun, a single unbroken gold line, candy balls with softbox glints, one outline morphing through six shapes, halftone photos cut out with scissors, frosted glass blurring the real pixels behind it, screen-printed primaries out of register, a slit sun sinking behind a neon grid played off tape, hollow fuse beads on a pegboard melting together under an iron, pits knocked through desert varnish, a red grid showing through flaking plaster, stones laid row by row along an outline, daylight through leaded glass, burnished gold that mirrors the room, left-handed hatching in iron-gall ink, black paper cut with scissors, wood type printed a hair out of register, red and black plates slipping apart, airbrush fades inside knife-cut friskets, Ben-Day dots on yellowed newsprint, one photo key pulled across hand-painted colour, characters struck through a fading ribbon, flat-shaded triangles dithered to 15 bits, spray drifting past cut card, satin stitches catching the light by their angle, ink lines printed white on Prussian blue, wax scribbles skipping the paper's pits, phosphor glowing behind curved glass, heat leaking out of a kitchen, cobalt fired into tin glaze tile by tile, ochre blown onto rock lit by a fire, 1-bit patterns in an old paint program, slip silhouettes incised to the clay, graphite that never quite reaches black, X-rays adding up through a suitcase, grey cels shot on scratched film, gouge marks in a rolled-up block, a birthday smeared onto tape, seven flat colours lifting off each other, an acorn squashing and stretching through a world drawn as it goes, ballpoint ink blobbing at every corner of a hand-drawn game, inks multiplying through tracing paper on a light box, window cards floating on a pastel field over shadows tinted by it, a vermilion stamp running dry at one end, red ink pooling where the pen slowed down, dyed donkey hide glowing on a lamp-lit screen, gouache scumbled dry over a toned board, knit stitch by stitch, and dry pastel blue under a scratchy brush line, with chalk rain on top. No diffusion model, no API, no stock art. It is just Python with **numpy + Pillow** on a CPU: from 0.1 s (pixel art) to about 45 s (the soft 3D ray tracer) per 1920×1080 image.+| **秋日湖畔** · *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%"> |+| **借伞** · *The Shared Umbrella*<br><sub>Blue picture book · 蓝调绘本</sub> | **春水园林** · *Spring Water Garden*<br><sub>Jiangnan garden · 江南园林</sub> |+| <img src="examples/bluebook_shared_umbrella.jpg" width="100%"> | <img src="examples/jiangnan_spring_water.jpg" width="100%"> |++Every mark above is computed: paper fibres, ink washes and mist, dry-brush strokes, pigment granulation and blooms, torn-paper edges, pencil wax on paper tooth, cel-shaded clouds, risograph grain and halftones, lit impasto relief, woodblock grain and bokashi, dithered pixels, plasticine lit like a film set, sunlight through leaves on Prussian blue, twisted thread on Aida cloth, machined knobs behind a backlit dial, die-cut vinyl with a laminate gloss, streaky thermal print, graphite catching the tooth of graph paper, highlighter pooling at the start of a swipe, chalk dust settling under half-erased lessons, rain-lit neon glass mirrored in a wet street, a blue-pencil rough under boiling brush ink, an island ray-traced under one soft sun, a single unbroken gold line, candy balls with softbox glints, one outline morphing through six shapes, halftone photos cut out with scissors, frosted glass blurring the real pixels behind it, screen-printed primaries out of register, a slit sun sinking behind a neon grid played off tape, hollow fuse beads on a pegboard melting together under an iron, pits knocked through desert varnish, a red grid showing through flaking plaster, stones laid row by row along an outline, daylight through leaded glass, burnished gold that mirrors the room, left-handed hatching in iron-gall ink, black paper cut with scissors, wood type printed a hair out of register, red and black plates slipping apart, airbrush fades inside knife-cut friskets, Ben-Day dots on yellowed newsprint, one photo key pulled across hand-painted colour, characters struck through a fading ribbon, flat-shaded triangles dithered to 15 bits, spray drifting past cut card, satin stitches catching the light by their angle, ink lines printed white on Prussian blue, wax scribbles skipping the paper's pits, phosphor glowing behind curved glass, heat leaking out of a kitchen, cobalt fired into tin glaze tile by tile, ochre blown onto rock lit by a fire, 1-bit patterns in an old paint program, slip silhouettes incised to the clay, graphite that never quite reaches black, X-rays adding up through a suitcase, grey cels shot on scratched film, gouge marks in a rolled-up block, a birthday smeared onto tape, seven flat colours lifting off each other, an acorn squashing and stretching through a world drawn as it goes, ballpoint ink blobbing at every corner of a hand-drawn game, inks multiplying through tracing paper on a light box, window cards floating on a pastel field over shadows tinted by it, a vermilion stamp running dry at one end, red ink pooling where the pen slowed down, dyed donkey hide glowing on a lamp-lit screen, gouache scumbled dry over a toned board, knit stitch by stitch, dry pastel blue under a scratchy brush line, with chalk rain on top, and a spring garden built leaf by leaf, its tiled roofs and willows mirrored in a jade lake. 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.---@@ -134,7 +134,7 @@ Every mark above is computed: paper fibres, ink washes and mist, dry-brush strok### What it is-A [Claude Code](https://claude.com/claude-code) skill and a small painting library with sixty-six styles:+A [Claude Code](https://claude.com/claude-code) skill and a small painting library with sixty-seven styles:| Style | Module | What makes it read as the real medium ||---|---|---|@@ -204,6 +204,7 @@ A [Claude Code](https://claude.com/claude-code) skill and a small painting libra| **Pen & wash (钢笔淡彩)** | `lib/penwash.py` · `PenWash` | small cold-press sketch cards made the way a sketcher makes them — a fineliner line first, loose watercolour after, then the cards photographed on a table. Each card is its own sheet (paper tooth lit by the window, a cut edge that is not quite straight), drawn unturned and laid down at a slight angle. The ink line is near-uniform but hand-made: low-frequency wobble and tremor, width drifting a few per cent, a dot where the tip rested, a flick at some ends; closed shapes are one to three strokes that stop short or run past the join on the tangent, box corners overshoot, a stretch is sometimes gone over twice; parts have a depth, so an outline stops where a part in front covers it. Washes start from the intended region and are then painted loosely: slipped 2–5 px off the line (spilling over on one side, leaving white paper inside the line on the other), an edge re-found on a wandering threshold that follows the tooth, a darker dried rim, granulation in the valleys of the paper, faint flat-brush streaks, density mottle, wet-in-wet drops for cheeks and crust, cockling where the paper got wet — and a gentler slip for small shapes, so a nose never turns into a white ring. A flat background block that does not fill the card is painted around the figure with a white halo; opaque white gouache glints go on last. Ink and pigments are optical densities, so overlaps darken and mix. Helpers for goofy characters: big round glasses, dot eyes, tufts, simple hands, limbs, inked frames, ground lines. The photo: oak planks with cathedral grain and butt joints, soft card shadows and lit cut edges, a fineliner and a water brush shaded as cylinders (the clear barrel refracts what is under it), window fall-off, vignette and grain || **Retro gouache (复古水粉)** | `lib/gouache.py` · `GouachePortrait` | picture-book character portraits in opaque gouache, painted the way a gouache painter works, dark to light and big to small: a warm imprimatura scrubbed onto the board, an umber underdrawing, a background laid solid and then scumbled with a nearly dry brush in lighter and darker mixes, flat masses, forms modelled in a few value steps, textures, features and dry-brush highlights, then the grain of the printed page. Every coat is opaque (it replaces what is under it), and a wet brush picks up a little of the layer below. One stroke is a flat brush dragged along a short arc: the hairs carry different loads, so streaks run along it; the paint runs out as it goes, so the tail breaks into specks where only the tooth of the board catches it; the sides are ragged and the head is rounded. Edges are crisp but wander and break on the tooth. Forms are inflated into a dome (an exact ellipsoid for noses, bobbles and pearls), lit from the upper left, quantised into soft steps and mapped onto five mixed colours, then brushed over with short strokes that follow the form, so the steps meet in brushy seams; core shadows under a brim, a nose or a beard are thin multiply glazes, and cheeks are powdery blush. Knit is modelled stitch by stitch (V-shaped legs with twisted plies, cables twisting in a column, ribbing with sunken purl columns) and multiplied onto the paint, so the large value steps survive. Hair, brows, beards, curls and bobbles are thousands of tapered strands that follow a flow field and are sorted by the light. Felt is mottle, fibres and a fuzzy silhouette. Helpers for goofy faces: round eyes with lids and catchlights (a `look` that can go cross-eyed), big bulbous noses with nostrils and a glint, big ears || **Blue picture book (蓝调绘本)** | `lib/bluebook.py` · `BlueBook` | a page of a soft-blue modern picture book, drawn the way the illustrator works and then printed: colour blocks, a loose ink line, dark masses scribbled in, small accents, chalk whites, weather, print. The palette is held to three blues (powder, cornflower, a deep teal-blue), black ink and paper white, with only a little coral, flesh pink and mustard. Every tool works on one paper tooth, equalised so that "the tool reaches where the tooth is higher than 1 − contact" turns a pressure straight into a coverage fraction, and pre-dragged in eight directions so the bare specks a dry tool skips are drawn out along its stroke. An ink stroke is a brush or ink-pencil line: the path wobbles and trembles, the pressure lands fast, lifts slowly and swells and thins on the way, the hairs carry different loads and run dry along the stroke so the line breaks into dry white streaks, and its edge wanders with the tooth; every pixel knows its arc length and its offset across the mark (Pillow rasterises segment ids, numpy projects exactly). Closed shapes are not closed: a contour is one to three strokes that stop short or run past the join, now and then gone over again a couple of px off. Dark masses are zigzag scribbles that turn past the outline, one wrist-sized patch at a time. Colour is dry crayon, pastel or dry gouache laid loosely after the idea of the shape: the region slips a few px, its edge wanders, its border dries out, it goes on in stroke lanes with a mottled density, and white specks of paper show through; wax is semi-opaque (over white it is the colour, over ink it stays dark, blue over blue goes deeper) and the line always stays on top. The background is a rough-sided block that stops short of the page edge, its border brushed along itself and dragged dry. White chalk sits only on the tooth peaks over the blue; rain is short dry strokes with splashes, ripples, flicked spatter and fine speckle. Character helpers: big round heads drawn open, dot eyes with a white glint, tiny smiles, stippled blush and freckles, and fluffy white animals whose outline is a run of scalloped ink tufts with chalk fur crossing into the blue. The print step adds a slight softness, lifted blacks, paper speck, a centre gutter fold and tiny page numbers |+| **Jiangnan garden (江南园林)** | `lib/jiangnan.py` · `JiangnanGarden` | a lush, finely painted spring garden in the manner of a contemporary digital-gouache illustration, painted back to front the way a landscape painter works: sky, far hills, haze, the trees behind, the buildings, the far bank, the water, things on the water, the foreground, the hanging frame, the seal. Every painting call takes a `far` value that pulls colours toward a pale blue-green haze and flattens their contrast, and haze bands separate the depth planes. The unit of paint is a dab — a pointed leaf, a round petal, a sword blade — and thousands of them are laid at once: Pillow fills every polygon with its own id into a 2× supersampled id map (later ids cover earlier ones), numpy looks the ids up in a colour/alpha table and box-averages back down, so a dab costs well under a microsecond. Trees are sets of clumps, each lit as a dome by one sun from the upper left; a dab takes its colour from a ramp of mixed greens by the light of the clump it sits on, and the tree is built as a gouache painter builds it: a leafy dark underpaint, a mid-dark body, leaves breaking out across the silhouette, small clusters of lit leaves where the light is high, and a few palest dabs on top. Blossom trees are clusters of round petals sorted dark to light over shadowed petals and green leaves, with branches showing through; near branches carry individual five-petal flowers and buds. A weeping willow is a domed crown over hidden boughs with hundreds of hair-thin strands hanging in tresses, darker and bluer behind, lighter and yellower in front. The roof is a real surface S(u, v): concave slope, widening toward the eave, flaring, sharply upturned corners; it is rasterised as a quad mesh and every pixel's (u, v) is recovered by Newton steps, so roll and pan tiles, course lips, tile ends, drip tiles, the soffit with rafter ends, the eave shadow, an openwork ridge with curled ends and hip ridges running up into the flying corners are all shaded analytically. Lattice (grid, lantern frame, cracked ice) is drawn at 3× and lit on its edges; the zigzag bridge, its slabs, piers, posts and pierced panels are projected through a pinhole camera and shaded face by face. The lake mirrors the canvas above the bank line, rippled sideways, blurred vertically, darkened and mixed with the jade body colour toward the viewer; the bridge, a boat and an egret get their own reflections, and lily pads lie foreshortened on the water plane. Dappled leaf shade, a red lantern, a gilded plaque, a tiny worn seal, and a finish of slight softness, a glow around the lights and fine grain complete it |Ask Claude to *"draw it yourself"*, *"paint this with code"*, or *"claude绘图"*, and name a style if you like. Claude then:@@ -334,6 +335,12 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages- flat, round, mid-blue trees are balloons;- rain of one length and one colour is digital rain (use three values and a wide range of lengths).Leave the print step (gutter, page numbers, lifted blacks) for last, and lift only the blacks, or the white paper goes grey.+- **Jiangnan garden**: paint strictly back to front and give every plane its own `far`: the back trees must be bluer, paler and flatter than the buildings, or the picture turns into a sticker sheet. Build foliage from dabs, never from a filled blob with noise on it: a leafy dark underpaint, a body, leaves across the rim, and lit leaves only in small clusters where the clump faces the sun; more, smaller clumps give a broken, living silhouette. A willow is tresses of thin strands with gaps between them — leaves on random sides of the stem, not a herringbone — and its boughs belong under the crown, or they read as umbrella ribs. Blossom needs a dark underpaint made of dabs too (a smooth one shows through as mauve blotches). From an eye 3 m above the water a near balustrade hides the whole deck of a low bridge: keep only the far railing so the slabs and the zigzag read, and check that the faces turned toward the camera are the ones that survive culling. Keep the water's streaks faint (about 1%) or it rains; reflections must mirror what stands above them, softer and darker. Watch for accidental reads:+ - lily pads with a full red rim and a hard inner line are cartoon plates;+ - a lantern-frame window with a large empty centre over paper is a blank sign;+ - a flying egret with one narrow upright wing is a feather;+ - a pale empty band on a far bank is a wall of fog — plant it down to the water.+ Finish with dappled leaf shade on the sunlit walls and a soft glow, and keep the seal tiny.### Roadmap@@ -345,7 +352,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,加上一个小巧的绘图库,内置六十七种画风:| 画风 | 模块 | 为什么看起来像真的 ||---|---|---|@@ -415,6 +422,7 @@ Every style has a complete example: `python3 examples/<name>.py out.png --stages| **钢笔淡彩** | `lib/penwash.py` · `PenWash` | 照速写人的顺序画在冷压水彩小卡上:先针管笔线稿,再松散淡彩,最后把卡片放在桌上拍下来。每张卡是独立的一张纸(窗光照出的纸纹、略不直的切边),不转着画,放下时才带一个小角度。墨线几乎等宽但是手画的:低频手抖加颤动、线宽漂几个百分点、落笔一个小墨点、有的收尾一甩;闭合形状由一到三笔组成,接口停早留缺口或冲过头沿切线出头,方框的角相互出头,偶尔一段描两遍;部件分前后,被前面部件盖住的轮廓线自动断开。淡彩先算「本来要涂的区域」,再像手快那样涂:整块错位 2–5 px(一边出线、另一边在线里留白缝),边缘用游走的阈值重新取、顺着纸纹,干边更深,颗粒沉在纸纹的谷里,淡淡的平刷条纹,浓淡斑驳,腮红和面包烤色湿中湿滴进去,打湿处纸面起皱;小形状错位缩小,鼻子不会变成白圈。不铺满卡片的背景色块绕开人物、留一圈白边;白色水粉高光最后上。墨和颜料都按光密度叠加,相叠变深、混色。带画呆萌小人的部件:大圆眼镜、点点眼、翘头发、简单的手、四肢、手绘边框、地线。照片:带「山纹」年轮和拼接缝的橡木桌、卡片的软阴影和受光的切边、按圆柱打光的针管笔和水笔(透明水杆折射下面的东西)、窗光衰减、暗角和颗粒 || **复古水粉** | `lib/gouache.py` · `GouachePortrait` | 用不透明水粉画复古绘本里的大头像,照水粉画家的顺序从暗到亮、从大到小:画板上先刷一层暖色托底,用赭色起稿;背景先满载铺平,再用半干的笔蘸亮一点、暗一点的同色皴擦;然后平涂大块,用几阶色值塑形,再上质感、五官和干笔高光,最后是印刷书页的颗粒。每一层都不透明(盖住下面),湿笔会带起一点底色。一笔是扁笔沿短弧拖过去:鬃毛含色不同,所以顺着笔有条纹;颜料越拖越少,笔尾只在纸纹凸起上留下断续的丝和点;两侧毛边,落笔处圆头。边缘利落,但会游走、在纸纹上断开。形体先鼓成穹顶(鼻子、绒球、珍珠用精确的椭球),左上方一盏灯,受光分成几个软台阶、映射到五个调出来的颜色,再用顺着形体的短笔一笔笔盖上去,台阶之间是带笔触的接缝;帽檐、鼻子、胡子下面的暗部是一层薄薄的正片叠底,腮红是粉状的。毛衣一针一针地算:V 字两条带捻股的纱线、交替在前的麻花、凹下去的反针罗纹,乘到已有的颜料上,大的明暗不丢。头发、眉毛、胡子、卷发、绒球是成千上万根锥形细线,沿流向场走、按受光分档。毛毡是斑驳、短纤维和毛茸茸的轮廓。呆萌五官:带眼皮和高光的圆眼(`look` 可以对成斗鸡眼)、带鼻孔和亮点的大鼻子、大耳朵 || **蓝调绘本** | `lib/bluebook.py` · `BlueBook` | 一页软蓝色调的现代绘本,照绘本画家的顺序画、再印出来:先上色块,再松松地勾墨线,乱线排出暗部,加一点点睛色,压白粉笔,然后是天气,最后印刷。颜色守在三阶蓝(粉蓝、矢车菊蓝、深青蓝)、黑墨和纸白,只点一点珊瑚红、粉色腮红和芥末黄。所有工具都落在同一张纸纹上:纸纹做过直方图均衡,「工具碰到纸纹高于 1 − 接触压力的地方」就直接等于覆盖率;纸纹还预先沿八个方向拖开,干的工具漏掉的白点会顺着笔拉成短道。一笔墨线是毛笔或墨铅笔:路径带手抖和细颤,落笔快、收笔慢,沿途粗细起伏;几根笔毛含墨不同、越画越干,线会断成顺着笔的干白道,边缘随纸纹游走;每个像素都知道自己在这一笔上的弧长和横向偏移(Pillow 画线段序号,numpy 精确投影)。闭合的形状不闭合:一个轮廓分一到三笔,在接头前停下或冲过接头,偶尔再描一遍、偏开一两 px。暗部是转折冲出轮廓的之字乱线,一次一个手腕的范围。颜色是干蜡笔、粉彩或干水粉,按大概的形状松松地涂:整体错开几 px,边缘游走,靠边处变干,一道道笔道、浓淡斑驳,纸纹白点透出来;蜡是半透明的(白纸上是本色,墨上仍是黑,蓝上加蓝更深),墨线永远在颜色上面。背景是一块毛边、不到纸边的色块,边缘顺着边刷、拖干。白粉笔只挂在纸纹凸起上,压在蓝上;雨是短的干笔,加水花、水纹、甩点和细尘。角色部件:开口的大圆脑袋、带白高光的点点眼、小小的笑、点彩腮红和雀斑,白色毛绒动物的轮廓是一串扇贝形的墨线小弧,白毛越过边缘压在蓝上。印刷一步加轻微柔化、抬黑、细纸点、中缝折痕和小页码 |+| **江南园林** | `lib/jiangnan.py` · `JiangnanGarden` | 一幅繁茂、细腻的园林春景,像当代的数字水粉插画,照风景插画家的顺序从后往前画:天空、远山、雾、屋后的树、建筑、对岸、水、水上的东西、前景、垂挂的画框、印章。每个画法都带 `far`,越远颜色越往淡青绿的雾色靠、对比越低,深度层之间再铺雾带。颜料的单位是一笔:尖叶、圆花瓣、剑形叶;成千上万笔一次画完:Pillow 把每个多边形按序号填进 2 倍超采样的 id 图(后画的盖住先画的),numpy 按 id 查颜色和透明度再缩回来,一笔不到 1 微秒。树是一组团块,每块当成被左上方太阳照亮的穹顶;每一笔按它所在团块的光从一条混好的绿色色阶取色,整棵树照水粉画家的画法堆出来:叶片打的暗底、中暗的叶、穿出轮廓的叶、光强处一簇簇亮叶、顶上几笔最亮的。繁花树是一簇簇圆花瓣按明暗排序压在暗花瓣和绿叶上,枝条从缝里露出来;近处花枝是一朵朵五瓣花和花苞。垂柳是盖住枝的垂叶树冠,加几百根发丝细的柳丝一绺一绺垂下,后排暗、偏蓝,前排亮、偏黄。屋顶是一张真的曲面 S(u, v):上陡下缓、越往下越宽、翼角外甩、檐角急翘;曲面拆成网格画进 id 图,每个像素用牛顿迭代反求 (u, v),于是筒瓦板瓦、瓦口亮边、瓦当滴水、椽头和檐底、檐影、镂空花脊和卷起的脊头、一直通到翼角尖的戗脊都按解析式上色。槅扇(方格、灯笼锦、冰裂纹)在 3 倍图上画、棂条边上有明暗;九曲桥的石板、桥墩、望柱和镂空栏板经针孔相机投影、逐面上色。湖面按岸线镜像岸上的画面,横向被细浪推开、竖向模糊、压暗,越往近处越多地混进碧绿的本色;桥、船和白鹭各有自己的倒影,睡莲叶按透视压扁躺在水面上。再加墙上桥上的叶影、红灯笼、描金匾额、一方磨损的小红印,最后轻微柔化、亮部光晕和细颗粒 |对 Claude 说「claude绘图」「你自己画」「用代码画」,也可以指定画风。它会:1. **先定构图**:层次、焦点、留白,而且画面要图解内容本身;@@ -510,6 +518,7 @@ python3 examples/shadowpuppet_cuju.py out.jpg --stages stages/ # 皮影戏:python3 examples/penwash_neighbours.py out.jpg --stages stages/ # 钢笔淡彩:街角速写python3 examples/gouache_rainy_day.py out.jpg --stages stages/ # 复古水粉:雨天三人像python3 examples/bluebook_shared_umbrella.py out.jpg --stages stages/ # 蓝调绘本:借伞+python3 examples/jiangnan_spring_water.py out.jpg --stages stages/ # 江南园林:春水园林```### 作画要点(Claude 交图前逐条自查)@@ -589,6 +598,12 @@ python3 examples/bluebook_shared_umbrella.py out.jpg --stages stages/ # 蓝调- 平涂的圆形中蓝远树像气球;- 一样长、一样颜色的雨是数码雨(用三种深浅,长短拉开)。印刷(中缝、页码、抬黑)放到最后,而且只抬黑,否则白纸会变灰。+- **江南园林**:严格从后往前画,每一层给自己的 `far`:屋后的树要比建筑更蓝、更淡、更平,不然整幅画像一张贴纸。树冠只能用笔触堆,不要平涂一团再撒噪点:叶片打的暗底、满冠的叶、穿出轮廓的叶,亮叶只在团块朝阳的地方一小簇一小簇地落;团块多一点、小一点,轮廓才碎、才活。垂柳是一绺一绺的细柳丝,绺间留缝,叶子随机挂在茎的两侧、不要人字纹;枝要压在树冠下面,露出来就成了伞骨。繁花的暗底也要用笔触,平涂的暗底会从花缝里透出一块块紫褐色。眼高 3 m 时,近侧栏杆会挡住低平曲桥的整个桥面:只留远侧栏杆,石板和折线才读得出来,并确认朝向镜头的面没有被剔掉。水面的竖纹要很淡(1% 左右),不然像下雨;倒影要对得上岸上的东西,只是更柔、更暗。小心看错:+ - 一圈红边、一道硬内线的睡莲叶是卡通盘子;+ - 灯笼锦窗中间留一大块空框、底下是窗纸,就成了空白牌子;+ - 只有一只窄而竖的翅膀的飞鹭是一根羽毛;+ - 对岸一条发白的空带是一堵雾墙,要种满到水边。+ 最后在受光的墙上加叶影、整体加一点光晕,印章要小。### 计划diff --git a/SKILL.md b/SKILL.mdindex 0f36b40..a3a74f6 100644--- a/SKILL.md+++ b/SKILL.md@@ -1,6 +1,6 @@---name: claude绘图-description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型,由 Claude 用代码一笔一笔「画」出图片(程序化绘画)。内置六十六种画风:中国水墨、水彩、剪纸拼贴、韩国彩铅、日本动漫、编辑风手绘(Riso)、油画厚涂(梵高式流向笔触+颜料浮雕打光)、浮世绘木版画(晕色、木纹、墨线主版、青海波)、像素风(低分辨率+Bayer 抖动+像素字体)、黏土定格(高度图捏出的彩泥+影棚打光)、蓝晒(普鲁士蓝日光晒图,植物剪影透光)、十字绣(Aida 布十字绣+回针绣+缎面绣+法式结)、复古仪器面板(60 年代收音机/仪器正面:柚木、拉丝铝、旋钮、刻度窗、指示灯)、贴纸拼贴·小票(模切乙烯贴纸、热敏小票、和纸胶带、吊牌、橡皮章)、实验笔记本·贴纸(线圈方格本、铅笔图表、荧光笔、红笔圈、便利贴)、黑板板书(墨绿石板、粉笔颗粒、板擦残影、示意图与公式)、赛博朋克(雨夜霓虹街道、玻璃管霓虹招牌、全息广告、湿路面倒影)、卡通手绘(蓝铅笔稿、毛笔线、错位平涂、赛璐璐阴影、逐帧抖线)、等轴 2.5D(正等轴微缩模型、一个太阳照出三面明暗、悬浮数据卡)、单线画(一根不断开的线一笔画完、唯一点睛色)、柔光 3D(光线追踪的糖果色小球海和鼓鼓的软字、景深)、形变动画(一条轮廓依次变形、洋葱皮残影、缓动曲线)、报刊拼贴(牛皮纸、手撕旧报纸、网点老照片、勒索信拼贴字)、弥散玻璃(弥散渐变、磨砂玻璃卡片界面)、包豪斯几何(三原色几何、丝网印刷海报)、复古 Synthwave(切口落日、霓虹网格、镀铬字、录像带质感)、拼豆(钉板上的熔珠小管、熨烫熔合)、岩画(沙漠漆上凿出的凹坑图形、新旧凿痕、剥落)、古埃及墓室壁画(灰泥墙、红格起稿、分栏叙事、象形文字、剥落)、罗马马赛克(石子与玻璃沿轮廓一排排铺、灰缝、燕尾铭牌)、彩色玻璃花窗(哥特尖拱窗、通体着色玻璃、grisaille 彩绘与银染、铅条、透光)、泥金手抄本(羊皮纸、鹅毛笔哥特体、朱红标题、打磨金箔首字母)、达·芬奇手稿(铁胆墨水、左手排线、红粉笔、镜像手写、机械分解图)、剪影(黑纸剪出的侧影小像、薄金粉、椭圆金框)、凸版印刷海报(木活字、红黑双色错版、木刻插图)、苏联构成主义(红黑两版、斜条与楔形、西里尔大字、网点照片拼贴)、装饰艺术 Art Deco(1930 年代喷枪流线型海报、交替射线、阶梯高楼、金色 Deco 字)、黄金时代漫画(毛笔墨线、Ben-Day 网点、四色错版、新闻纸)、波普丝网(多格撞色平涂 + 错位的照相黑版)、ASCII 字符画(行式打印机、绿条连续纸、叠打)、低多边形(1999 年代 3D:平面着色、仿射贴图、逐顶点雾、15 位色抖动)、喷漆模板涂鸦(混凝土墙上多层卡纸模板喷绘、雾化与滴痕)、刺绣徽章(牛仔布上的机绣徽章:填充绣、缎面绣、锁边)、蓝图工程图(描图墨线晒成蓝底白线)、儿童蜡笔画(小孩在糙纸上的蜡笔涂抹)、绿屏终端 CRT(荧光字符画、扫描线、余辉)、热成像(先画温度场再上伪彩色)、代尔夫特蓝瓷砖(锡釉砖上的钴蓝手绘)、洞穴壁画(火光下的赭石、吹喷手印)、1-bit 早期画图软件(黑白整屏、8×8 图案填充)、古希腊黑绘陶瓶(黑釉剪影、刻线、饰带展开图)、铅笔素描(石墨排线、擦笔、边缘只剩线稿)、X 光片(安检透视、轮廓发亮、伪彩)、1930 年代黑白橡皮管动画(白手套、饼切眼、老胶片)、黑白麻胶版画(刻刀减法、手拓发花、套色错版)、VHS 家庭录像(钨丝灯偏色、色度渗色、REC)、扁平矢量(分层几何色块、七色、层间投影)、绘本角色动画(小角色挤压拉伸的真动画)、圆珠笔涂鸦(蓝红圆珠笔线稿、墨团、彩铅、页边涂鸦)、描图纸叠层(灯箱上的黑线底图 + 一张张单色描图纸叠片:正片叠底、套准十字、定位钉、绘图胶带)、粉彩界面 · Pastel UI(产品发布片式的界面画面:纯色粉彩底与大光斑、macOS 窗口卡片、胶囊与粗黑标题色条、状态标签与 ✓ / ✗ 徽章、放大镜、从卡片边探头的扁平小图标)、阅卷批改 · Exam Grading(绿毛毡桌上被红笔批改的答题卡:定位黑块、考号涂卡、得分格与阅卷栏、长尾夹夹住的标准答案卡、油墨不均的朱红印章、立体红笔、波浪线 / 圈 / 引线 / 批注 / 叉 / 圈起来的分数)、皮影戏 · Shadow Puppetry(油灯照亮的幕布上,雕空、透明染色的驴皮关节人偶:镂空纹样、阳刻空脸、雉翎盔头、线结与操纵杆、离幕时虚化的双影;雕花戏台、红漆金字牌匾、红灯笼)、钢笔淡彩 · Pen & Wash(速写小卡上的针管笔线稿 + 松散淡彩:线条抖、出头、不闭合,颜色错位出线、留白缝、干边与颗粒,不铺满的背景色块;大头、圆眼镜、点点眼、红鼻子的呆萌小人;卡片拍在木桌上,旁边放着针管笔和水笔)、复古水粉 · Retro Gouache(复古绘本风的水粉大头像:不透明水粉从暗到亮一层层盖上去,单色背景用干笔皴擦;大红鼻子、腮红、圆眼和大耳朵用几阶色值塑出来;看得见针脚的毛衣和毛线帽,一根根的头发和胡子,毛毡;最后是印刷书页的纸纹)、蓝调绘本 · Blue Picture Book(软蓝色调的现代绘本跨页:几乎只用粉蓝、矢车菊蓝、深青蓝三阶蓝加黑墨和纸白,只点一点珊瑚红、粉色腮红和芥末黄;毛笔 / 墨铅笔线干、抖、断,粗细不匀,线不闭合,暗部用快速来回的乱线排出来;颜色是干蜡笔、粉彩、干水粉,错位出线,纸纹的白点透出来;白粉笔痕压在蓝上,甩点和细尘;背景蓝块毛边、不到纸边;大圆脑袋、带高光的点点眼、点彩腮红和雀斑、火柴腿穿靴子的小人,乱线毛边的白色毛绒动物;最后印在书上:中缝和页码)。用户说「claude绘图」「用代码画」「你自己画」「不用生图模型画」「程序化绘画」,或点名以上任一画风(含黏土、彩泥、定格动画、蓝晒、晒图、十字绣、刺绣、复古面板、老式收音机、贴纸、小票、收据、手帐拼贴、实验笔记本、方格本、荧光笔、便利贴、黑板、板书、粉笔、赛博朋克、霓虹、雨夜街道、卡通、手绘卡通、逐帧手绘、抖线、等轴、2.5D、微缩模型、单线画、一笔画、线条动画、柔光 3D、3D 渲染、C4D 风、软糖字、小球海、形变、变形动画、报刊拼贴、剪报、达达、勒索信字、网点印刷、弥散渐变、玻璃拟态、毛玻璃、包豪斯、几何构成、丝网印刷、Synthwave、蒸汽波、合成器浪潮、80 年代复古、拼豆、拼拼豆、熔珠、熨豆、豆豆画、钉板、烫豆、岩画、岩刻、凿刻、石刻、沙漠漆、史前壁刻、大角羊、古埃及、埃及壁画、墓室壁画、法老时代、象形文字、尼罗河、底比斯、罗马马赛克、马赛克镶嵌、镶嵌画、石子拼画、地砖画、古罗马地板、彩色玻璃、彩绘玻璃、花窗、玻璃花窗、教堂花窗、哥特花窗、铅条玻璃、泥金手抄本、手抄本、彩饰手抄本、中世纪手稿、羊皮纸、哥特体、花体首字母、泥金、贴金、星盘、达芬奇、达·芬奇、达芬奇手稿、手稿风、文艺复兴手稿、发明手稿、镜像字、镜像书写、扑翼机、红粉笔、钢笔排线、机械草图、分解图、剪影、剪影肖像、侧影、侧面像、黑纸剪影、剪影小像、椭圆金框、乔治时代肖像、摄政时期肖像、凸版印刷、活版印刷、木活字、铅字海报、马戏团海报、复古海报、老海报、19 世纪海报、双色套印、错版、套色错位、木刻插图、构成主义、苏联海报、苏联构成主义、俄国先锋派、罗德琴科风、红黑海报、照片蒙太奇、照片拼贴海报、西里尔字、装饰艺术、装饰风、流线型、流线型海报、1930 年代海报、旅行海报、铁路海报、火车海报、喷枪画、喷笔画、阶梯高楼、射线背景、盖茨比风、黄金时代漫画、老漫画、复古漫画、美漫封面、漫画封面、Ben-Day 网点、本戴点、网点上色、四色印刷、四色错版、新闻纸、对白框、拟声字、1940 年代漫画、波普、波普艺术、波普丝网、沃霍尔风、丝网版画头像、撞色头像、多格重复头像、六宫格撞色头像、ASCII、字符画、字符艺术、文字画、行式打印机、绿条纸、连续打印纸、针孔打印纸、老电脑打印、叠打、低多边形、低面数、低模、多边形风、千禧年 3D、90 年代 3D、复古 3D 游戏、老游戏截图、PS1 风、N64 风、平面着色、线框、游戏 HUD、飞行游戏、穿环、喷漆、模板涂鸦、镂空模板、喷漆模板、模板喷绘、街头涂鸦、街头艺术、墙绘、滴漆、班克西风格、刺绣徽章、徽章、布章、臂章、刺绣贴、绣标、锁边、牛仔外套徽章、户外徽章、营地徽章、弧形条章、蓝图、工程图、施工图、蜡笔画、儿童画、绿屏终端、CRT、显像管、热成像、热像仪、温度图、代尔夫特、荷兰蓝瓷砖、洞穴壁画、史前壁画、赭石、1-bit、黑白画图软件、MacPaint 风、黑绘、古希腊陶瓶、希腊瓶画、铅笔素描、素描、铅笔画、X 光、X 光片、安检图像、橡皮管动画、黑白卡通、老动画、麻胶版画、黑白版画、藏书票、VHS、家庭录像、录像带、扁平插画、扁平风、矢量插画、绘本动画、角色动画、挤压拉伸、圆珠笔、圆珠笔涂鸦、原子笔、页边涂鸦、课本涂鸦、手画棋盘、描图纸、硫酸纸、叠片、叠层、分色片、灯箱、拷贝台、透光台、套准、定位钉、粉彩界面、粉彩 UI、Dot 风、Dot 那种风格、产品发布会界面、发布会质感、窗口卡片、macOS 窗口、界面卡片、讲解片界面页、小图标探头、阅卷、阅卷批改、批改、判卷、改卷、改作业、答题卡、试卷、考卷、测验卷、红笔批改、红笔打分、打分数、盖章批改、朱红印章、标准答案卡、长尾夹、讲解片评测 / 打分页、皮影、皮影戏、影子戏、驴皮影、灯影戏、皮影人偶、雕花戏台、戏台牌匾、亮相、钢笔淡彩、淡彩、淡彩速写、钢笔淡彩小人、针管笔、勾线笔、针管笔加水彩、线稿上色、速写卡片、速写本小人、水彩小卡、城市速写、街头速写、水笔、自来水笔、复古水粉、水粉、水粉画、不透明水粉、哑光丙烯、复古绘本、绘本插画、绘本大头像、童书插画、复古童书、大头像、大鼻子人物、针织毛衣、麻花毛衣、毛线帽、毛毡帽、卷发、胡子、蓝调绘本、蓝色绘本、软蓝绘本、蓝调童书、软蓝童书插画、蓝色童书插画、蓝色系绘本、限色绘本、蓝白绘本、现代绘本跨页、手绘绘本跨页、绘本跨页、绘本内页、干笔墨线、墨铅笔线、粉彩蜡笔质感绘本、白色毛绒动物、毛绒白熊、点彩腮红),或 "draw it yourself", "paint with code", "procedural painting", "watercolor / collage / colored pencil / anime / editorial / impasto oil / ukiyo-e / pixel art / clay / claymation / cyanotype / sun print / cross-stitch / embroidery / retro instrument panel / vintage radio / sticker collage / receipt / lab notebook / graph paper / chalkboard / blackboard / cyberpunk / neon city / cartoon / hand-drawn animation / isometric / 2.5D / continuous line / one-line drawing / soft 3D / 3D render / puffy letters / ball pit / shape morph / morphing / newspaper collage / Dada / ransom note / halftone / glassmorphism / aurora gradient / Bauhaus / geometric poster / screen print / synthwave / retrowave / outrun / perler beads / hama beads / artkal / fuse beads / melty beads / pegboard beads / petroglyph / rock art / rock carving / desert varnish / Egyptian tomb painting / ancient Egypt / hieroglyphs / Theban tomb / Roman mosaic / floor mosaic / tesserae / opus vermiculatum / Pompeii mosaic / stained glass / leaded glass / church window / Gothic window / grisaille / illuminated manuscript / medieval manuscript / book of hours / gold leaf / illuminated initial / blackletter / vellum / astrolabe / da Vinci notebook / Leonardo codex / Renaissance sketchbook / mirror writing / iron-gall ink / red chalk / sanguine / ornithopter / exploded view / inventor's sketch / silhouette / silhouette portrait / cut-paper profile / shade portrait / Georgian portrait / Regency portrait / oval gilt frame / letterpress / wood type / playbill / circus poster / Victorian poster / two-colour misregistration / woodcut poster / constructivism / constructivist poster / Soviet avant-garde / Russian avant-garde / Rodchenko style / photomontage poster / art deco / streamline moderne / 1930s travel poster / railway poster / airbrush poster / sunburst rays / Gatsby style / golden age comic / vintage comic book / comic cover / Ben-Day dots / four-color printing / newsprint / speech balloon / pulp cover / pop art / Warhol-style / pop silkscreen / silkscreen portrait / repeated pop portrait grid / ASCII art / text art / typewriter art / line printer / greenbar / fanfold paper / tractor feed / overstrike / printer plot / low poly / low-poly / retro 3D / 90s 3D game / PS1 style / N64 style / software rasterizer / flat shading / affine texture mapping / vertex fog / game HUD / stencil / stencil graffiti / spray paint stencil / street art / drips and overspray / Banksy-style stencil / embroidered patch / embroidery patch / iron-on patch / sew-on patch / merit badge / camp badge / merrow border / rocker patch / denim jacket patches / blueprint / technical drawing / crayon / kid's drawing / CRT terminal / green screen / thermal camera / thermal imaging / Delft tiles / Delft blue / cave painting / ochre / Lascaux-style / 1-bit / MacPaint-style / black-figure / Greek vase / pencil drawing / graphite / X-ray / baggage scanner / rubber hose / 1930s cartoon / linocut / lino print / VHS / home video / flat vector / flat illustration / storybook animation / squash and stretch / ballpoint / biro / ballpoint doodle / margin doodles / hand-drawn board game / overlay sheets / tracing-paper overlays / light box / colour separations / registration marks / acetate overlay / pastel UI / Dot-style product film / launch-film interface / macOS window cards / exam grading / grading an answer sheet / red-pen marking / graded test paper / rubber-stamped answer sheet / shadow puppet / shadow puppetry / Chinese shadow play / leather shadow puppets / backlit puppet screen / pen and wash / pen & wash / line and wash / ink and watercolour / ink and watercolor / fineliner sketch / fineliner and watercolour / sketchbook characters / sketch cards / urban sketching / water brush / gouache / retro gouache / gouache portrait / gouache illustration / opaque gouache / matte acrylic / picture-book portrait / vintage picture book / retro children's book illustration / mid-century children's book / big-nosed character portrait / cable-knit sweater / knitted bobble hat / blue picture book / soft blue picture book / soft-blue children's book illustration / modern picture book / limited-palette picture book / picture-book spread / scratchy ink line / dry-brush ink line / ink pencil line / crayon and pastel texture / chalky white marks / blue and coral palette / fluffy white bear without an image model" 时使用;也用于需要逐步画出(draw-on)动画的插画。单独说「剪纸」指剪纸拼贴、「刺绣」指十字绣、「丝网印刷 / screen print」指包豪斯几何;「打马赛克」是打码,不是马赛克画风;单说「蓝图」指蓝图工程图,「蓝晒 / 晒图」仍指蓝晒;「铅笔 / 素描」指铅笔素描,「彩铅」指韩国彩铅;「像素」仍指像素风,「1-bit / 黑白画图软件」指 1-bit 早期画图软件;「霓虹」仍指赛博朋克;「喷漆 / 街头涂鸦」仍指喷漆模板涂鸦,「圆珠笔 / 随手涂鸦 / 页边涂鸦」指圆珠笔涂鸦;「描图纸 / 硫酸纸 / 叠片 / 灯箱」指描图纸叠层(蓝图工程图那张描图布是晒成蓝图的,不是叠片);「Dot 风 / 粉彩界面 / 窗口卡片 / 发布会界面」指粉彩界面(纯色底 + 白色实心窗口卡片),要磨砂玻璃和弥散渐变仍用弥散玻璃;「阅卷 / 批改 / 答题卡 / 判卷 / 红笔打分」指阅卷批改,实验记录里的红笔圈和便利贴仍用实验笔记本,带「已付」橡皮章的小票拼贴仍用贴纸拼贴 · 小票;「皮影 / 皮影戏 / 影子戏」指皮影戏(透光的彩色驴皮人偶),黑纸剪出的侧影小像仍用剪影,彩纸剪贴仍用剪纸拼贴。「钢笔淡彩 / 淡彩速写 / 针管笔加水彩 / 线稿上色的速写小卡」指钢笔淡彩;单说「水彩」仍指水彩(风景、花卉的大片晕染),蓝铅笔稿 + 毛笔线 + 赛璐璐阴影的拟人小物仍用卡通手绘,「素描 / 铅笔」仍指铅笔素描。「水粉 / 复古水粉 / 绘本大头像 / 复古童书插画」指复古水粉(不透明水粉画的特写大头像);梵高式厚涂的风景、名画感仍用油画厚涂,扁平矢量、会挤压拉伸的小角色动画(「绘本动画」)仍用绘本角色动画,针管笔线稿加淡彩的速写小卡仍用钢笔淡彩,撞色多格的头像仍用波普丝网。「蓝调绘本 / 软蓝绘本 / 蓝色童书插画 / 绘本跨页」指蓝调绘本(软蓝限色的现代绘本跨页:干笔墨线 + 干蜡笔粉彩上色 + 白粉笔痕);单说「绘本」仍指绘本角色动画,「水粉 / 绘本大头像」仍指复古水粉,「编辑风 / Riso」仍指编辑风手绘,针管笔线稿加淡彩的速写小卡仍用钢笔淡彩,小孩自己画的蜡笔画仍用儿童蜡笔画。+description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型,由 Claude 用代码一笔一笔「画」出图片(程序化绘画)。内置六十七种画风:中国水墨、水彩、剪纸拼贴、韩国彩铅、日本动漫、编辑风手绘(Riso)、油画厚涂(梵高式流向笔触+颜料浮雕打光)、浮世绘木版画(晕色、木纹、墨线主版、青海波)、像素风(低分辨率+Bayer 抖动+像素字体)、黏土定格(高度图捏出的彩泥+影棚打光)、蓝晒(普鲁士蓝日光晒图,植物剪影透光)、十字绣(Aida 布十字绣+回针绣+缎面绣+法式结)、复古仪器面板(60 年代收音机/仪器正面:柚木、拉丝铝、旋钮、刻度窗、指示灯)、贴纸拼贴·小票(模切乙烯贴纸、热敏小票、和纸胶带、吊牌、橡皮章)、实验笔记本·贴纸(线圈方格本、铅笔图表、荧光笔、红笔圈、便利贴)、黑板板书(墨绿石板、粉笔颗粒、板擦残影、示意图与公式)、赛博朋克(雨夜霓虹街道、玻璃管霓虹招牌、全息广告、湿路面倒影)、卡通手绘(蓝铅笔稿、毛笔线、错位平涂、赛璐璐阴影、逐帧抖线)、等轴 2.5D(正等轴微缩模型、一个太阳照出三面明暗、悬浮数据卡)、单线画(一根不断开的线一笔画完、唯一点睛色)、柔光 3D(光线追踪的糖果色小球海和鼓鼓的软字、景深)、形变动画(一条轮廓依次变形、洋葱皮残影、缓动曲线)、报刊拼贴(牛皮纸、手撕旧报纸、网点老照片、勒索信拼贴字)、弥散玻璃(弥散渐变、磨砂玻璃卡片界面)、包豪斯几何(三原色几何、丝网印刷海报)、复古 Synthwave(切口落日、霓虹网格、镀铬字、录像带质感)、拼豆(钉板上的熔珠小管、熨烫熔合)、岩画(沙漠漆上凿出的凹坑图形、新旧凿痕、剥落)、古埃及墓室壁画(灰泥墙、红格起稿、分栏叙事、象形文字、剥落)、罗马马赛克(石子与玻璃沿轮廓一排排铺、灰缝、燕尾铭牌)、彩色玻璃花窗(哥特尖拱窗、通体着色玻璃、grisaille 彩绘与银染、铅条、透光)、泥金手抄本(羊皮纸、鹅毛笔哥特体、朱红标题、打磨金箔首字母)、达·芬奇手稿(铁胆墨水、左手排线、红粉笔、镜像手写、机械分解图)、剪影(黑纸剪出的侧影小像、薄金粉、椭圆金框)、凸版印刷海报(木活字、红黑双色错版、木刻插图)、苏联构成主义(红黑两版、斜条与楔形、西里尔大字、网点照片拼贴)、装饰艺术 Art Deco(1930 年代喷枪流线型海报、交替射线、阶梯高楼、金色 Deco 字)、黄金时代漫画(毛笔墨线、Ben-Day 网点、四色错版、新闻纸)、波普丝网(多格撞色平涂 + 错位的照相黑版)、ASCII 字符画(行式打印机、绿条连续纸、叠打)、低多边形(1999 年代 3D:平面着色、仿射贴图、逐顶点雾、15 位色抖动)、喷漆模板涂鸦(混凝土墙上多层卡纸模板喷绘、雾化与滴痕)、刺绣徽章(牛仔布上的机绣徽章:填充绣、缎面绣、锁边)、蓝图工程图(描图墨线晒成蓝底白线)、儿童蜡笔画(小孩在糙纸上的蜡笔涂抹)、绿屏终端 CRT(荧光字符画、扫描线、余辉)、热成像(先画温度场再上伪彩色)、代尔夫特蓝瓷砖(锡釉砖上的钴蓝手绘)、洞穴壁画(火光下的赭石、吹喷手印)、1-bit 早期画图软件(黑白整屏、8×8 图案填充)、古希腊黑绘陶瓶(黑釉剪影、刻线、饰带展开图)、铅笔素描(石墨排线、擦笔、边缘只剩线稿)、X 光片(安检透视、轮廓发亮、伪彩)、1930 年代黑白橡皮管动画(白手套、饼切眼、老胶片)、黑白麻胶版画(刻刀减法、手拓发花、套色错版)、VHS 家庭录像(钨丝灯偏色、色度渗色、REC)、扁平矢量(分层几何色块、七色、层间投影)、绘本角色动画(小角色挤压拉伸的真动画)、圆珠笔涂鸦(蓝红圆珠笔线稿、墨团、彩铅、页边涂鸦)、描图纸叠层(灯箱上的黑线底图 + 一张张单色描图纸叠片:正片叠底、套准十字、定位钉、绘图胶带)、粉彩界面 · Pastel UI(产品发布片式的界面画面:纯色粉彩底与大光斑、macOS 窗口卡片、胶囊与粗黑标题色条、状态标签与 ✓ / ✗ 徽章、放大镜、从卡片边探头的扁平小图标)、阅卷批改 · Exam Grading(绿毛毡桌上被红笔批改的答题卡:定位黑块、考号涂卡、得分格与阅卷栏、长尾夹夹住的标准答案卡、油墨不均的朱红印章、立体红笔、波浪线 / 圈 / 引线 / 批注 / 叉 / 圈起来的分数)、皮影戏 · Shadow Puppetry(油灯照亮的幕布上,雕空、透明染色的驴皮关节人偶:镂空纹样、阳刻空脸、雉翎盔头、线结与操纵杆、离幕时虚化的双影;雕花戏台、红漆金字牌匾、红灯笼)、钢笔淡彩 · Pen & Wash(速写小卡上的针管笔线稿 + 松散淡彩:线条抖、出头、不闭合,颜色错位出线、留白缝、干边与颗粒,不铺满的背景色块;大头、圆眼镜、点点眼、红鼻子的呆萌小人;卡片拍在木桌上,旁边放着针管笔和水笔)、复古水粉 · Retro Gouache(复古绘本风的水粉大头像:不透明水粉从暗到亮一层层盖上去,单色背景用干笔皴擦;大红鼻子、腮红、圆眼和大耳朵用几阶色值塑出来;看得见针脚的毛衣和毛线帽,一根根的头发和胡子,毛毡;最后是印刷书页的纸纹)、蓝调绘本 · Blue Picture Book(软蓝色调的现代绘本跨页:几乎只用粉蓝、矢车菊蓝、深青蓝三阶蓝加黑墨和纸白,只点一点珊瑚红、粉色腮红和芥末黄;毛笔 / 墨铅笔线干、抖、断,粗细不匀,线不闭合,暗部用快速来回的乱线排出来;颜色是干蜡笔、粉彩、干水粉,错位出线,纸纹的白点透出来;白粉笔痕压在蓝上,甩点和细尘;背景蓝块毛边、不到纸边;大圆脑袋、带高光的点点眼、点彩腮红和雀斑、火柴腿穿靴子的小人,乱线毛边的白色毛绒动物;最后印在书上:中缝和页码)、江南园林 · Jiangnan Garden(细笔园林春景,数字水粉插画:成千上万片叶形小笔触按一个太阳堆出树冠,暗芯、亮边、一簇簇的高光;白色和淡粉的繁花是一簇簇圆点花瓣,枝条从缝里露出来;垂柳是一绺一绺发丝般的细枝挂满小叶;黛瓦飞檐是真的瓦垄:筒瓦板瓦一行行、檐口瓦当滴水、翘起的翼角和卷起的脊头;粉墙月洞门、冰裂纹漏窗、翡翠绿槅扇和挂落、红灯笼、匾额;九曲石桥、石阶、小木船;碧绿湖面倒映岸上的一切,更柔、更暗,加涟漪和细竖纹;睡莲、白鹭;从前景花枝到雾里青山层层退远,墙上桥上落着叶影;最后一方小红印)。用户说「claude绘图」「用代码画」「你自己画」「不用生图模型画」「程序化绘画」,或点名以上任一画风(含黏土、彩泥、定格动画、蓝晒、晒图、十字绣、刺绣、复古面板、老式收音机、贴纸、小票、收据、手帐拼贴、实验笔记本、方格本、荧光笔、便利贴、黑板、板书、粉笔、赛博朋克、霓虹、雨夜街道、卡通、手绘卡通、逐帧手绘、抖线、等轴、2.5D、微缩模型、单线画、一笔画、线条动画、柔光 3D、3D 渲染、C4D 风、软糖字、小球海、形变、变形动画、报刊拼贴、剪报、达达、勒索信字、网点印刷、弥散渐变、玻璃拟态、毛玻璃、包豪斯、几何构成、丝网印刷、Synthwave、蒸汽波、合成器浪潮、80 年代复古、拼豆、拼拼豆、熔珠、熨豆、豆豆画、钉板、烫豆、岩画、岩刻、凿刻、石刻、沙漠漆、史前壁刻、大角羊、古埃及、埃及壁画、墓室壁画、法老时代、象形文字、尼罗河、底比斯、罗马马赛克、马赛克镶嵌、镶嵌画、石子拼画、地砖画、古罗马地板、彩色玻璃、彩绘玻璃、花窗、玻璃花窗、教堂花窗、哥特花窗、铅条玻璃、泥金手抄本、手抄本、彩饰手抄本、中世纪手稿、羊皮纸、哥特体、花体首字母、泥金、贴金、星盘、达芬奇、达·芬奇、达芬奇手稿、手稿风、文艺复兴手稿、发明手稿、镜像字、镜像书写、扑翼机、红粉笔、钢笔排线、机械草图、分解图、剪影、剪影肖像、侧影、侧面像、黑纸剪影、剪影小像、椭圆金框、乔治时代肖像、摄政时期肖像、凸版印刷、活版印刷、木活字、铅字海报、马戏团海报、复古海报、老海报、19 世纪海报、双色套印、错版、套色错位、木刻插图、构成主义、苏联海报、苏联构成主义、俄国先锋派、罗德琴科风、红黑海报、照片蒙太奇、照片拼贴海报、西里尔字、装饰艺术、装饰风、流线型、流线型海报、1930 年代海报、旅行海报、铁路海报、火车海报、喷枪画、喷笔画、阶梯高楼、射线背景、盖茨比风、黄金时代漫画、老漫画、复古漫画、美漫封面、漫画封面、Ben-Day 网点、本戴点、网点上色、四色印刷、四色错版、新闻纸、对白框、拟声字、1940 年代漫画、波普、波普艺术、波普丝网、沃霍尔风、丝网版画头像、撞色头像、多格重复头像、六宫格撞色头像、ASCII、字符画、字符艺术、文字画、行式打印机、绿条纸、连续打印纸、针孔打印纸、老电脑打印、叠打、低多边形、低面数、低模、多边形风、千禧年 3D、90 年代 3D、复古 3D 游戏、老游戏截图、PS1 风、N64 风、平面着色、线框、游戏 HUD、飞行游戏、穿环、喷漆、模板涂鸦、镂空模板、喷漆模板、模板喷绘、街头涂鸦、街头艺术、墙绘、滴漆、班克西风格、刺绣徽章、徽章、布章、臂章、刺绣贴、绣标、锁边、牛仔外套徽章、户外徽章、营地徽章、弧形条章、蓝图、工程图、施工图、蜡笔画、儿童画、绿屏终端、CRT、显像管、热成像、热像仪、温度图、代尔夫特、荷兰蓝瓷砖、洞穴壁画、史前壁画、赭石、1-bit、黑白画图软件、MacPaint 风、黑绘、古希腊陶瓶、希腊瓶画、铅笔素描、素描、铅笔画、X 光、X 光片、安检图像、橡皮管动画、黑白卡通、老动画、麻胶版画、黑白版画、藏书票、VHS、家庭录像、录像带、扁平插画、扁平风、矢量插画、绘本动画、角色动画、挤压拉伸、圆珠笔、圆珠笔涂鸦、原子笔、页边涂鸦、课本涂鸦、手画棋盘、描图纸、硫酸纸、叠片、叠层、分色片、灯箱、拷贝台、透光台、套准、定位钉、粉彩界面、粉彩 UI、Dot 风、Dot 那种风格、产品发布会界面、发布会质感、窗口卡片、macOS 窗口、界面卡片、讲解片界面页、小图标探头、阅卷、阅卷批改、批改、判卷、改卷、改作业、答题卡、试卷、考卷、测验卷、红笔批改、红笔打分、打分数、盖章批改、朱红印章、标准答案卡、长尾夹、讲解片评测 / 打分页、皮影、皮影戏、影子戏、驴皮影、灯影戏、皮影人偶、雕花戏台、戏台牌匾、亮相、钢笔淡彩、淡彩、淡彩速写、钢笔淡彩小人、针管笔、勾线笔、针管笔加水彩、线稿上色、速写卡片、速写本小人、水彩小卡、城市速写、街头速写、水笔、自来水笔、复古水粉、水粉、水粉画、不透明水粉、哑光丙烯、复古绘本、绘本插画、绘本大头像、童书插画、复古童书、大头像、大鼻子人物、针织毛衣、麻花毛衣、毛线帽、毛毡帽、卷发、胡子、蓝调绘本、蓝色绘本、软蓝绘本、蓝调童书、软蓝童书插画、蓝色童书插画、蓝色系绘本、限色绘本、蓝白绘本、现代绘本跨页、手绘绘本跨页、绘本跨页、绘本内页、干笔墨线、墨铅笔线、粉彩蜡笔质感绘本、白色毛绒动物、毛绒白熊、点彩腮红、江南园林、园林春景、春水园林、中式园林插画、古典园林插画、国风园林插画、苏式园林、细笔园林、园林风景插画、水榭、临水茶榭、亭台楼阁、粉墙黛瓦、黛瓦白墙、飞檐翘角、翼角起翘、月洞门、漏窗、冰裂纹窗、槅扇、挂落、九曲桥、曲桥、垂柳园林、碧水倒影、园林倒影、睡莲池、数字水粉风景、细腻厚涂风景),或 "draw it yourself", "paint with code", "procedural painting", "watercolor / collage / colored pencil / anime / editorial / impasto oil / ukiyo-e / pixel art / clay / claymation / cyanotype / sun print / cross-stitch / embroidery / retro instrument panel / vintage radio / sticker collage / receipt / lab notebook / graph paper / chalkboard / blackboard / cyberpunk / neon city / cartoon / hand-drawn animation / isometric / 2.5D / continuous line / one-line drawing / soft 3D / 3D render / puffy letters / ball pit / shape morph / morphing / newspaper collage / Dada / ransom note / halftone / glassmorphism / aurora gradient / Bauhaus / geometric poster / screen print / synthwave / retrowave / outrun / perler beads / hama beads / artkal / fuse beads / melty beads / pegboard beads / petroglyph / rock art / rock carving / desert varnish / Egyptian tomb painting / ancient Egypt / hieroglyphs / Theban tomb / Roman mosaic / floor mosaic / tesserae / opus vermiculatum / Pompeii mosaic / stained glass / leaded glass / church window / Gothic window / grisaille / illuminated manuscript / medieval manuscript / book of hours / gold leaf / illuminated initial / blackletter / vellum / astrolabe / da Vinci notebook / Leonardo codex / Renaissance sketchbook / mirror writing / iron-gall ink / red chalk / sanguine / ornithopter / exploded view / inventor's sketch / silhouette / silhouette portrait / cut-paper profile / shade portrait / Georgian portrait / Regency portrait / oval gilt frame / letterpress / wood type / playbill / circus poster / Victorian poster / two-colour misregistration / woodcut poster / constructivism / constructivist poster / Soviet avant-garde / Russian avant-garde / Rodchenko style / photomontage poster / art deco / streamline moderne / 1930s travel poster / railway poster / airbrush poster / sunburst rays / Gatsby style / golden age comic / vintage comic book / comic cover / Ben-Day dots / four-color printing / newsprint / speech balloon / pulp cover / pop art / Warhol-style / pop silkscreen / silkscreen portrait / repeated pop portrait grid / ASCII art / text art / typewriter art / line printer / greenbar / fanfold paper / tractor feed / overstrike / printer plot / low poly / low-poly / retro 3D / 90s 3D game / PS1 style / N64 style / software rasterizer / flat shading / affine texture mapping / vertex fog / game HUD / stencil / stencil graffiti / spray paint stencil / street art / drips and overspray / Banksy-style stencil / embroidered patch / embroidery patch / iron-on patch / sew-on patch / merit badge / camp badge / merrow border / rocker patch / denim jacket patches / blueprint / technical drawing / crayon / kid's drawing / CRT terminal / green screen / thermal camera / thermal imaging / Delft tiles / Delft blue / cave painting / ochre / Lascaux-style / 1-bit / MacPaint-style / black-figure / Greek vase / pencil drawing / graphite / X-ray / baggage scanner / rubber hose / 1930s cartoon / linocut / lino print / VHS / home video / flat vector / flat illustration / storybook animation / squash and stretch / ballpoint / biro / ballpoint doodle / margin doodles / hand-drawn board game / overlay sheets / tracing-paper overlays / light box / colour separations / registration marks / acetate overlay / pastel UI / Dot-style product film / launch-film interface / macOS window cards / exam grading / grading an answer sheet / red-pen marking / graded test paper / rubber-stamped answer sheet / shadow puppet / shadow puppetry / Chinese shadow play / leather shadow puppets / backlit puppet screen / pen and wash / pen & wash / line and wash / ink and watercolour / ink and watercolor / fineliner sketch / fineliner and watercolour / sketchbook characters / sketch cards / urban sketching / water brush / gouache / retro gouache / gouache portrait / gouache illustration / opaque gouache / matte acrylic / picture-book portrait / vintage picture book / retro children's book illustration / mid-century children's book / big-nosed character portrait / cable-knit sweater / knitted bobble hat / blue picture book / soft blue picture book / soft-blue children's book illustration / modern picture book / limited-palette picture book / picture-book spread / scratchy ink line / dry-brush ink line / ink pencil line / crayon and pastel texture / chalky white marks / blue and coral palette / fluffy white bear / Jiangnan garden / Chinese garden / classical Chinese garden illustration / Chinese water garden / spring garden illustration / lush painterly garden / waterside pavilion / moon gate / lattice windows / zigzag bridge / weeping willow garden / upturned eaves / grey-tiled roof / blossom trees and reflections / lily pond with egrets / digital gouache landscape without an image model" 时使用;也用于需要逐步画出(draw-on)动画的插画。单独说「剪纸」指剪纸拼贴、「刺绣」指十字绣、「丝网印刷 / screen print」指包豪斯几何;「打马赛克」是打码,不是马赛克画风;单说「蓝图」指蓝图工程图,「蓝晒 / 晒图」仍指蓝晒;「铅笔 / 素描」指铅笔素描,「彩铅」指韩国彩铅;「像素」仍指像素风,「1-bit / 黑白画图软件」指 1-bit 早期画图软件;「霓虹」仍指赛博朋克;「喷漆 / 街头涂鸦」仍指喷漆模板涂鸦,「圆珠笔 / 随手涂鸦 / 页边涂鸦」指圆珠笔涂鸦;「描图纸 / 硫酸纸 / 叠片 / 灯箱」指描图纸叠层(蓝图工程图那张描图布是晒成蓝图的,不是叠片);「Dot 风 / 粉彩界面 / 窗口卡片 / 发布会界面」指粉彩界面(纯色底 + 白色实心窗口卡片),要磨砂玻璃和弥散渐变仍用弥散玻璃;「阅卷 / 批改 / 答题卡 / 判卷 / 红笔打分」指阅卷批改,实验记录里的红笔圈和便利贴仍用实验笔记本,带「已付」橡皮章的小票拼贴仍用贴纸拼贴 · 小票;「皮影 / 皮影戏 / 影子戏」指皮影戏(透光的彩色驴皮人偶),黑纸剪出的侧影小像仍用剪影,彩纸剪贴仍用剪纸拼贴。「钢笔淡彩 / 淡彩速写 / 针管笔加水彩 / 线稿上色的速写小卡」指钢笔淡彩;单说「水彩」仍指水彩(风景、花卉的大片晕染),蓝铅笔稿 + 毛笔线 + 赛璐璐阴影的拟人小物仍用卡通手绘,「素描 / 铅笔」仍指铅笔素描。「水粉 / 复古水粉 / 绘本大头像 / 复古童书插画」指复古水粉(不透明水粉画的特写大头像);梵高式厚涂的风景、名画感仍用油画厚涂,扁平矢量、会挤压拉伸的小角色动画(「绘本动画」)仍用绘本角色动画,针管笔线稿加淡彩的速写小卡仍用钢笔淡彩,撞色多格的头像仍用波普丝网。「蓝调绘本 / 软蓝绘本 / 蓝色童书插画 / 绘本跨页」指蓝调绘本(软蓝限色的现代绘本跨页:干笔墨线 + 干蜡笔粉彩上色 + 白粉笔痕);单说「绘本」仍指绘本角色动画,「水粉 / 绘本大头像」仍指复古水粉,「编辑风 / Riso」仍指编辑风手绘,针管笔线稿加淡彩的速写小卡仍用钢笔淡彩,小孩自己画的蜡笔画仍用儿童蜡笔画。「江南园林 / 园林春景 / 中式园林插画 / 粉墙黛瓦 / 飞檐 / 月洞门 / 九曲桥」指江南园林(细笔数字水粉的园林春景:叶形小笔触堆出的繁茂树冠、繁花、垂柳、黛瓦飞檐、碧水倒影、层层远山);单说「水墨 / 山水」仍指水墨,单说「水彩」仍指水彩,动漫背景 / 赛璐璐天空仍指日本动漫,浮世绘仍是浮世绘;梵高式厚涂的风景仍用油画厚涂,皮影人偶的一场戏仍用皮影戏。---# Claude 绘图@@ -80,6 +80,7 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型| 钢笔淡彩 · Pen & Wash | `lib/penwash.py` · `PenWash` | `examples/penwash_neighbours.py` 街角速写 · Sketchbook Neighbours(橡木桌上并排四张冷压水彩小卡,一张一个街坊在做一件小事:吹着口哨的邮差,钴蓝帽子和外套,挎包塞得太满,两封信从背后逃出去扑扇着飞走;戴超大圆眼镜的奶奶给花盆浇水,猫却钻进了盆里,水滴正落在它两耳之间(眯眼、爪子扒着盆沿),真正的那朵红花在旁边干等;踩滑板车的小孩,钴蓝头盔大了两号、压到眉毛,吐着舌头,膝盖贴着创可贴,身后速度线和尘土;圆滚滚的面包师戴高高的白帽子,抱着一根比他还长的法棍,法棍从手绘边框里戳出去,一只麻雀落在尖上啄;针管笔线条抖、出头、不闭合、偶尔描两遍,淡彩错位出线、在线里留白缝、干边、颗粒,腮红湿中湿,不铺满的背景色块绕开人物留白边,白色水粉高光;卡片有阴影和受光的切边,旁边放着一支针管笔、一支水笔(透明杆里的水和气泡、染了颜色的尼龙笔尖)和水笔的笔帽;`--stages` 出 9 个阶段:空桌、白卡、两批墨线、两遍淡彩、背景色块、高光、放下笔) | 约 3 秒(成品)/ 约 6 秒(含阶段) || 复古水粉 · Retro Gouache | `lib/gouache.py` · `GouachePortrait` | `examples/gouache_rainy_day.py` 雨天三人像 · Rainy-Day Portraits(米色画板上并排三幅竖长的绘本大头像,每幅一块刷出来的单色背景:浅海玻璃绿底上的老渔夫,黄色防水雨帽上还挂着雨珠、帽檐尖上吊着一滴水,巨大的红鼻子、白色浓眉、大耳朵、一圈白色下巴胡子,藏青麻花毛衣配罗纹领,胸前毛毡口袋里探出一条银色小鱼、张着「O」字嘴,他眯着眼往下看它;绿底上被一顶巨大的芥末黄毛线帽和红白条纹围巾埋住的小孩,橙色大绒球,两只毛线手套捧着一杯冒热气的可可,杯里漂着两块棉花糖,他盯着棉花糖看成了斗鸡眼;蓝到黄渐变底上的高个女士,橙色小卷堆成一座高塔发型,蓝眼影、珍珠耳坠、红色高领、钴蓝大衣配青绿毛毡翻领,斜眼瞟着爬上她肩膀的蜗牛,蜗牛身后的大衣上还有一道发亮的黏液;不透明水粉从暗到亮:托底色、赭色起稿、背景干笔皴擦、平涂大块、几阶色值塑形(鼻子、脸颊、帽子)、帽檐和鼻子下的软投影、粉状腮红、V 字平针与麻花、罗纹、一根根发丝和胡子、毛毡、受光处的干笔高光,最后是印刷书页的纸纹;`--stages` 出 8 个阶段:托底色、起稿、背景、平涂、塑形、质感、五官与道具、高光) | 约 7 秒(成品)/ 约 8 秒(含阶段) || 蓝调绘本 · Blue Picture Book | `lib/bluebook.py` · `BlueBook` | `examples/bluebook_shared_umbrella.py` 借伞 · The Shared Umbrella(软蓝雨天里的一张绘本跨页,背景蓝块毛边、不到纸边:左页是一个小小的公交站,玻璃候车亭里的长椅空着,只有一只蜗牛独占整条干燥的长椅,旁边是画着小巴士的圆站牌、亮着芥末黄灯的路灯,路灯下的大水洼里一只鸭妈妈带着两只小鸭玩得正欢;右页一个穿钴蓝雨衣、扎两个珊瑚红小揪揪的小女孩,双臂伸到最高,把一把珊瑚红小伞举向一只巨大、害羞、毛茸茸的白熊——伞只遮住了它的鼻子,雨落在它的耳朵和头顶,也落在小女孩自己的头发上,她一点也不在意,仰着头冲它笑;白熊低头看着自己并在一起的爪子,脸红了;水洼里映着一点红伞,蓝黑乱线的灌木里开着几朵珊瑚红小花;照绘本画家的顺序:空白纸、蓝色色块(天空块、雾里的远树、灌木、雨衣、候车亭、水洼)、松的墨线(线不闭合、偶尔描两遍)、乱线排出的暗部、珊瑚红点缀和点彩腮红、白粉笔(云、白毛、水纹、玻璃反光)、雨丝 / 水花 / 甩点 / 细尘,最后印在书上(中缝、页码、印刷的柔化);`--stages` 出 7 个阶段加成品:空白纸、蓝色色块、墨线、暗部、点缀色、粉笔白、雨) | 约 5 秒 |+| 江南园林 · Jiangnan Garden | `lib/jiangnan.py` · `JiangnanGarden` | `examples/jiangnan_spring_water.py` 春水园林 · Spring Water Garden(一幅横幅的江南园林春景,从前景的花枝和柳丝之间望进去:画面中间是一池碧绿的春水,岸上的一切都倒映在里面,更柔、更暗,带涟漪和细竖纹;一座带镂空石栏板的九曲石桥折了三折,穿过水面通向一道粉墙,墙上的月洞门里露出另一个洒满阳光的小院(竹子、粉色花树、一块湖石、远处又一道白墙),旁边一扇冰裂纹漏窗,墙上落着叶影;粉墙旁是一座临水茶榭,黛瓦歇山顶、翼角高高翘起、脊头卷起,翡翠绿的槅扇门和灯笼锦窗、檐下挂落、一对红灯笼、一块写着「听雨」的小匾,台基上几盆花;茶榭右边一棵开满白花的树下,一条小木船系在石阶边;左岸一棵大垂柳,墙后一棵层层托盘的松树和一片深浅不一的树冠,再后面是雾里的青山;近处水面上一丛丛睡莲叶和几朵粉色睡莲,一只白鹭站在水中的石头上,另一只从松树前掠过;前景左下是深绿的灌木、白色小花和弯弯的鸢尾叶,右下一丛粉色杜鹃,左上垂下几缕近处的柳丝,右上一枝粉色花枝,花瓣在空中飘、在水面上漂;右下角一方小红印「春水」;照风景插画家的顺序从后往前画:天空和远山、远树和雾、建筑、对岸的园子、水和倒影、桥和船、睡莲和白鹭、前景草木、垂挂的画框,最后是印章和收尾的柔化、光晕、颗粒;`--stages` 出 9 个阶段加成品:天空和远山、远树、建筑、对岸、水、桥和船、睡莲和白鹭、前景、画框) | 约 6 秒 |各画风共用 `lib/core.py` 里的底层工具:噪声、模糊、样条曲线、多边形遮罩、有机轮廓 `blob_pts`、毛笔 `bristle_stroke`、中文字体查找;新四种还用到补零平移 `shift`、文字遮罩 `text_mask`、西文字体查找 `latin_font`/`load_font`,以及高度图打光 `height_normals`、`height_shadow`(沿光线步进的投影)、`ambient_occlusion`。@@ -149,7 +150,8 @@ description: Claude 绘图 / Claude Drawing —— 不借助任何生图模型- 中国传统与民间艺术、节庆(元宵、庙会、过年)、戏曲和民间故事、古代体育与游戏(蹴鞠、赛龙舟、舞狮)、「一场好戏」式的小叙事(登场—交手—亮相),讲解片里的「历史 / 传统 / 一场比赛的高光时刻」页,要人物有动作又不能用真人 → 皮影戏(要黑纸剪的侧影小像用剪影;要彩纸剪贴的童趣用剪纸拼贴;要山水留白用水墨);- 人物小品、街坊邻居与日常小事(送信、浇花、骑车、买面包)、一组角色卡 / 人设卡、旅行和城市速写里「一个人在做一件小事」、轻松幽默的配图,讲解片里「一组用户 / 角色 / 团队成员」的介绍页 → 钢笔淡彩(要蓝铅笔稿、毛笔线和赛璐璐阴影的拟人小物用卡通手绘;要风景和花卉的大片晕染用水彩;要真的动起来的角色用绘本角色动画;要草稿纸上的随手涂鸦用圆珠笔涂鸦);- 人物大头像、角色特写、一组人设的「封面像」、温暖怀旧的复古童书 / 绘本插画,要有摸得着的手感(毛衣针脚、毛线帽、胡子和卷发、毛毡),讲解片里「这个人登场」的特写页 → 复古水粉(要线稿加淡彩、「一个人在做一件小事」的速写小卡用钢笔淡彩;要真的动起来的扁平小角色用绘本角色动画;要梵高式厚涂的风景用油画厚涂;要撞色多格的头像用波普丝网);-- 温柔又好笑的小故事、绘本跨页或内页、童书封面和插页、「一个小角色帮另一个」这类有情节的一幕,下雨、下雪、夜晚这类安静的天气,要一眼就是「手画的现代绘本」,颜色只要一种主色(软蓝)加一点点睛色 → 蓝调绘本(要单人特写大头像、看得见毛衣针脚用复古水粉;要速写小卡上的针管笔线稿加淡彩用钢笔淡彩;要真的动起来的扁平小角色用绘本角色动画;要小孩自己画的蜡笔画用儿童蜡笔画;要网点和套色的观点插画用编辑风手绘)。+- 温柔又好笑的小故事、绘本跨页或内页、童书封面和插页、「一个小角色帮另一个」这类有情节的一幕,下雨、下雪、夜晚这类安静的天气,要一眼就是「手画的现代绘本」,颜色只要一种主色(软蓝)加一点点睛色 → 蓝调绘本(要单人特写大头像、看得见毛衣针脚用复古水粉;要速写小卡上的针管笔线稿加淡彩用钢笔淡彩;要真的动起来的扁平小角色用绘本角色动画;要小孩自己画的蜡笔画用儿童蜡笔画;要网点和套色的观点插画用编辑风手绘);+- 中国古典园林、江南春景、亭台楼阁和水、旅行与城市文化里的「园林 / 古镇 / 春天」,节气和节日(春分、清明、谷雨)的配图和海报,要繁茂、细腻、一眼就是「精心画出来的插画」的风景,讲解片里的「中国传统 / 生活美学 / 春天」页 → 江南园林(要留白的写意山水用水墨;要大片松散的晕染用水彩;要赛璐璐天空和夏日少年感用日本动漫;要木版套色和海浪用浮世绘;要皮影人物的一场戏用皮影戏)。每种画风一幅范例作为质量基准(范例都不用禅意主题);水墨另加一幅「月印万川」(留白托月、水面倒影)。@@ -1113,6 +1115,27 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask- 收尾:`printed(amount, gutter=x)` 印在书上;`folio(x, y, '14', size)` 小页码;`render()`、`composite()`、`stage(name)`、`save(path, stages_dir)`;`save('x.jpg')` 默认 quality 88、4:4:4 色度。- 颜色用 `COLOURS` 里的名字(paper chalk ink mist powder cornflower blue cobalt deep teal navy slate coral tomato cheek flesh freckle mustard butter)或 '#rrggbb';常量 `COLOURS`、`INK`。+**江南园林 `JiangnanGarden`**:+- 思路:照风景插画家的顺序从后往前画(天空 → 远山 → 雾 → 远树 → 屋后的树 → 建筑 → 对岸的园子 → 水面和倒影 → 水上的东西 → 前景 → 垂挂的画框 → 印章),不透明的颜料盖住后面的,画的顺序就是遮挡关系。+ - 空气透视:每个画法都有 `far`(0 近 – 1 很远),越远颜色越往雾色(淡青绿)靠、对比越低;深度层之间用 `haze()` 铺一道雾带,最浓处在山脚。+ - 笔触:一笔就是一个小多边形(尖叶、圆花瓣、剑形叶、圆点),各有大小、角度和颜色。成千上万笔一次画完:Pillow 把每个多边形按序号填进 2 倍超采样的整数 id 图(序号就是先后,后画的盖住先画的),numpy 按 id 查颜色和透明度表,再缩回 1 倍,边缘都有抗锯齿,一笔不到 1 微秒;颜料里叠一层固定的细画布纹理,明暗差几个百分点。+ - 光:太阳在左上、略靠前。树冠是一组团块(椭圆,排在后面的在前);每一笔先找到自己落在哪个团块上(包含它的最前面那个),把团块当穹顶:法线给漫射,整团越往下越暗,再加低频噪声打散。这个 0–1 的值从一条混好的绿色色阶里取色(深青绿的芯 → 中绿 → 黄绿 → 淡的阳光绿)。+ - 树冠照水粉画家的画法:暗底(团块的芯 + 1.7 倍大的暗叶,底色的边缘也是叶子)→ 满冠中暗的叶 → 穿出轮廓的叶 → 受光值高的地方一簇簇(5–14 片)亮叶 → 最亮的几笔。叶尖朝外、微微下垂;近景灌木用 `veins` 给亮叶加一道浅叶脉。托盘松是同一个模型:歪扭的树干加几层扁平的针叶盘,针叶用很细的叶片、几乎不下垂。+ - 繁花树:枝干、笔触暗底(暗花瓣 + 深绿叶,不是一块平涂)、细枝、几片嫩叶,然后几百个花簇按明暗排序(亮的压在暗的上面),簇里朝阳的花瓣更白,枝条从簇间的缝里露出来;`blossom_branch()` 是近景花枝:一朵朵五瓣花、花蕊、花苞和嫩叶。+ - 垂柳:树干和几根弯枝先画,再用一层垂叶的树冠盖住枝;几百上千根柳丝一绺一绺(同一处垂下 3–9 根,绺与绺之间留缝),从枝上或树冠里出来,先往外拱一点再垂下,带一点摆;每根是发丝细的茎,两侧随机地挂着小窄叶,略张开、朝下。从后往前画(后排暗、偏蓝,前排亮、偏黄),受光一侧和梢头的新叶更亮。+ - 屋顶:正面看的歇山顶是一张曲面 S(u, v)(u 横向 −1..1,v 从正脊 0 到檐口 1):上陡下缓(举折,檐口一段被透视压扁),越往下越宽,翼角向外甩出,檐口两端急速起翘。曲面拆成小四边形网格画进 id 图,每个像素用两步牛顿迭代反求精确的 (u, v),瓦就能解析地上色:筒瓦(左侧受光,旁边一道暗缝)和板瓦一行隔一行,每层瓦口一道亮边、下面一道阴影,每片瓦各有一点明暗,偶尔一片发绿;檐口一排瓦当和滴水,檐下是椽头和檐底,墙面上落一道檐影;正脊有镂空花脊和卷起的脊头,戗脊一直通到翘起的翼角尖。+ - 建筑:粉墙是平涂加低频斑驳、檐下雨渍、发绿的墙脚和一层淡笔触;`dapple()` 是树叶在受光面上投下的叶影(阈值噪声的冷色斑,离投影的树越近越重)。槅扇和窗(方格、斜格、灯笼锦、冰裂纹)在 3 倍图上画棂条,左上沿亮、右下沿暗,在里面的暗室或窗纸上投一点影;柱子是漆过的圆柱加柱础;灯笼是带骨的红色椭球,金色顶底和流苏;匾额是带框的木板和描金字;台基、台阶和桥都是一块块有缝的石头,每块各有明暗。九曲桥是真的几何:桥段、石板、桥墩、望柱、镂空栏板和扶手都经针孔相机(`camera()`、`project()`)投影,每个面按法线上色,背对镜头的面剔掉。+ - 水:湖面是碧绿的本色,远处映着天更淡。倒影是岸线以上的画面按岸线镜像,横向被细浪推开,竖向模糊(离岸越远越糊),压暗,并按菲涅尔越往近处越多地混进本色,所以和岸上的东西对得上,只是更柔、更暗。立在水里的东西自带倒影:桥把几何的高度取反再投影一遍,船和白鹭把自己那一层按水线翻下去。最后是从水面本身取色的横向笔触、淡淡的涟漪线(映天的亮、映岸的暗)和细竖纹。睡莲叶经相机躺在水面上(椭圆按 眼高 / 距离 压扁),带缺口、叶脉、亮的远边、暗的近半边和一点影子。+ - 收尾 `grain()`:轻微柔化、亮部一圈春天的光晕、暗部偏青、细颗粒、极淡的画布纹和竖纹;`seal()` 一方边缘磨损的小红印,白字。+- 构造:`JiangnanGarden(W, H, seed, keep_stages=True, stages_dir=None)`(总像素不超过 4096²);`camera(horizon, eye, focal, cx)` 定湖面上的针孔相机,配 `project(X, Y, Z)`、`ground_y(Z)`、`depth_at(y)`、`px_per_m(Z)`。画布坐标是像素;世界坐标是米(X 向右、Y 从水面向上、Z 向远)。+- 底层:`dabs(xs, ys, length, width, colours, angle, shape='leaf'|'round'|'blade'|'dot', alpha, far)` 一次画很多笔(角度用弧度);`stroke(path, w0, w1, colour)`;`fill(mask, colour, alpha)`;`poly(pts)`、`ellipse(cx, cy, rx, ry)` 返回画布大小的遮罩;`crown(cx, cy, w, h, n, size)` 生成团块 (cx, cy, rx, ry);`with g.clipped(mask):` 只画在遮罩里(月洞门里的景)。+- 天空和远处:`sky(top, bottom, y1, clouds)`;`hills(ridge, base, colour, far)` 山脊样条、浮雕噪声打光、树冠凸起的轮廓、山脚渐隐;`haze(y0, y1, y2, colour, strength)` 从 y0 升到 y1、到 y2 消失的雾带。+- 草木:`foliage(clumps, ramp_='spring', leaf=(5, 9), density, far, light, droop, aspect, veins, edge, highlights)`;`blossom_tree(branches, clumps, kind='white'|'pink'|'azalea', petal, density, far, leaves, gaps)`,branches 是 [(path, w0, w1), …];`blossom_branch(path, w0, w1, kind, flowers, spread, size)`;`willow(trunk, boughs, strands, length, ramp_, leaf, far, sway, crown, tips, gap, bundle, splay, aspect, crown_anchor)`;`pine(trunk, limbs, pads)`;`branch(path, w0, w1)`;`reeds(x0, x1, y 或 f(x), n, height, lean, width, bend)` 弯曲的剑形叶;`petals(region, n, kind, water)`;`rock(cx, cy, rx, ry)`;`pot(x, y, w, h, colour, band)` 返回盆口中心。+- 建筑:`wall(x0, y0, x1, y1, colour, stains, damp)`;`dapple(x0, y0, x1, y1, amount, scale, cover, falloff=(x, y, r), mask)`;`roof(cx, y_ridge, y_eave, ridge_w, eave_w, upturn, flare, rows, courses, ridge_h, soffit, shadow)` 返回曲面函数;`coping(x0, x1, y, h)` 墙头瓦;`column(x, y0, y1, w)`;`beam(x0, x1, y0, y1)`;`lattice(x0, y0, x1, y1, pattern='lantern'|'grid'|'diamond'|'ice', cell, bar, frame, back='interior'|'paper'|颜色|None, kind='window'|'door')`;`fretwork(x0, x1, y0, h)` 挂落;`round_window(cx, cy, r, ring, pattern 或 inside=函数(遮罩), ground, reveal)` 漏窗 / 月洞门;`stonework(x0, y0, x1, y1, course, block, damp)`;`steps(x0, x1, y, n, rise, tread, grow)`;`bridge(path=[(X, Z), …], width, deck, thick, rail, post, rails='both'|'rear'|'none', reflection)`;`lantern(x, y, h, cord)`;`plaque(cx, cy, w, h, text)`。+- 水:`lake(y0, y1, far_colour, near_colour, bank)`;`reflect(bank, strength, blur, ripple, darken, fresnel, src)`(`src` 传画水之前的画布);`layer()` + `reflect_layer(before, axis, box)` 给船、白鹭这类东西单独做倒影;`ripples(box, n, light, dark, alpha, brush)`;`lily_pads(pads=[(X, Z, 半径米)], flowers=[(X, Z, 大小米)])`;`lotus(x, y, s)`;`boat(x0, x1, y, h)`;`egret(x, y, s, pose='stand'|'fly', facing)`。+- 收尾:`seal(x, y, w, h, text)`;`grain(amount)`;`render()`、`composite()`、`stage(name)`、`save(path, stages_dir)`;`save('x.jpg')` 默认 quality 88、4:4:4 色度。+- 颜色用 `PAINTS` 里的名字(sky sky_low haze cloud plaster coral jade jade_dark jade_light lacquer beam interior paper stone tile board gold wood lantern seal bark bark_light water water_deep water_far terracotta porcelain egret)或 '#rrggbb';色阶用 `RAMPS` 里的名字(spring jade deep olive willow far white pink azalea tile stone rock pad)或自己给一串颜色;常量 `LIGHT`。+**顺序**:都是先远后近、先大后小,文字最后叠加。水墨的雾要画在它该吞没的东西之后;水彩的叶梗要先画,并且只画在叶子外面。## 三、毛病清单(都真实出现过)@@ -2155,6 +2178,31 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask| 背景块角上一道干笔斜着戳出纸外 | 贴边的干笔用 `clip` 限在块的边缘附近 || 印刷一步把白纸压灰,动图最后一帧整体一暗 | 「黑色抬到墨色」原来是整体混进 5% 深墨:改成 c0 + 颜色 × (1 − c0),白纸不动,只抬黑 |+**江南园林**++| 问题 | 改法 |+|---|---|+| 树冠是一团团带噪点的绿球(「西兰花」) | 每个团块当穹顶打光;暗底先画团块的芯,再画 1.7 倍大的暗叶(底色边缘也是叶子),叶片穿出轮廓,亮叶 5–14 片一簇、只落在受光值高的地方;团块 24 个、大小 0.15–0.34,轮廓才碎;屋后的树 far 0.3、更后一排 0.4–0.6,越远越蓝、越平 |+| 垂柳是一整片石灰绿的帘子 | 柳丝 3–9 根一绺,绺与绺之间留缝;叶子 3–5 px、宽只有长的 0.28;后排的绺暗、偏蓝,前排亮、偏黄,受光一侧再亮一点 |+| 柳树顶上露出几道细黑弧线,像伞骨 | 先画枝,再用一层垂叶的树冠盖住,三成柳丝从树冠里长出来,树冠顶上才不是一条硬线 |+| 近处的柳丝是一根根麻花辫 | 叶子严格左右交替,成了人字纹:改成随机挂在一侧,离茎张开 0.18–0.5 弧度,长短不一;只画 34 根,每根稀一点,叶片更瘦(宽 0.22) |+| 九曲桥是一排横在水上的灰栏杆 | 太近、太大、栏杆太高、望柱太密:起点退到 15 m,栏高 0.5 m,望柱 1.9 m 一根;眼高 3 m 时近侧栏杆会把桥面整个挡住,改成只留远侧栏杆(很多曲桥本来就只有一侧栏杆),石板和缝才看得见,折线才读得出来 |+| 桥面像一块漂在水上的薄板 | 桥板侧面和桥墩的法向算反了,朝向镜头的面被剔掉:法向改成 (−e_z, 0, e_x),桥板厚度和桥墩才出来 |+| 石桥满是麻点,像花岗岩 | 画布纹理 0.07 → 0.025,每个面只做一点明暗抖动 |+| 水面竖纹太重,像在下雨 | 细竖纹 3.5% → 1.3%,竖向模糊 9 → 14 px;另加从水面本身取色的横向笔触,水才像画出来的 |+| 睡莲叶是一圈红边的卡通盘子 | 卷边露出红背的只留 12%,边更细;近半边压暗改成 alpha 0.45、内缘收到 0.55 / 0.3(不再是一圈内线),远边一道浅亮边;叶子按几丛分布,不铺满水面 |+| 白花树是一团紫灰色的棉花 | 平涂的暗底缩到团块的 0.55,改成偏绿的深色,再用暗花瓣和深绿叶的笔触打底;花簇数量 ×1.5、每簇 12–25 瓣,受光一侧的花瓣更白 |+| 粉色灌木里露出几块平涂的褐紫色大斑 | 平滑的椭圆暗底换成笔触暗底(45% 深绿叶 + 55% 暗花瓣),椭圆只留团块中心 |+| 窗格中间一块黑方块像个洞,换成窗纸后又像一块空白牌子 | 侧窗用糊纸的底;灯笼锦中间的空框缩到宽 40%、高 34% |+| 漏窗被柳丝挡住 | 挪到月洞门和茶榭之间那段墙上 |+| 屋顶一片死黑、看不出瓦 | 瓦的色阶提亮;筒瓦受光侧 0.6,瓦口亮边 +0.3、下面的阴影 −0.26,越往檐口越亮(反射天光) |+| 飞着的白鹭像一根白羽毛 | 翅膀改成宽、往后掠的形状,翼尖分出五根飞羽,远侧翅膀发灰,颈缩回去,腿拖在后面 |+| 远山被树全挡住,看不出层次 | 两层山脊抬高 40–70 px;山脚 60 px 渐隐(不然动图前几帧山脚是一条硬横线) |+| 对岸右边是一片发白的雾墙 | 补上岸边的灌木和小树,一直到水边 |+| 光是平的,看不出春天的太阳 | 墙上、台基上、桥上加叶影(阈值噪声的冷色斑,离投影的树越近越重;桥上用桥的遮罩限住,不压暗水面);檐下阴影 0.42 → 0.5 |+| 所有树都一个样 | 墙后加一棵托盘松(针叶用细叶片、几乎不下垂);前景加白色小花和弯曲、带受光边的鸢尾叶(原来是直挺挺的绿刺) |+| 墙和水面太干净,像矢量图 | 墙上叠一层淡笔触(alpha 0.6,明暗浮动 −3.5% 到 +2.5%);收尾加轻微柔化、亮部光晕、暗部偏青 |+## 四、做成动画- 各画风都有 `stage(name)` 和 `save(path, stages_dir)`,按阶段依次淡入叠化,就是「一幅画被逐步画出来」。README 里的动图就是这样做的。@@ -2189,6 +2237,11 @@ from core import spline, curve, blob_pts, fbm1d, blur, polygon_mask- 调色板:第一帧几乎只有纸白,只给它 12 色;230 色从和它不同的像素切(饱和 ×3、末帧 ×3);再留 12 色,其中 3 个是强制的深中性色(墨线和眼睛保持黑,不变藏青),另外 9 色只从末帧误差最大(> 18 级)的像素里切。- 固定 4×4 Bayer。和屏上已显示颜色差不到 7 级(叠化帧)或 4 级(关键帧)的像素沿用上一帧,末帧精确发送。- 结果:43 帧、12.05 秒、约 1.04 MB,按解码结果逐帧自检,末帧 p99 误差 18。+- 江南园林的动图(脚本在 `claude_drawing/jiangnan_work/make_gif_jiangnan.py`):+ - 阶段:天空和远山 → 远树和雾 → 粉墙、月洞门和茶榭 → 垂柳、白花树和对岸 → 湖面和倒影 → 九曲桥和小船 → 睡莲和白鹭 → 前景草木 → 垂下的柳丝和花枝 → 印章和收尾(成品)。每段 900 毫秒 + 5 帧叠化。+ - 调色板:第一帧(天空渐变和远山)给 40 色;200 色从和它不同的像素切(末帧 ×3),按满屏叶子和繁花的需要加权:绿色 ×2.5、白和浅色 ×2、其他饱和色(灯笼、睡莲、杜鹃)×3,满屏的绿才不出色带、白花不发灰;再留 14 色,其中 3 个是强制的深中性色(瓦缝、树皮、窗格空隙),另外 11 色只从末帧误差最大(> 16 级)的像素里切。+ - 固定 4×4 Bayer。和屏上已显示颜色差不到 7 级(叠化帧)或 4 级(关键帧)的像素沿用上一帧,末帧精确发送。+ - 结果:55 帧、14.75 秒、约 1.57 MB,按解码结果逐帧自检,末帧 p99 误差 18。- 绘本角色动画的动图是真动画,不是阶段叠化:`Storybook.gif()` 按时间逐帧渲染,720×405、15 fps(GIF 延时只能写厘秒,按累计取整写成 7、7、6 厘秒交替),共用一张加权调色板 + 固定 4×4 Bayer,没变的像素记成品红透明,151 帧(动作 9.95 秒 + 末帧停 1.4 秒)约 0.56 MB;范例加 `--gif out.gif` 出这张,`--stages` 的关键帧仍可喂给上面的阶段动图工具。- 形变动画可以直接出真动画:`Morph.at(keys, T)` 给出全局时间 T 的轮廓,逐帧渲染即可。- 更细的逐笔动画:把一组笔画单独画到透明层上导出,再用 Motion Canvas 遮罩按顺序显现。这个还没做成现成接口。@@ -2263,6 +2316,7 @@ lib/shadowpuppet.py 皮影戏(油灯照亮的幕布、两个灯芯;按光lib/penwash.py 钢笔淡彩(冷压水彩小卡:受光纸纹、不直的切边;针管笔线:手抖、出头、不闭合、描两遍、按 z 遮挡断线;淡彩:错位出线与留白缝、游走的边、干边、颗粒、平刷条纹、湿中湿、起皱;不铺满的背景色块与白边;白色水粉;呆萌小人部件;橡木桌、卡片阴影、针管笔与透明水笔)lib/gouache.py 复古水粉(托底色的画板与纸纹;不透明水粉:鬃毛条纹、越用越干、挂在纸纹上的干笔,湿笔带起底色;毛边;穹顶光照的几阶色值塑形与球体塑形;软投影、粉状腮红、干笔高光;圆眼、大鼻子、大耳朵;V 字平针、麻花、罗纹;顺着流向的发丝、胡子、绒球、卷发;毛毡;印刷书页的颗粒)lib/bluebook.py 蓝调绘本(直方图均衡的纸纹与 8 个方向拖开的纸纹;毛笔 / 墨铅笔线:手抖、落笔收笔、粗细起伏、笔毛含墨、越画越干、顺笔的干白道、不闭合的轮廓与再描一遍;之字乱线暗部、平行短排线、草叶;干蜡笔 / 粉彩 / 干水粉上色:错位、游走的边、干边、笔道、纸纹白点、半透明混色,墨线始终在上;毛边、不到纸边的背景色块;白粉笔;雨丝、水花、水纹、甩点、细尘;大圆脑袋、点点眼、点彩腮红、雀斑、扇贝形毛边和白毛;印刷:柔化、抬黑、中缝、页码)+lib/jiangnan.py 江南园林(叶形小笔触的 id 图光栅化:Pillow 按序号填多边形、numpy 查色表、2 倍超采样;按团块穹顶光照取色的树冠:暗底、穿出轮廓的叶、成簇的高光、最亮的几笔;花簇按明暗排序的繁花树、五瓣花的近景花枝;一绺绺细枝的垂柳、托盘松、弯曲的鸢尾叶;网格反求 (u, 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_jiangnan_spring_water.gif b/examples/drawing_jiangnan_spring_water.gifnew file mode 100644index 0000000..91f19b4Binary files /dev/null and b/examples/drawing_jiangnan_spring_water.gif differdiff --git a/examples/jiangnan_spring_water.jpg b/examples/jiangnan_spring_water.jpgnew file mode 100644index 0000000..d361f89Binary files /dev/null and b/examples/jiangnan_spring_water.jpg differdiff --git a/examples/jiangnan_spring_water.py b/examples/jiangnan_spring_water.pynew file mode 100644index 0000000..acfdb6f--- /dev/null+++ b/examples/jiangnan_spring_water.py@@ -0,0 +1,273 @@+"""Example (Jiangnan garden): 春水园林 · Spring Water Garden -- a lush, finely painted spring garden in one wide view.++Seen through a frame of pink blossom and hanging willow strands: a still jade lake across the middle of the picture+with soft reflections; a zigzag stone bridge with pierced balustrades crossing it toward a whitewashed garden wall,+whose moon gate shows a glimpse of another, sunlit garden behind (bamboo, a pink tree, a rock); next to it a+waterside teahouse with a grey-tiled hip-and-gable roof and upturned flying corners, jade lattice doors and windows,+a hanging lattice frieze, a pair of red lanterns and a small plaque, 听雨 (listening to the rain); a little wooden+boat tied below a white blossom tree at the stone steps; lily pads with pink water lilies, an egret on a stepping+stone and another skimming the water; a big weeping willow on the far bank; hazy blue-green hills behind; a tiny red+seal in the corner.++Painted back to front: sky and hills -> distant trees and haze -> buildings -> the garden on the far bank -> water+and reflections -> bridge and boat -> lily pads and egrets -> foreground foliage -> the hanging frame -> details.+--stages writes those steps as snapshots for the draw-on. No image model.+python3 jiangnan_spring_water.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 jiangnan import JiangnanGarden++W, H = 1920, 1080+BRIDGE = [(-11.5, 15.0), (-5.0, 19.5), (-8.4, 24.5), (-6.6, 29.6)]+++def bank_line():+ """the waterline of the far bank, per column (the teahouse platform stands a little nearer)"""+ x = np.arange(W, dtype=np.float32)+ b = 592 + 3 * np.sin(x / 61.0) + 2 * np.sin(x / 23.0 + 1.3)+ b = np.where((x > 866) & (x < 1454), 606.0, b)+ b = np.where(x >= 1454, 598 + 2 * np.sin(x / 41.0), b)+ return b.astype(np.float32)+++class Garden:+ def __init__(self, g):+ self.g = g+ self.bank = bank_line()++ # ------------------------------------------------------------ 1 sky and hills+ def sky_hills(self):+ g = self.g+ g.sky(top='#7ea4c0', bottom='#cfdcd6', y1=470, clouds=0.8, seed=1)+ g.hills([(-40, 236), (180, 200), (420, 168), (640, 214), (860, 176), (1090, 150), (1320, 190), (1560, 158),+ (1780, 196), (1960, 182)], base=500, colour='#86a6a6', far=0.66, seed=2)+ g.haze(200, 400, 520, strength=0.35, seed=3)+ g.hills([(-40, 330), (260, 288), (560, 312), (860, 266), (1180, 300), (1500, 262), (1760, 296), (1960, 282)],+ base=500, colour='#7a9a90', far=0.48, seed=4)+ g.haze(330, 460, 520, strength=0.45, seed=5)++ # ------------------------------------------------------------ 2 distant and back trees+ def far_trees(self):+ g = self.g+ r = np.random.default_rng(10)+ for i, x in enumerate(np.arange(-40, 1980, 80)):+ y = 445 + r.uniform(-16, 8)+ g.foliage(g.crown(x, y, r.uniform(110, 170), r.uniform(50, 80), n=8, seed=100 + i), 'far', leaf=(2.5, 4.5),+ density=0.9, far=0.6, highlights=0.4, edge=0.6, seed=200 + i)+ g.haze(380, 470, 540, strength=0.35, seed=6)+ # a band of canopy behind the garden, in several depths: bluer and softer the further back+ back = [(380, 380, 'jade'), (520, 360, 'far'), (700, 390, 'jade'), (1500, 380, 'jade'), (1660, 360, 'far'),+ (1840, 380, 'jade'), (40, 380, 'jade'), (200, 360, 'far')]+ for i, (x, y, rp) in enumerate(back):+ g.foliage(g.crown(x, y, r.uniform(180, 240), r.uniform(120, 170), n=14, seed=250 + i), rp, leaf=(2.6, 4.6),+ density=1.0, far=0.4, highlights=0.6, seed=260 + i)+ g.haze(300, 440, 560, strength=0.2, seed=8)+ # the trees right behind the wall and the teahouse: different kinds, sizes and greens+ specs = [(450, 352, 210, 150, 'jade', 0.0), (640, 318, 250, 190, 'spring', 0.05),+ (1000, 262, 280, 230, 'spring', 0.06), (1190, 214, 320, 240, 'jade', 0.0), (1385, 262, 250, 230, 'olive', 0.04),+ (1560, 318, 230, 190, 'jade', 0.0), (1735, 288, 270, 230, 'deep', 0.0), (1890, 318, 220, 240, 'spring', -0.03),+ (100, 320, 260, 220, 'jade', 0.0)]+ for i, (x, y, w, h, rp, lt) in enumerate(specs):+ K = g.crown(x, y, w, h, n=24, size=(0.15, 0.34), seed=300 + i)+ g.foliage(K, rp, leaf=(3.0, 5.4), density=1.15, far=0.3, light=lt, seed=400 + i)+ g.haze(330, 470, 600, strength=0.2, seed=7)+ # a garden pine behind the wall, its flat tiers of needles+ g.pine(([(842, 430), (836, 360), (850, 290), (838, 220)], 16, 7),+ [([(840, 330), (790, 318), (752, 300)], 6, 3), ([(846, 290), (900, 270), (930, 262)], 5, 2.5),+ ([(838, 250), (812, 230), (790, 222)], 4, 2)],+ [(760, 300, 70, 26), (915, 262, 64, 24), (800, 222, 58, 22), (846, 190, 50, 22), (852, 350, 80, 30)],+ far=0.22, seed=410)++ # ------------------------------------------------------------ 3 buildings+ def glimpse(self, m):+ g = self.g+ g.fill(m, '#d9e6e2')+ g.foliage(g.crown(640, 470, 200, 90, n=8, seed=51), 'spring', leaf=(3, 6), far=0.05, light=0.18, seed=52)+ g.blossom_tree([], g.crown(690, 482, 70, 50, n=5, seed=53), 'pink', petal=(2.4, 4), light=0.15, seed=54)+ g.wall(560, 506, 730, 556, 'plaster', stains=0.2, damp=0.3, seed=55)+ g.coping(556, 734, 506, h=10, seed=56)+ yy = np.arange(H, dtype=np.float32)[:, None]+ g.fill(((yy > 553) & (yy < 580)).astype(np.float32) * np.ones((1, W), np.float32), '#cfc8b6')+ g.rock(690, 552, 13, 20, seed=57)+ for k, x in enumerate((596, 604, 611, 618)):+ g.stroke([(x, 556), (x + 2, 500), (x + 5, 456)], 2.2, 1.4, colour='#6f8f45')+ g.foliage(np.array([[600, 470, 22, 26], [612, 498, 20, 22], [596, 520, 16, 18]], np.float32), 'spring',+ leaf=(5, 8), aspect=0.28, droop=0.9, far=0.05, light=0.12, seed=58)+ g.haze(440, 580, None, colour='#f4efe0', strength=0.12, seed=59)++ def buildings(self):+ g = self.g+ # garden wall with the moon gate and a round leak window+ g.wall(358, 423, 905, 578, 'plaster', seed=60)+ g.stonework(358, 568, 905, 580, course=(12, 12), block=(40, 80), damp=0.2, seed=61)+ g.round_window(640, 515, 62, ring=7, inside=self.glimpse, ground=571, reveal=5)+ g.round_window(805, 486, 27, ring=6, pattern='ice', cell=10, back='#dfe4dc')+ g.dapple(358, 423, 905, 572, amount=0.32, scale=22, cover=0.55, falloff=(380, 380, 330), seed=65)+ g.dapple(700, 423, 905, 572, amount=0.22, scale=18, cover=0.6, falloff=(840, 380, 200), seed=66)+ g.coping(352, 910, 423, h=22, seed=62)+ # the teahouse+ g.stonework(866, 569, 1454, 607, course=(12, 13), block=(40, 90), damp=0.5, seed=63)+ yy = np.arange(H, dtype=np.float32)[:, None]; xx = np.arange(W, dtype=np.float32)[None]+ g.fill(((yy > 404) & (yy < 569) & (xx > 893) & (xx < 1427)).astype(np.float32), '#1c2522')+ for x0, x1 in ((907, 1061), (1259, 1413)):+ g.wall(x0, 524, x1, 569, 'plaster', stains=0.1, damp=0.6, seed=int(x0))+ g.stonework(x0, 561, x1, 569, course=(8, 8), block=(30, 60), seed=int(x0) + 1)+ xm = (x0 + x1) / 2+ g.lattice(x0, 446, xm, 524, 'lantern', cell=10, bar=1.9, frame=3.5, back='paper')+ g.lattice(xm, 446, x1, 524, 'lantern', cell=10, bar=1.9, frame=3.5, back='paper')+ for i in range(4):+ a = 1075 + i * 42.5+ g.lattice(a, 444, a + 42.5, 569, 'grid', cell=9, bar=1.7, frame=3.2, kind='door', seed=70 + i)+ for x0, x1 in ((907, 1061), (1075, 1245), (1259, 1413)):+ g.fretwork(x0, x1, 424, h=16, cell=7)+ g.beam(893, 1427, 408, 424)+ for x in (900, 1068, 1252, 1420):+ g.column(x, 408, 569, 13)+ g.roof(1160, 292, 398, 360, 668, upturn=50, flare=32, rows=52, courses=15, ridge_h=18, soffit=10, shadow=46, seed=64)+ g.plaque(1160, 432, 92, 28, '听雨')+ for x in (1036, 1284):+ g.lantern(x, 404, h=36, cord=12)++ # ------------------------------------------------------------ 4 the garden on the far bank+ def garden(self):+ g = self.g+ b = self.bank+ # the far bank behind the big willow, then the willow+ for i, (x, y, w, h) in enumerate(((60, 540, 200, 110), (230, 560, 180, 70))):+ g.foliage(g.crown(x, y, w, h, n=10, seed=520 + i), 'jade', leaf=(3.5, 6), far=0.18, seed=530 + i)+ trunk = ([(246, 600), (258, 530), (284, 440), (300, 360)], 36, 18)+ boughs = [([(298, 370), (240, 310), (150, 285), (40, 300)], 10, 3), ([(300, 360), (340, 305), (430, 280), (520, 305)], 10, 3),+ ([(296, 380), (210, 340), (110, 345), (10, 375)], 8, 3), ([(300, 350), (300, 295), (270, 258), (200, 250)], 8, 3),+ ([(302, 360), (380, 330), (460, 340), (500, 375)], 7, 3)]+ crown = g.crown(270, 280, 470, 150, n=14, seed=80)+ g.willow(trunk, boughs, strands=1100, length=(120, 300), ramp_='willow', leaf=(3.0, 5.2), far=0.1, sway=0.3,+ tips=590, crown=crown, gap=2.3, splay=(0.06, 0.3), crown_anchor=0.3, seed=81)+ # the far banks left of the wall and right of the teahouse: shrubs and small trees down to the water+ for i, (x, y, w, h, rp) in enumerate(((1530, 520, 220, 130, 'jade'), (1700, 505, 260, 150, 'deep'), (1880, 515, 230, 150, 'jade'),+ (1470, 560, 120, 60, 'spring'), (1800, 565, 200, 60, 'spring'))):+ g.foliage(g.crown(x, y, w, h, n=12, size=(0.2, 0.42), seed=500 + i), rp, leaf=(3.5, 6), far=0.16, seed=510 + i)+ # bank stones and low planting+ r = np.random.default_rng(90)+ for x in (372, 430, 520, 780, 840):+ g.rock(x + r.uniform(-8, 8), b[int(x)] - 6, r.uniform(16, 26), r.uniform(9, 13), seed=int(x))+ g.foliage(np.array([[400, 566, 40, 22], [455, 572, 34, 18], [530, 570, 30, 16], [770, 568, 36, 20], [845, 566, 40, 22]], np.float32),+ 'deep', leaf=(4, 7), far=0.08, seed=91)+ g.blossom_tree([], np.array([[420, 560, 26, 14], [790, 562, 22, 12]], np.float32), 'azalea', petal=(2.4, 4.0), leaves=0.3, seed=92)+ g.reeds(860, 905, lambda x: b[x.astype(int)] - 2, n=26, height=(16, 34), seed=93)+ # potted plants on the platform+ for x, col, kind in ((935, 'porcelain', 'deep'), (1232, 'terracotta', 'azalea'), (1300, 'terracotta', 'spring'), (1440, 'porcelain', 'deep')):+ rx, ry = g.pot(x, 569, 22, 18, col, band='#5a7fa8' if col == 'porcelain' else None)+ if kind == 'azalea':+ g.foliage(np.array([[rx, ry - 9, 15, 10]], np.float32), 'deep', leaf=(3, 5), seed=int(x))+ g.blossom_tree([], np.array([[rx, ry - 10, 14, 8]], np.float32), 'azalea', petal=(2, 3.4), leaves=0.2, seed=int(x) + 1)+ else:+ g.foliage(np.array([[rx - 5, ry - 10, 11, 10], [rx + 6, ry - 12, 11, 11], [rx, ry - 20, 9, 9]], np.float32), kind, leaf=(3, 6), seed=int(x))+ # steps down to the water and the white blossom tree with its bank+ g.stonework(1454, 590, 1920, 600, course=(10, 10), block=(40, 70), damp=0.4, seed=94)+ g.steps(1462, 1520, 569, n=4, rise=6.0, tread=3.4, grow=2.5, seed=95)+ g.foliage(np.array([[1560, 578, 40, 20], [1640, 582, 50, 18], [1760, 578, 46, 22], [1880, 576, 52, 24]], np.float32),+ 'deep', leaf=(4, 7), far=0.06, seed=96)+ branches = [([(1612, 598), (1606, 520), (1590, 450), (1560, 380)], 16, 6), ([(1606, 520), (1660, 450), (1720, 400)], 10, 4),+ ([(1595, 470), (1520, 420), (1480, 380)], 8, 3), ([(1590, 450), (1610, 360), (1640, 310)], 7, 3)]+ g.blossom_tree(branches, g.crown(1630, 400, 380, 250, n=16, seed=97), 'white', petal=(3.2, 5.6), density=1.0, far=0.06, seed=98)+ g.reeds(1530, 1600, lambda x: b[x.astype(int)] - 1, n=24, height=(18, 36), seed=99)+ g.dapple(1300, 560, 1520, 608, amount=0.3, scale=14, cover=0.5, falloff=(1560, 560, 260), seed=100)++ # ------------------------------------------------------------ 5 water+ def water(self):+ g = self.g+ b = self.bank+ src = g.C.copy()+ g.lake(int(b.min()) - 2, H, bank=b, seed=110)+ g.reflect(b, strength=0.82, blur=(2.0, 8.0), ripple=2.4, src=src, seed=111)+ g.ripples((0, int(b.min()), W, H), n=900, light='#dcebe6', dark='#2f6358', alpha=0.28, seed=112)++ # ------------------------------------------------------------ 6 bridge and boat+ def bridge_boat(self):+ g = self.g+ g.bridge(BRIDGE, width=1.5, deck=0.32, rail=0.5, post=1.9, reflection=True, rails='rear', seed=120)+ before = g.layer()+ g.bridge(BRIDGE, width=1.5, deck=0.32, rail=0.5, post=1.9, rails='rear', seed=121)+ on_bridge = (np.abs(g.C - before).max(-1) > 0.01).astype(np.float32)+ g.dapple(0, 560, 560, 760, amount=0.3, scale=16, cover=0.55, falloff=(220, 560, 400), mask=on_bridge, seed=124)+ before = g.layer()+ g.boat(1478, 1748, 629, h=22, seed=122)+ g.reflect_layer(before, 629, (1460, 560, 1770, 629), strength=0.7, seed=123)+ g.stroke([(1488, 612), (1500, 596), (1506, 588)], 1.4, 1.2, colour='#6b5a40')++ # ------------------------------------------------------------ 7 lily pads, lotus, egrets+ def pads_egrets(self):+ g = self.g+ r = np.random.default_rng(130)+ pads = []+ for cx_, cz, n in ((0.6, 8.6, 16), (2.6, 9.6, 13), (3.9, 8.0, 9), (-0.9, 11.2, 8), (1.6, 12.6, 7), (4.4, 11.6, 6)):+ for _ in range(n):+ pads.append((cx_ + r.normal(0, 0.55), cz + r.normal(0, 0.8), r.uniform(0.12, 0.27)))+ flowers = [(0.2, 9.0, 0.22), (1.6, 8.0, 0.26), (2.9, 10.5, 0.2), (3.8, 8.6, 0.24), (-0.8, 11.5, 0.18), (1.0, 12.4, 0.17)]+ g.lily_pads(pads, flowers=flowers, seed=131)+ # an egret on a stepping stone, and one skimming the water+ x, y = g.project(3.2, 0.0, 15.0)+ g.rock(float(x), float(y) - 4, 22, 9, seed=132)+ before = g.layer()+ g.egret(float(x) - 2, float(y) - 9, s=78, pose='stand', facing=-1, seed=133)+ g.reflect_layer(before, float(y) - 2, (x - 60, y - 100, x + 60, y - 2), strength=0.6, seed=134)+ g.egret(770, 300, s=58, pose='fly', facing=1, seed=135)+ g.petals((300, 640, 1500, 1060), n=160, kind='white', size=(2.5, 4.5), water=True, seed=136)++ # ------------------------------------------------------------ 8 foreground foliage+ def foreground(self):+ g = self.g+ K = np.array([[60, 980, 160, 110], [250, 1010, 170, 100], [430, 1040, 140, 90], [-20, 880, 120, 140],+ [140, 900, 120, 90], [330, 950, 120, 80], [560, 1070, 120, 60]], np.float32)+ g.foliage(K, 'deep', leaf=(10, 18), density=1.0, droop=0.3, veins=True, seed=140)+ g.blossom_tree([], np.array([[150, 905, 70, 40], [300, 960, 60, 34], [40, 860, 50, 40]], np.float32), 'white',+ petal=(4, 6.5), density=0.8, leaves=0.25, gaps=0.5, seed=143)+ g.reeds(380, 660, lambda x: 1084 - 0.0 * x, n=34, height=(70, 170), ramp_='deep', lean=0.32, width=0.07, seed=144)+ K2 = np.array([[1660, 900, 130, 110], [1820, 860, 140, 140], [1960, 940, 140, 160], [1560, 1000, 140, 100],+ [1760, 1010, 160, 100], [1920, 1050, 120, 80]], np.float32)+ g.foliage(K2, 'deep', leaf=(10, 18), density=1.0, droop=0.3, veins=True, seed=141)+ g.blossom_tree([], np.array([[1700, 880, 90, 60], [1830, 830, 100, 70], [1640, 960, 80, 50], [1880, 940, 90, 70]], np.float32),+ 'pink', petal=(5, 9), density=0.9, leaves=0.2, seed=142)++ # ------------------------------------------------------------ 9 the hanging frame+ def frame(self):+ g = self.g+ boughs = [([(-60, -40), (80, -24), (220, -20), (360, -44)], 10, 4), ([(-60, -30), (40, -16), (140, -22)], 7, 3)]+ g.willow(None, boughs, strands=34, length=(240, 660), ramp_='willow', leaf=(12, 19), far=0.0, sway=0.2,+ light=-0.2, gap=6.5, stem=1.3, bundle=(1, 3), spread=14, splay=(0.18, 0.5), aspect=0.22, seed=150)+ g.blossom_branch([(1960, 150), (1820, 110), (1660, 140), (1520, 100), (1360, 128), (1250, 112)], 20, 4, 'pink', flowers=120,+ spread=32, size=(14, 23), twigs=9, seed=151)+ g.blossom_branch([(1940, -20), (1840, 40), (1760, 30)], 10, 3, 'pink', flowers=26, spread=24, size=(13, 19), seed=152)+ g.petals((1000, 0, 1920, 760), n=80, kind='pink', size=(4, 8), seed=153)++ def details(self):+ g = self.g+ g.seal(1858, 990, 24, 44, '春水')+ g.grain(1.0)+++PHASES = ('sky_hills', 'far_trees', 'buildings', 'garden', 'water', 'bridge_boat', 'pads_egrets', 'foreground', 'frame')+++def main():+ out = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith('--') else 'jiangnan_spring_water.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('JN_TIMING') else (lambda n: None)+ g = JiangnanGarden(W, H, seed=8, keep_stages=bool(stages), stages_dir=stages)+ g.camera(horizon=450, eye=3.0, focal=1400)+ sc = Garden(g)+ for ph in PHASES:+ getattr(sc, ph)()+ tick(ph)+ g.stage(ph)+ sc.details()+ g.save(out, stages_dir=stages)+ tick('saved')+ print('saved', out)+++if __name__ == '__main__':+ main()diff --git a/lib/jiangnan.py b/lib/jiangnan.pynew file mode 100644index 0000000..9a09bef--- /dev/null+++ b/lib/jiangnan.py@@ -0,0 +1,1924 @@+"""jiangnan — 江南园林 / Jiangnan Garden: a lush, finely painted spring garden illustration (numpy + Pillow only).++The look: a contemporary digital-gouache illustration of a Chinese water garden in spring. Dark grey tiled roofs+with upturned eaves, whitewashed or coral walls, jade-green lattice, red lanterns, stone steps and balustrades; and+above all plants -- trees built from thousands of small leaf-shaped dabs, blossom trees of white and pale pink+clusters, weeping willows that are curtains of fine hanging strands -- over a still jade lake that mirrors them,+with hazy blue-green hills behind and a foreground of branches framing the view. Nothing here is a filter on flat+shapes: every coloured pixel is laid by a dab, a stroke or a modelled surface, in the order a painter works.++Physical model+ order The picture is painted back to front, as a landscape painter does: sky, far hills, haze, distant tree+ lines, the trees behind the buildings, the buildings, the garden in front of them, the water (which can+ only be painted once everything it mirrors exists), things on the water, and last the foreground+ branches that frame the view. Opaque paint covers what is under it, so the order is the occlusion.+ atmosphere Air between the eye and a distant thing scatters a pale blue-green veil over it: the further away, the+ more its colours move toward the haze colour and the less contrast it has (`far` in 0..1 on every+ painting call). Between depth planes `haze()` lays a soft veil band, strongest where the ground meets+ the hills, so each plane separates from the one behind it.+ dabs The unit of paint is a dab: a small opaque polygon (a pointed leaf, a rounded petal, a sword blade, a+ soft round) with its own size, angle and colour. Thousands of dabs are rasterised in one go: Pillow+ fills each polygon with its own integer id into a 2x supersampled id map (painter's order = id order,+ later dabs cover earlier ones), numpy looks every id up in a colour/alpha table and box-averages back+ to 1x, so every edge is anti-aliased and a dab costs well under a microsecond. Inside the paint a fine+ fixed canvas-tooth texture varies the value by a few percent.+ light One sun from the upper left and a little in front (LIGHT). A foliage mass is a set of clumps (ellipses;+ later clumps are in front). Each dab asks which clump it sits on (the front-most one that contains it)+ and treats that clump as a dome: its normal gives a diffuse term, lower parts of the mass are darker+ (occlusion), and a low-frequency noise breaks it up. That 0..1 value picks the dab's colour from a ramp+ of mixed greens (deep blue-green core -> mid green -> yellow-green -> pale sunlit green).+ foliage A tree is painted the way a gouache painter builds it: a dark underpaint (the clump cores, then big+ dark leaf dabs, so even the underpaint has a leafy edge), a body of mid-dark leaf dabs everywhere, leaves+ breaking out across the silhouette, then the light: dabs gathered in small clusters (5-14 leaves around+ a centre) where the light value is high, so each clump gets a sunny upper-left rim and a dark core, and+ finally a sprinkle of the palest dabs on the very top. Leaves point outward from their clump and droop a+ little; `veins` adds a pale midrib to the lit leaves of near shrubs. A pine is a crooked trunk with flat+ tiers of needle pads (the same model with needle-thin dabs and little droop).+ blossom A blossom tree is a few dark branches, an underpaint of shadowed petals and dark green leaves (dabs, not+ a flat blob), twigs, a few young green leaves, then hundreds of small clusters of round petal dabs; clusters are sorted dark to light, so the+ sunlit ones lie on top of the shaded ones, and inside each cluster the petals facing the sun are paler+ -- the clustered highlights of a blooming crown, with branches showing through the gaps.+ `blossom_branch()` paints a near branch with individual five-petal flowers, buds and young leaves.+ willow A weeping willow is a trunk, a few arching boughs hidden under a domed crown of drooping leaves, and+ many hundred hanging strands gathered in tresses (a few strands from nearly the same point, with gaps+ between tresses). A strand leaves its bough or the crown, arches out briefly and hangs down with a+ little sway; it is a hair-thin stem with small narrow leaves along it, on random sides, splayed a little+ from the stem and angled down. Strands are painted back (darker, bluer) to front (lighter,+ yellower), the lit side of the crown is brighter and the tips carry the new growth, so it reads as a+ curtain of separate strands with gaps, not a green sheet.+ roof A hip-and-gable roof seen from the front is a surface S(u, v): u across (-1..1), v from the ridge (0) to+ the eave (1). The slope is concave (steep at the ridge, flatter and foreshortened at the eave), it widens+ toward the eave, the corners flare outward and the eave curve rises sharply at both ends (upturned+ corners). The surface is rasterised as a mesh of small quads into an id map, and every pixel's exact+ (u, v) is recovered with two Newton steps on the mesh, so the tiles can be shaded analytically: rows of+ half-round roll tiles (lit on their left flank, dark seam beside them) alternate with concave pan+ tiles, every course has a bright lip and a shadow below it, every tile has its own small value jitter.+ Round tile ends and drip tiles line the eave; under it the underside (soffit) with rafter ends and a+ soft shadow fall on the facade; a ridge with openwork and curled ends crowns it and hip ridges run down+ to the flying corner tips.+ buildings Plaster walls are flat paint with low-frequency mottling, rain stains from the coping, a damp,+ greener base and a layer of faint brush marks. Sunlight falling through leaves leaves dappled shade on+ a sunlit surface (`dapple()`: a thresholded noise of soft cool patches, strongest near the tree that+ casts it). Lattice (grid, lantern-frame or cracked-ice pattern) is drawn as a bar mask at 3x, lit on+ its upper-left edges, shadowed on its lower-right ones, and casts a small shadow on the dark interior+ or on the paper behind it. Columns are lacquered cylinders on stone bases; lanterns are ribbed red+ ellipsoids with gold caps and tassels; plaques are framed boards with gilded characters; steps, the+ platform and the bridge are stone blocks with joints, each block with its own value. The zigzag bridge+ is real geometry: segments, slabs, piers, posts, pierced panels and rails are projected through a+ pinhole camera (`camera()`, `project()`), every face shaded by its normal and culled when it faces+ away; a rear-only balustrade keeps the deck visible from a low eye.+ water The lake is a jade body colour, paler where it reflects the far sky. A reflection is the canvas above+ the bank mirrored about the bank line, pulled sideways by small ripples, blurred vertically (more with+ distance from the bank), darkened and mixed with the body colour (more toward the viewer, as Fresnel+ says), so it matches what stands above it, only softer and darker. Things standing in the water (the+ bridge, a boat, an egret) get their own reflection: the bridge by projecting its geometry with heights+ negated, the others by mirroring their own painted layer about their waterline. Then horizontal brush+ marks sampled from the water as painted, faint ripple lines (pale where they catch the sky, dark where+ they catch the bank) and a fine vertical streak texture. Lily pads lie on the water plane through the+ camera (ellipses foreshortened by eye height / distance) with a notch, veins, a lit far rim, a shaded+ near half and a soft shadow.+ finish `grain()`: a slight painterly softness, a soft glow around the lights (spring haze), shadows nudged+ toward a cool blue-green, a fine grain, the faintest canvas weave and vertical streak; `seal()`: a small+ red seal with white characters, its edge worn.++API (canvas pixel coordinates; colours are names in PAINTS / RAMPS or '#rrggbb'; `far` 0 near .. 1 very far)+ surface JiangnanGarden(W, H, seed, keep_stages, stages_dir); camera(horizon, eye, focal, cx); project(X, Y, Z);+ ground_y(Z); depth_at(y); px_per_m(Z); clipped(mask) context+ low level dabs(xs, ys, length, width, colours, angle, shape, alpha, far); stroke(path, w0, w1, colour);+ fill(mask, colour, alpha); poly(pts) / ellipse(cx, cy, rx, ry) masks; crown(cx, cy, w, h, n) -> clumps+ air sky(top, bottom, y1, clouds); hills(ridge, base, colour, far); haze(y0, y1, y2, colour, strength)+ plants foliage(clumps, ramp, leaf, density, far, light, droop, veins); blossom_tree(branches, clumps, kind,+ petal, far); blossom_branch(path, w0, w1, kind, flowers); willow(trunk, boughs, strands, length, ramp,+ leaf, far, crown, tips); pine(trunk, limbs, pads); branch(path, w0, w1); reeds(x0, x1, y, n, height);+ petals(region, n, kind, water); rock(cx, cy, rx, ry); pot(x, y, w, h, colour)+ buildings wall(x0, y0, x1, y1, colour); dapple(x0, y0, x1, y1, amount, falloff, mask); roof(cx, y_ridge, y_eave,+ ridge_w, eave_w, upturn, flare); coping(x0, x1, y, h); column(x, y0, y1, w); beam(x0, x1, y0, y1);+ lattice(x0, y0, x1, y1, pattern, kind, back); fretwork(x0, x1, y0, h); round_window(cx, cy, r, ring,+ pattern | inside, ground);+ stonework(x0, y0, x1, y1); steps(x0, x1, y, n, rise, tread); bridge(path, width, deck, rail,+ reflection, rails); lantern(x, y, h); plaque(cx, cy, w, h, text)+ water lake(y0, y1, far_colour, near_colour, bank); reflect(bank, strength, blur, ripple, src); layer() ++ reflect_layer(before, axis, box); ripples(box, n, brush); lily_pads(pads, flowers); lotus(x, y, s);+ boat(x0, x1, y, h); egret(x, y, s, pose)+ finish seal(x, y, w, h, text); grain(amount); render(); composite(); stage(name); save(path, stages_dir)++ import sys; sys.path.insert(0, 'lib')+ from jiangnan import JiangnanGarden+ g = JiangnanGarden(1920, 1080, seed=3)+ g.camera(horizon=450, eye=3.0, focal=1400)+ g.sky(); g.hills([(0, 300), (500, 220), (1100, 280), (1920, 240)], base=520, far=0.8)+ g.foliage(g.crown(600, 380, 420, 220, n=14), 'jade', leaf=(4, 7), far=0.3)+ g.roof(960, 300, 400, 360, 640, upturn=44, flare=26)+ g.lake(600, 1080, bank=600); g.reflect(600)+ g.seal(1840, 980, 26, 46, '春水'); g.grain(); g.save('garden.jpg')+"""+import io+import os+from contextlib import contextmanager+import numpy as np+from PIL import Image, ImageDraw, ImageFilter, ImageFont+from core import blur, fbm1d, spline, noise2d, smoothstep, blob_pts, cjk_font+++PAINTS = {+ 'sky': '#7fa6c2', 'sky_low': '#cbdcd8', 'haze': '#b7cbc5', 'cloud': '#f3f4ef',+ 'plaster': '#efebe2', 'coral': '#d8695b', 'jade': '#3f8b73', 'jade_dark': '#1f5244', 'jade_light': '#86c3a8',+ 'lacquer': '#a3402f', 'beam': '#5b3128', 'interior': '#1d2a27', 'paper': '#e8e1cc',+ 'stone': '#bdb9ab', 'tile': '#46524f', 'board': '#2c2620', 'gold': '#d9b45c', 'wood': '#6e5038',+ 'lantern': '#d63a2a', 'seal': '#b9312a', 'bark': '#3f332e', 'bark_light': '#8c7c6c',+ 'water': '#5c9d8c', 'water_deep': '#2e6c60', 'water_far': '#94c0b3',+ 'terracotta': '#b8663f', 'porcelain': '#dfe6e6', 'egret': '#f6f5f0',+}++RAMPS = {+ 'spring': ['#18302a', '#284a36', '#3f6a3c', '#638a43', '#97b45a', '#cbd98e'],+ 'jade': ['#11262a', '#1b3c3a', '#2a594c', '#467a59', '#759f6e', '#adc795'],+ 'deep': ['#0b1d1a', '#13302a', '#1f4b37', '#3a7041', '#6f9c56', '#aac884'],+ 'olive': ['#25301e', '#3a4829', '#566834', '#7c8f46', '#a8b664', '#d0d897'],+ 'willow': ['#1b372d', '#2e512f', '#4a6f33', '#6f9240', '#9cb75e', '#cbd996'],+ 'far': ['#4c6e69', '#5f8078', '#759384', '#8ea891', '#a9bea4', '#c6d4bc'],+ 'white': ['#7d8584', '#a6a8ab', '#cbc6ca', '#e8e1e0', '#f8f3ee', '#fffefa'],+ 'pink': ['#9a4d68', '#bd6c88', '#dc93a8', '#efb6c3', '#f8d4db', '#fff0f1'],+ 'azalea': ['#7a2a45', '#a73d5f', '#cf5d80', '#e886a2', '#f5b0c3', '#fdd9e2'],+ 'tile': ['#20272b', '#323d42', '#4a5759', '#6b7a79', '#95a3a0', '#bfcac6'],+ 'stone': ['#5d5c55', '#7d7c72', '#9d9b8f', '#bdbaad', '#d7d4c7', '#ecebe0'],+ 'rock': ['#4f5552', '#6c716c', '#8b8f88', '#aaada4', '#c8cac0', '#e3e4da'],+ 'pad': ['#1c3a33', '#2b5440', '#3f6f46', '#5f8c4c', '#8fae62', '#c0d18e'],+}+LIGHT = (-0.52, -0.62, 0.58) # toward the sun: left, up (screen y is down) and toward the viewer++_LEAF = np.array([(1, 0), (0.62, 0.36), (0.15, 0.5), (-0.35, 0.44), (-0.78, 0.24), (-1, 0), (-0.78, -0.24),+ (-0.35, -0.44), (0.15, -0.5), (0.62, -0.36)], np.float32)+_t = np.linspace(0, 2 * np.pi, 10, endpoint=False)+_ROUND = np.stack([np.cos(_t), 0.5 * np.sin(_t)], 1).astype(np.float32)+_BLADE = np.array([(1, 0), (0.55, 0.36), (-0.2, 0.5), (-0.8, 0.42), (-1, 0.15), (-1, -0.15), (-0.8, -0.42),+ (-0.2, -0.5), (0.55, -0.36)], np.float32)+_t = np.linspace(0, 2 * np.pi, 7, endpoint=False)+_DOT = np.stack([np.cos(_t), 0.5 * np.sin(_t)], 1).astype(np.float32)+SHAPES = {'leaf': _LEAF, 'round': _ROUND, 'blade': _BLADE, 'dot': _DOT}+++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(spec):+ """a RAMPS name or a list of colours -> (K, 3) array, dark -> light"""+ if isinstance(spec, np.ndarray): return spec.astype(np.float32)+ if isinstance(spec, str): spec = RAMPS[spec]+ return np.stack([hexc(c) for c in spec]).astype(np.float32)+++def ramp_at(R, l):+ """colour at 0..1 positions l along ramp R (vectorised)"""+ l = np.clip(np.asarray(l, np.float32), 0, 1) * (len(R) - 1)+ i = np.minimum(l.astype(np.int32), len(R) - 2)+ f = (l - i)[..., None]+ return R[i] * (1 - f) + R[i + 1] * f+++def _blur1(a, sigma, axis):+ """gaussian-ish blur along one axis (3 box passes via cumulative sums)"""+ if sigma <= 0.3: return a.astype(np.float32)+ w = int(np.sqrt(12 * sigma * sigma / 3 + 1)); w += (w % 2 == 0); r = w // 2+ out = a.astype(np.float32)+ for _ in range(3):+ pad = [(0, 0)] * out.ndim; pad[axis] = (r + 1, r)+ c = np.cumsum(np.pad(out, pad, mode='edge'), axis=axis, dtype=np.float64)+ n = c.shape[axis]+ out = ((np.take(c, np.arange(w, n), axis=axis) - np.take(c, np.arange(0, n - w), axis=axis)) / w).astype(np.float32)+ return out+++def _tube(path, w0, w1=None, per=6, wob=0.0, seed=0):+ """outline polygon of a thick path (width w0 at the start -> w1 at the end)"""+ P = np.asarray(path, np.float32)+ Q = spline(P, per) if len(P) > 2 else np.stack([np.linspace(P[0, 0], P[-1, 0], 8), np.linspace(P[0, 1], P[-1, 1], 8)], 1)+ 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+ if wob: hw = hw * (1 + wob * fbm1d(len(Q), 12, 3, seed)[:, None])+ L, R = Q + nrm * hw, Q - nrm * hw+ tip = [Q[-1] + d[-1] * hw[-1, 0] * 0.6]+ base = [Q[0] - d[0] * hw[0, 0] * 0.4]+ return np.vstack([L, tip, R[::-1], base]).astype(np.float32), Q, nrm+++class JiangnanGarden:+ PAINTS = PAINTS+ RAMPS = RAMPS+ 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('sky_low')+ r = np.random.default_rng(seed + 11)+ t = blur(r.random((H, W)).astype(np.float32), 0.6)+ self.TX = ((t - t.mean()) / (t.std() + 1e-6)).astype(np.float32) # canvas tooth inside the paint+ self.N1 = noise2d(H, W, 46, 3, seed + 12) # light breakup for masses+ L = np.asarray(LIGHT, np.float32); self.L = L / np.linalg.norm(L)+ self.haze_col = hexc('haze')+ self._clip = None+ self.grain_amt = 0.0+ self.camera()++ def _r(self, seed=None):+ return np.random.default_rng(int(self.rng.integers(1 << 30)) if seed is None else seed)++ # ================================================================== camera (for things on the water plane)+ def camera(self, horizon=450.0, eye=3.0, focal=1400.0, cx=None):+ """pinhole camera over the lake: eye height in metres, horizon row, focal length in px"""+ self.cam = (float(horizon), float(eye), float(focal), float(self.W / 2 if cx is None else cx))++ def project(self, X, Y, Z):+ """world metres (X right, Y up from the water, Z away from the eye) -> canvas px"""+ hz, e, f, cx = self.cam+ X, Y, Z = (np.asarray(v, np.float32) for v in (X, Y, Z))+ return cx + f * X / Z, hz + f * (e - Y) / Z++ def ground_y(self, Z):+ hz, e, f, _ = self.cam+ return hz + f * e / np.asarray(Z, np.float32)++ def depth_at(self, y):+ hz, e, f, _ = self.cam+ return f * e / np.maximum(np.asarray(y, np.float32) - hz, 1e-3)++ def px_per_m(self, Z):+ return self.cam[2] / np.asarray(Z, np.float32)++ # ================================================================== the dab rasteriser+ @contextmanager+ def clipped(self, mask):+ """paint only inside mask (e.g. the view through a moon gate)"""+ old = self._clip+ self._clip = mask if old is None else mask * old+ try: yield+ finally: self._clip = old++ def _far(self, cols, far):+ if not far: return cols+ a = 0.82 * float(np.clip(far, 0, 1)) ** 0.9+ lum = cols.mean(-1, keepdims=True)+ c = lum + (cols - lum) * (1 - 0.35 * far)+ return c * (1 - a) + self.haze_col * a++ def _paint(self, groups, ss=2, tex=0.04):+ """rasterise groups of polygons in order: [(P, colours, alpha), ...]; P is (N, k, 2) or a list of (k, 2)"""+ groups = [g for g in groups if g is not None and len(g[0])]+ if not groups: return+ lo = np.array([1e9, 1e9]); hi = np.array([-1e9, -1e9])+ for P, _, _ in groups:+ if isinstance(P, np.ndarray):+ lo = np.minimum(lo, P.reshape(-1, 2).min(0)); hi = np.maximum(hi, P.reshape(-1, 2).max(0))+ else:+ for p in P:+ lo = np.minimum(lo, np.min(p, 0)); hi = np.maximum(hi, np.max(p, 0))+ x0, y0 = max(0, int(np.floor(lo[0])) - 1), max(0, int(np.floor(lo[1])) - 1)+ x1, y1 = min(self.W, int(np.ceil(hi[0])) + 2), min(self.H, int(np.ceil(hi[1])) + 2)+ if x1 <= x0 or y1 <= y0: return+ w, h = x1 - x0, y1 - y0+ im = Image.new('I', (w * ss, h * ss), 0)+ d = ImageDraw.Draw(im)+ cols_all, alph_all = [np.zeros((1, 3), np.float32)], [np.zeros(1, np.float32)]+ idx = 1+ off = np.array([x0, y0], np.float32)+ for P, cols, alpha in groups:+ if isinstance(P, np.ndarray):+ Q = ((P - off) * ss).reshape(len(P), -1).tolist()+ else:+ Q = [((np.asarray(p, np.float32) - off) * ss).ravel().tolist() for p in P]+ n = len(Q)+ for q in Q:+ if len(q) >= 6: d.polygon(q, fill=idx)+ idx += 1+ cols_all.append(np.broadcast_to(np.asarray(cols, np.float32), (n, 3)))+ alph_all.append(np.broadcast_to(np.asarray(alpha, np.float32), (n,)))+ cols = np.concatenate(cols_all); alph = np.concatenate(alph_all)+ pal = np.empty((idx, 4), np.float32)+ pal[:, :3] = np.clip(cols, 0, 1) * alph[:, None]; pal[:, 3] = alph+ ids = np.asarray(im)+ Cs = self.C[y0:y1, x0:x1]+ for r0 in range(0, h, 200):+ r1 = min(h, r0 + 200)+ look = pal[ids[r0 * ss:r1 * ss]].reshape(r1 - r0, ss, w, ss, 4).mean((1, 3))+ A = look[..., 3]; Pm = look[..., :3]+ if self._clip is not None:+ f = self._clip[y0 + r0:y0 + r1, x0:x1]; A = A * f; Pm = Pm * f[..., None]+ if tex: Pm = Pm * (1 + tex * self.TX[y0 + r0:y0 + r1, x0:x1, None])+ Cs[r0:r1] = Cs[r0:r1] * (1 - A[..., None]) + Pm++ def _shapes(self, xs, ys, length, width, angle, shape='leaf', jitter=0.08, r=None):+ """(N, k, 2) polygons of dabs"""+ r = r if r is not None else self._r()+ T = SHAPES[shape] if isinstance(shape, str) else np.asarray(shape, np.float32)+ n = len(xs)+ Lh = np.broadcast_to(np.asarray(length, np.float32), (n,))[:, None] / 2+ Wd = np.broadcast_to(np.asarray(width, np.float32), (n,))[:, None]+ a = np.broadcast_to(np.asarray(angle, np.float32), (n,))[:, None]+ jit = 1 + jitter * r.normal(0, 1, (n, len(T))).astype(np.float32)+ lx = T[None, :, 0] * Lh * jit; ly = T[None, :, 1] * Wd * jit+ c, s = np.cos(a), np.sin(a)+ P = np.empty((n, len(T), 2), np.float32)+ P[..., 0] = np.asarray(xs, np.float32)[:, None] + lx * c - ly * s+ P[..., 1] = np.asarray(ys, np.float32)[:, None] + lx * s + ly * c+ return P++ def dabs(self, xs, ys, length, width, colours, angle=0.0, shape='leaf', alpha=1.0, far=0.0, ss=2, tex=0.04, seed=None):+ """paint many dabs at once (angles in radians)"""+ cols = self._far(np.broadcast_to(np.asarray(colours, np.float32), (len(xs), 3)).copy(), far)+ self._paint([(self._shapes(xs, ys, length, width, angle, shape, r=self._r(seed)), cols, alpha)], ss, tex)++ def stroke(self, path, w0, w1=None, colour='bark', alpha=1.0, far=0.0, wob=0.0, ss=2):+ """one tapered stroke along a path"""+ P, _, _ = _tube(path, w0, w1, wob=wob, seed=int(self.rng.integers(1 << 30)))+ self._paint([([P], self._far(hexc(colour)[None], far), alpha)], ss)++ def fill(self, mask, colour, alpha=1.0, sl=None):+ """flat paint through a float mask (full canvas, or the region sl)"""+ sl = sl or (slice(None), slice(None))+ A = mask[sl] * alpha if mask.shape[:2] == self.C.shape[:2] else mask * alpha+ if self._clip is not None: A = A * self._clip[sl]+ Cs = self.C[sl]+ col = np.asarray(colour, np.float32) if np.ndim(colour) == 3 else hexc(colour)+ Cs += (col - Cs) * A[..., None]++ def poly(self, pts, ss=2):+ im = Image.new('L', (self.W * ss, self.H * ss), 0)+ ImageDraw.Draw(im).polygon([(float(x) * ss, float(y) * ss) for x, y in pts], fill=255)+ if ss > 1: im = im.resize((self.W, self.H), Image.BOX)+ return np.asarray(im, np.float32) / 255++ def ellipse(self, cx, cy, rx, ry=None):+ ry = rx if ry is None else ry+ yy = np.arange(self.H, dtype=np.float32)[:, None]; xx = np.arange(self.W, dtype=np.float32)[None, :]+ dd = np.sqrt(((xx - cx) / rx) ** 2 + ((yy - cy) / ry) ** 2)+ e = 1.0 / max(1.5, min(rx, ry))+ return smoothstep(1 + e, 1 - e, dd).astype(np.float32)++ # ================================================================== sky, hills, haze+ def sky(self, top='sky', bottom='sky_low', y1=None, clouds=0.5, seed=None):+ """soft spring sky: a slightly desaturated blue going pale toward the horizon, thin clouds, broad soft dabs"""+ r = self._r(seed)+ y1 = self.H * 0.5 if y1 is None else y1+ yy = np.arange(self.H, dtype=np.float32)+ t = smoothstep(-0.1 * y1, y1, yy) ** 0.85+ col = hexc(top)[None] * (1 - t[:, None]) + hexc(bottom)[None] * t[:, None]+ self.C[:] = col[:, None, :]+ if clouds:+ n = noise2d(self.H, self.W, 260, 4, int(r.integers(1 << 30)))+ n2 = noise2d(self.H, self.W, 60, 3, int(r.integers(1 << 30)))+ band = smoothstep(0.0, 0.25 * y1, yy)[:, None] * (1 - smoothstep(0.75 * y1, 1.05 * y1, yy))[:, None]+ a = smoothstep(0.52, 0.82, n * 0.85 + n2 * 0.15) * band * clouds+ self.fill(a, 'cloud', 0.7)+ self.fill(smoothstep(0.62, 0.9, n) * band * clouds, mix('cloud', '#c9cfd8', 0.6), 0.25)+ k = 380+ xs = r.uniform(-60, self.W + 60, k); ys = r.uniform(-40, y1 * 1.1, k)+ tt = np.clip(smoothstep(-0.1 * y1, y1, ys) ** 0.85, 0, 1)[:, None]+ cc = hexc(top)[None] * (1 - tt) + hexc(bottom)[None] * tt + r.normal(0, 0.012, (k, 3))+ L = r.uniform(80, 220, k)+ self.dabs(xs, ys, L, L * r.uniform(0.25, 0.45, k), cc, r.normal(0, 0.12, k), 'round', alpha=0.22, ss=1, tex=0.02)++ def hills(self, ridge, base=None, colour='#7f9f98', far=0.7, trees=1.0, light=0.0, seed=None):+ """a hazy range: filled ridge, slopes shaded by an embossed noise, a tree-bumped silhouette and tiny dabs"""+ r = self._r(seed)+ Q = spline(np.asarray(ridge, np.float32), 24)+ base = self.H if base is None else base+ pts = np.vstack([Q, [(Q[-1, 0], base), (Q[0, 0], base)]])+ m = self.poly(pts)+ y0 = int(max(0, Q[:, 1].min() - 12)); sl = (slice(y0, int(base)), slice(None))+ h = int(base) - y0+ n = noise2d(h, self.W, 70, 4, int(r.integers(1 << 30)))+ emb = (np.roll(n, 3, 1) - np.roll(n, -3, 1)) * 0.8 + (np.roll(n, 3, 0) - np.roll(n, -3, 0)) * 0.6+ yy = np.arange(y0, base, dtype=np.float32)[:, None]+ ridge_y = np.interp(np.arange(self.W), Q[:, 0], Q[:, 1])[None]+ depth = np.clip((yy - ridge_y) / max(1.0, h * 0.8), 0, 1)+ sh = np.clip(0.5 + 2.2 * emb + light - 0.25 * depth, 0, 1)+ base_c = hexc(colour)+ dark, lite = base_c * 0.82, mix(base_c, '#e8eee2', 0.22)+ col = dark * (1 - sh[..., None]) + lite * sh[..., None]+ col = col * (1 - depth[..., None] * 0.35) + self.haze_col * depth[..., None] * 0.35+ col = self._far(col, far)+ A = m[sl] * smoothstep(base, base - 60, yy)+ if self._clip is not None: A = A * self._clip[sl]+ self.C[sl] += (col - self.C[sl]) * A[..., None]+ if trees:+ k = int(len(Q) * 1.6 * trees)+ i = r.integers(0, len(Q), k)+ xs = Q[i, 0] + r.normal(0, 2, k); ys = Q[i, 1] + r.uniform(-3, 7, k)+ s = r.uniform(4, 11, k) * (0.6 + 0.6 * (1 - far))+ cc = self._far(np.repeat(mix(base_c, '#e8eee2', 0.05)[None], k, 0) * r.uniform(0.86, 1.04, (k, 1)), far)+ self._paint([(self._shapes(xs, ys, s, s * 0.8, 0, 'round', 0.15, r), cc, 0.95)], 2, 0.02)+ k = int(h * self.W / 90 * trees)+ xs = r.uniform(0, self.W, k); ys = r.uniform(y0, base, k)+ inside = m[ys.astype(int).clip(0, self.H - 1), xs.astype(int).clip(0, self.W - 1)] > 0.5+ xs, ys = xs[inside], ys[inside]+ if len(xs):+ iy = (ys - y0).astype(int).clip(0, h - 1); ix = xs.astype(int).clip(0, self.W - 1)+ c = col[iy, ix] * r.uniform(0.94, 1.05, (len(xs), 1))+ s = r.uniform(3, 7, len(xs)) * (0.6 + 0.6 * (1 - far))+ self._paint([(self._shapes(xs, ys, s, s * 0.8, 0, 'round', 0.15, r), c, 0.8)], 2, 0.02)+ return m++ def haze(self, y0, y1, y2=None, colour='haze', strength=0.6, mask=None, seed=None):+ """a veil of air: rising from 0 at y0 to `strength` at y1, fading out again by y2 (if given)"""+ r = self._r(seed)+ a0, a1 = int(max(0, y0)), int(min(self.H, y2 if y2 is not None else self.H))+ yy = np.arange(a0, a1, dtype=np.float32)[:, None]+ a = smoothstep(y0, y1, yy)+ if y2 is not None: a = a * (1 - smoothstep(y1, y2, yy))+ n = noise2d(a1 - a0, self.W, 160, 3, int(r.integers(1 << 30)))+ a = a * strength * (0.75 + 0.5 * n)+ if mask is not None: a = a * mask[a0:a1]+ if self._clip is not None: a = a * self._clip[a0:a1]+ Cs = self.C[a0:a1]+ Cs += (hexc(colour) - Cs) * a[..., None]++ # ================================================================== plants+ def crown(self, cx, cy, w, h, n=12, size=(0.26, 0.46), seed=None, flat=0.85):+ """clumps (cx, cy, rx, ry) filling an ellipse, sorted so the lower ones are in front"""+ r = self._r(seed)+ out = [(cx, cy + h * 0.05, w * 0.3, h * 0.32)]+ for i in range(n):+ s = r.uniform(*size) * (0.75 if i > n * 0.6 else 1.0)+ a = r.uniform(0, 2 * np.pi)+ d = (0.35 + 0.65 * np.sqrt(r.uniform(0, 1))) * (1 - s * 0.75)+ x = cx + np.cos(a) * d * w / 2; y = cy + np.sin(a) * d * h / 2 * (0.8 if np.sin(a) > 0 else 1.0)+ rx = s * w / 2; out.append((x, y, rx, rx * r.uniform(flat - 0.15, flat + 0.05)))+ out = np.array(out, np.float32)+ return out[np.argsort(out[:, 1] + r.normal(0, h * 0.06, len(out)))]++ def _lit(self, x, y, K, light=None):+ """light value 0..1 of points on a clumped mass, the owning clump and the normalised radius on it"""+ Lv = self.L if light is None else light+ n = len(x)+ dif = np.empty(n, np.float32); own = np.empty(n, np.int32); dd = np.empty(n, np.float32)+ dmin = np.empty(n, np.float32)+ for a in range(0, n, 20000):+ b = min(n, a + 20000)+ qx = (x[a:b, None] - K[None, :, 0]) / K[None, :, 2]+ qy = (y[a:b, None] - K[None, :, 1]) / K[None, :, 3]+ d2 = qx * qx + qy * qy+ inside = d2 < 1+ anyin = inside.any(1)+ o = np.where(anyin, K.shape[0] - 1 - np.argmax(inside[:, ::-1], 1), np.argmin(d2, 1))+ ar = np.arange(b - a)+ ox, oy = qx[ar, o], qy[ar, o]+ dr = np.sqrt(ox * ox + oy * oy)+ nz = np.sqrt(np.clip(1 - np.minimum(dr, 1) ** 2, 0.04, 1))+ nn = np.stack([ox, oy, nz], 1); nn /= np.linalg.norm(nn, axis=1, keepdims=True)+ dif[a:b] = np.clip(nn @ Lv, 0, 1)+ own[a:b] = o; dd[a:b] = dr; dmin[a:b] = np.sqrt(d2.min(1))+ return dif, own, dd, dmin++ def _noise_at(self, x, y):+ return self.N1[np.clip(y.astype(np.int32), 0, self.H - 1), np.clip(x.astype(np.int32), 0, self.W - 1)]++ def _sample(self, K, n, r, dmax=1.0, dmin_=0.0):+ """n points on the clumped mass (normalised distance to the nearest clump in [dmin_, dmax], with a ragged rim)"""+ x0 = (K[:, 0] - K[:, 2]).min() * 1.0 - 4; x1 = (K[:, 0] + K[:, 2]).max() + 4+ y0 = (K[:, 1] - K[:, 3]).min() - 4; y1 = (K[:, 1] + K[:, 3]).max() + 4+ xs, ys = [], []+ got, tries = 0, 0+ while got < n and tries < 12:+ m = int((n - got) * 2.5) + 64+ x = r.uniform(x0, x1, m).astype(np.float32); y = r.uniform(y0, y1, m).astype(np.float32)+ dm = np.full(m, 9.0, np.float32)+ for k in K:+ dm = np.minimum(dm, np.sqrt(((x - k[0]) / k[2]) ** 2 + ((y - k[1]) / k[3]) ** 2))+ dm = dm * (1 + 0.16 * (self._noise_at(x, y) - 0.5))+ ok = (dm <= dmax) & (dm >= dmin_)+ xs.append(x[ok]); ys.append(y[ok]); got += int(ok.sum()); tries += 1+ x = np.concatenate(xs)[:n]; y = np.concatenate(ys)[:n]+ return x, y++ def _area(self, K, r):+ x0 = (K[:, 0] - K[:, 2]).min(); x1 = (K[:, 0] + K[:, 2]).max()+ y0 = (K[:, 1] - K[:, 3]).min(); y1 = (K[:, 1] + K[:, 3]).max()+ m = 6000+ x = r.uniform(x0, x1, m); y = r.uniform(y0, y1, m)+ dm = np.full(m, 9.0)+ for k in K: dm = np.minimum(dm, ((x - k[0]) / k[2]) ** 2 + ((y - k[1]) / k[3]) ** 2)+ return float((dm < 1).mean() * (x1 - x0) * (y1 - y0))++ def _light_value(self, x, y, K, occl=0.35, light=0.0, noise=0.16):+ dif, own, dd, dmin = self._lit(x, y, K)+ ytop = (K[:, 1] - K[:, 3]).min(); ybot = (K[:, 1] + K[:, 3]).max()+ vert = np.clip((y - ytop) / max(1.0, ybot - ytop), 0, 1)+ l = 0.1 + 0.9 * dif+ l = l * (1 - occl * vert ** 1.3) + noise * (self._noise_at(x, y) - 0.5) + light+ return np.clip(l, 0, 1), own, dd, dmin++ def _leaf_angle(self, x, y, K, own, droop, r):+ ox = x - K[own, 0]; oy = y - K[own, 1]+ nrm = np.sqrt(ox * ox + oy * oy) + 1e-3+ vx = ox / nrm * (1 - droop); vy = oy / nrm * (1 - droop) + droop+ return np.arctan2(vy, vx) + r.normal(0, 0.55, len(x))++ def foliage(self, clumps, ramp_='spring', leaf=(5, 9), density=1.0, far=0.0, light=0.0, droop=0.35,+ highlights=1.0, edge=1.0, aspect=0.48, shape='leaf', occl=0.35, veins=False, under=True,+ tex=0.05, seed=None):+ """a foliage mass built from leaf dabs: dark underpaint, mid body, leaves across the rim, lit clusters, sparkle"""+ r = self._r(seed)+ K = np.asarray(clumps, np.float32).reshape(-1, 4)+ R = ramp(ramp_)+ L0, L1 = leaf; la = 0.5 * (L0 + L1)+ area = self._area(K, r)+ groups = []+ jit = lambda n: r.normal(0, 0.016, (n, 3)).astype(np.float32)+ if under:+ polys = [blob_pts(k[0], k[1], k[2] * 0.7, k[3] * 0.7, 0.14, 40, int(r.integers(1 << 20))) for k in K]+ yk = (K[:, 1] - K[:, 1].min()) / max(1.0, np.ptp(K[:, 1]))+ cols = ramp_at(R, 0.04 + 0.1 * (1 - yk) + light * 0.4)+ groups.append((polys, self._far(cols, far), 1.0))+ n0 = int(area / (la * la * aspect * 3.2) * 1.2 * density)+ x, y = self._sample(K, n0, r, 0.97)+ l, own, dd, dmin = self._light_value(x, y, K, occl, light)+ Ls = r.uniform(L0, L1, len(x)) * 1.7+ groups.append((self._shapes(x, y, Ls, Ls * aspect, self._leaf_angle(x, y, K, own, droop, r), shape, 0.1, r),+ self._far(ramp_at(R, l * 0.42 + r.uniform(-0.04, 0.05, len(x))) + jit(len(x)), far), 1.0))+ # body+ n1 = int(area / (la * la * aspect) * 1.5 * density)+ x, y = self._sample(K, n1, r, 1.0)+ l, own, dd, dmin = self._light_value(x, y, K, occl, light)+ cols = ramp_at(R, l * 0.78 + r.uniform(-0.07, 0.07, len(x))) + jit(len(x))+ Ls = r.uniform(L0, L1, len(x))+ groups.append((self._shapes(x, y, Ls, Ls * aspect, self._leaf_angle(x, y, K, own, droop, r), shape, 0.08, r),+ self._far(cols, far), 1.0))+ # leaves across the silhouette+ if edge:+ n2 = int(np.sqrt(area) * 2.4 * edge * density * 6 / la)+ x, y = self._sample(K, n2, r, 1.13, 0.86)+ l, own, dd, dmin = self._light_value(x, y, K, occl, light)+ cols = ramp_at(R, l * 0.9 + r.uniform(-0.06, 0.06, len(x))) + jit(len(x))+ Ls = r.uniform(L0, L1 * 1.1, len(x))+ groups.append((self._shapes(x, y, Ls, Ls * aspect, self._leaf_angle(x, y, K, own, droop * 0.6, r), shape, 0.08, r),+ self._far(cols, far), 1.0))+ # light, in clusters+ nc = int(area / (la * la * aspect) * 0.11 * highlights * density)+ cx, cy = self._sample(K, nc * 3, r, 1.0)+ lc, own, dd, dmin = self._light_value(cx, cy, K, occl, light)+ keep = r.random(len(cx)) < smoothstep(0.4, 0.85, lc)+ cx, cy, lc = cx[keep][:nc], cy[keep][:nc], lc[keep][:nc]+ if len(cx):+ m = r.integers(5, 15, len(cx))+ ci = np.repeat(np.arange(len(cx)), m)+ x = cx[ci] + r.normal(0, la * 1.1, len(ci)); y = cy[ci] + r.normal(0, la * 0.9, len(ci))+ l2, own, dd, dmin = self._light_value(x, y, K, occl, light)+ ok = dmin < 1.06+ x, y, l2, own, ci = x[ok], y[ok], l2[ok], own[ok], ci[ok]+ o = np.argsort(lc[ci])+ x, y, l2, own, ci = x[o], y[o], l2[o], own[o], ci[o]+ ll = 0.5 * lc[ci] + 0.45 * l2 + 0.1 + r.uniform(-0.09, 0.07, len(x))+ cols = ramp_at(R, ll) + jit(len(x))+ Ls = r.uniform(L0 * 0.85, L1 * 0.95, len(x))+ groups.append((self._shapes(x, y, Ls, Ls * aspect, self._leaf_angle(x, y, K, own, droop, r), shape, 0.08, r),+ self._far(cols, far), 1.0))+ if veins:+ sel = ll > 0.62+ xv, yv = x[sel], y[sel]+ av = self._leaf_angle(xv, yv, K, own[sel], droop, r)+ groups.append((self._shapes(xv, yv, Ls[sel] * 0.75, Ls[sel] * 0.07, av, 'leaf', 0.0, r),+ self._far(ramp_at(R, ll[sel] + 0.2), far), 0.5))+ # sparkle: the palest dabs on the very top of the light+ sel = ll > 0.82+ if sel.any():+ xs_, ys_ = x[sel], y[sel]+ k = len(xs_)+ Ls = r.uniform(L0 * 0.6, L0 * 1.0, k)+ groups.append((self._shapes(xs_ + r.normal(0, 1.5, k), ys_ + r.normal(0, 1.5, k), Ls, Ls * aspect,+ r.uniform(0, np.pi, k), shape, 0.1, r),+ self._far(ramp_at(R, np.full(k, 0.97)) + jit(k), far), 0.9))+ self._paint(groups, 2, tex)++ def branch(self, path, w0, w1=None, colour='bark', lit='bark_light', far=0.0, light=0.55, wob=0.12, ss=2):+ """a woody limb: dark tube, a lit flank toward the sun, a few bark marks"""+ r = self._r()+ P, Q, nrm = _tube(path, w0, w1, wob=wob, seed=int(r.integers(1 << 30)))+ groups = [([P], self._far(hexc(colour)[None], far), 1.0)]+ w1 = w0 if w1 is None else w1+ hw = np.linspace(w0, w1, len(Q)) / 2+ side = np.sign((nrm @ self.L[:2]).mean() + 1e-6)+ lp = Q + nrm * side * hw[:, None] * 0.42+ if len(Q) > 3 and light > 0:+ P2, _, _ = _tube(lp[::max(1, len(lp) // 12)], w0 * 0.42, w1 * 0.3)+ groups.append(([P2], self._far(hexc(lit)[None], far), light))+ self._paint(groups, ss)++ def blossom_tree(self, branches, clumps, kind='white', petal=(3.0, 5.5), density=1.0, far=0.0, leaves=0.14,+ light=0.0, twigs=1.0, occl=0.3, gaps=0.35, seed=None):+ """a tree in bloom: branches, shadow underpaint, twigs, young leaves, then clusters of petal dabs dark -> light"""+ r = self._r(seed)+ K = np.asarray(clumps, np.float32).reshape(-1, 4)+ R = ramp(kind)+ G = ramp('spring')+ for b in branches: self.branch(b[0], b[1], b[2], far=far)+ p0, p1 = petal; pa = 0.5 * (p0 + p1)+ area = self._area(K, r)+ groups = []+ polys = [blob_pts(k[0], k[1], k[2] * 0.55, k[3] * 0.55, 0.2, 36, int(r.integers(1 << 20))) for k in K]+ sh = mix(ramp_at(R, 0.08), '#3c5a46', 0.6)+ groups.append((polys, self._far(np.repeat(sh[None], len(K), 0) * r.uniform(0.9, 1.06, (len(K), 1)), far), 1.0))+ n0 = int(area / (pa * pa * 3.0) * 1.1 * density)+ x, y = self._sample(K, n0, r, 0.95)+ l, own, dd, dmin = self._light_value(x, y, K, occl, light)+ Ls = r.uniform(p0 * 1.5, p1 * 1.9, len(x))+ green = r.random(len(x)) < 0.45+ cu = np.where(green[:, None], ramp_at(G, l * 0.38 + 0.04), ramp_at(R, l * 0.3 + 0.04) * 0.92 + hexc('#3c5a46') * 0.08)+ groups.append((self._shapes(x, y, Ls, Ls * np.where(green, 0.45, 0.6), r.uniform(0, np.pi, len(x)), 'leaf', 0.12, r),+ self._far(cu, far), 1.0))+ self._paint(groups, 2); groups = []+ if twigs:+ tw = []+ for k in K:+ for _ in range(int(3 * twigs)):+ a = r.uniform(0, 2 * np.pi); L = r.uniform(0.5, 1.0)+ p0_ = (k[0] + r.normal(0, k[2] * 0.2), k[1] + r.normal(0, k[3] * 0.2))+ p1_ = (p0_[0] + np.cos(a) * k[2] * L, p0_[1] + np.sin(a) * k[3] * L)+ mid = ((p0_[0] + p1_[0]) / 2 + r.normal(0, 4), (p0_[1] + p1_[1]) / 2 + r.normal(0, 4))+ tw.append(_tube([p0_, mid, p1_], max(1.2, pa * 0.45), 0.6)[0])+ groups.append((tw, self._far(hexc('bark')[None] * 1.1, far), 0.9))+ if leaves:+ nl = int(area / (pa * pa) * 0.22 * leaves * density)+ x, y = self._sample(K, nl, r, 1.0)+ l, own, dd, dmin = self._light_value(x, y, K, occl, light)+ Ls = r.uniform(p0 * 1.3, p1 * 1.6, len(x))+ groups.append((self._shapes(x, y, Ls, Ls * 0.45, r.uniform(0, np.pi, len(x)), 'leaf', 0.08, r),+ self._far(ramp_at(G, 0.25 + 0.6 * l), far), 1.0))+ # clusters of petals+ rc = pa * 3.2+ nc = int(area / (np.pi * rc * rc) * 4.0 * density)+ cx, cy = self._sample(K, nc, r, 1.02)+ lc, own, dd, dmin = self._light_value(cx, cy, K, occl, light)+ if gaps:+ keep = (self._noise_at(cx * 1.7 % self.W, cy * 1.7 % self.H) > gaps * 0.55) | (lc > 0.55)+ cx, cy, lc = cx[keep], cy[keep], lc[keep]+ o = np.argsort(lc + r.normal(0, 0.05, len(lc)))+ cx, cy, lc = cx[o], cy[o], lc[o]+ m = r.integers(12, 26, len(cx))+ ci = np.repeat(np.arange(len(cx)), m)+ dx = r.normal(0, rc * 0.5, len(ci)); dy = r.normal(0, rc * 0.42, len(ci))+ x = cx[ci] + dx; y = cy[ci] + dy+ side = -(dx * self.L[0] + dy * self.L[1]) / rc+ ll = lc[ci] * 0.75 + 0.17 + 0.22 * side + r.uniform(-0.06, 0.06, len(ci))+ Ls = r.uniform(p0, p1, len(ci))+ groups.append((self._shapes(x, y, Ls, Ls * 0.42 * r.uniform(0.8, 1.0, len(ci)), r.uniform(0, np.pi, len(ci)),+ 'round', 0.14, r),+ self._far(ramp_at(R, ll) + r.normal(0, 0.012, (len(ci), 3)), far), 1.0))+ sel = ll > 0.78+ if sel.any():+ k = int(sel.sum())+ Ls = r.uniform(p0 * 0.7, p0 * 1.1, k)+ groups.append((self._shapes(x[sel] + r.normal(0, 1.2, k), y[sel] + r.normal(0, 1.2, k), Ls, Ls * 0.45,+ r.uniform(0, np.pi, k), 'round', 0.1, r),+ self._far(ramp_at(R, np.full(k, 1.0)), far), 0.95))+ self._paint(groups, 2, 0.03)++ def blossom_branch(self, path, w0, w1, kind='pink', flowers=60, spread=26, size=(9, 15), leaves=0.5, buds=0.3,+ far=0.0, twigs=6, seed=None):+ """a near branch in bloom: a limb, short twigs, five-petal flowers, buds and young leaves"""+ r = self._r(seed)+ self.branch(path, w0, w1, far=far)+ _, Q, nrm = _tube(path, w0, w1)+ R = ramp(kind); G = ramp('spring')+ tw = []+ ends = []+ for _ in range(twigs):+ i = r.integers(len(Q) // 6, len(Q) - 1)+ a0 = np.arctan2(*(np.gradient(Q, axis=0)[i][::-1]))+ a = a0 + r.choice([-1, 1]) * r.uniform(0.5, 1.1)+ L = r.uniform(spread * 1.2, spread * 2.6)+ p0_ = Q[i]; p1_ = p0_ + L * np.array([np.cos(a), np.sin(a)])+ mid = (p0_ + p1_) / 2 + r.normal(0, 5, 2)+ tw.append(_tube([p0_, mid, p1_], max(2.0, w1 * 0.8), 1.2)[0])+ ends.append(spline(np.array([p0_, mid, p1_]), 6))+ self._paint([(tw, self._far(hexc('bark')[None], far), 1.0)])+ # flower positions along the limb and twigs+ tracks = [Q] + ends+ fx, fy = [], []+ for _ in range(flowers):+ T = tracks[r.integers(0, len(tracks))]+ j = r.integers(0, len(T))+ fx.append(T[j, 0] + r.normal(0, spread * 0.45)); fy.append(T[j, 1] + r.normal(0, spread * 0.4))+ fx, fy = np.array(fx, np.float32), np.array(fy, np.float32)+ o = np.argsort(fy + r.normal(0, 10, len(fy)))+ fx, fy = fx[o], fy[o]+ groups = []+ if leaves:+ nl = int(flowers * leaves * 2)+ T = np.vstack(tracks)+ j = r.integers(0, len(T), nl)+ lx = T[j, 0] + r.normal(0, spread * 0.5, nl); ly = T[j, 1] + r.normal(0, spread * 0.45, nl)+ Ls = r.uniform(size[0] * 0.9, size[1] * 1.3, nl)+ la = r.uniform(0, 2 * np.pi, nl)+ ll = 0.35 + 0.5 * r.random(nl)+ groups.append((self._shapes(lx, ly, Ls, Ls * 0.42, la, 'leaf', 0.06, r), self._far(ramp_at(G, ll), far), 1.0))+ groups.append((self._shapes(lx, ly, Ls * 0.8, Ls * 0.05, la, 'leaf', 0.0, r), self._far(ramp_at(G, ll + 0.18), far), 0.6))+ S = r.uniform(*size, len(fx))+ tilt = r.uniform(0.55, 1.0, len(fx)); rot = r.uniform(0, 2 * np.pi, len(fx))+ lit = np.clip(0.55 + 0.35 * r.random(len(fx)), 0, 1)+ Pp, Cp = [], []+ for i in range(len(fx)):+ for k in range(5):+ a = rot[i] + k * 2 * np.pi / 5+ ox, oy = np.cos(a) * S[i] * 0.33, np.sin(a) * S[i] * 0.33 * tilt[i]+ Pp.append((fx[i] + ox, fy[i] + oy, S[i] * 0.62, S[i] * 0.27, np.arctan2(oy, ox + 1e-6)))+ sidel = -(ox * self.L[0] + oy * self.L[1]) / S[i]+ Cp.append(lit[i] + 0.35 * sidel)+ Pp = np.array(Pp, np.float32); Cp = np.array(Cp, np.float32)+ groups.append((self._shapes(Pp[:, 0], Pp[:, 1], Pp[:, 2], Pp[:, 3], Pp[:, 4], 'round', 0.06, r),+ self._far(ramp_at(R, Cp), far), 1.0))+ cen = np.repeat(mix('#e9d36a', '#b8524f', 0.25)[None], len(fx), 0)+ groups.append((self._shapes(fx, fy, S * 0.22, S * 0.11, 0, 'round', 0.1, r), self._far(cen, far), 1.0))+ k = int(len(fx) * 4)+ a = r.uniform(0, 2 * np.pi, k); ii = r.integers(0, len(fx), k)+ groups.append((self._shapes(fx[ii] + np.cos(a) * S[ii] * 0.16, fy[ii] + np.sin(a) * S[ii] * 0.12, 2.2, 1.1, 0, 'dot', 0.1, r),+ self._far(np.repeat(mix('#b04a52', '#e6c05a', 0.3)[None], k, 0), far), 0.9))+ if buds:+ nb = int(flowers * buds)+ T = np.vstack(tracks); j = r.integers(0, len(T), nb)+ bx = T[j, 0] + r.normal(0, spread * 0.3, nb); by = T[j, 1] + r.normal(0, spread * 0.3, nb)+ Ls = r.uniform(size[0] * 0.45, size[0] * 0.7, nb)+ groups.append((self._shapes(bx, by, Ls, Ls * 0.55, r.uniform(-2.5, -0.6, nb), 'leaf', 0.05, r),+ self._far(ramp_at(R, r.uniform(0.15, 0.45, nb)), far), 1.0))+ self._paint(groups, 2, 0.03)++ def willow(self, trunk, boughs, strands=500, length=(120, 260), ramp_='willow', leaf=(3.5, 6.0), far=0.0,+ sway=0.25, light=0.0, crown=None, tips=None, gap=2.8, stem=1.0, bundle=(3, 9), spread=7.0, splay=(0.1, 0.34),+ aspect=0.28, crown_anchor=0.0, show_boughs=True, seed=None):+ """a weeping willow: trunk and boughs, then strands hanging from the boughs in tresses, back (dark) to front+ (light). trunk = (path, w0, w1) or None; boughs = list of (path, w0, w1); tips: lowest row the strands reach"""+ r = self._r(seed)+ R = ramp(ramp_)+ if trunk is not None: self.branch(*trunk, far=far)+ anchors = []+ for b in boughs:+ if show_boughs: self.branch(b[0], b[1], b[2], far=far, light=0.4)+ Q = spline(np.asarray(b[0], np.float32), 10)+ anchors.append(Q[len(Q) // 6:])+ if crown is not None and crown_anchor > 0:+ Kc = np.asarray(crown, np.float32)+ xc, yc = self._sample(Kc, int(sum(len(a) for a in anchors) * crown_anchor / (1 - crown_anchor + 1e-3)) + 1, r, 0.9)+ anchors.append(np.stack([xc, yc], 1))+ if crown is not None:+ self.foliage(crown, ramp_, leaf=(leaf[0] * 1.2, leaf[1] * 1.4), density=1.1, far=far, droop=0.9,+ aspect=0.3, light=light - 0.1, edge=0.7, highlights=0.5)+ A = np.vstack(anchors)+ cxm = A[:, 0].mean(); wx = max(1.0, np.ptp(A[:, 0]))+ nb = max(1, strands // int(np.mean(bundle)))+ bid = r.integers(0, len(A), nb)+ bdepth = r.random(nb)+ bL = r.uniform(*length, nb)+ recs = []+ for k in range(nb):+ for _ in range(r.integers(bundle[0], bundle[1] + 1)):+ recs.append((bdepth[k] + r.normal(0, 0.06), k))+ recs.sort()+ stems, scol, Pl, Cl = [], [], [], []+ for dep, k in recs:+ x0, y0 = A[bid[k]] + r.normal(0, spread, 2) * np.array([1.0, 0.4])+ L = bL[k] * r.uniform(0.8, 1.15)+ if tips is not None: L = min(L, max(20.0, tips - y0 + r.normal(0, 14)))+ n = max(4, int(L / 6))+ t = np.linspace(0, 1, n)+ out = np.sign(x0 - cxm + 1e-3) * r.uniform(3, 12)+ sw = sway * L * 0.1 * (r.normal(0, 1) * 0.6 + 0.4 * np.sin(k))+ xs = x0 + out * np.sin(np.minimum(t * 3.0, 1.0) * np.pi / 2) + sw * t ** 2 + r.normal(0, 0.5, n).cumsum() * 0.3+ ys = y0 - 5 * np.sin(np.minimum(t * 4, 1) * np.pi) * r.uniform(0.2, 1) + L * t+ path = np.stack([xs, ys], 1)+ side = np.clip(0.5 - 0.6 * (x0 - cxm) / wx, 0, 1)+ base_l = 0.06 + 0.62 * np.clip(dep, 0, 1) + 0.16 * side + light+ stems.append(_tube(path, stem, stem * 0.6, per=3)[0]); scol.append(ramp_at(R, base_l * 0.55))+ Q = spline(path, 3)+ seg = np.linalg.norm(np.diff(Q, axis=0), axis=1); s = np.concatenate([[0], np.cumsum(seg)])+ m = max(2, int(s[-1] / gap))+ sp = np.sort(r.uniform(0.04, 1.0, m)) * s[-1]+ px = np.interp(sp, s, Q[:, 0]); py = np.interp(sp, s, Q[:, 1])+ tx = np.interp(sp + 1, s, Q[:, 0]) - px; ty = np.interp(sp + 1, s, Q[:, 1]) - py+ ta = np.arctan2(ty, tx)+ alt = np.where(r.random(m) < 0.5, 1.0, -1.0)+ ang = ta + alt * r.uniform(splay[0], splay[1], m) + r.normal(0, 0.06, m)+ Ls = r.uniform(*leaf, m) * (0.8 + 0.3 * sp / s[-1]) * r.uniform(0.7, 1.15, m)+ ll = base_l + 0.14 * sp / s[-1] + r.uniform(-0.08, 0.08, m) + (self._noise_at(px, py) - 0.5) * 0.18 + 0.07 * alt+ off = alt * Ls * r.uniform(0.08, 0.28, m)+ Pl.append(np.stack([px + np.cos(ta) * Ls * 0.35 - np.sin(ta) * off, py + np.sin(ta) * Ls * 0.35 + np.cos(ta) * off, Ls, ang], 1))+ Cl.append(ramp_at(R, ll))+ groups = []+ nslice = 8+ bounds = np.linspace(0, len(recs), nslice + 1).astype(int)+ for a, b in zip(bounds[:-1], bounds[1:]):+ if b <= a: continue+ groups.append((stems[a:b], self._far(np.array(scol[a:b], np.float32), far), 0.65))+ P = np.vstack(Pl[a:b]); Cc = np.vstack(Cl[a:b])+ groups.append((self._shapes(P[:, 0], P[:, 1], P[:, 2], P[:, 2] * aspect, P[:, 3], 'leaf', 0.08, r),+ self._far(Cc + r.normal(0, 0.012, Cc.shape), far), 1.0))+ self._paint(groups, 2, 0.03)++ def reeds(self, x0, x1, y, n=60, height=(20, 50), ramp_='spring', far=0.0, lean=0.25, width=0.12, bend=0.5, seed=None):+ """sword-leaved plants (iris, grass) rising from a base line y (number or function of x): tapered, curving+ blades, darker in the clump, lit along the edge that faces the sun"""+ r = self._r(seed)+ R = ramp(ramp_)+ xs = r.uniform(x0, x1, n)+ ys = y(xs) if callable(y) else np.full(n, float(y))+ L = r.uniform(*height, n)+ a0 = -np.pi / 2 + r.normal(0, lean, n)+ c = (a0 + np.pi / 2) * bend * 2 + r.normal(0, 0.15, n)+ l = np.clip(0.25 + 0.45 * r.random(n) + 0.2 * (a0 < -np.pi / 2), 0, 1)+ o = np.argsort(l)+ blades, cols, lit, lcols = [], [], [], []+ for i in o:+ t = np.linspace(0, 1, 7)+ ang = a0[i] + c[i] * t ** 1.6+ step = L[i] / 6+ px = xs[i] + np.concatenate([[0], np.cumsum(np.cos(ang[:-1]) * step)])+ py = ys[i] + np.concatenate([[0], np.cumsum(np.sin(ang[:-1]) * step)])+ path = np.stack([px, py], 1)+ w0 = max(1.5, L[i] * width)+ blades.append(_tube(path, w0, 0.5, per=4)[0]); cols.append(ramp_at(R, l[i]))+ if L[i] > 30:+ side = -1.0 if np.cos(a0[i]) < 0 else 1.0+ lit.append(_tube(path + np.array([side * -w0 * 0.22, 0]), w0 * 0.3, 0.3, per=4)[0])+ lcols.append(ramp_at(R, l[i] + 0.25))+ self._paint([(blades, self._far(np.array(cols), far), 1.0), (lit, self._far(np.array(lcols), far), 0.6)], 2, 0.03)++ def pine(self, trunk, limbs, pads, ramp_='deep', needle=(4, 7), far=0.0, light=0.0, seed=None):+ """a garden pine: a leaning, crooked trunk, a few limbs, and flat tiers of needle pads (needle-thin dabs)"""+ r = self._r(seed)+ self.branch(*trunk, far=far, wob=0.25)+ for lb in limbs: self.branch(*lb, far=far, wob=0.2)+ P = np.asarray(pads, np.float32).reshape(-1, 4)+ for k in P[np.argsort(P[:, 1])]:+ K = np.array([[k[0] - k[2] * 0.35, k[1] + k[3] * 0.1, k[2] * 0.6, k[3] * 0.85],+ [k[0] + k[2] * 0.3, k[1] + k[3] * 0.05, k[2] * 0.62, k[3] * 0.8],+ [k[0] + r.normal(0, k[2] * 0.1), k[1] - k[3] * 0.3, k[2] * 0.55, k[3] * 0.7]], np.float32)+ self.foliage(K, ramp_, leaf=needle, density=1.2, far=far, light=light, droop=0.05, aspect=0.2, occl=0.55,+ highlights=1.2, edge=1.2)++ def petals(self, region, n=200, kind='pink', size=(2.5, 5), water=False, far=0.0, alpha=0.95, seed=None):+ """loose petals in the air (tumbling) or lying on the water (flat, with a tiny shadow); region = (x0, y0, x1, y1)"""+ r = self._r(seed)+ x0, y0, x1, y1 = region+ x = r.uniform(x0, x1, n); y = r.uniform(y0, y1, n)+ s = r.uniform(*size, n)+ R = ramp(kind)+ if water:+ ang = r.normal(0, 0.25, n); asp = 0.32+ self.dabs(x + 0.8, y + 1.2, s, s * asp, np.repeat(hexc('water_deep')[None] * 0.8, n, 0), ang, 'round', 0.35, far)+ else:+ ang = r.uniform(0, np.pi, n); asp = r.uniform(0.3, 0.5, n)+ self.dabs(x, y, s, s * asp, ramp_at(R, r.uniform(0.55, 1.0, n)), ang, 'round', alpha, far)++ def rock(self, cx, cy, rx, ry, ramp_='rock', far=0.0, moss=0.3, seed=None):+ """a weathered garden stone: lumpy outline, lit as a dome, painted with small dabs, dark crevices, moss"""+ r = self._r(seed)+ R = ramp(ramp_)+ pts = blob_pts(cx, cy, rx, ry, 0.12, 48, int(r.integers(1 << 20)))+ pts[:, 1] = np.minimum(pts[:, 1], cy + ry * 0.55)+ groups = [([pts], self._far(ramp_at(R, 0.3)[None], far), 1.0)]+ K = np.array([[cx, cy, rx, ry]], np.float32)+ n = int(rx * ry * 0.5)+ x = cx + r.uniform(-1, 1, n) * rx * 0.95; y = cy + r.uniform(-1, 0.55, n) * ry * 0.95+ ok = ((x - cx) / rx) ** 2 + ((y - cy) / ry) ** 2 < 0.9+ x, y = x[ok], y[ok]+ l, own, dd, dmin = self._light_value(x, y, K, 0.25, 0.0, 0.3)+ s = r.uniform(3, 7, len(x)) * max(0.6, min(1.6, rx / 40))+ groups.append((self._shapes(x, y, s, s * 0.6, r.uniform(-0.4, 0.4, len(x)), 'round', 0.2, r),+ self._far(ramp_at(R, l * 1.05), far), 1.0))+ cr = []+ for _ in range(int(3 + rx / 15)):+ a = r.uniform(cx - rx * 0.6, cx + rx * 0.6); b = r.uniform(cy - ry * 0.4, cy + ry * 0.3)+ cr.append(_tube([(a, b), (a + r.normal(0, rx * 0.2), b + r.uniform(2, ry * 0.3))], 1.6, 0.6)[0])+ groups.append((cr, self._far(ramp_at(R, 0.05)[None], far), 0.6))+ if moss:+ k = int(rx * moss * 3)+ x = cx + r.uniform(-0.9, 0.9, k) * rx; y = cy + ry * r.uniform(0.15, 0.5, k)+ groups.append((self._shapes(x, y, r.uniform(2, 5, k), 1.6, 0, 'round', 0.2, r),+ self._far(ramp_at(ramp('olive'), r.uniform(0.3, 0.7, k)), far), 0.9))+ self._paint(groups)++ def pot(self, x, y, w, h, colour='terracotta', band=None, far=0.0):+ """a flowerpot standing on y (its foot), lit from the left; returns the rim centre and width"""+ P = np.array([(x - w / 2, y - h), (x + w / 2, y - h), (x + w * 0.36, y), (x - w * 0.36, y)], np.float32)+ base = hexc(colour)+ groups = [([P], self._far(base[None], far), 1.0)]+ k = 10+ for i in range(k):+ t0, t1 = i / k, (i + 1) / k+ sh = 0.78 + 0.42 * np.cos((t0 - 0.3) * np.pi) ** 2 if t0 < 0.8 else 0.7+ q = np.array([(x - w / 2 + w * t0, y - h), (x - w / 2 + w * t1, y - h),+ (x - w * 0.36 + w * 0.72 * t1, y), (x - w * 0.36 + w * 0.72 * t0, y)], np.float32)+ groups.append(([q], self._far((base * sh)[None], far), 0.85))+ rim = np.array([(x - w / 2 - 2, y - h - 4), (x + w / 2 + 2, y - h - 4), (x + w / 2 + 1, y - h + 3), (x - w / 2 - 1, y - h + 3)], np.float32)+ groups.append(([rim], self._far((base * 1.08)[None], far), 1.0))+ if band:+ b = np.array([(x - w * 0.47, y - h * 0.7), (x + w * 0.47, y - h * 0.7), (x + w * 0.43, y - h * 0.5), (x - w * 0.43, y - h * 0.5)], np.float32)+ groups.append(([b], self._far(hexc(band)[None], far), 0.9))+ groups.append(([np.array([(x - w * 0.42, y - 1), (x + w * 0.46, y - 1), (x + w * 0.5, y + 3), (x - w * 0.36, y + 3)], np.float32)],+ self._far(np.array([[0.2, 0.2, 0.18]], np.float32), far), 0.35))+ self._paint(groups)+ return x, y - h++ # ================================================================== architecture+ def wall(self, x0, y0, x1, y1, colour='plaster', stains=0.5, damp=0.5, far=0.0, seed=None):+ """a plastered wall: flat paint, low-frequency mottling, rain stains from the top, a damp greener base"""+ r = self._r(seed)+ x0, y0, x1, y1 = int(x0), int(y0), int(x1), int(y1)+ h, w = y1 - y0, x1 - x0+ sl = (slice(y0, y1), slice(x0, x1))+ base = hexc(colour)+ n = noise2d(h, w, 90, 4, int(r.integers(1 << 30)))+ col = base * (0.965 + 0.06 * n[..., None])+ st = _blur1(_blur1(r.random((h, w)).astype(np.float32), 0.8, 1), 14, 0)+ st = (st - st.mean()) / (st.std() + 1e-6)+ yy = np.linspace(0, 1, h, dtype=np.float32)[:, None]+ drip = smoothstep(0.5, 2.2, st) * (1 - yy) ** 1.5 * stains+ col = col * (1 - 0.1 * drip[..., None]) + hexc('#8c8a80') * 0.1 * drip[..., None]+ dmp = smoothstep(0.78, 1.0, yy + 0.06 * (n - 0.5)) * damp+ col = col * (1 - 0.18 * dmp[..., None]) + hexc('#7d8c74') * 0.18 * dmp[..., None]+ col = self._far(col, far)+ A = np.ones((h, w), np.float32)+ if self._clip is not None: A = self._clip[sl]+ self.C[sl] += (col - self.C[sl]) * A[..., None]+ k = int(w * h / 260)+ xs = r.uniform(x0, x1, k); ys = r.uniform(y0, y1, k)+ c = col[(ys - y0).astype(int).clip(0, h - 1), (xs - x0).astype(int).clip(0, w - 1)] * r.uniform(0.965, 1.025, (k, 1))+ s = r.uniform(8, 26, k)+ self._paint([(self._shapes(xs, ys, s, s * 0.3, r.normal(0, 0.18, k), 'round', 0.12, r), c, 0.6)], 2, 0.03)++ def _roof_surface(self, cx, y_ridge, y_eave, wr, we, upturn, flare):+ D = y_eave - y_ridge++ def surf(u, v):+ v = np.clip(v, 0, 1); au = np.abs(u)+ x = cx + u * (wr + (we - wr) * v ** 1.7) + np.sign(u) * flare * au ** 6 * v ** 3+ y = y_ridge + D * (0.35 * v + 0.65 * (1 - (1 - v) ** 2)) - upturn * au ** 4 * v ** 2.5+ return x, y+ return surf++ def roof(self, cx, y_ridge, y_eave, ridge_w, eave_w, upturn=40.0, flare=24.0, rows=None, courses=None,+ ridge_h=14.0, soffit=10.0, shadow=40.0, ramp_='tile', far=0.0, ends=True, hips=True, ridge_ends=True,+ openwork=True, seed=None):+ """a grey-tiled hip-and-gable roof seen from the front, with upturned flying corners"""+ r = self._r(seed)+ R = ramp(ramp_)+ wr, we = ridge_w / 2, eave_w / 2+ surf = self._roof_surface(cx, y_ridge, y_eave, wr, we, upturn, flare)+ rows = rows or int(eave_w / 13)+ courses = courses or max(6, int((y_eave - y_ridge) / 7))+ # shadow of the eave on whatever stands below it+ if shadow:+ us = np.linspace(-1, 1, 200); ex, ey = surf(us, np.ones_like(us))+ xa, xb = int(max(0, ex.min() + 10)), int(min(self.W, ex.max() - 10))+ ya, yb = int(max(0, ey.min())), int(min(self.H, y_eave + soffit + shadow))+ if xb > xa and yb > ya:+ yy = np.arange(ya, yb, dtype=np.float32)[:, None]; xx = np.arange(xa, xb, dtype=np.float32)[None]+ e = np.interp(xx, ex, ey)+ prof = smoothstep(e + soffit + shadow, e + soffit * 0.6, yy) * (yy > e)+ edge = smoothstep(xa, xa + 30, xx) * smoothstep(xb, xb - 30, xx)+ a = prof * edge * 0.5+ if self._clip is not None: a = a * self._clip[ya:yb, xa:xb]+ Cs = self.C[ya:yb, xa:xb]+ Cs *= (1 - a[..., None] * (1 - hexc('#56607a')[None, None] * 0.9))+ # soffit: the underside of the eave, rafter ends, fascia+ nu_s = 120+ us = np.linspace(-1, 1, nu_s)+ ex, ey = surf(us, np.ones_like(us))+ sof = soffit * (1 + 0.6 * np.abs(us) ** 4)+ P = np.vstack([np.stack([ex, ey], 1), np.stack([ex, ey + sof], 1)[::-1]]).astype(np.float32)+ groups = [([P], self._far(hexc('#3a2c26')[None], far), 1.0)]+ nr = int(eave_w / 9)+ ur = np.linspace(-0.97, 0.97, nr)+ rx_, ry_ = surf(ur, np.ones_like(ur))+ rs = soffit * (1 + 0.6 * np.abs(ur) ** 4)+ groups.append((self._shapes(rx_, ry_ + rs * 0.45, np.full(nr, 3.2), np.full(nr, 1.7 * rs / soffit), np.pi / 2, 'round', 0.05, r),+ self._far(hexc('#8a6a52')[None] * r.uniform(0.85, 1.05, (nr, 1)), far), 1.0))+ P2 = np.vstack([np.stack([ex, ey + sof - 2.2], 1), np.stack([ex, ey + sof], 1)[::-1]]).astype(np.float32)+ groups.append(([P2], self._far(hexc('#241b18')[None], far), 0.9))+ self._paint(groups)+ # the tiled slope: mesh -> id map -> (u, v) by Newton steps -> analytic tiles+ ss = 2+ nu, nv = int(eave_w / 3) + 8, int((y_eave - y_ridge) / 3) + 8+ ug = np.linspace(-1, 1, nu + 1); vg = np.linspace(0, 1, nv + 1)+ UX, VX = np.meshgrid(ug, vg)+ GX, GY = surf(UX, VX)+ x0 = int(max(0, GX.min() - 3)); x1 = int(min(self.W, GX.max() + 4))+ y0 = int(max(0, GY.min() - 3)); y1 = int(min(self.H, GY.max() + 4))+ w, h = x1 - x0, y1 - y0+ im = Image.new('I', (w * ss, h * ss), 0); d = ImageDraw.Draw(im)+ for j in range(nv):+ for i in range(nu):+ q = [((GX[j, i] - x0) * ss, (GY[j, i] - y0) * ss), ((GX[j, i + 1] - x0) * ss, (GY[j, i + 1] - y0) * ss),+ ((GX[j + 1, i + 1] - x0) * ss, (GY[j + 1, i + 1] - y0) * ss), ((GX[j + 1, i] - x0) * ss, (GY[j + 1, i] - y0) * ss)]+ d.polygon(q, fill=j * nu + i + 1)+ ids = np.asarray(im).astype(np.int64)+ M = ids > 0+ jj, ii = np.divmod(np.maximum(ids - 1, 0), nu)+ u = ug[ii] + (ug[1] - ug[0]) * 0.5; v = vg[jj] + (vg[1] - vg[0]) * 0.5+ Y, X = np.mgrid[0:h * ss, 0:w * ss].astype(np.float32)+ X = X / ss + x0 + 0.25; Y = Y / ss + y0 + 0.25+ eps = 1e-3+ for _ in range(2):+ fx, fy = surf(u, v)+ ax, ay = surf(u + eps, v); bx, by = surf(u, v + eps)+ J11, J21 = (ax - fx) / eps, (ay - fy) / eps+ J12, J22 = (bx - fx) / eps, (by - fy) / eps+ det = J11 * J22 - J12 * J21+ det = np.where(np.abs(det) < 1e-6, 1e-6, det)+ ex_, ey_ = X - fx, Y - fy+ du = (J22 * ex_ - J12 * ey_) / det; dv = (-J21 * ex_ + J11 * ey_) / det+ u = np.clip(u + np.clip(du, -0.02, 0.02), -1, 1); v = np.clip(v + np.clip(dv, -0.05, 0.05), 0, 1)+ U = (u + 1) / 2 * rows+ ci = np.floor(U); f = U - ci - 0.5+ Vc = v * courses+ cj = np.floor(Vc); g = Vc - cj+ hsh = np.sin(ci * 12.9898 + cj * 78.233) * 43758.5453; hsh = hsh - np.floor(hsh)+ roll = np.abs(f) < 0.23+ p = f / 0.23+ val = np.where(roll, 0.6 - 0.34 * p - 0.22 * p * p, 0.3 + 0.07 * np.cos(np.clip((np.abs(f) - 0.23) / 0.27, 0, 1) * np.pi))+ seam = smoothstep(0.17, 0.0, np.abs(np.abs(f) - 0.23))+ val = val - 0.16 * seam+ lip = smoothstep(0.7, 0.86, g) * (1 - smoothstep(0.9, 0.97, g))+ shd = smoothstep(0.14, 0.0, g)+ val = val + np.where(roll, 0.3 * lip - 0.26 * shd, 0.07 * lip - 0.12 * shd)+ val = val + 0.08 * (hsh - 0.5) + 0.1 * v - 0.08 * u * np.abs(u) ** 3 - 0.06 * (1 - v) ** 3+ col = ramp_at(R, val)+ moss = (hsh > 0.86) & ~roll+ col = np.where(moss[..., None], col * 0.85 + hexc('#5f6e48') * 0.15, col)+ col = self._far(col, far)+ A = M.astype(np.float32)+ col = (col * A[..., None]).reshape(h, ss, w, ss, 3).mean((1, 3))+ A = A.reshape(h, ss, w, ss).mean((1, 3))+ col = col / np.maximum(A[..., None], 1e-4)+ if self._clip is not None: A = A * self._clip[y0:y1, x0:x1]+ col = col * (1 + 0.035 * self.TX[y0:y1, x0:x1, None])+ Cs = self.C[y0:y1, x0:x1]+ Cs += (col - Cs) * A[..., None]+ groups = []+ # tile ends and drip tiles along the eave+ if ends:+ uc = ((np.arange(rows) + 0.5) / rows) * 2 - 1+ ex, ey = surf(uc, np.ones_like(uc))+ sp = (we * 2 / rows) * (1 + 3 * np.abs(uc) ** 5 * flare / max(we, 1))+ rr = sp * 0.36+ up = (np.arange(rows - 1) + 1) / rows * 2 - 1+ dx_, dy_ = surf(up, np.ones_like(up))+ dsp = (we * 2 / rows)+ tri = np.stack([np.stack([dx_ - dsp * 0.3, dy_ - 1], 1), np.stack([dx_ + dsp * 0.3, dy_ - 1], 1),+ np.stack([dx_, dy_ + dsp * 0.42], 1)], 1)+ groups.append((tri, self._far(ramp_at(R, 0.32)[None] * r.uniform(0.9, 1.1, (len(up), 1)), far), 1.0))+ groups.append((self._shapes(ex, ey, rr * 2, rr, 0, 'round', 0.04, r),+ self._far(ramp_at(R, 0.55)[None] * r.uniform(0.92, 1.08, (rows, 1)), far), 1.0))+ groups.append((self._shapes(ex + rr * 0.15, ey + rr * 0.15, rr * 1.35, rr * 0.68, 0, 'round', 0.04, r),+ self._far(ramp_at(R, 0.18)[None], far), 1.0))+ groups.append((self._shapes(ex - rr * 0.32, ey - rr * 0.32, rr * 0.7, rr * 0.18, -0.8, 'leaf', 0.0, r),+ self._far(ramp_at(R, 0.95)[None], far), 0.7))+ # hip ridges down to the flying corners+ if hips:+ for sgn in (-1, 1):+ vv = np.linspace(0.02, 1, 24)+ hx, hy = surf(np.full_like(vv, sgn), vv)+ c_x, c_y = hx[-1], hy[-1]+ tx, ty = hx[-1] - hx[-3], hy[-1] - hy[-3]+ tn = np.hypot(tx, ty) + 1e-6+ tip = [(c_x + tx / tn * upturn * 0.25 + sgn * upturn * 0.15, c_y - upturn * 0.35),+ (c_x + sgn * upturn * 0.42, c_y - upturn * 0.85), (c_x + sgn * upturn * 0.36, c_y - upturn * 1.15)]+ path = np.vstack([np.stack([hx, hy], 1), tip])+ Ph, Qh, nh = _tube(path, ridge_h * 0.72, 2.0, per=3)+ groups.append(([Ph], self._far(ramp_at(R, 0.2)[None], far), 1.0))+ Pl, _, _ = _tube(Qh[:: max(1, len(Qh) // 20)] + np.array([sgn * 0.6, -ridge_h * 0.18]), ridge_h * 0.22, 0.8, per=2)+ groups.append(([Pl], self._far(ramp_at(R, 0.62 if sgn < 0 else 0.45)[None], far), 0.9))+ # the main ridge, its openwork and curled ends+ if ridge_h:+ xr0, xr1 = cx - wr - ridge_h * 0.3, cx + wr + ridge_h * 0.3+ body = np.array([(xr0, y_ridge + 2), (xr0, y_ridge - ridge_h), (xr1, y_ridge - ridge_h), (xr1, y_ridge + 2)], np.float32)+ groups.append(([body], self._far(ramp_at(R, 0.24)[None], far), 1.0))+ yc0, yc1 = y_ridge - ridge_h - 3, y_ridge - ridge_h + 1+ cap = np.array([(xr0 - 2, yc0), (xr1 + 2, yc0), (xr1 + 2, yc1), (xr0 - 2, yc1)], np.float32)+ groups.append(([cap], self._far(ramp_at(R, 0.5)[None], far), 1.0))+ if openwork and ridge_h >= 9:+ k = int((xr1 - xr0) / (ridge_h * 0.7))+ xs = np.linspace(xr0 + ridge_h, xr1 - ridge_h, k)+ groups.append((self._shapes(xs, np.full(k, y_ridge - ridge_h * 0.45), np.full(k, ridge_h * 0.5),+ np.full(k, ridge_h * 0.26), 0, 'round', 0.03, r),+ self._far(ramp_at(R, 0.05)[None], far), 1.0))+ groups.append((self._shapes(xs - ridge_h * 0.06, np.full(k, y_ridge - ridge_h * 0.52), np.full(k, ridge_h * 0.3),+ np.full(k, ridge_h * 0.08), 0, 'round', 0.03, r),+ self._far(ramp_at(R, 0.6)[None], far), 0.7))+ if ridge_ends:+ for sgn, xe in ((-1, xr0), (1, xr1)):+ hh = ridge_h+ path = [(xe - sgn * hh * 0.6, y_ridge - hh * 0.5), (xe + sgn * hh * 0.5, y_ridge - hh * 0.9),+ (xe + sgn * hh * 1.2, y_ridge - hh * 1.9), (xe + sgn * hh * 1.25, y_ridge - hh * 2.8),+ (xe + sgn * hh * 0.85, y_ridge - hh * 3.25)]+ Pe, Qe, _ = _tube(path, hh * 1.05, hh * 0.32, per=4)+ groups.append(([Pe], self._far(ramp_at(R, 0.22)[None], far), 1.0))+ Pl, _, _ = _tube(np.array(path) + np.array([-sgn * hh * 0.18, -hh * 0.12]), hh * 0.25, hh * 0.08, per=4)+ groups.append(([Pl], self._far(ramp_at(R, 0.62)[None], far), 0.85))+ self._paint(groups)+ return surf++ def dapple(self, x0, y0, x1, y1, amount=0.3, scale=16.0, cover=0.5, falloff=None, mask=None, colour='#4e6680', seed=None):+ """dappled shade cast by leaves onto a sunlit surface: soft-edged patches of cool shadow with sun flecks+ between them; falloff = (x, y, radius): strongest near the tree that casts it"""+ r = self._r(seed)+ x0, y0, x1, y1 = (int(max(0, v)) for v in (x0, y0, x1, y1))+ x1, y1 = min(self.W, x1), min(self.H, y1)+ h, w = y1 - y0, x1 - x0+ if h <= 0 or w <= 0: return+ n = noise2d(h, w, scale, 3, int(r.integers(1 << 30)))+ a = smoothstep(cover - 0.06, cover + 0.06, n) * amount+ if falloff is not None:+ fx, fy, fr = falloff+ yy = np.arange(y0, y1, dtype=np.float32)[:, None]; xx = np.arange(x0, x1, dtype=np.float32)[None]+ a = a * np.clip(1 - np.hypot(xx - fx, yy - fy) / fr, 0, 1) ** 0.8+ if mask is not None: a = a * mask[y0:y1, x0:x1]+ if self._clip is not None: a = a * self._clip[y0:y1, x0:x1]+ Cs = self.C[y0:y1, x0:x1]+ Cs *= (1 - a[..., None] * (1 - hexc(colour)[None, None]))++ def coping(self, x0, x1, y, h=20, far=0.0, seed=None):+ """the little tiled roof along the top of a garden wall"""+ return self.roof((x0 + x1) / 2, y - h, y, (x1 - x0) - h * 0.8, x1 - x0, upturn=h * 0.45, flare=h * 0.2,+ rows=int((x1 - x0) / 8.5), courses=max(4, int(h / 5)), ridge_h=max(4.0, h * 0.32),+ soffit=max(3.0, h * 0.2), shadow=h * 0.9, far=far, openwork=False, seed=seed)++ def column(self, x, y0, y1, w=12, colour='lacquer', base='stone', far=0.0):+ """a lacquered round column on a stone base, lit from the left"""+ k = 9+ groups = []+ c = hexc(colour)+ for i in range(k):+ t0, t1 = i / k, (i + 1) / k+ tm = (t0 + t1) / 2+ sh = 0.62 + 0.6 * np.cos((tm - 0.28) * np.pi * 0.9) ** 2 * (tm < 0.85) + 0.05+ q = np.array([(x - w / 2 + w * t0, y0), (x - w / 2 + w * t1, y0), (x - w / 2 + w * t1, y1), (x - w / 2 + w * t0, y1)], np.float32)+ groups.append(([q], self._far((c * sh)[None], far), 1.0))+ bw = w * 1.7; bh = w * 0.8+ b = np.array([(x - bw / 2, y1 - bh), (x + bw / 2, y1 - bh), (x + bw * 0.56, y1), (x - bw * 0.56, y1)], np.float32)+ groups.append(([b], self._far(ramp_at(ramp('stone'), 0.6)[None], far), 1.0))+ b2 = np.array([(x + bw * 0.1, y1 - bh), (x + bw / 2, y1 - bh), (x + bw * 0.56, y1), (x + bw * 0.1, y1)], np.float32)+ groups.append(([b2], self._far(ramp_at(ramp('stone'), 0.35)[None], far), 0.8))+ self._paint(groups)++ def beam(self, x0, x1, y0, y1, colour='beam', band='jade_dark', far=0.0):+ """a lacquered lintel between columns, a painted band along it and a lit upper edge"""+ h = y1 - y0+ q = lambda a, b: np.array([(x0, a), (x1, a), (x1, b), (x0, b)], np.float32)+ self._paint([([q(y0, y1)], self._far(hexc(colour)[None], far), 1.0),+ ([q(y0 + h * 0.44, y0 + h * 0.62)], self._far(hexc(band)[None], far), 0.9),+ ([q(y0, y0 + 1.5)], self._far(mix(colour, '#f0d0b0', 0.35)[None], far), 0.8)], 2, 0.03)++ def lattice(self, x0, y0, x1, y1, pattern='lantern', cell=13, bar=2.0, frame=4.0, colour='jade', back='interior',+ kind='window', far=0.0, seed=None):+ """jade lattice: window (all lattice), door (lattice, waist panel, skirt panel) or open fretwork (back=None)"""+ r = self._r(seed)+ x0, y0, x1, y1 = int(x0), int(y0), int(x1), int(y1)+ w, h = x1 - x0, y1 - y0+ if w < 4 or h < 4: return+ ss = 3+ im = Image.new('L', (w * ss, h * ss), 0); d = ImageDraw.Draw(im)+ pm = Image.new('L', (w * ss, h * ss), 0); dp = ImageDraw.Draw(pm)+ fw = max(1, int(frame * ss)); bw = max(1, int(bar * ss))+ d.rectangle([0, 0, w * ss - 1, h * ss - 1], outline=255, width=fw)+ zones = [(fw, h * ss - fw)]+ if kind == 'door':+ a = int(h * ss * 0.58); b = int(h * ss * 0.67); c = int(h * ss * 0.71)+ zones = [(fw, a)]+ d.rectangle([0, a, w * ss, a + fw], fill=255); d.rectangle([0, b, w * ss, c], fill=255)+ dp.rectangle([fw, a + fw, w * ss - fw, b], fill=255)+ dp.rectangle([fw, c, w * ss - fw, h * ss - fw], fill=255)+ for za, zb in zones:+ X0, X1 = fw, w * ss - fw+ if pattern == 'grid':+ cs = cell * ss+ for x in np.arange(X0 + cs, X1, cs): d.line([(x, za), (x, zb)], fill=255, width=bw)+ for y in np.arange(za + cs, zb, cs): d.line([(X0, y), (X1, y)], fill=255, width=bw)+ elif pattern == 'diamond':+ cs = cell * ss+ for k in np.arange(-(zb - za), X1 - X0 + (zb - za), cs):+ d.line([(X0 + k, za), (X0 + k + (zb - za), zb)], fill=255, width=bw)+ d.line([(X0 + k, zb), (X0 + k + (zb - za), za)], fill=255, width=bw)+ elif pattern == 'ice':+ hh, ww = (zb - za) // ss, (X1 - X0) // ss+ npt = max(4, int(hh * ww / (cell * cell * 1.3)))+ px = r.uniform(0, ww, npt); py = r.uniform(0, hh, npt)+ yy, xx = np.mgrid[0:hh, 0:ww]+ dd = (xx[..., None] - px) ** 2 + (yy[..., None] - py) ** 2+ lab = np.argmin(dd, -1)+ edge = np.zeros((hh, ww), bool)+ edge[:, 1:] |= lab[:, 1:] != lab[:, :-1]; edge[1:, :] |= lab[1:, :] != lab[:-1, :]+ e = Image.fromarray((edge * 255).astype(np.uint8)).resize((ww * ss, hh * ss), Image.NEAREST)+ e = e.filter(ImageFilter.MaxFilter(max(3, bw | 1)))+ im.paste(255, (X0, za), e)+ else: # 'lantern' (灯笼锦): an open centre framed by bars, short ties out to the frame, small grid around+ W_, H_ = X1 - X0, zb - za+ cx0, cx1 = X0 + W_ * 0.3, X1 - W_ * 0.3+ cy0, cy1 = za + H_ * 0.33, zb - H_ * 0.33+ d.rectangle([cx0, cy0, cx1, cy1], outline=255, width=bw)+ cs = cell * ss+ for x in np.arange(X0 + cs * 0.8, X1, cs):+ if x < cx0 or x > cx1: d.line([(x, za), (x, zb)], fill=255, width=bw)+ else:+ d.line([(x, za), (x, cy0)], fill=255, width=bw); d.line([(x, cy1), (x, zb)], fill=255, width=bw)+ for y in np.arange(za + cs * 0.8, zb, cs):+ if y < cy0 or y > cy1: d.line([(X0, y), (X1, y)], fill=255, width=bw)+ else:+ d.line([(X0, y), (cx0, y)], fill=255, width=bw); d.line([(cx1, y), (X1, y)], fill=255, width=bw)+ Bm = np.asarray(im, np.float32) / 255+ Pm = np.asarray(pm, np.float32) / 255+ jade = hexc(colour)+ lite, dark = mix(jade, '#d8f0dc', 0.42), jade * 0.5+ o = max(1, int(ss * 1.0))+ up = np.zeros_like(Bm); up[o:, o:] = Bm[:-o, :-o] # bar shifted down-right+ dn = np.zeros_like(Bm); dn[:-o, :-o] = Bm[o:, o:]+ litE = np.clip(Bm - up, 0, 1); darkE = np.clip(Bm - dn, 0, 1)+ so = 2 * ss+ sh = np.zeros_like(Bm); sh[so:, so:] = Bm[:-so, :-so]+ yy = np.linspace(0, 1, h * ss, dtype=np.float32)[:, None]+ if back is not None:+ if back == 'interior':+ bcol = hexc('interior')[None, None] * (1.15 - 0.3 * yy[..., None])+ xx = np.linspace(0, 1, w * ss, dtype=np.float32)[None]+ sheen = smoothstep(0.1, 0.0, np.abs((xx + yy * 0.6) - 0.55 - 0.2 * r.random()))+ bcol = bcol + 0.08 * sheen[..., None]+ else:+ bcol = hexc(back)[None, None] * (1.04 - 0.12 * yy[..., None])+ Cb = np.broadcast_to(bcol, (h * ss, w * ss, 3)).copy()+ Cb *= (1 - 0.45 * sh * (1 - Bm))[..., None]+ A0 = np.ones((h * ss, w * ss), np.float32)+ else:+ Cb = np.zeros((h * ss, w * ss, 3), np.float32); A0 = np.zeros((h * ss, w * ss), np.float32)+ pan = jade * (0.95 - 0.12 * yy[..., None])+ Cb = Cb * (1 - Pm[..., None]) + pan * Pm[..., None]+ A0 = np.maximum(A0, Pm)+ if kind == 'door':+ ip = Image.new('L', (w * ss, h * ss), 0); di = ImageDraw.Draw(ip)+ for a, b in ((0.585, 0.665), (0.73, 0.98)):+ di.rectangle([fw + 2.5 * ss, int(h * ss * a) + 2 * ss, w * ss - fw - 2.5 * ss, int(h * ss * b) - 2 * ss], outline=255, width=max(1, ss))+ Im = np.asarray(ip, np.float32) / 255+ Cb = Cb * (1 - 0.35 * Im[..., None]) + dark * 0.35 * Im[..., None]+ Im2 = np.zeros_like(Im); Im2[ss:, ss:] = Im[:-ss, :-ss]+ Cb = Cb * (1 - 0.4 * Im2[..., None]) + lite * 0.4 * Im2[..., None]+ barc = jade[None, None] * (1 + 0.04 * r.normal(0, 1)) * np.ones((h * ss, w * ss, 1), np.float32)+ barc = barc * (1 - litE[..., None]) + lite * litE[..., None]+ barc = barc * (1 - 0.7 * darkE[..., None]) + dark * 0.7 * darkE[..., None]+ Cb = Cb * (1 - Bm[..., None]) + barc * Bm[..., None]+ A0 = np.maximum(A0, Bm)+ Cb = self._far(Cb, far)+ Cd = (Cb * A0[..., None]).reshape(h, ss, w, ss, 3).mean((1, 3))+ Ad = A0.reshape(h, ss, w, ss).mean((1, 3))+ sl = (slice(y0, y1), slice(x0, x1))+ if self._clip is not None:+ f = self._clip[sl]; Ad = Ad * f; Cd = Cd * f[..., None]+ self.C[sl] = self.C[sl] * (1 - Ad[..., None]) + Cd++ def fretwork(self, x0, x1, y0, h=18, cell=8, colour='jade', far=0.0):+ """挂落: the open lattice frieze hanging under a beam between two columns, with a stepped lower edge"""+ self.lattice(x0, y0, x1, y0 + h, 'grid', cell, 1.6, 2.2, colour, None, 'window', far)+ step = int(cell * 1.5)+ for x in range(int(x0) + step, int(x1) - step, step * 2):+ self.lattice(x, y0 + h - 2, x + step, y0 + h + cell * 0.8, 'grid', cell, 1.6, 2.2, colour, None, 'window', far)++ def round_window(self, cx, cy, r, ring=7.0, pattern='ice', inside=None, ground=None, far=0.0, reveal=4.0,+ colour='#a4a8a2', cell=12, back='paper'):+ """a round opening in a wall: a lattice window (pattern) or, with inside=callable(mask), a moon gate showing+ another view; ground cuts the circle at that row (a gate standing on its threshold)"""+ opening = self.ellipse(cx, cy, r, r)+ if ground is not None:+ yy = np.arange(self.H, dtype=np.float32)[:, None]+ opening = opening * (yy < ground)+ if inside is not None:+ with self.clipped(opening): inside(opening)+ else:+ with self.clipped(opening):+ self.lattice(cx - r - 2, cy - r - 2, cx + r + 2, cy + r + 2, pattern, cell, 2.0, 0.0, 'jade', back, 'window', far)+ if reveal:+ rv = np.clip(self.ellipse(cx, cy, r, r) - self.ellipse(cx + reveal, cy - reveal * 0.6, r, r), 0, 1)+ if ground is not None: rv = rv * (np.arange(self.H)[:, None] < ground)+ self.fill(rv, self._far(mix('plaster', '#b9b4a6', 0.35)[None, None], far)[0, 0], 0.95)+ outer = self.ellipse(cx, cy, r + ring, r + ring)+ band = np.clip(outer - self.ellipse(cx, cy, r, r), 0, 1)+ if ground is not None: band = band * (np.arange(self.H)[:, None] < ground)+ yy = np.arange(self.H, dtype=np.float32)[:, None]; xx = np.arange(self.W, dtype=np.float32)[None]+ ang = np.arctan2(yy - cy, xx - cx)+ lt = 0.5 - 0.5 * np.cos(ang - np.arctan2(-self.L[1], -self.L[0]))+ c0 = hexc(colour)+ y_a, y_b = int(max(0, cy - r - ring - 2)), int(min(self.H, cy + r + ring + 2))+ x_a, x_b = int(max(0, cx - r - ring - 2)), int(min(self.W, cx + r + ring + 2))+ sl = (slice(y_a, y_b), slice(x_a, x_b))+ col = c0 * (0.78 + 0.4 * lt[sl][..., None])+ col = self._far(col, far)+ A = band[sl]+ if self._clip is not None: A = A * self._clip[sl]+ self.C[sl] += (col - self.C[sl]) * A[..., None]+ inner = np.clip(self.ellipse(cx, cy, r + 1.2, r + 1.2) - self.ellipse(cx, cy, r - 0.3, r - 0.3), 0, 1)+ if ground is not None: inner = inner * (yy < ground)+ self.fill(inner, self._far(c0[None, None] * 0.45, far)[0, 0], 0.7)+ return opening++ def stonework(self, x0, y0, x1, y1, course=(10, 14), block=(26, 60), ramp_='stone', far=0.0, damp=0.4, light=0.0, seed=None):+ """a dressed-stone face: courses of blocks with mortar joints, each block its own value, a lit top edge"""+ r = self._r(seed)+ R = ramp(ramp_)+ groups = [([np.array([(x0, y0), (x1, y0), (x1, y1), (x0, y1)], np.float32)], self._far(ramp_at(R, 0.2)[None], far), 1.0)]+ P, Cc = [], []+ y = y0+ while y < y1 - 1:+ hh = min(r.uniform(*course), y1 - y)+ x = x0 - r.uniform(0, block[1] * 0.6)+ while x < x1:+ ww = r.uniform(*block)+ a, b = max(x, x0), min(x + ww, x1)+ if b - a > 2:+ P.append(np.array([(a + 0.7, y + 0.6), (b - 0.7, y + 0.6), (b - 0.7, y + hh - 0.7), (a + 0.7, y + hh - 0.7)], np.float32))+ t = (y + hh / 2 - y0) / max(1, y1 - y0)+ Cc.append(0.62 + light + r.uniform(-0.1, 0.08) - damp * 0.35 * t ** 2)+ x += ww+ y += hh+ groups.append((P, self._far(ramp_at(R, np.array(Cc)), far), 1.0))+ groups.append(([np.array([(x0, y0), (x1, y0), (x1, y0 + 2.2), (x0, y0 + 2.2)], np.float32)], self._far(ramp_at(R, 0.9)[None], far), 0.9))+ self._paint(groups, 2, 0.06)++ def steps(self, x0, x1, y, n=4, rise=8.0, tread=5.0, grow=3.0, ramp_='stone', far=0.0, moss=0.4, seed=None):+ """a flight of stone steps coming toward the viewer from row y: treads (lit), risers (shaded), slab joints"""+ r = self._r(seed)+ R = ramp(ramp_)+ groups = []+ for k in range(n):+ a, b = x0 - grow * k, x1 + grow * k+ yt = y + k * (rise + tread)+ t = k / max(1, n - 1)+ tr = np.array([(a, yt), (b, yt), (b + grow, yt + tread), (a - grow, yt + tread)], np.float32)+ rs = np.array([(a - grow, yt + tread), (b + grow, yt + tread), (b + grow, yt + tread + rise), (a - grow, yt + tread + rise)], np.float32)+ groups.append(([tr], self._far(ramp_at(R, 0.82 - 0.18 * t * moss)[None], far), 1.0))+ groups.append(([rs], self._far(ramp_at(R, 0.42 - 0.15 * t * moss)[None], far), 1.0))+ nj = int((b - a) / r.uniform(28, 46))+ for xj in r.uniform(a + 6, b - 6, nj):+ groups.append(([np.array([(xj, yt + tread), (xj + 1.3, yt + tread), (xj + 1.3, yt + tread + rise), (xj, yt + tread + rise)], np.float32)],+ self._far(ramp_at(R, 0.15)[None], far), 0.8))+ if moss and k >= n // 2:+ m = int((b - a) / 5 * moss)+ groups.append((self._shapes(r.uniform(a, b, m), np.full(m, yt + tread + rise) - r.uniform(0, 3, m),+ r.uniform(3, 7, m), 1.8, 0, 'round', 0.2, r),+ self._far(ramp_at(ramp('olive'), r.uniform(0.3, 0.65, m)), far), 0.9))+ self._paint(groups, 2, 0.06)+ return y + n * (rise + tread)++ def _proj(self, pts):+ p = np.asarray(pts, np.float32)+ x, y = self.project(p[:, 0], p[:, 1], p[:, 2])+ return np.stack([x, y], 1)++ def bridge(self, path, width=1.6, deck=0.45, thick=0.22, rail=0.62, post=1.3, ramp_='stone', reflection=False,+ rails='both', far=0.0, seed=None):+ """a zigzag stone bridge on the water plane: path = [(X, Z), ...] in metres, near -> far; each segment has+ stone piers, a slab deck with joints and two balustrades of posts, pierced panels and a top rail.+ reflection=True paints the mirror image (heights negated, softened) for the water; rails = 'both', 'rear'+ (the far balustrade only, so the deck shows from a low eye) or 'none'"""+ r = self._r(seed)+ R = ramp(ramp_)+ sg = -1.0 if reflection else 1.0+ before = self.C.copy() if reflection else None+ Lw = np.array([-0.5, 0.72, -0.48], np.float32); Lw /= np.linalg.norm(Lw)+ P = np.asarray(path, np.float32)+ groups = []++ def face(pts3, normal, base=0.0, a=1.0, jit=0.0):+ nrm = np.asarray(normal, np.float32); nrm = nrm / (np.linalg.norm(nrm) + 1e-6)+ if reflection: nrm = nrm * np.array([1, -1, 1], np.float32)+ lam = float(np.clip(nrm @ Lw, 0, 1))+ val = 0.25 + 0.62 * lam + base + jit * r.normal()+ q = np.asarray(pts3, np.float32).copy(); q[:, 1] *= sg+ groups.append(([self._proj(q)], self._far(ramp_at(R, val)[None], far), a))++ def visible(pts3, normal):+ c = np.asarray(pts3, np.float32).mean(0); c[1] *= sg+ n = np.asarray(normal, np.float32).copy(); n[1] *= sg+ eye = np.array([0, self.cam[1], 0], np.float32)+ return float(n @ (eye - c)) > 0++ nseg = len(P) - 1+ for si in range(nseg - 1, -1, -1):+ A, B = P[si], P[si + 1]+ dvec = (B - A); Ls = float(np.linalg.norm(dvec)); dvec = dvec / Ls+ nvec = np.array([-dvec[1], dvec[0]], np.float32)+ ext = width * 0.5+ A2 = A - dvec * (ext if si > 0 else 0); B2 = B + dvec * (ext if si < nseg - 1 else 0)++ def pt(p2, off, yv):+ q = p2 + nvec * off+ return (q[0], yv, q[1])+ # piers+ for t in np.linspace(0, 1, max(2, int(Ls / 2.6) + 1)):+ c = A + (B - A) * t+ pw, pd = 0.28, width * 0.42+ f4 = [(c - dvec * pw + nvec * pd), (c + dvec * pw + nvec * pd), (c + dvec * pw - nvec * pd), (c - dvec * pw - nvec * pd)]+ for i in range(4):+ a3, b3 = f4[i], f4[(i + 1) % 4]+ q = [(a3[0], 0.0, a3[1]), (b3[0], 0.0, b3[1]), (b3[0], deck - thick, b3[1]), (a3[0], deck - thick, a3[1])]+ e = b3 - a3; nn = np.array([-e[1], 0, e[0]], np.float32)+ if visible(q, nn): face(q, nn, -0.18, 1.0, 0.03)+ # deck slab+ top = [pt(A2, width / 2, deck), pt(B2, width / 2, deck), pt(B2, -width / 2, deck), pt(A2, -width / 2, deck)]+ bot = [(x, deck - thick, z) for x, _, z in top]+ for i in range(4):+ q = [top[i], top[(i + 1) % 4], bot[(i + 1) % 4], bot[i]]+ e = np.array(top[(i + 1) % 4]) - np.array(top[i]); nn = np.array([-e[2], 0, e[0]], np.float32)+ if visible(q, nn): face(q, nn, -0.05, 1.0, 0.02)+ if not reflection:+ face(top, (0, 1, 0), 0.08)+ nj = int(Ls / 0.9)+ for t in np.linspace(0.05, 0.95, max(1, nj)):+ c = A2 + (B2 - A2) * t+ q = [pt(c, width / 2, deck + 0.001), pt(c + dvec * 0.04, width / 2, deck + 0.001),+ pt(c + dvec * 0.04, -width / 2, deck + 0.001), pt(c, -width / 2, deck + 0.001)]+ groups.append(([self._proj(q)], self._far(ramp_at(R, 0.3)[None], far), 0.7))+ else:+ face(bot, (0, -1, 0), -0.25)+ # balustrades: rear one first+ sides = sorted((-1, 1), key=lambda s: -np.linalg.norm((A + B) / 2 + nvec * s * width / 2))+ if rails == 'rear': sides = sides[:1]+ elif rails == 'none': sides = []+ for s in sides:+ off = s * (width / 2 - 0.08)+ npost = max(2, int(Ls / post) + 1)+ ts = np.linspace(0, 1, npost)+ outward = np.array([nvec[0] * s, 0, nvec[1] * s], np.float32)+ facing = outward if visible([pt(A + (B - A) * 0.5, off, deck + rail / 2)], outward) else -outward+ for k in range(npost - 1):+ pa_ = A + (B - A) * ts[k]; pb_ = A + (B - A) * ts[k + 1]+ pa_ = pa_ + dvec * 0.08; pb_ = pb_ - dvec * 0.08+ y_lo, y_hi = deck + 0.06, deck + rail - 0.07+ # pierced panel: four strips around an opening+ def q2(s0, s1, h0, h1):+ a3 = pa_ + (pb_ - pa_) * s0; b3 = pa_ + (pb_ - pa_) * s1+ return [pt(a3, off, y_lo + (y_hi - y_lo) * h0), pt(b3, off, y_lo + (y_hi - y_lo) * h0),+ pt(b3, off, y_lo + (y_hi - y_lo) * h1), pt(a3, off, y_lo + (y_hi - y_lo) * h1)]+ for qq in (q2(0, 1, 0, 0.28), q2(0, 1, 0.72, 1), q2(0, 0.16, 0.28, 0.72), q2(0.84, 1, 0.28, 0.72)):+ face(qq, facing, -0.06, 1.0, 0.02)+ lip = q2(0.16, 0.84, 0.66, 0.72)+ face(lip, (0, -1, 0), -0.2, 0.8)+ # top rail+ ra, rb = A + dvec * 0.02, B - dvec * 0.02+ yr = deck + rail - 0.07+ face([pt(ra, off, yr + 0.07), pt(rb, off, yr + 0.07), pt(rb, off, yr), pt(ra, off, yr)], facing, 0.0)+ if not reflection:+ yt_ = yr + 0.07+ face([pt(ra, off - 0.07, yt_), pt(rb, off - 0.07, yt_), pt(rb, off + 0.07, yt_), pt(ra, off + 0.07, yt_)], (0, 1, 0), 0.06)+ # posts+ for t in ts:+ c = A + (B - A) * t+ pw = 0.075+ yb, yt = deck, deck + rail + 0.1+ for nn2 in (np.array([dvec[0], 0, dvec[1]]), -np.array([dvec[0], 0, dvec[1]]), outward, -outward):+ cen = c + np.array([nn2[0], nn2[2]]) * pw+ tang = np.array([-nn2[2], nn2[0]]) * pw+ q = [(cen[0] - tang[0] + nvec[0] * off, yb, cen[1] - tang[1] + nvec[1] * off),+ (cen[0] + tang[0] + nvec[0] * off, yb, cen[1] + tang[1] + nvec[1] * off),+ (cen[0] + tang[0] + nvec[0] * off, yt, cen[1] + tang[1] + nvec[1] * off),+ (cen[0] - tang[0] + nvec[0] * off, yt, cen[1] - tang[1] + nvec[1] * off)]+ if visible(q, nn2): face(q, nn2, 0.02, 1.0, 0.03)+ if not reflection:+ cc = c + nvec * off+ cap = [(cc[0] - pw * 1.2, yt + 0.03, cc[1] - pw * 1.2), (cc[0] + pw * 1.2, yt + 0.03, cc[1] - pw * 1.2),+ (cc[0] + pw * 1.2, yt + 0.03, cc[1] + pw * 1.2), (cc[0] - pw * 1.2, yt + 0.03, cc[1] + pw * 1.2)]+ face(cap, (0, 1, 0), 0.12)+ self._paint(groups, 2, 0.025)+ if reflection: # a reflection is softer and a little transparent+ D = _blur1(_blur1(self.C - before, 3.0, 0), 1.0, 1)+ self.C[:] = before + D * 0.8++ def lantern(self, x, y, h=40, colour='lantern', cord=14, far=0.0, seed=None):+ """a red silk lantern hanging from (x, y): cord, gold caps, ribbed lit body, tassel"""+ r = self._r(seed)+ rx, ry = h * 0.42, h * 0.5+ cy = y + cord + h * 0.09 + ry+ groups = [([_tube([(x, y), (x, y + cord + 2)], 1.4, 1.2)[0]], self._far(hexc('#2b211d')[None], far), 1.0)]+ groups.append(([np.array([(x - rx * 0.45, cy - ry - h * 0.1), (x + rx * 0.45, cy - ry - h * 0.1),+ (x + rx * 0.5, cy - ry + h * 0.04), (x - rx * 0.5, cy - ry + h * 0.04)], np.float32)],+ self._far(hexc('#8a6a2c')[None], far), 1.0))+ t = np.linspace(0, 2 * np.pi, 48)+ body = np.stack([x + rx * np.cos(t), cy + ry * np.sin(t) * 0.94], 1).astype(np.float32)+ base = hexc(colour)+ groups.append(([body], self._far(base[None] * 0.72, far), 1.0))+ for k, (sx, sy, a) in enumerate([(0.86, 0.88, 1.0), (0.66, 0.78, 1.0), (0.44, 0.6, 1.0)]):+ ox, oy = -rx * 0.18 * (k + 1) * 0.6, -ry * 0.12 * (k + 1) * 0.6+ e = np.stack([x + ox + rx * sx * np.cos(t), cy + oy + ry * sy * np.sin(t) * 0.94], 1).astype(np.float32)+ groups.append(([e], self._far(mix(base, '#ffb07a', 0.12 + 0.18 * k)[None], far), 0.8))+ ribs = []+ for s in np.linspace(-0.8, 0.8, 5):+ yy = np.linspace(-0.92, 0.92, 14)+ xs = x + rx * s * np.sqrt(1 - yy ** 2); ys = cy + ry * yy * 0.94+ ribs.append(_tube(np.stack([xs, ys], 1), 1.1, 1.1, per=2)[0])+ groups.append((ribs, self._far(base[None] * 0.55, far), 0.55))+ groups.append(([np.array([(x - rx * 0.45, cy + ry * 0.86), (x + rx * 0.45, cy + ry * 0.86),+ (x + rx * 0.4, cy + ry + h * 0.1), (x - rx * 0.4, cy + ry + h * 0.1)], np.float32)],+ self._far(hexc('#8a6a2c')[None], far), 1.0))+ ty = cy + ry + h * 0.1+ tas = [_tube([(x + dx, ty), (x + dx * 1.4 + r.normal(0, 0.6), ty + h * 0.55)], 1.2, 0.8, per=2)[0] for dx in np.linspace(-rx * 0.22, rx * 0.22, 7)]+ groups.append((tas, self._far(base[None] * 0.9, far), 0.95))+ groups.append(([np.stack([x + 2.2 * np.cos(t), ty + 2.5 + 2.2 * np.sin(t)], 1).astype(np.float32)], self._far(hexc('gold')[None], far), 1.0))+ self._paint(groups, 3, 0.02)++ def plaque(self, cx, cy, w, h, text, board='board', letters='gold', frame='#6b4a2f', far=0.0, size=None, font=None):+ """a framed name board with gilded characters (read left to right)"""+ x0, y0, x1, y1 = cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2+ groups = [([np.array([(x0, y0), (x1, y0), (x1, y1), (x0, y1)], np.float32)], self._far(hexc(frame)[None], far), 1.0)]+ b = 3.0+ groups.append(([np.array([(x0 + b, y0 + b), (x1 - b, y0 + b), (x1 - b, y1 - b), (x0 + b, y1 - b)], np.float32)],+ self._far(hexc(board)[None], far), 1.0))+ groups.append(([np.array([(x0, y0), (x1, y0), (x1, y0 + 1.4), (x0, y0 + 1.4)], np.float32)], self._far(mix(frame, '#f0d7a0', 0.4)[None], far), 0.9))+ self._paint(groups, 3, 0.03)+ fp = font or cjk_font()+ if not fp: return+ size = size or h * 0.66+ f = ImageFont.truetype(fp, int(size * 3))+ im = Image.new('L', (int(w * 3), int(h * 3)), 0)+ ImageDraw.Draw(im).text((w * 1.5, h * 1.5), text, font=f, fill=255, anchor='mm')+ m = np.asarray(im.resize((int(w), int(h)), Image.BOX), np.float32) / 255+ x0i, y0i = int(round(x0)), int(round(y0))+ sl = (slice(y0i, y0i + m.shape[0]), slice(x0i, x0i + m.shape[1]))+ sh = np.zeros_like(m); sh[1:, 1:] = m[:-1, :-1]+ g = hexc(letters)+ A = sh * 0.6+ self.C[sl] = self.C[sl] * (1 - A[..., None]) + self._far(hexc('#120d0a')[None, None], far) * A[..., None]+ yy = np.linspace(0, 1, m.shape[0], dtype=np.float32)[:, None, None]+ gc = self._far(mix(g, '#fff0c0', 0.3) * (1 - yy) + g * 0.85 * yy, far)+ self.C[sl] = self.C[sl] * (1 - m[..., None]) + gc * m[..., None]++ # ================================================================== water+ def lake(self, y0, y1, far_colour='water_far', near_colour='water_deep', mid='water', bank=None, seed=None):+ """the still jade body colour: paler far away (where it mirrors the hazy sky), deeper toward the viewer"""+ r = self._r(seed)+ y0, y1 = int(y0), int(y1)+ yy = np.arange(y0, y1, dtype=np.float32)[:, None]+ t = ((yy - y0) / max(1, y1 - y0)) ** 0.8+ c = np.where(t[..., None] < 0.35, mix(far_colour, mid, 0)[None, None] * (1 - t[..., None] / 0.35) + hexc(mid) * (t[..., None] / 0.35),+ hexc(mid) * (1 - (t[..., None] - 0.35) / 0.65) + hexc(near_colour) * ((t[..., None] - 0.35) / 0.65))+ n = noise2d(y1 - y0, self.W, 120, 3, int(r.integers(1 << 30)))+ c = c * (0.97 + 0.06 * n[..., None])+ A = np.ones((y1 - y0, self.W), np.float32)+ if bank is not None:+ b = np.broadcast_to(np.asarray(bank, np.float32), (self.W,))+ A = smoothstep(b[None] - 0.5, b[None] + 1.0, yy)+ if self._clip is not None: A = A * self._clip[y0:y1]+ self.C[y0:y1] += (np.broadcast_to(c, (y1 - y0, self.W, 3)) - self.C[y0:y1]) * A[..., None]+ self.water_y0, self.water_y1 = y0, y1+ self.water_bank = np.broadcast_to(np.asarray(bank if bank is not None else y0, np.float32), (self.W,)).copy()+ self._water_body = self.C.copy()++ def reflect(self, bank=None, strength=0.85, blur=(2.0, 9.0), ripple=2.2, darken=0.82, tint='water', fresnel=0.55,+ y1=None, src=None, mask=None, seed=None):+ """mirror what stands above the bank line into the water: rippled sideways, blurred vertically (more with+ distance), darkened and mixed with the body colour (more toward the viewer)"""+ r = self._r(seed)+ bank = self.water_bank if bank is None else np.broadcast_to(np.asarray(bank, np.float32), (self.W,))+ S = self.C if src is None else src+ y0 = int(np.floor(bank.min())); y1 = int(self.H if y1 is None else y1)+ yy = np.arange(y0, y1, dtype=np.float32)[:, None]+ xx = np.arange(self.W, dtype=np.float32)[None]+ dist = yy - bank[None]+ ph = fbm1d(y1 - y0 + 1, 9, 3, int(r.integers(1 << 30)))[: y1 - y0, None]+ rn = noise2d(y1 - y0, self.W, 40, 2, int(r.integers(1 << 30))) - 0.5+ dx = ripple * (np.sin(yy * 0.9 + ph * 6) * 0.6 + rn * 1.6) * (0.4 + 0.6 * np.clip(dist / 200, 0, 1.5))+ sy = np.clip(np.round(bank[None] - dist * 1.0), 0, self.H - 1).astype(np.int32)+ sx = np.clip(np.round(xx + dx), 0, self.W - 1).astype(np.int32)+ Rf = S[sy, sx]+ b1 = _blur1(Rf, blur[0], 0); b2 = _blur1(_blur1(Rf, blur[1], 0), 1.2, 1)+ k = np.clip(dist / 260, 0, 1)[..., None]+ Rf = b1 * (1 - k) + b2 * k+ body = self._water_body[y0:y1]+ Rf = Rf * darken+ fr = np.clip(dist / max(1, self.H - bank.mean()), 0, 1)[..., None]+ Rf = Rf * (1 - fresnel * fr) + body * fresnel * fr+ Rf = Rf * 0.86 + hexc(tint) * 0.14+ A = (dist > 0).astype(np.float32) * strength+ A = A * smoothstep(0, 3, dist)+ if mask is not None: A = A * mask[y0:y1]+ if self._clip is not None: A = A * self._clip[y0:y1]+ Cs = self.C[y0:y1]+ Cs += (Rf - Cs) * A[..., None]++ def layer(self):+ """snapshot before painting something that stands in the water (see reflect_layer)"""+ return self.C.copy()++ def reflect_layer(self, before, axis, box, strength=0.75, blur=(1.5, 5.0), ripple=1.5, darken=0.72, below=None, seed=None):+ """mirror only what was painted since `before` (a boat, an egret) about its waterline row `axis`"""+ r = self._r(seed)+ x0, y0, x1, y1 = (int(v) for v in box)+ x0, x1 = max(0, x0), min(self.W, x1); y0 = max(0, y0)+ axis = int(axis)+ D = self.C[y0:axis] - before[y0:axis, :, :][..., :]+ D = D[:, x0:x1]+ A = (np.abs(D).max(-1) > 0.004).astype(np.float32)+ hgt = axis - y0+ yb = int(min(self.H, axis + hgt * 1.0))+ n = yb - axis+ if n <= 0: return+ src = self.C[y0:axis, x0:x1] * A[..., None]+ M = src[::-1][:n]; Am = A[::-1][:n]+ yy = np.arange(n, dtype=np.float32)[:, None]+ sh = np.round(ripple * np.sin(yy * 0.8 + r.uniform(0, 6))).astype(int)+ Mx = np.empty_like(M); Ax = np.empty_like(Am)+ for i in range(n):+ Mx[i] = np.roll(M[i], sh[i, 0], 0); Ax[i] = np.roll(Am[i], sh[i, 0], 0)+ Mx = _blur1(_blur1(Mx, blur[1], 0), blur[0], 1); Ax = _blur1(_blur1(Ax, blur[1], 0), blur[0], 1)+ col = Mx / np.maximum(Ax[..., None], 1e-3) * darken+ body = self._water_body[axis:yb, x0:x1]+ col = col * 0.8 + body * 0.2+ a = np.clip(Ax, 0, 1) * strength * (1 - 0.5 * yy / max(1, n))+ if below is not None: a = a * below[axis:yb, x0:x1]+ Cs = self.C[axis:yb, x0:x1]+ Cs += (col - Cs) * a[..., None]++ def ripples(self, box, n=400, light='#d6e6e0', dark=None, alpha=0.35, length=(10, 60), brush=1.0, seed=None):+ """faint horizontal ripple lines: pale where they catch the sky, dark where they catch the bank;+ longer and thicker toward the viewer; plus a fine vertical streak texture over the water"""+ r = self._r(seed)+ x0, y0, x1, y1 = box+ y = y0 + (y1 - y0) * r.random(n) ** 0.8+ t = (y - y0) / max(1, y1 - y0)+ x = r.uniform(x0, x1, n)+ L = r.uniform(*length, n) * (0.4 + 0.9 * t)+ wd = 0.8 + 1.6 * t+ cols = np.repeat(hexc(light)[None], n, 0)+ if dark is not None:+ dk = r.random(n) < 0.45+ cols[dk] = hexc(dark)+ if brush:+ k = int((x1 - x0) * (y1 - y0) / 260 * brush)+ bx = r.uniform(x0, x1, k); by = y0 + (y1 - y0) * r.random(k) ** 0.9+ bank = getattr(self, 'water_bank', None)+ if bank is not None:+ ok = by > bank[np.clip(bx.astype(int), 0, self.W - 1)] + 3+ bx, by = bx[ok], by[ok]+ tb = (by - y0) / max(1, y1 - y0)+ bc = self.C[np.clip(by.astype(int), 0, self.H - 1), np.clip(bx.astype(int), 0, self.W - 1)] * r.uniform(0.95, 1.05, (len(bx), 1))+ self.dabs(bx, by, r.uniform(20, 70, len(bx)) * (0.5 + tb), 1.5 + 3 * tb, bc, r.normal(0, 0.015, len(bx)), 'leaf', 0.4, 0.0, 2, 0.0)+ self.dabs(x, y, L, wd, cols, r.normal(0, 0.01, n), 'leaf', alpha, 0.0, 2, 0.0)+ ya, yb = int(y0), int(y1)+ st = _blur1(_blur1(r.normal(0, 1, (yb - ya, self.W)).astype(np.float32), 14, 0), 0.7, 1)+ st = st / (st.std() + 1e-6)+ A = np.zeros((yb - ya, self.W), np.float32); A[:, int(x0):int(x1)] = 1+ if self._clip is not None: A = A * self._clip[ya:yb]+ bank = getattr(self, 'water_bank', None)+ if bank is not None: A = A * (np.arange(ya, yb)[:, None] > bank[None] + 1)+ self.C[ya:yb] *= (1 + 0.013 * st * A)[..., None]++ def lily_pads(self, pads, ramp_='pad', far=0.0, flowers=(), seed=None):+ """water-lily pads lying on the lake: pads = [(X, Z, radius_m), ...] through the camera; each pad an+ ellipse with its notch, a shadow, lit veins and a pale rim, some curled to show a red underside"""+ r = self._r(seed)+ R = ramp(ramp_)+ pads = sorted(pads, key=lambda p: -p[1])+ e = self.cam[1]+ groups_sh, groups, rims, veins, shades = [], [], [], [], []+ csh, cpad, crim, cvn, cshade = [], [], [], [], []+ for X, Z, rad in pads:+ x, y = self.project(X, 0.0, Z)+ rx = float(self.px_per_m(Z) * rad); ry = rx * min(0.6, e / Z * 1.35)+ rot = r.uniform(0, 2 * np.pi)+ gap = r.uniform(0.32, 0.5)+ t = np.linspace(rot + gap / 2, rot + 2 * np.pi - gap / 2, 30)+ rr = 1 + 0.03 * r.normal(0, 1, len(t))+ pts = np.vstack([np.stack([x + rx * rr * np.cos(t), y + ry * rr * np.sin(t)], 1), [(x + rx * 0.05 * np.cos(rot), y)]]).astype(np.float32)+ groups_sh.append(pts + np.array([1.0, max(1.0, ry * 0.18)], np.float32)); csh.append(hexc('water_deep') * 0.6)+ lv = r.uniform(0.35, 0.7)+ groups.append(pts); cpad.append(ramp_at(R, lv))+ if r.random() < 0.12:+ t2 = np.linspace(np.pi * 0.25, np.pi * 0.75, 12)+ cr = np.vstack([np.stack([x + rx * np.cos(t2), y + ry * np.sin(t2)], 1),+ np.stack([x + rx * 0.95 * np.cos(t2[::-1]), y + ry * 0.86 * np.sin(t2[::-1]) - ry * 0.04], 1)]).astype(np.float32)+ rims.append(cr); crim.append(mix('#8a5040', '#b07a5a', r.random()))+ t4 = np.linspace(0.1, np.pi - 0.1, 12)+ sh2 = np.vstack([np.stack([x + rx * 0.98 * np.cos(t4), y + ry * 0.98 * np.sin(t4)], 1),+ np.stack([x + rx * 0.55 * np.cos(t4[::-1]), y + ry * 0.3 * np.sin(t4[::-1])], 1)]).astype(np.float32)+ shades.append(sh2); cshade.append(ramp_at(R, lv - 0.22))+ t3 = np.linspace(np.pi * 1.05, np.pi * 1.95, 12)+ ar = np.vstack([np.stack([x + rx * 0.97 * np.cos(t3), y + ry * 0.97 * np.sin(t3)], 1),+ np.stack([x + rx * 0.86 * np.cos(t3[::-1]), y + ry * 0.8 * np.sin(t3[::-1])], 1)]).astype(np.float32)+ rims.append(ar); crim.append(mix(ramp_at(R, lv + 0.25), '#cfe0d6', 0.25))+ for va in np.linspace(rot + 0.6, rot + 2 * np.pi - 0.6, 6):+ veins.append(_tube([(x, y), (x + rx * 0.85 * np.cos(va), y + ry * 0.85 * np.sin(va))], max(0.6, rx * 0.03), 0.4, per=2)[0])+ cvn.append(ramp_at(R, lv + 0.22))+ self._paint([(groups_sh, np.array(csh), 0.4)], 2, 0.0)+ self._paint([(groups, self._far(np.array(cpad) + r.normal(0, 0.015, (len(cpad), 3)), far), 1.0),+ (shades, self._far(np.array(cshade), far), 0.45), (veins, self._far(np.array(cvn), far), 0.4),+ (rims, self._far(np.array(crim), far), 0.75)], 2, 0.04)+ for X, Z, s in flowers:+ x, y = self.project(X, 0.0, Z)+ self.lotus(float(x), float(y), float(self.px_per_m(Z) * s), far=far)++ def lotus(self, x, y, s, kind='pink', far=0.0, seed=None):+ """a pink water lily lying on its pad: a flat ring of outer petals, an upright cup of inner petals, gold heart"""+ r = self._r(seed)+ R = ramp(kind)+ groups = []+ k = 10+ a = np.linspace(0, 2 * np.pi, k, endpoint=False) + r.uniform(0, 1)+ flat = 0.42+ ox, oy = np.cos(a) * s * 0.42, np.sin(a) * s * 0.42 * flat+ ang = np.arctan2(oy, ox)+ back = oy < 0+ lv = np.where(back, 0.35, 0.55) + r.uniform(-0.08, 0.08, k)+ o = np.argsort(oy)+ groups.append((self._shapes(x + ox[o], y + oy[o], np.full(k, s * 0.62), np.full(k, s * 0.2), ang[o], 'leaf', 0.05, r),+ self._far(ramp_at(R, lv[o]), far), 1.0))+ m = 7+ a2 = np.linspace(-np.pi * 0.85, -np.pi * 0.15, m) + r.normal(0, 0.06, m)+ cx_ = x + np.cos(a2) * s * 0.14; cy_ = y - s * 0.12 + np.sin(a2) * s * 0.18+ lv2 = 0.62 + 0.3 * (np.cos(a2) < 0) + r.uniform(-0.05, 0.05, m)+ groups.append((self._shapes(cx_, cy_, np.full(m, s * 0.5), np.full(m, s * 0.18), a2, 'leaf', 0.05, r),+ self._far(ramp_at(R, lv2), far), 1.0))+ groups.append((self._shapes(np.array([x]), np.array([y - s * 0.08]), np.array([s * 0.2]), np.array([s * 0.07]), 0, 'round', 0.0, r),+ self._far(hexc('#f0c95a')[None], far), 1.0))+ groups.append((self._shapes(cx_, cy_ - s * 0.06, np.full(m, s * 0.18), np.full(m, s * 0.05), a2, 'leaf', 0.0, r),+ self._far(ramp_at(R, np.full(m, 1.0)), far), 0.8))+ self._paint(groups, 3, 0.0)++ def boat(self, x0, x1, y, h=26, colour='wood', far=0.0, pole=True, seed=None):+ """a small wooden boat lying along the bank, waterline at row y, seen a little from above"""+ r = self._r(seed)+ n = 40+ t = np.linspace(0, 1, n)+ L = x1 - x0+ xs = x0 + L * t+ sheer = y - h - h * 0.95 * np.abs(2 * t - 1) ** 3.2+ far_g = sheer - h * 0.42 * (1 - np.abs(2 * t - 1) ** 2.4)+ wl = y + 1.5 * np.sin(t * np.pi)+ base = hexc(colour)+ groups = []+ inner = np.vstack([np.stack([xs, far_g], 1), np.stack([xs[::-1], sheer[::-1]], 1)]).astype(np.float32)+ groups.append(([inner], self._far((base * 0.55)[None], far), 1.0))+ floor = np.vstack([np.stack([xs[8:-8], (far_g[8:-8] * 0.4 + sheer[8:-8] * 0.6)], 1),+ np.stack([xs[8:-8][::-1], sheer[8:-8][::-1] - 1], 1)]).astype(np.float32)+ groups.append(([floor], self._far((base * 0.8)[None], far), 1.0))+ ribs = []+ for tt in np.linspace(0.2, 0.8, 6):+ i = int(tt * (n - 1))+ ribs.append(_tube([(xs[i], far_g[i]), (xs[i], sheer[i])], 1.6, 1.6, per=2)[0])+ groups.append((ribs, self._far((base * 0.4)[None], far), 0.9))+ hull = np.vstack([np.stack([xs, sheer], 1), np.stack([xs[::-1], wl[::-1]], 1)]).astype(np.float32)+ groups.append(([hull], self._far(base[None] * 0.9, far), 1.0))+ for k, f in enumerate((0.33, 0.62)):+ yk = sheer + (wl - sheer) * f+ groups.append(([_tube(np.stack([xs[2:-2], yk[2:-2]], 1), 1.2, 1.2, per=1)[0]], self._far((base * 0.6)[None], far), 0.8))+ band = np.vstack([np.stack([xs, sheer - 1.5], 1), np.stack([xs[::-1], sheer[::-1] + 3.2], 1)]).astype(np.float32)+ groups.append(([band], self._far(mix(base, '#e8d2a8', 0.45)[None], far), 1.0))+ dk = np.vstack([np.stack([xs, wl - h * 0.25], 1), np.stack([xs[::-1], wl[::-1]], 1)]).astype(np.float32)+ groups.append(([dk], self._far((base * 0.55)[None], far), 0.6))+ gl = np.vstack([np.stack([xs, far_g - 1.2], 1), np.stack([xs[::-1], far_g[::-1] + 1.8], 1)]).astype(np.float32)+ groups.append(([gl], self._far(mix(base, '#d9c39a', 0.3)[None], far), 1.0))+ if pole:+ groups.append(([_tube([(x0 + L * 0.18, far_g[7] - 2), (x0 + L * 0.95, far_g[-6] - h * 0.6)], 2.4, 2.0, per=2)[0]],+ self._far(hexc('#c2a46a')[None], far), 1.0))+ self._paint(groups, 2, 0.05)++ def egret(self, x, y, s=40, pose='stand', facing=-1, far=0.0, seed=None):+ """a little white egret: standing (feet at (x, y), s = height) or flying (body at (x, y), s = wing length)"""+ r = self._r(seed)+ W_ = hexc('egret'); Sh = mix('egret', '#93a2b4', 0.5); Mid = mix('egret', '#b9c3cc', 0.5)+ f = float(facing)+ t = np.linspace(0, 2 * np.pi, 40)++ def P(pts):+ q = np.asarray(pts, np.float32).copy(); q[:, 0] = x + f * q[:, 0] * s; q[:, 1] = y + q[:, 1] * s+ return q+ groups = []+ if pose == 'stand':+ legs = [_tube(P([(0.02, -0.44), (0.0, -0.22), (-0.01, 0.0)]), s * 0.022, s * 0.016, per=3)[0],+ _tube(P([(-0.04, -0.44), (-0.09, -0.24), (-0.1, -0.02)]), s * 0.022, s * 0.016, per=3)[0]]+ groups.append((legs, self._far(hexc('#26251f')[None], far), 1.0))+ body = np.stack([0.24 * np.cos(t), 0.1 * np.sin(t)], 1)+ rot = 0.42+ body = np.stack([body[:, 0] * np.cos(rot) - body[:, 1] * np.sin(rot), body[:, 0] * np.sin(rot) + body[:, 1] * np.cos(rot)], 1)+ body = body + np.array([-0.02, -0.52])+ body[:, 1] -= np.clip(body[:, 0], 0, None) * 0.15+ groups.append(([P(body)], self._far(Mid[None], far), 1.0))+ groups.append(([P(body * np.array([0.92, 0.86]) + np.array([0.0, -0.075]))], self._far(W_[None], far), 1.0))+ tail = [(-0.18, -0.48), (-0.32, -0.36), (-0.3, -0.33), (-0.14, -0.43)]+ groups.append(([P(tail)], self._far(Sh[None], far), 1.0))+ neck = [(0.13, -0.6), (0.2, -0.72), (0.12, -0.83), (0.11, -0.93), (0.17, -1.0)]+ groups.append(([_tube(P(neck), s * 0.075, s * 0.055, per=6)[0]], self._far(W_[None], far), 1.0))+ groups.append(([P(np.stack([0.18 + 0.055 * np.cos(t), -1.0 + 0.042 * np.sin(t)], 1))], self._far(W_[None], far), 1.0))+ groups.append(([P([(0.22, -1.015), (0.46, -0.99), (0.22, -0.985)])], self._far(hexc('#d9a53a')[None], far), 1.0))+ groups.append(([P(np.stack([0.2 + 0.012 * np.cos(t), -1.012 + 0.012 * np.sin(t)], 1))], self._far(hexc('#1a1a18')[None], far), 1.0))+ groups.append(([_tube(P([(0.1, -0.56), (0.02, -0.5), (-0.12, -0.44)]), s * 0.03, s * 0.01, per=3)[0]],+ self._far(Sh[None], far), 0.7))+ else:+ def wing(root, tip, sweep, width, k=14):+ # a broad rounded wing from a root on the back to a tip, its trailing edge swept back+ rt, tp = np.array(root, np.float32), np.array(tip, np.float32)+ tt = np.linspace(0, 1, k)[:, None]+ lead = rt + (tp - rt) * tt + np.array([0.06, 0.0]) * np.sin(tt * np.pi)+ trail = rt + np.array([-width, 0.04]) + (tp - rt - np.array([-width, 0.04])) * tt + np.array([-sweep, 0.0]) * np.sin(tt * np.pi)+ return np.vstack([lead, trail[::-1]])+ groups.append(([P(wing((0.1, -0.03), (0.18, -0.8), 0.1, 0.2))], self._far(Sh[None], far), 1.0))+ groups.append(([P(np.stack([0.27 * np.cos(t), 0.075 * np.sin(t)], 1) + np.array([0.0, 0.015]))], self._far(Mid[None], far), 1.0))+ groups.append(([P(np.stack([0.25 * np.cos(t), 0.055 * np.sin(t)], 1))], self._far(W_[None], far), 1.0))+ groups.append(([_tube(P([(0.18, -0.01), (0.27, -0.06), (0.31, -0.04)]), s * 0.075, s * 0.055, per=3)[0]], self._far(W_[None], far), 1.0))+ groups.append(([P([(0.33, -0.055), (0.56, -0.03), (0.33, -0.025)])], self._far(hexc('#d9a53a')[None], far), 1.0))+ groups.append(([_tube(P([(-0.2, 0.02), (-0.44, 0.05), (-0.6, 0.06)]), s * 0.02, s * 0.015, per=2)[0]],+ self._far(hexc('#26251f')[None], far), 1.0))+ nw = wing((0.06, -0.02), (-0.16, -0.9), 0.16, 0.26)+ groups.append(([P(nw)], self._far(W_[None], far), 1.0))+ for k in range(5):+ tp = np.array([-0.16 - 0.05 * k, -0.9 + 0.07 * k])+ groups.append(([P([tp + (0.03, 0.02), tp + (-0.06, -0.01), tp + (0.0, 0.08)])], self._far(W_[None], far), 1.0))+ groups.append(([P(wing((0.0, -0.03), (-0.14, -0.62), 0.08, 0.12) + np.array([-0.04, 0.02]))], self._far(Mid[None], far), 0.5))+ self._paint(groups, 3, 0.0)++ # ================================================================== finish+ def seal(self, x, y, w=26, h=46, text='春水', colour='seal', seed=None):+ """a small red seal, characters cut out in white, edges worn"""+ r = self._r(seed)+ x0, y0 = int(x), int(y); w, h = int(w), int(h)+ ss = 3+ im = Image.new('L', (w * ss, h * ss), 0); d = ImageDraw.Draw(im)+ d.rectangle([0, 0, w * ss - 1, h * ss - 1], fill=255)+ fp = cjk_font()+ if fp:+ n = len(text)+ fs = int(min(w * 0.78, h * 0.86 / n) * ss)+ f = ImageFont.truetype(fp, fs)+ for i, ch in enumerate(text):+ d.text((w * ss / 2, (h * (i + 0.5) / n) * ss), ch, font=f, fill=0, anchor='mm')+ d.rectangle([2 * ss, 2 * ss, w * ss - 2 * ss - 1, h * ss - 2 * ss - 1], outline=0, width=ss)+ m = np.asarray(im.resize((w, h), Image.BOX), np.float32) / 255+ n = noise2d(h, w, 5, 2, int(r.integers(1 << 30)))+ m = m * smoothstep(0.06, 0.22, n + 0.25)+ edge = np.ones_like(m); edge[0, :] *= r.uniform(0.3, 1, w); edge[-1, :] *= r.uniform(0.3, 1, w)+ edge[:, 0] *= r.uniform(0.3, 1, h); edge[:, -1] *= r.uniform(0.3, 1, h)+ A = np.clip(m * edge, 0, 1) * 0.96+ sl = (slice(y0, y0 + h), slice(x0, x0 + w))+ c = hexc(colour)[None, None] * (0.94 + 0.12 * n[..., None])+ self.C[sl] = self.C[sl] * (1 - A[..., None]) + c * A[..., None]++ def grain(self, amount=1.0):+ """finish: slight painterly softness, fine grain and the faintest canvas weave (applied in render)"""+ self.grain_amt = float(amount)++ def render(self):+ out = self.C+ p = self.grain_amt+ if p:+ soft = np.stack([blur(out[..., i], 0.9) for i in range(3)], -1)+ out = out * (1 - 0.32 * p) + soft * 0.32 * p+ lum = out.mean(-1)+ glow = blur(np.clip(lum - 0.6, 0, 1), 16)+ out = out + p * 0.22 * glow[..., None] * hexc('#fff3dc')+ lum = out.mean(-1, keepdims=True)+ out = lum + (out - lum) * (1 - 0.05 * p)+ out = out + p * 0.035 * (1 - lum) ** 2 * (hexc('#3d6470') - 0.25)+ if not hasattr(self, '_grain'):+ r = np.random.default_rng(self.seed + 7)+ g = r.normal(0, 1, (self.H, self.W)).astype(np.float32)+ g = 0.6 * g + 0.4 * blur(g, 0.9) * 2.0+ yy = np.arange(self.H, dtype=np.float32)[:, None]; xx = np.arange(self.W, dtype=np.float32)[None]+ weave = np.sin(xx * 2.1 + 0.5 * np.sin(yy * 0.07)) * np.sin(yy * 2.0) * 0.5+ st = _blur1(r.normal(0, 1, (self.H, self.W)).astype(np.float32), 5, 0)+ st = st / (st.std() + 1e-6)+ self._grain = (0.013 * g + 0.006 * weave + 0.006 * st).astype(np.float32)+ out = out * (1 + p * self._grain[..., 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