pixelcanvas 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pixelcanvas/__init__.py +77 -0
- pixelcanvas/_args.py +238 -0
- pixelcanvas/_runtime/scenes/__init__.py +0 -0
- pixelcanvas/_runtime/scenes/_template_animals.py +65 -0
- pixelcanvas/_runtime/scenes/_template_animation.py +60 -0
- pixelcanvas/_runtime/scenes/_template_banner.py +63 -0
- pixelcanvas/_runtime/scenes/_template_blank.py +45 -0
- pixelcanvas/_runtime/scenes/_template_card.py +61 -0
- pixelcanvas/_runtime/scenes/_template_characters.py +56 -0
- pixelcanvas/_runtime/scenes/_template_chart.py +52 -0
- pixelcanvas/_runtime/scenes/_template_comic.py +70 -0
- pixelcanvas/_runtime/scenes/_template_dashboard.py +53 -0
- pixelcanvas/_runtime/scenes/_template_diagram.py +59 -0
- pixelcanvas/_runtime/scenes/_template_drawing.py +60 -0
- pixelcanvas/_runtime/scenes/_template_figure.py +57 -0
- pixelcanvas/_runtime/scenes/_template_floorplan.py +58 -0
- pixelcanvas/_runtime/scenes/_template_icons.py +70 -0
- pixelcanvas/_runtime/scenes/_template_illustration.py +68 -0
- pixelcanvas/_runtime/scenes/_template_infographic.py +60 -0
- pixelcanvas/_runtime/scenes/_template_interior.py +60 -0
- pixelcanvas/_runtime/scenes/_template_isometric.py +58 -0
- pixelcanvas/_runtime/scenes/_template_landscape.py +70 -0
- pixelcanvas/_runtime/scenes/_template_nature.py +69 -0
- pixelcanvas/_runtime/scenes/_template_people.py +66 -0
- pixelcanvas/_runtime/scenes/_template_pets.py +57 -0
- pixelcanvas/_runtime/scenes/_template_photo.py +58 -0
- pixelcanvas/_runtime/scenes/_template_poster.py +57 -0
- pixelcanvas/_runtime/scenes/_template_product.py +52 -0
- pixelcanvas/_runtime/scenes/_template_scene3d.py +54 -0
- pixelcanvas/_runtime/scenes/_template_still_life.py +62 -0
- pixelcanvas/_runtime/scenes/_template_styled.py +57 -0
- pixelcanvas/_runtime/scenes/_template_ui.py +59 -0
- pixelcanvas/_runtime/scenes/_template_wallpaper.py +39 -0
- pixelcanvas/_runtime/scenes/anim_campfire.py +132 -0
- pixelcanvas/_runtime/scenes/aurora_lake.py +151 -0
- pixelcanvas/_runtime/scenes/backdrop_mountain_dawn.py +36 -0
- pixelcanvas/_runtime/scenes/backdrop_sheet.py +74 -0
- pixelcanvas/_runtime/scenes/backdrop_wallpapers.py +87 -0
- pixelcanvas/_runtime/scenes/chart_dashboard.py +86 -0
- pixelcanvas/_runtime/scenes/chart_figure.py +77 -0
- pixelcanvas/_runtime/scenes/chart_subscriptions.py +50 -0
- pixelcanvas/_runtime/scenes/city_dusk.py +64 -0
- pixelcanvas/_runtime/scenes/clay_campsite.py +69 -0
- pixelcanvas/_runtime/scenes/clay_cast.py +82 -0
- pixelcanvas/_runtime/scenes/clay_picnic.py +102 -0
- pixelcanvas/_runtime/scenes/clay_stickers.py +67 -0
- pixelcanvas/_runtime/scenes/clay_zoo.py +110 -0
- pixelcanvas/_runtime/scenes/creature_meadow.py +102 -0
- pixelcanvas/_runtime/scenes/creature_parade.py +106 -0
- pixelcanvas/_runtime/scenes/diagram_architecture.py +73 -0
- pixelcanvas/_runtime/scenes/diagram_explainer.py +88 -0
- pixelcanvas/_runtime/scenes/diagram_flowchart.py +60 -0
- pixelcanvas/_runtime/scenes/diagram_login_sequence.py +55 -0
- pixelcanvas/_runtime/scenes/diagram_stone_lantern.py +63 -0
- pixelcanvas/_runtime/scenes/drafting_apartment.py +111 -0
- pixelcanvas/_runtime/scenes/drafting_bracket.py +128 -0
- pixelcanvas/_runtime/scenes/drafting_floorplan.py +97 -0
- pixelcanvas/_runtime/scenes/elements_campfire.py +106 -0
- pixelcanvas/_runtime/scenes/elements_sheet.py +385 -0
- pixelcanvas/_runtime/scenes/elements_storm.py +59 -0
- pixelcanvas/_runtime/scenes/figure_cafe.py +129 -0
- pixelcanvas/_runtime/scenes/figure_cast.py +73 -0
- pixelcanvas/_runtime/scenes/flora_garden.py +149 -0
- pixelcanvas/_runtime/scenes/flora_sheet.py +91 -0
- pixelcanvas/_runtime/scenes/form_room.py +138 -0
- pixelcanvas/_runtime/scenes/form_still_life.py +134 -0
- pixelcanvas/_runtime/scenes/illustration_anime.py +107 -0
- pixelcanvas/_runtime/scenes/illustration_chef.py +136 -0
- pixelcanvas/_runtime/scenes/illustration_jazz.py +92 -0
- pixelcanvas/_runtime/scenes/illustration_stickers.py +201 -0
- pixelcanvas/_runtime/scenes/illustration_ukiyoe.py +123 -0
- pixelcanvas/_runtime/scenes/layout_cafe_menu.py +51 -0
- pixelcanvas/_runtime/scenes/layout_readme_banner.py +60 -0
- pixelcanvas/_runtime/scenes/mountains_sunset.py +138 -0
- pixelcanvas/_runtime/scenes/neon_poster.py +103 -0
- pixelcanvas/_runtime/scenes/night_sky.py +63 -0
- pixelcanvas/_runtime/scenes/palette_sheet.py +100 -0
- pixelcanvas/_runtime/scenes/pictogram_sheet.py +122 -0
- pixelcanvas/_runtime/scenes/poster_farmers_market.py +77 -0
- pixelcanvas/_runtime/scenes/sea_sunset.py +72 -0
- pixelcanvas/_runtime/scenes/solid_earbuds.py +41 -0
- pixelcanvas/_runtime/scenes/solid_isometric.py +66 -0
- pixelcanvas/_runtime/scenes/solid_product.py +52 -0
- pixelcanvas/_runtime/scenes/solid_reading_nook.py +62 -0
- pixelcanvas/_runtime/scenes/solid_toys.py +53 -0
- pixelcanvas/_runtime/scenes/specs/animals.json +12 -0
- pixelcanvas/_runtime/scenes/specs/card.json +14 -0
- pixelcanvas/_runtime/scenes/specs/chart.json +11 -0
- pixelcanvas/_runtime/scenes/specs/dashboard.json +16 -0
- pixelcanvas/_runtime/scenes/specs/diagram.json +17 -0
- pixelcanvas/_runtime/scenes/specs/icons.json +16 -0
- pixelcanvas/_runtime/scenes/specs/landscape.json +11 -0
- pixelcanvas/_runtime/scenes/specs/nature.json +13 -0
- pixelcanvas/_runtime/scenes/specs/people.json +14 -0
- pixelcanvas/_runtime/scenes/specs/poster.json +19 -0
- pixelcanvas/_runtime/scenes/specs/room.json +20 -0
- pixelcanvas/_runtime/scenes/specs/scene.json +13 -0
- pixelcanvas/_runtime/scenes/specs/scene3d.json +16 -0
- pixelcanvas/_runtime/scenes/specs/still_life.json +11 -0
- pixelcanvas/_runtime/scenes/specs/ui.json +12 -0
- pixelcanvas/_runtime/scenes/specs/wallpaper.json +12 -0
- pixelcanvas/_runtime/scenes/still_life.py +115 -0
- pixelcanvas/_runtime/scenes/style_showcase.py +69 -0
- pixelcanvas/_runtime/scenes/texture_swatches.py +124 -0
- pixelcanvas/_runtime/scenes/texture_wall.py +177 -0
- pixelcanvas/_runtime/scenes/type_poster.py +121 -0
- pixelcanvas/_runtime/scenes/type_specimen.py +146 -0
- pixelcanvas/_runtime/scenes/ui_components.py +117 -0
- pixelcanvas/_runtime/scenes/ui_landing.py +76 -0
- pixelcanvas/_runtime/scenes/ui_landing_hero.py +47 -0
- pixelcanvas/_runtime/scenes/ui_meditation.py +51 -0
- pixelcanvas/_runtime/scenes/ui_mobile_app.py +116 -0
- pixelcanvas/_runtime/scenes/vector_app_icons.py +32 -0
- pixelcanvas/_runtime/scenes/vector_icons.py +71 -0
- pixelcanvas/_runtime/skills/pixelcanvas/SKILL.md +179 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/api.md +257 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/backdrops.md +164 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/catalog.md +77 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/charts.md +185 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/clay.md +220 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/creatures.md +165 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/diagrams.md +197 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/drafting.md +232 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/elements.md +204 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/figures.md +161 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/flora.md +192 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/forms.md +214 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/illustration.md +250 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/pictograms.md +196 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/reference.md +102 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/review.md +250 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/solid.md +233 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/spec.md +158 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/styles.md +242 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/techniques.md +319 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/textures.md +177 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/typography.md +248 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/ui.md +188 -0
- pixelcanvas/_runtime/skills/pixelcanvas/references/vector.md +187 -0
- pixelcanvas/_runtime/skills/pixelcanvas/scripts/bootstrap.py +307 -0
- pixelcanvas/_runtime/skills/pixelcanvas-lite/SKILL.md +70 -0
- pixelcanvas/_runtime/skills/pixelcanvas-lite/scripts/bootstrap.py +307 -0
- pixelcanvas/_runtime/skills/pixelcanvas-lite/tools/compose.py +42 -0
- pixelcanvas/_runtime/tools/build_gallery.py +152 -0
- pixelcanvas/_runtime/tools/compose.py +464 -0
- pixelcanvas/_runtime/tools/fonts.py +297 -0
- pixelcanvas/_runtime/tools/install_skill.py +160 -0
- pixelcanvas/_runtime/tools/kit.py +128 -0
- pixelcanvas/_runtime/tools/layers.py +121 -0
- pixelcanvas/_runtime/tools/look.py +783 -0
- pixelcanvas/_runtime/tools/match.py +50 -0
- pixelcanvas/_runtime/tools/new_scene.py +2380 -0
- pixelcanvas/_runtime/tools/pc.py +24 -0
- pixelcanvas/_runtime/tools/release_check.py +463 -0
- pixelcanvas/_runtime/tools/render.py +1490 -0
- pixelcanvas/_runtime/tools/styles.py +183 -0
- pixelcanvas/backdrop.py +2229 -0
- pixelcanvas/brush.py +78 -0
- pixelcanvas/canvas.py +590 -0
- pixelcanvas/catalog.py +3805 -0
- pixelcanvas/chart.py +2936 -0
- pixelcanvas/clay/__init__.py +58 -0
- pixelcanvas/clay/_manifest.py +75 -0
- pixelcanvas/clay/animal.py +209 -0
- pixelcanvas/clay/animal_build.py +783 -0
- pixelcanvas/clay/animal_rig.py +275 -0
- pixelcanvas/clay/character.py +1352 -0
- pixelcanvas/clay/face.py +288 -0
- pixelcanvas/clay/families.py +630 -0
- pixelcanvas/clay/hair.py +352 -0
- pixelcanvas/clay/markings.py +188 -0
- pixelcanvas/clay/props.py +486 -0
- pixelcanvas/clay/registry.py +185 -0
- pixelcanvas/clay/rig.py +367 -0
- pixelcanvas/clay/shapes.py +404 -0
- pixelcanvas/clay/species.py +424 -0
- pixelcanvas/clay/tables.py +173 -0
- pixelcanvas/cli.py +518 -0
- pixelcanvas/color.py +191 -0
- pixelcanvas/creature.py +4545 -0
- pixelcanvas/diagram.py +5232 -0
- pixelcanvas/drafting.py +4303 -0
- pixelcanvas/elements.py +3364 -0
- pixelcanvas/figure.py +3693 -0
- pixelcanvas/filters.py +313 -0
- pixelcanvas/flora.py +4528 -0
- pixelcanvas/form.py +2807 -0
- pixelcanvas/illustrate.py +1485 -0
- pixelcanvas/layers.py +759 -0
- pixelcanvas/layout.py +1141 -0
- pixelcanvas/manifest.py +4591 -0
- pixelcanvas/masks.py +155 -0
- pixelcanvas/mcp_server.py +634 -0
- pixelcanvas/noise.py +247 -0
- pixelcanvas/palette.py +762 -0
- pixelcanvas/pictograms/__init__.py +1075 -0
- pixelcanvas/pictograms/everyday.py +935 -0
- pixelcanvas/pictograms/kitchen_apps.py +245 -0
- pixelcanvas/pictograms/living.py +1080 -0
- pixelcanvas/pictograms/music_transport_buildings.py +995 -0
- pixelcanvas/pictograms/outdoor_home.py +223 -0
- pixelcanvas/pictograms/produce.py +158 -0
- pixelcanvas/pictograms/symbols.py +895 -0
- pixelcanvas/pictograms/tech_bio_story.py +307 -0
- pixelcanvas/reference.py +581 -0
- pixelcanvas/scenery.py +542 -0
- pixelcanvas/sdf.py +220 -0
- pixelcanvas/solid.py +5063 -0
- pixelcanvas/spec.py +5867 -0
- pixelcanvas/stylize.py +2502 -0
- pixelcanvas/text.py +3667 -0
- pixelcanvas/texture.py +2621 -0
- pixelcanvas/ui.py +6048 -0
- pixelcanvas/vector.py +2943 -0
- pixelcanvas/vision.py +597 -0
- pixelcanvas-0.4.0.dist-info/METADATA +110 -0
- pixelcanvas-0.4.0.dist-info/RECORD +221 -0
- pixelcanvas-0.4.0.dist-info/WHEEL +5 -0
- pixelcanvas-0.4.0.dist-info/entry_points.txt +2 -0
- pixelcanvas-0.4.0.dist-info/licenses/LICENSE +21 -0
- pixelcanvas-0.4.0.dist-info/top_level.txt +1 -0
pixelcanvas/__init__.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
pixelcanvas — draw and retouch pictures with pixel-level computation (numpy + Pillow)
|
|
4
|
+
=====================================================================================
|
|
5
|
+
|
|
6
|
+
Three layers of API:
|
|
7
|
+
|
|
8
|
+
* Low level (``from pixelcanvas import *``): Canvas, noise, masks, brushes, blending, filters, colour, text.
|
|
9
|
+
Anything can be drawn from this layer.
|
|
10
|
+
* Freehand (``from pixelcanvas import Sketch, paper, grade``, module ``illustrate``): shapes in canvas fractions,
|
|
11
|
+
one-call shading / outline / shadow / glow, local frames for characters; ``cv.draw()`` is a supersampled Pillow
|
|
12
|
+
ImageDraw layer on the same canvas.
|
|
13
|
+
* Kits, loaded on first use (``from pixelcanvas import flora, elements, solid, diagram, chart, drafting, texture,
|
|
14
|
+
vector, layout, stylize, form, figure, creature, clay, pictograms, palette, backdrop, ui, spec, catalog``): one
|
|
15
|
+
call per subject — a tree, a campfire, a 3D mug, a flowchart, a chart, an engineering sheet, a material, a style.
|
|
16
|
+
* Landscape recipes (``from pixelcanvas.scenery import *``): Scene + sky / sun / clouds / mountains / mist / river /
|
|
17
|
+
trees / light rays / post-processing.
|
|
18
|
+
|
|
19
|
+
Every kit records what it drew in ``cv.manifest`` (see ``pixelcanvas.manifest``), so ``render.py --check`` can say
|
|
20
|
+
in plain text which objects are in the picture, where, and whether the request was met.
|
|
21
|
+
|
|
22
|
+
Conventions
|
|
23
|
+
-----------
|
|
24
|
+
* Coordinates: x right, y down; arrays ``arr[y, x]``; ``cv.xy()`` gives the (X, Y) pixel grids, ``cv.uv()`` 0~1 (U, V).
|
|
25
|
+
* Masks: float32 (H, W), 0 = untouched, 1 = fully painted.
|
|
26
|
+
* Colours: '#rrggbb' / (r, g, b) 0~1 / (255, 128, 0) / a full (H, W, 3) map; HDR values > 1 are allowed.
|
|
27
|
+
* Order: background (gradient) → far to near, each through its mask → post (bloom / soft_clip / contrast /
|
|
28
|
+
vignette) → save.
|
|
29
|
+
|
|
30
|
+
Minimal example
|
|
31
|
+
---------------
|
|
32
|
+
>>> from pixelcanvas import *
|
|
33
|
+
>>> cv = Canvas(640, 360)
|
|
34
|
+
>>> cv.gradient([(0, '#0b1a3a'), (1, '#f6c28f')]) # sky gradient
|
|
35
|
+
>>> X, Y = cv.xy()
|
|
36
|
+
>>> cv.glow(400, 200, 60, '#fff0c0', strength=1.2) # glow (HDR)
|
|
37
|
+
>>> ridge = 220 - 60 * fbm1d(640, 120, seed=1) # ridge line: one y per column
|
|
38
|
+
>>> cv.paint('#223344', clamp01(Y - ridge[None, :] + 0.5)) # below the ridge = mountain
|
|
39
|
+
>>> cv.put(10, 10, '#ff0000') # one pixel
|
|
40
|
+
>>> cv.soft_clip(0.8).save('demo.png', preview='demo_small.jpg')
|
|
41
|
+
"""
|
|
42
|
+
import importlib as _importlib
|
|
43
|
+
|
|
44
|
+
from . import color, noise, masks, brush, filters, text, sdf, vision, layers, manifest
|
|
45
|
+
from .color import * # noqa: F401,F403
|
|
46
|
+
from .noise import * # noqa: F401,F403
|
|
47
|
+
from .masks import * # noqa: F401,F403
|
|
48
|
+
from .brush import * # noqa: F401,F403
|
|
49
|
+
from .filters import * # noqa: F401,F403
|
|
50
|
+
from .text import * # noqa: F401,F403
|
|
51
|
+
from .canvas import Canvas
|
|
52
|
+
from . import illustrate
|
|
53
|
+
from .illustrate import Sketch, paper, grade, limit_palette, MOODS, grow, edge, signed_distance
|
|
54
|
+
|
|
55
|
+
__version__ = "0.4.0"
|
|
56
|
+
|
|
57
|
+
# heavy kits: imported on first attribute access (``pixelcanvas.flora`` / ``from pixelcanvas import flora``) and
|
|
58
|
+
# never star-imported, so names such as box / union / texture never shadow the 2D helpers above
|
|
59
|
+
_LAZY = ("stylize", "scenery", "vector", "diagram", "chart", "drafting", "solid", "texture", "elements", "flora",
|
|
60
|
+
"form", "figure", "creature", "layout", "clay", "pictograms", "palette", "backdrop", "ui", "spec", "catalog",
|
|
61
|
+
"cli", "mcp_server")
|
|
62
|
+
|
|
63
|
+
__all__ = ["Canvas", "__version__"] + color.__all__ + noise.__all__ + masks.__all__ + brush.__all__ + filters.__all__ \
|
|
64
|
+
+ text.__all__ + ["sdf", "vision", "layers", "stylize", "manifest", "illustrate", "Sketch", "paper", "grade",
|
|
65
|
+
"limit_palette", "MOODS", "grow", "edge", "signed_distance"]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def __getattr__(name):
|
|
69
|
+
if name in _LAZY:
|
|
70
|
+
mod = _importlib.import_module(f".{name}", __name__)
|
|
71
|
+
globals()[name] = mod
|
|
72
|
+
return mod
|
|
73
|
+
raise AttributeError(f"module 'pixelcanvas' has no attribute {name!r}")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def __dir__():
|
|
77
|
+
return sorted(set(globals()) | set(_LAZY))
|
pixelcanvas/_args.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"""Strict keyword options shared by the pixelcanvas modules.
|
|
2
|
+
|
|
3
|
+
``reject_unknown`` turns a silently ignored misspelt option into a TypeError that names the closest valid option;
|
|
4
|
+
``unknown_name`` / ``check_choice`` do the same for registry names and enumerated values; ``module_getattr`` gives a
|
|
5
|
+
module a did-you-mean AttributeError (one line in the module: ``__getattr__ = module_getattr(__name__, HINTS)``).
|
|
6
|
+
"""
|
|
7
|
+
import difflib
|
|
8
|
+
import inspect
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
# spellings people naturally use; each group lists interchangeable names (the first allowed one wins)
|
|
12
|
+
_WORDS = (("colour", "color"), ("centre", "center"), ("grey", "gray"))
|
|
13
|
+
GROUPS = (("tag", "tags"), ("width", "w"), ("height", "h"), ("radius", "r"), ("opacity", "alpha"),
|
|
14
|
+
("bg", "background"), ("fg", "foreground", "ink"), ("line_width", "stroke_width", "lw"),
|
|
15
|
+
("pos", "position", "at", "xy"))
|
|
16
|
+
ONE_WAY = {"size": "font_size"} # given name -> option it means (not the reverse: size is often a real option)
|
|
17
|
+
ALIASES = dict(ONE_WAY)
|
|
18
|
+
_MAX_LISTED = 15
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _spell(name):
|
|
22
|
+
for a, b in _WORDS:
|
|
23
|
+
if a in name:
|
|
24
|
+
name = name.replace(a, b)
|
|
25
|
+
return name
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _variants(name):
|
|
29
|
+
"""The given name, its colour/centre/grey spelling and its singular / plural forms."""
|
|
30
|
+
out = [name]
|
|
31
|
+
for n in (name, _spell(name)):
|
|
32
|
+
for v in (n, n[:-1] if n.endswith("s") else n + "s"):
|
|
33
|
+
if v not in out:
|
|
34
|
+
out.append(v)
|
|
35
|
+
return out
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _synonyms(name):
|
|
39
|
+
out = []
|
|
40
|
+
for g in GROUPS:
|
|
41
|
+
if name in g:
|
|
42
|
+
out += [m for m in g if m != name]
|
|
43
|
+
if name in ONE_WAY:
|
|
44
|
+
out.append(ONE_WAY[name])
|
|
45
|
+
return out
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _resolve(name, allowed, aliases):
|
|
49
|
+
if name in allowed:
|
|
50
|
+
return name
|
|
51
|
+
if aliases and aliases.get(name) in allowed:
|
|
52
|
+
return aliases[name]
|
|
53
|
+
for v in _variants(name):
|
|
54
|
+
if v in allowed:
|
|
55
|
+
return v
|
|
56
|
+
if aliases and aliases.get(v) in allowed:
|
|
57
|
+
return aliases[v]
|
|
58
|
+
for s in _synonyms(v):
|
|
59
|
+
for t in _variants(s):
|
|
60
|
+
if t in allowed:
|
|
61
|
+
return t
|
|
62
|
+
# compound names: fill_colour -> fill_color, stroke_lw -> stroke_stroke_width ...
|
|
63
|
+
for g in GROUPS:
|
|
64
|
+
for m in g:
|
|
65
|
+
if name.endswith("_" + m):
|
|
66
|
+
for t in g:
|
|
67
|
+
for u in _variants(name[: -len(m)] + t):
|
|
68
|
+
if u in allowed:
|
|
69
|
+
return u
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def normalise(given, aliases=None, allowed=None):
|
|
74
|
+
"""Return ``given`` with aliased option names replaced by canonical ones.
|
|
75
|
+
|
|
76
|
+
Without ``allowed`` only names in the alias tables are rewritten (colour->color, grey->gray, ...).
|
|
77
|
+
Raises TypeError if a name and its alias are both given."""
|
|
78
|
+
out = {}
|
|
79
|
+
for k, v in given.items():
|
|
80
|
+
c = k
|
|
81
|
+
if allowed is not None:
|
|
82
|
+
c = _resolve(k, allowed, aliases) or k
|
|
83
|
+
else:
|
|
84
|
+
if aliases and k in aliases:
|
|
85
|
+
c = aliases[k]
|
|
86
|
+
else:
|
|
87
|
+
c = _spell(k)
|
|
88
|
+
if c in out:
|
|
89
|
+
raise TypeError("option '%s' given twice (also spelt '%s')" % (c, k))
|
|
90
|
+
out[c] = v
|
|
91
|
+
return out
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _options_text(allowed):
|
|
95
|
+
names = list(allowed)
|
|
96
|
+
if not names:
|
|
97
|
+
return "(none)"
|
|
98
|
+
shown = names[:_MAX_LISTED]
|
|
99
|
+
return ", ".join(shown) + (", …" if len(names) > _MAX_LISTED else "")
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def reject_unknown(owner, given, allowed, aliases=None):
|
|
103
|
+
"""Normalise aliases in ``given`` and raise TypeError for any name not in ``allowed``.
|
|
104
|
+
|
|
105
|
+
Message: "<owner>: unknown option 'tags' — did you mean 'tag'? Options: a, b, c"."""
|
|
106
|
+
allowed = list(allowed)
|
|
107
|
+
aset = set(allowed)
|
|
108
|
+
out = {}
|
|
109
|
+
src = {}
|
|
110
|
+
for k, v in given.items():
|
|
111
|
+
c = _resolve(k, aset, aliases)
|
|
112
|
+
if c is None:
|
|
113
|
+
close = difflib.get_close_matches(k, allowed, n=3, cutoff=0.6)
|
|
114
|
+
hint = (" — did you mean %s?" % " or ".join("'%s'" % m for m in close)) if close else ""
|
|
115
|
+
raise TypeError("%s: unknown option '%s'%s Options: %s" % (
|
|
116
|
+
owner, k, hint if hint else " —", _options_text(allowed)))
|
|
117
|
+
if c in out:
|
|
118
|
+
raise TypeError("%s: option '%s' given twice (also spelt '%s')" % (owner, c, src[c]))
|
|
119
|
+
out[c] = v
|
|
120
|
+
src[c] = k
|
|
121
|
+
return out
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def unknown_name(kind, name, valid, hint=None):
|
|
125
|
+
"""Return a ValueError for an unknown registry name, with the closest valid names."""
|
|
126
|
+
valid = [str(v) for v in valid]
|
|
127
|
+
close = difflib.get_close_matches(str(name), valid, n=3, cutoff=0.5)
|
|
128
|
+
msg = "unknown %s '%s'" % (kind, name)
|
|
129
|
+
if close:
|
|
130
|
+
msg += " — did you mean %s?" % " or ".join("'%s'" % m for m in close)
|
|
131
|
+
if hint:
|
|
132
|
+
msg += " " + hint
|
|
133
|
+
else:
|
|
134
|
+
msg += " Valid: " + _options_text(sorted(valid))
|
|
135
|
+
return ValueError(msg)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def check_choice(owner, option, value, choices):
|
|
139
|
+
"""Return ``value`` if it is one of ``choices``, else raise ValueError naming the closest choice."""
|
|
140
|
+
if value in choices:
|
|
141
|
+
return value
|
|
142
|
+
ch = [str(c) for c in choices]
|
|
143
|
+
close = difflib.get_close_matches(str(value), ch, n=3, cutoff=0.5)
|
|
144
|
+
msg = "%s: invalid %s %r" % (owner, option, value)
|
|
145
|
+
if close:
|
|
146
|
+
msg += " — did you mean %s?" % " or ".join("'%s'" % m for m in close)
|
|
147
|
+
raise ValueError(msg + " Choices: " + _options_text(ch))
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def signature_options(func):
|
|
151
|
+
"""Keyword names ``func`` accepts (excluding self/cls, *args and **kwargs)."""
|
|
152
|
+
try:
|
|
153
|
+
sig = inspect.signature(func)
|
|
154
|
+
except (TypeError, ValueError):
|
|
155
|
+
return []
|
|
156
|
+
return [n for n, p in sig.parameters.items()
|
|
157
|
+
if n not in ("self", "cls") and p.kind in (p.POSITIONAL_OR_KEYWORD, p.KEYWORD_ONLY)]
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def strict(func, owner=None, aliases=None):
|
|
161
|
+
"""Wrap ``func`` (explicit signature, no ``**kwargs``) so unknown keywords raise the helpful TypeError and
|
|
162
|
+
aliased spellings (colour, tags, w ...) are accepted. Returned unchanged if it takes ``**kwargs``."""
|
|
163
|
+
import functools
|
|
164
|
+
try:
|
|
165
|
+
params = inspect.signature(func).parameters.values()
|
|
166
|
+
except (TypeError, ValueError):
|
|
167
|
+
return func
|
|
168
|
+
if any(p.kind is p.VAR_KEYWORD for p in params):
|
|
169
|
+
return func
|
|
170
|
+
names = signature_options(func)
|
|
171
|
+
known = frozenset(names)
|
|
172
|
+
label = owner or getattr(func, "__qualname__", getattr(func, "__name__", "call"))
|
|
173
|
+
|
|
174
|
+
@functools.wraps(func)
|
|
175
|
+
def wrapper(*a, **k):
|
|
176
|
+
if k and not known.issuperset(k):
|
|
177
|
+
k = reject_unknown(label, k, names, aliases)
|
|
178
|
+
return func(*a, **k)
|
|
179
|
+
return wrapper
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def strict_methods(cls, skip=(), aliases=None, init=True):
|
|
183
|
+
"""Apply ``strict`` to the public methods (and ``__init__``) of ``cls`` that have explicit signatures."""
|
|
184
|
+
import types
|
|
185
|
+
for name, fn in list(vars(cls).items()):
|
|
186
|
+
if not isinstance(fn, types.FunctionType) or name in skip:
|
|
187
|
+
continue
|
|
188
|
+
if name.startswith("_") and not (init and name == "__init__"):
|
|
189
|
+
continue
|
|
190
|
+
owner = cls.__name__ if name == "__init__" else cls.__name__ + "." + name
|
|
191
|
+
setattr(cls, name, strict(fn, owner, aliases))
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _norm_name(s):
|
|
195
|
+
return s.lower().replace("_", "")
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def module_getattr(module_name, hints=None):
|
|
199
|
+
"""Return a module-level ``__getattr__`` that explains a missing name instead of a bare AttributeError.
|
|
200
|
+
|
|
201
|
+
Use it as the last line of a kit: ``__getattr__ = module_getattr(__name__, {"rectangle": "use sdf.sd_box(...)"})``.
|
|
202
|
+
The error names the closest public functions of the module (``__all__`` when defined, else every public
|
|
203
|
+
function / class); ``hints`` maps a likely wrong name (lower case) to the advice shown for it. Dunder and
|
|
204
|
+
underscore names (probed by hasattr, copy, pickle, doctest, pytest) raise the plain AttributeError at once."""
|
|
205
|
+
short = module_name.rsplit(".", 1)[-1]
|
|
206
|
+
table = {_norm_name(k): v for k, v in (hints or {}).items()}
|
|
207
|
+
|
|
208
|
+
def __getattr__(name):
|
|
209
|
+
if name.startswith("_"):
|
|
210
|
+
raise AttributeError("module %r has no attribute %r" % (module_name, name))
|
|
211
|
+
mod = sys.modules.get(module_name)
|
|
212
|
+
names = list(getattr(mod, "__all__", None) or [])
|
|
213
|
+
if not names and mod is not None:
|
|
214
|
+
import types
|
|
215
|
+
names = [n for n, v in vars(mod).items() if not n.startswith("_") and
|
|
216
|
+
isinstance(v, (types.FunctionType, type)) and getattr(v, "__module__", None) == module_name]
|
|
217
|
+
names = [n for n in names if n != name]
|
|
218
|
+
g = _norm_name(name)
|
|
219
|
+
close = [n for n in names if _norm_name(n) == g]
|
|
220
|
+
if len(g) >= 3:
|
|
221
|
+
close += [n for n in names if n not in close and (g in _norm_name(n) or
|
|
222
|
+
(len(_norm_name(n)) >= 4 and _norm_name(n) in g))]
|
|
223
|
+
close += [n for n in difflib.get_close_matches(name, names, n=4, cutoff=0.6) if n not in close]
|
|
224
|
+
close = close[:4]
|
|
225
|
+
msg = "%s has no %r" % (short, name)
|
|
226
|
+
hint = table.get(g)
|
|
227
|
+
if hint:
|
|
228
|
+
msg += " — " + hint
|
|
229
|
+
if close:
|
|
230
|
+
msg += " (closest names: %s)" % ", ".join(close)
|
|
231
|
+
elif close:
|
|
232
|
+
msg += " — did you mean %s?" % " or ".join("%s.%s" % (short, n) for n in close)
|
|
233
|
+
else:
|
|
234
|
+
shown = ", ".join(names[:_MAX_LISTED])
|
|
235
|
+
msg += " — public names: %s%s" % (shown, ", ..." if len(names) > _MAX_LISTED else "")
|
|
236
|
+
raise AttributeError(msg)
|
|
237
|
+
|
|
238
|
+
return __getattr__
|
|
File without changes
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Two animals in a natural setting: a horse and a fox in a summer meadow (creature + flora + elements)
|
|
3
|
+
|
|
4
|
+
* Format: 1920x1080
|
|
5
|
+
* Focal point: <the galloping horse on the left third, the fox watching from the right foreground>
|
|
6
|
+
* Light: <late-morning sun from the upper left (LIGHT); each animal casts a soft shadow to the right>
|
|
7
|
+
* Far / middle / near: <hazy tree line / horse on the field / fox, flowers and tall grass>
|
|
8
|
+
* Palette: <blue sky, warm greens, bay horse, red fox, flower accents>
|
|
9
|
+
* Exact text: <none>
|
|
10
|
+
"""
|
|
11
|
+
# Read skills/pixelcanvas/references/creatures.md (species, poses, coats) and flora.md (meadow, grass).
|
|
12
|
+
from pixelcanvas import Canvas
|
|
13
|
+
from pixelcanvas.creature import Creature
|
|
14
|
+
from pixelcanvas.elements import sky, cumulus
|
|
15
|
+
from pixelcanvas.flora import forest, meadow, grass
|
|
16
|
+
from pixelcanvas.texture import fill, plane_uv
|
|
17
|
+
from pixelcanvas.form import set_light
|
|
18
|
+
from pixelcanvas import clamp01
|
|
19
|
+
|
|
20
|
+
PROMPT = "" # paste the request here, verbatim - --check compares the picture against it
|
|
21
|
+
NAME = "my_animals"
|
|
22
|
+
DEFAULT_SIZE = (1920, 1080)
|
|
23
|
+
DEFAULT_SEED = 1
|
|
24
|
+
|
|
25
|
+
HORIZON = 0.45
|
|
26
|
+
LIGHT = (-0.7, -0.62) # direction towards the light (upper left)
|
|
27
|
+
BIG = dict(species="horse", pose="gallop", at=(0.37, 0.72), size=0.36, facing="left")
|
|
28
|
+
SMALL = dict(species="fox", pose="sit", at=(0.8, 0.93), size=0.27, facing="left") # species() lists 54 names
|
|
29
|
+
COAT = "palomino" # a COATS name: bay, black horse, grey, tabby ... or None
|
|
30
|
+
FLOWERS = ("poppy", "daisy", "cornflower")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def render(width=DEFAULT_SIZE[0], height=DEFAULT_SIZE[1], seed=DEFAULT_SEED, log=None):
|
|
34
|
+
log = log or (lambda m: None)
|
|
35
|
+
cv = Canvas(width, height)
|
|
36
|
+
X, Y = cv.xy()
|
|
37
|
+
set_light(direction=LIGHT, elevation=42)
|
|
38
|
+
# >>> setting: new_scene.py --prompt draws the request's place here (room, street, park, beach, night)
|
|
39
|
+
log("sky") # sky kind + one cloud
|
|
40
|
+
sky(cv, "day", horizon=HORIZON)
|
|
41
|
+
cumulus(cv, at=(0.7, 0.3), size=520, seed=seed, light=(-LIGHT[0], LIGHT[1]))
|
|
42
|
+
log("trees") # small and hazy = far away
|
|
43
|
+
forest(cv, region=(-0.05, HORIZON - 0.04, 1.05, HORIZON + 0.01), n=40, height=(0.05, 0.11), haze=("#cfdcd2", 0.5),
|
|
44
|
+
seed=seed + 1, light=LIGHT)
|
|
45
|
+
log("field") # texture name sets the material
|
|
46
|
+
fill(cv, clamp01((Y / height - HORIZON) * height + 0.5), "moss", uv=plane_uv(height, width, horizon=HORIZON - 0.1),
|
|
47
|
+
tint="#8fae52", light=LIGHT, seed=seed)
|
|
48
|
+
meadow(cv, region=(0.0, 0.54, 1.0, 0.7), density=0.8, grass_height=0.03, seed=seed + 2, light=LIGHT)
|
|
49
|
+
# <<< setting
|
|
50
|
+
# >>> subjects: new_scene.py --prompt writes one call per subject of the request here
|
|
51
|
+
log("big animal") # pose, phase (stride 0~1), cast = ground shadow
|
|
52
|
+
a = Creature(BIG["species"], size=BIG["size"], facing=BIG["facing"], coat=COAT, seed=seed)
|
|
53
|
+
a.pose(BIG["pose"], phase=0.25).draw(cv, at=BIG["at"], cast=dict(opacity=0.35, length=0.6))
|
|
54
|
+
log("meadow") # flowers in front of the horse, behind the fox
|
|
55
|
+
meadow(cv, region=(0.0, 0.7, 1.0, 0.86), flowers=FLOWERS, grass_height=0.05, seed=seed + 3, light=LIGHT)
|
|
56
|
+
log("small animal")
|
|
57
|
+
b = Creature(SMALL["species"], size=SMALL["size"], facing=SMALL["facing"], view="three-quarter", seed=seed)
|
|
58
|
+
b.pose(SMALL["pose"], head_turn=12.0).draw(cv, at=SMALL["at"])
|
|
59
|
+
log("foreground grass")
|
|
60
|
+
grass(cv, region=(0.0, 0.88, 1.0, 1.02), tufts=40, height=0.09, blades=24, seed=seed + 4, wind=0.12, light=LIGHT)
|
|
61
|
+
# <<< subjects
|
|
62
|
+
|
|
63
|
+
log("post")
|
|
64
|
+
cv.vignette(0.22, 0.7).soft_clip(0.9).grain(0.008, seed)
|
|
65
|
+
return cv
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Looping animation driven by T = 0 -> 1: lanterns rising over a lake (elements)
|
|
3
|
+
|
|
4
|
+
* Format: 1280x720, FRAMES frames at FPS (a still at T = 0)
|
|
5
|
+
* Loop: <every motion is periodic in T: positions use (start + k * T) % 1 with whole k, wobbles sin(2 pi k T)>
|
|
6
|
+
* Focal point: <the lantern group rising over the lake, centre>
|
|
7
|
+
* Light: <moon upper right, warm lanterns; their reflections in the lake>
|
|
8
|
+
* Far / middle / near: <stars, moon, clouds / lanterns / lake and the dark shore>
|
|
9
|
+
* Exact text: <none>
|
|
10
|
+
"""
|
|
11
|
+
# Read skills/pixelcanvas/references/elements.md (sky, lanterns, lake, clouds); render.py --animate renders T = 0 -> 1.
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
from pixelcanvas import Canvas, clamp01, fbm1d, smoothstep
|
|
15
|
+
from pixelcanvas.elements import sky, stars, moon, cumulus, lantern
|
|
16
|
+
|
|
17
|
+
PROMPT = "" # paste the request here, verbatim - --check compares the picture against it
|
|
18
|
+
NAME = "my_animation"
|
|
19
|
+
DEFAULT_SIZE = (1280, 720)
|
|
20
|
+
DEFAULT_SEED = 1
|
|
21
|
+
|
|
22
|
+
T = 0.0 # animation phase 0..1; T = 1 looks exactly like T = 0
|
|
23
|
+
FRAMES, FPS = 48, 24
|
|
24
|
+
HORIZON = 0.62
|
|
25
|
+
LANTERNS = [(0.45, 0.0, 150), (0.56, 0.2, 130), (0.36, 0.4, 140), (0.64, 0.6, 120), (0.5, 0.8, 110)] # u, phase, px
|
|
26
|
+
CLOUDS = [(0.1, 0.2, 460), (0.45, 0.32, 320)] # start u, v, width px
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def render(width=DEFAULT_SIZE[0], height=DEFAULT_SIZE[1], seed=DEFAULT_SEED, log=None):
|
|
30
|
+
log = log or (lambda m: None)
|
|
31
|
+
cv = Canvas(width, height)
|
|
32
|
+
tau = 2 * np.pi * T
|
|
33
|
+
|
|
34
|
+
log("sky") # still parts first
|
|
35
|
+
sky(cv, "twilight", horizon=HORIZON)
|
|
36
|
+
stars(cv, density=0.6, milky_way=False, horizon=HORIZON, seed=seed)
|
|
37
|
+
moon(cv, at=(0.84, 0.16), size=36, phase=0.6, seed=seed)
|
|
38
|
+
log("clouds") # drift one screen width per loop, wrap off-screen
|
|
39
|
+
for i, (u0, v, size) in enumerate(CLOUDS):
|
|
40
|
+
cumulus(cv, at=(((u0 + T) % 1) * 1.6 - 0.3, v), size=size, seed=seed + i, lit="#a49ac0", shadow="#2c2b4a")
|
|
41
|
+
log("lanterns") # rise once per loop; grow in, shrink with height
|
|
42
|
+
for i, (u, phase, size) in enumerate(LANTERNS):
|
|
43
|
+
t = (phase + T) % 1
|
|
44
|
+
at = (u + 0.02 * np.sin(tau + 2 * i), HORIZON - 0.08 - 0.75 * t)
|
|
45
|
+
s = size * (1 - 0.6 * t) * smoothstep(0, 0.12, t)
|
|
46
|
+
if s > 2 and at[1] > -0.03: # skip lanterns that are too small or off the top
|
|
47
|
+
lantern(cv, at=at, size=s, style="paper", paper="#f08a3a")
|
|
48
|
+
|
|
49
|
+
log("lake") # mirror of everything above, ripples move with T
|
|
50
|
+
X, Y = cv.xy()
|
|
51
|
+
hy, S = HORIZON * height, height / 1080
|
|
52
|
+
ripple = 4 * S * np.sin(Y / (5 * S) + tau) * clamp01((Y - hy) / (0.3 * height))
|
|
53
|
+
cv.paint(cv.sample(X + ripple, np.clip(2 * hy - Y, 0, height - 1)) * 0.75, clamp01(Y - hy + 0.5))
|
|
54
|
+
log("shore")
|
|
55
|
+
shore = (0.92 + 0.03 * fbm1d(width, 300 * S, 4, seed=seed + 5)) * height
|
|
56
|
+
cv.paint("#06080e", clamp01(Y - shore[None, :] + 0.5))
|
|
57
|
+
|
|
58
|
+
log("post")
|
|
59
|
+
cv.bloom(0.85, 14 * S, 0.3).soft_clip(0.82).grain(0.01, seed)
|
|
60
|
+
return cv
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""README banner / hero / header: backdrop, big title, tagline, a window or illustration on the right (ui.window)
|
|
3
|
+
|
|
4
|
+
* Format: 1600x640 README banner (1280x640 social preview, 1920x1080 hero, 1500x500 header)
|
|
5
|
+
* Focal point: <the project name, left; the terminal window on the right shows it in use>
|
|
6
|
+
* Text hierarchy: <KICKER -> TITLE (one or two words, huge) -> TAGLINE -> INSTALL chip>
|
|
7
|
+
* Light: <soft glow behind the window; the window casts a soft shadow>
|
|
8
|
+
* Palette: <BG gradient (top-left -> bottom-right), INK for type, ACCENT for prompt and chip>
|
|
9
|
+
* Exact text: <TITLE, TAGLINE, COMMANDS copied verbatim from the request>
|
|
10
|
+
"""
|
|
11
|
+
# Read skills/pixelcanvas/references/ui.md (window) and typography.md (stack, roles).
|
|
12
|
+
from pixelcanvas import Canvas
|
|
13
|
+
from pixelcanvas.backdrop import backdrop
|
|
14
|
+
from pixelcanvas.layout import Layout, stack
|
|
15
|
+
from pixelcanvas.ui import window
|
|
16
|
+
|
|
17
|
+
PROMPT = "" # paste the request here, verbatim - --check compares the picture against it
|
|
18
|
+
KIND = "design"
|
|
19
|
+
NAME = "my_banner"
|
|
20
|
+
DEFAULT_SIZE = (1600, 640)
|
|
21
|
+
DEFAULT_SEED = 1
|
|
22
|
+
|
|
23
|
+
KICKER = "open source \u00b7 MIT"
|
|
24
|
+
TITLE = "driftwood"
|
|
25
|
+
TAGLINE = "Your dotfiles, on every machine."
|
|
26
|
+
INSTALL = "brew install driftwood" # a chip under the tagline; "" for none
|
|
27
|
+
PANEL = "terminal" # terminal, code, browser, card, or "" for a text-only banner
|
|
28
|
+
COMMANDS = ["$ driftwood init", "\u2713 tracking 42 files", "$ driftwood push", "$ driftwood pull --host laptop"]
|
|
29
|
+
BG = ["#14b8a6", "#0e5a7a", "#0b1a3a", "#1d2b64"] # backdrop palette, light -> deep
|
|
30
|
+
COLORS = ("#f4f1ea", "#7ee8c7") # ink for the type, accent for prompt and chip
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def render(width=DEFAULT_SIZE[0], height=DEFAULT_SIZE[1], seed=DEFAULT_SEED, log=None):
|
|
34
|
+
log = log or (lambda m: None)
|
|
35
|
+
cv = Canvas(width, height)
|
|
36
|
+
S = height / 1080
|
|
37
|
+
INK, ACCENT = COLORS
|
|
38
|
+
|
|
39
|
+
log("background")
|
|
40
|
+
backdrop(cv, "mesh", palette=BG, seed=seed)
|
|
41
|
+
cv.glow(0.74 * width, 0.5 * height, 0.45 * height, ACCENT, 0.16)
|
|
42
|
+
|
|
43
|
+
log("window") # the window hugs its lines and fits the right half
|
|
44
|
+
text_w = 0.5 if PANEL else 0.86
|
|
45
|
+
if PANEL:
|
|
46
|
+
window(cv, PANEL, COMMANDS, box=(0.52, 0.1, 0.96, 0.9), title=f"~/{TITLE} \u2014 zsh", accent=ACCENT)
|
|
47
|
+
|
|
48
|
+
log("text") # stack sizes and spaces the lines in the left box
|
|
49
|
+
L = Layout(cv, margin=0.1)
|
|
50
|
+
shadow = dict(dx=0, dy=4 * S, blur=18 * S, opacity=0.45)
|
|
51
|
+
items = [{"text": KICKER, "role": "kicker", "color": ACCENT, "size": 32 * S},
|
|
52
|
+
{"text": TITLE, "role": "title", "color": INK, "font": "display", "max_size": 260, "shadow": shadow},
|
|
53
|
+
{"text": TAGLINE, "role": "subtitle", "color": INK, "size": 64 * S, "shadow": shadow}]
|
|
54
|
+
box = L.sub(0, 0.0, text_w, 0.82 if INSTALL else 1.0)
|
|
55
|
+
lines = stack(cv, box, [i for i in items if i["text"]], valign="middle")
|
|
56
|
+
if INSTALL: # the chip sits under the tagline, inside the margin
|
|
57
|
+
fs = 40 * S
|
|
58
|
+
cv.text(INSTALL, (lines[-1][0] + 0.6 * fs, lines[-1][3] + 1.2 * fs), fs, "#0b1a2a", anchor="lt",
|
|
59
|
+
font="mono", plate=dict(kind="pill", color=ACCENT, opacity=1.0))
|
|
60
|
+
|
|
61
|
+
log("post")
|
|
62
|
+
cv.vignette(0.18, 0.75).grain(0.006, seed)
|
|
63
|
+
return cv
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Bare conventions on an empty canvas, for the low-level API (Canvas, sdf, noise)
|
|
3
|
+
|
|
4
|
+
* Format: 1920x1080
|
|
5
|
+
* Focal point: <what is biggest / brightest / most saturated, and where (u, v)>
|
|
6
|
+
* Light: <where it comes from; every lit side faces it>
|
|
7
|
+
* Far / middle / near (or text hierarchy): <...>
|
|
8
|
+
* Palette: <3-5 colours>
|
|
9
|
+
* Exact text: <copied verbatim from the request>
|
|
10
|
+
"""
|
|
11
|
+
# Read skills/pixelcanvas/references/api.md (Canvas, masks, sdf, noise, filters) and techniques.md (how to draw X).
|
|
12
|
+
from pixelcanvas import Canvas, sdf, fbm2d
|
|
13
|
+
|
|
14
|
+
PROMPT = "" # paste the request here, verbatim - --check compares the picture against it
|
|
15
|
+
NAME = "my_blank"
|
|
16
|
+
DEFAULT_SIZE = (1920, 1080)
|
|
17
|
+
DEFAULT_SEED = 1
|
|
18
|
+
|
|
19
|
+
BG = [(0.0, "#1b2438"), (1.0, "#3b4a6b")] # background gradient stops, top -> bottom
|
|
20
|
+
SUBJECT = "#ffb347"
|
|
21
|
+
SUBJECT_AT, SUBJECT_R = (0.5, 0.5), 0.18 # centre (u, v) and radius as a fraction of the height
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def render(width=DEFAULT_SIZE[0], height=DEFAULT_SIZE[1], seed=DEFAULT_SEED, log=None):
|
|
25
|
+
log = log or (lambda m: None)
|
|
26
|
+
cv = Canvas(width, height)
|
|
27
|
+
X, Y = cv.xy()
|
|
28
|
+
S = height / 1080 # pixel sizes are designed at 1080p and multiplied by S
|
|
29
|
+
|
|
30
|
+
# >>> setting: new_scene.py --prompt draws the request's place here (room, street, park, beach, night)
|
|
31
|
+
log("background") # one log() per object a person may move or hide
|
|
32
|
+
cv.gradient(BG)
|
|
33
|
+
cv.paint("#ffffff", (fbm2d(height, width, 300 * S, 4, seed=seed) * 0.5 + 0.5) * 0.04, "add")
|
|
34
|
+
|
|
35
|
+
# <<< setting
|
|
36
|
+
# >>> subjects: new_scene.py --prompt writes one call per subject of the request here
|
|
37
|
+
log("subject") # mask first (sdf / noise), colour second, cv.paint draws
|
|
38
|
+
d = sdf.sd_circle(X, Y, SUBJECT_AT[0] * width, SUBJECT_AT[1] * height, SUBJECT_R * height)
|
|
39
|
+
cv.paint(SUBJECT, sdf.glow(d, 60 * S) * 0.3, "add")
|
|
40
|
+
cv.paint(SUBJECT, sdf.fill(d))
|
|
41
|
+
# <<< subjects
|
|
42
|
+
|
|
43
|
+
log("post") # post-processing last
|
|
44
|
+
cv.vignette(0.25).soft_clip(0.85).grain(0.01, seed)
|
|
45
|
+
return cv
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Social card / thumbnail / link preview: a headline beside an illustration (text + pictograms)
|
|
3
|
+
|
|
4
|
+
* Format: 1280x720 thumbnail (1200x630 link card, 1080x1080 square)
|
|
5
|
+
* Focal point: <the headline on the left; the illustration on the right>
|
|
6
|
+
* Text hierarchy: <badge -> HEADLINE (2-6 words, huge) -> one subtitle line>
|
|
7
|
+
* Light: <a warm glow behind the illustration; text gets a soft shadow for contrast>
|
|
8
|
+
* Palette: <two background colours, cream ink, one accent for the badge>
|
|
9
|
+
* Exact text: <HEADLINE, SUBTITLE, BADGE copied verbatim from the request>
|
|
10
|
+
"""
|
|
11
|
+
# Read skills/pixelcanvas/references/typography.md (sections 1, 6, 8) and pictograms.md (shaded style).
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
from pixelcanvas import Canvas, lerp, pictograms
|
|
15
|
+
from pixelcanvas.layout import Layout, stack
|
|
16
|
+
|
|
17
|
+
PROMPT = "" # paste the request here, verbatim - --check compares the picture against it
|
|
18
|
+
KIND = "design"
|
|
19
|
+
NAME = "my_card"
|
|
20
|
+
DEFAULT_SIZE = (1280, 720)
|
|
21
|
+
DEFAULT_SEED = 1
|
|
22
|
+
|
|
23
|
+
BADGE = "NEW EPISODE"
|
|
24
|
+
HEADLINE = "Chasing the Last Light"
|
|
25
|
+
SUBTITLE = "A weekend in the hills"
|
|
26
|
+
INK, ACCENT = "#fff6e8", "#e8613a"
|
|
27
|
+
BG = [(0, "#25275e"), (1, "#6e3466")] # background, top -> bottom
|
|
28
|
+
GLOW = "#ffb36b" # light behind the illustration
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def render(width=DEFAULT_SIZE[0], height=DEFAULT_SIZE[1], seed=DEFAULT_SEED, log=None):
|
|
32
|
+
log = log or (lambda m: None)
|
|
33
|
+
cv = Canvas(width, height)
|
|
34
|
+
X, Y = cv.xy()
|
|
35
|
+
S = height / 1080
|
|
36
|
+
u0, v0, u1, v1 = 0.56, 0.16, 0.95, 0.88 # the illustration's area (fractions); the text takes the left
|
|
37
|
+
|
|
38
|
+
log("background")
|
|
39
|
+
cv.gradient(BG)
|
|
40
|
+
cv.paint(GLOW, np.exp(-((X / width - 0.75) ** 2 * (width / height) ** 2 + (Y / height - 0.5) ** 2) / 0.09) * 0.45,
|
|
41
|
+
"add")
|
|
42
|
+
# >>> subjects stage: new_scene.py --prompt writes one call per subject of the request here
|
|
43
|
+
log("hills") # pictograms in the shaded style read as illustrations
|
|
44
|
+
pictograms.pictogram(cv, "mountain", at=(u0 + 0.42 * (u1 - u0), v1), size=0.62 * (v1 - v0), color="#8a5a9c",
|
|
45
|
+
style="shaded", shadow=True, anchor="bm")
|
|
46
|
+
log("sun")
|
|
47
|
+
pictograms.pictogram(cv, "sun", at=(u0 + 0.78 * (u1 - u0), v0 + 0.3 * (v1 - v0)), size=0.3 * (v1 - v0),
|
|
48
|
+
color="#ffc857", style="shaded")
|
|
49
|
+
# <<< subjects
|
|
50
|
+
|
|
51
|
+
log("text") # stack sizes and spaces the lines; an empty line is skipped
|
|
52
|
+
L = Layout(cv, margin=0.07)
|
|
53
|
+
shadow = dict(dx=0, dy=4 * S, blur=18 * S, opacity=0.55)
|
|
54
|
+
lines = [{"text": BADGE, "role": "kicker", "color": INK, "bold": True, "plate": dict(kind="pill", color=ACCENT)},
|
|
55
|
+
{"text": HEADLINE, "role": "title", "color": INK, "font": "display", "shadow": shadow},
|
|
56
|
+
{"text": SUBTITLE, "role": "subtitle", "color": lerp(INK, ACCENT, 0.25), "shadow": shadow}]
|
|
57
|
+
stack(cv, L.sub(0, 0.04, 0.55, 0.9), [ln for ln in lines if ln["text"]], valign="middle")
|
|
58
|
+
|
|
59
|
+
log("post")
|
|
60
|
+
cv.vignette(0.25).soft_clip(0.85).grain(0.008, seed)
|
|
61
|
+
return cv
|