Spaces:
Running
Running
v12: seed variation (slider + 4 variations)
Browse filesFiles changed (21)
- app.py+24-6
- pydraw/__init__.py+8-3
- pydraw/compose.py+10
- pydraw/concepts/animals2.py+1-1
- pydraw/concepts/core.py+24-4
- pydraw/concepts/food.py+16-1
- pydraw/concepts/food2.py+1-1
- pydraw/concepts/indoor.py+1-1
- pydraw/concepts/misc3.py+17-2
- pydraw/concepts/misc5.py+11-1
- pydraw/concepts/misc7.py+1-1
- pydraw/concepts/misc8.pyAdded+474
- pydraw/concepts/objects2.py+28-1
- pydraw/concepts/objects4.py+1-1
- pydraw/concepts/people.py+15
- pydraw/concepts/vehicles.py+12-1
- pydraw/layout.py+19-3
- pydraw/lexicon.py+6
- pydraw/preview.pyAdded+45
- pydraw/understanding.py+13-2
- pydraw/variation.pyAdded+90
10 unmodified lines11121314151617181920213 unmodified lines2526272829305 unmodified lines36373839404142434445464748495010 unmodified lines"four green apples and a banana on a table", "a dog chasing a ball on the beach", "a snowman next to a pine tree"]def run(prompt, seed, style, size):t = time.time()img = plot(prompt, seed=int(seed), size=int(size), style=style)im = Image.new("RGB", (img.width, img.height))im.putdata([p for row in img.pixels for p in row])sc = img.scenesummary = "**%s** | place: %s | time: %s | style: %s | %.2fs | %d rules fired" % (", ".join("%d x %s%s" % (e["count"], (e["color"] + " ") if e["color"] else "", e["concept"]) for e in sc["entities"]) or "(nothing drawable)",3 unmodified linesreturn im, summary, "\n".join(img.trace)with gr.Blocks(title="pydraw") as demo:gr.Markdown("# pydraw\nText to image with rules only: no weights, no training, no image files. ""%d concepts, pure Python on CPU. Style words work too: watercolor, pencil sketch, black and white, "5 unmodified linesseed = gr.Number(label="Seed", value=0, precision=0)style = gr.Dropdown(["pixel", "smooth"], value="pixel", label="Renderer")size = gr.Dropdown([256, 512, 768], value=512, label="Size")btn = gr.Button("Draw", variant="primary")summary = gr.Markdown()gr.Examples(EXAMPLES, inputs=prompt)with gr.Column(scale=1):out = gr.Image(label="Image", type="pil")with gr.Accordion("Rules that fired", open=False):trace = gr.Textbox(lines=18, show_label=False)btn.click(run, [prompt, seed, style, size], [out, summary, trace])prompt.submit(run, [prompt, seed, style, size], [out, summary, trace])if __name__ == "__main__":demo.queue(default_concurrency_limit=2).launch()10 unmodified lines111213141516171819202122232425263 unmodified lines3031323334353637383940415 unmodified lines4748495051525354555657585960616263646566676810 unmodified lines"four green apples and a banana on a table", "a dog chasing a ball on the beach", "a snowman next to a pine tree"]def to_pil(img):im = Image.new("RGB", (img.width, img.height))im.putdata([p for row in img.pixels for p in row])return imdef run(prompt, seed, style, size, variation):t = time.time()img = plot(prompt, seed=int(seed), size=int(size), style=style, variation=float(variation))im = to_pil(img)sc = img.scenesummary = "**%s** | place: %s | time: %s | style: %s | %.2fs | %d rules fired" % (", ".join("%d x %s%s" % (e["count"], (e["color"] + " ") if e["color"] else "", e["concept"]) for e in sc["entities"]) or "(nothing drawable)",3 unmodified linesreturn im, summary, "\n".join(img.trace)def run4(prompt, seed, style, size, variation):s0 = int(seed)return [(to_pil(plot(prompt, seed=s0 + k, size=int(size), style=style, variation=float(variation))), "seed %d" % (s0 + k))for k in range(4)]with gr.Blocks(title="pydraw") as demo:gr.Markdown("# pydraw\nText to image with rules only: no weights, no training, no image files. ""%d concepts, pure Python on CPU. Style words work too: watercolor, pencil sketch, black and white, "5 unmodified linesseed = gr.Number(label="Seed", value=0, precision=0)style = gr.Dropdown(["pixel", "smooth"], value="pixel", label="Renderer")size = gr.Dropdown([256, 512, 768], value=512, label="Size")variation = gr.Slider(0, 1, value=1, step=0.25, label="Variation",info="Varies only what the prompt leaves open (breed, colour of unnamed things, time, setting, framing). 0 = canonical image.")with gr.Row():btn = gr.Button("Draw", variant="primary")btn4 = gr.Button("4 variations")summary = gr.Markdown()gr.Examples(EXAMPLES, inputs=prompt)with gr.Column(scale=1):out = gr.Image(label="Image", type="pil")gal = gr.Gallery(label="4 variations (seed, seed+1, ...)", columns=2, height="auto")with gr.Accordion("Rules that fired", open=False):trace = gr.Textbox(lines=18, show_label=False)ins = [prompt, seed, style, size, variation]btn.click(run, ins, [out, summary, trace], api_name="run")prompt.submit(run, ins, [out, summary, trace])btn4.click(run4, ins, gal, api_name="run4")if __name__ == "__main__":demo.queue(default_concurrency_limit=2).launch()
12 unmodified lines1314151617181920212223242526272829303125 unmodified lines5758596061626312 unmodified linesfrom .compose import composefrom .canvas import Imagefrom . import pixelart, styles__all__ = ["plot", "Image", "CONCEPTS"]def plot(text, seed=0, size=512, style="pixel", res=None):"""Render `text` into an Image of size x size pixels. Same text + seed -> same image.style="pixel": drawn at `res` (default size/2) with crisp edges, outlined, palette-snapped, then upscaled 2x.style="smooth": anti-aliased drawing (at size/2, upscaled), used automatically for painterly prompt styles.Style words in the prompt ("watercolor", "sketch", "black and white", "neon", "sepia", "pastel", "oil painting")override the default renderer and add a finishing pass."""trace = []rng = random.Random(seed)scene = parse(text, trace)pstyle = scene.get("style")if pstyle == "abstract":import re as _re25 unmodified linesEXP = dict(kv.split("=") for kv in os.environ.get("PYDRAW_EXP", "").split(",") if "=" in kv) # dev-only A/B knobsif renderer == "pixel":# rule: draw at half the output size (512 -> 256): more detail scored better on every benchmark than 128R = res or int(EXP.get("res", max(96, size // 2)))insts, y0 = layout(scene, R, R, rng, trace)if scene.get("abstract_comp"):# rule: abstract shapes float and overlap across the whole frame at varied sizes12 unmodified lines13141516171819202122232425262728293031323334353625 unmodified lines6263646566676812 unmodified linesfrom .compose import composefrom .canvas import Imagefrom . import pixelart, stylesfrom .variation import vary__all__ = ["plot", "Image", "CONCEPTS"]def plot(text, seed=0, size=512, style="pixel", res=None, variation=1.0):"""Render `text` into an Image of size x size pixels. Same text + seed -> same image.style="pixel": drawn at `res` (default size/2) with crisp edges, outlined, palette-snapped, then upscaled 2x.style="smooth": anti-aliased drawing (at size/2, upscaled), used automatically for painterly prompt styles.Style words in the prompt ("watercolor", "sketch", "black and white", "neon", "sepia", "pastel", "oil painting")override the default renderer and add a finishing pass.variation (0..1): how much the seed may vary what the prompt leaves open (breed, time of day, setting, framing, mood)."""trace = []rng = random.Random(seed)scene = parse(text, trace)import os as _os_ev = dict(kv.split("=") for kv in _os.environ.get("PYDRAW_EXP", "").split(",") if "=" in kv)vary(scene, trace, random.Random(seed * 7919 + 13), float(_ev.get("vary", variation)))pstyle = scene.get("style")if pstyle == "abstract":import re as _re25 unmodified linesEXP = dict(kv.split("=") for kv in os.environ.get("PYDRAW_EXP", "").split(",") if "=" in kv) # dev-only A/B knobsif renderer == "pixel":# rule: draw at half the output size (512 -> 256): more detail scored better on every benchmark than 128R = res or int(EXP.get("res", size // 2 if size >= 256 else size))insts, y0 = layout(scene, R, R, rng, trace)if scene.get("abstract_comp"):# rule: abstract shapes float and overlap across the whole frame at varied sizes
63 unmodified lines6465666768696 unmodified lines76777879808163 unmodified linest = scene["time"]warm = {"day": (1.06, 1.0, .9), "sunset": (1.1, .96, .85), "night": (.95, 1.0, 1.1)}[t]cool = (.85, .95, 1.12)for y, row in enumerate(cv.px):idr = cv.ids[y]for x, p in enumerate(row):6 unmodified linesv = p[i] * m[i]v = 255 * ((v / 255) * .85 + .15 * ((v / 255) ** 2 * (3 - 2 * v / 255)))p[i] = vdef compose(scene, insts, y0, W, H, rng, trace, ss=2):63 unmodified lines6465666768697071727374756 unmodified lines8283848586878889909163 unmodified linest = scene["time"]warm = {"day": (1.06, 1.0, .9), "sunset": (1.1, .96, .85), "night": (.95, 1.0, 1.1)}[t]cool = (.85, .95, 1.12)mood = scene.get("vary", {}).get("mood", "neutral")if mood == "warm": # rule (variation): colour moods shift the grade's highlight/shadow tintswarm, cool = (1.1, 1.0, .84), (.92, .94, 1.04)elif mood == "cool":warm, cool = (1.0, 1.0, 1.0), (.82, .95, 1.18)sat = 1.15 if mood == "vivid" else 1.0for y, row in enumerate(cv.px):idr = cv.ids[y]for x, p in enumerate(row):6 unmodified linesv = p[i] * m[i]v = 255 * ((v / 255) * .85 + .15 * ((v / 255) ** 2 * (3 - 2 * v / 255)))p[i] = vif sat != 1.0:l2 = .3 * p[0] + .59 * p[1] + .11 * p[2]for i in range(3):p[i] = min(255, max(0, l2 + (p[i] - l2) * sat))def compose(scene, insts, y0, W, H, rng, trace, ss=2):
1230 unmodified lines12311232123312341235123612371230 unmodified linesconcept("penguin", height=.75, aspect=.62, row="front", setting="snow", animal=True, on_top=.95,default_color=(36, 34, 40), synonyms=["emperor penguin", "king penguin"])(draw_penguin)concept("owl", height=.42, aspect=.75, row="front", setting="field", animal=True, on_top=.95,default_color=(140, 100, 64), synonyms=["owlet", "barn owl", "snowy owl", "hoot owl"],natural_colors={"white": (238, 236, 230), "brown": (140, 100, 64), "gray": (135, 130, 128)})(draw_owl)concept("butterfly", height=.12, aspect=1.35, row="sky", setting="field", animal=True, flying=True, shadow=False,default_color=(242, 140, 30), synonyms=["moth", "monarch", "monarch butterfly"],1230 unmodified lines12311232123312341235123612371230 unmodified linesconcept("penguin", height=.75, aspect=.62, row="front", setting="snow", animal=True, on_top=.95,default_color=(36, 34, 40), synonyms=["emperor penguin", "king penguin"])(draw_penguin)concept("owl", height=.42, aspect=.75, row="front", setting="field", animal=True, on_top=.95,default_color=(140, 100, 64), synonyms=["owlet", "barn owl", "snowy owl", "hoot owl"], implied_colors={"snowy owl": "white"},natural_colors={"white": (238, 236, 230), "brown": (140, 100, 64), "gray": (135, 130, 128)})(draw_owl)concept("butterfly", height=.12, aspect=1.35, row="sky", setting="field", animal=True, flying=True, shadow=False,default_color=(242, 140, 30), synonyms=["moth", "monarch", "monarch butterfly"],
69 unmodified lines70717273747511 unmodified lines8788899091921101 unmodified lines11941195119611971198119912002 unmodified lines120312041205120612071208120987 unmodified lines1297129812991300130113025 unmodified lines130813091310131113121313131415 unmodified lines1330133113321333133469 unmodified linesDOG_BREEDS = [(("pupp", "pup"), dict(base=(205, 150, 92), lg=.25, bt=.16, bl=.19, hr=.19, sn=.07, snr=.07, sc=.74, ears="flop",tail="wag", puppy=True)),(("corgi",), dict(base=(214, 122, 52), belly=WHITE, ears="up", ear_h=.16, tail="stub", marks="corgi",lg=.17, bt=.15, bl=.29, hr=.15, sn=.12, snr=.058, sc=.92, ear_k=1.0, collar=False)),(("dalmatian",), dict(base=(240, 237, 230), ears="flop", ear_k=None, tail="wag", marks="spots", lg=.39,11 unmodified linessnr=.064, ear_k=.85)),(("beagle",), dict(base=(200, 130, 62), belly=WHITE, ears="long", tail="wag", marks="beagle", lg=.31,bt=.15, bl=.25, hr=.14, sn=.12, snr=.065, ear_k=.85)),(("terrier",), dict(base=(205, 172, 118), ears="fold", tail="stub_up", marks="saddle", lg=.3, bt=.14,bl=.23, hr=.13, sn=.12, snr=.06, sc=.85)),]1101 unmodified lines# ---------------------------------------------------------------- flowerFLOWER_PALETTE = ["red", "yellow", "pink", "purple", "white", "orange"]FLOWER_KIND = [(("rose",), "rose"), (("tulip",), "tulip"), (("daisy", "daisies"), "daisy"), (("sunflower",), "sunflower"),(("lily", "lilies"), "lily")]STEM = (62, 132, 52)LEAF = (72, 148, 56)2 unmodified linesL, h, x, y, rng = ctx.L, inst.h, inst.x, inst.y, inst.rngkind = pick(word_of(inst), FLOWER_KIND, "flower")unit = getattr(cv, "unit", 1.0)default = {"rose": "red", "daisy": "white", "sunflower": "yellow", "lily": "white"}.get(kind)col = rgb(inst.color or default or rng.choice(FLOWER_PALETTE), (230, 60, 80))hx, hy = x + h * .04, y - h * .8# rule: thin stems so the bloom owns most of the pixels (keeps the prompt colour dominant)87 unmodified lineslit_ellipse(cv, L, hx + math.cos(a) * R * .58, hy + math.sin(a) * R * .58, R * .45, max(.6 * unit, R * .13), col, rot=a)lit_ellipse(cv, L, hx, hy, R * .32, R * .32, (245, 190, 40) if inst.color != "yellow" else (150, 90, 30))return# generic flower: five round petals + centreR = h * .19for k in range(5):5 unmodified lines# ---------------------------------------------------------------- registryconcept("dog", height=.62, aspect=1.3, row="front", setting="field", animal=True, on_top=.72,synonyms=["puppy", "pup", "doggy", "hound", "doggo", "terrier", "poodle", "corgi", "beagle", "husky","dachshund", "wiener dog", "sausage dog", "bulldog"],implied_colors={"labrador": "golden", "retriever": "golden", "golden retriever": "golden", "dalmatian": "white","labrador retriever": "golden"},plurals={"puppy": "puppies"})(draw_dog)15 unmodified linesconcept("ball", height=.3, aspect=1.0, row="front", setting="field", on_top=1.0,synonyms=["sports ball", "soccer ball", "football", "basketball", "beach ball", "beachball", "volleyball", "tennis ball", "baseball"])(draw_ball)concept("flower", height=.45, aspect=.55, row="front", setting="field", on_top=1.0,synonyms=["tulip", "bloom", "blossom"], implied_colors={"rose": "red", "daisy": "white", "sunflower": "yellow", "lily": "white"},plurals={"daisy": "daisies", "lily": "lilies"})(draw_flower)69 unmodified lines70717273747576777811 unmodified lines9091929394959697981101 unmodified lines12001201120212031204120512062 unmodified lines120912101211121212131214121587 unmodified lines13031304130513061307130813091310131113121313131413151316131713181319132013215 unmodified lines1327132813291330133113321333133415 unmodified lines1350135113521353135469 unmodified linesDOG_BREEDS = [(("pupp", "pup"), dict(base=(205, 150, 92), lg=.25, bt=.16, bl=.19, hr=.19, sn=.07, snr=.07, sc=.74, ears="flop",tail="wag", puppy=True)),# rule: doodles = poodle clip + floppy ears in apricot/cream(("doodle",), dict(base=(226, 196, 150), ears="flop", ear_k=.85, tail="plume", marks="plain", lg=.35, bt=.15,bl=.25, hr=.145, sn=.12, snr=.06)),(("corgi",), dict(base=(214, 122, 52), belly=WHITE, ears="up", ear_h=.16, tail="stub", marks="corgi",lg=.17, bt=.15, bl=.29, hr=.15, sn=.12, snr=.058, sc=.92, ear_k=1.0, collar=False)),(("dalmatian",), dict(base=(240, 237, 230), ears="flop", ear_k=None, tail="wag", marks="spots", lg=.39,11 unmodified linessnr=.064, ear_k=.85)),(("beagle",), dict(base=(200, 130, 62), belly=WHITE, ears="long", tail="wag", marks="beagle", lg=.31,bt=.15, bl=.25, hr=.14, sn=.12, snr=.065, ear_k=.85)),# rule: shiba inu = fox-red coat, white cheeks/chest (corgi-style marks), pricked ears and a tail curled over the back(("shiba", "akita"), dict(base=(208, 120, 58), belly=WHITE, ears="up", ear_h=.14, tail="curl", marks="corgi",lg=.31, bt=.15, bl=.25, hr=.145, sn=.11, snr=.058, ear_k=1.0, collar=False)),(("terrier",), dict(base=(205, 172, 118), ears="fold", tail="stub_up", marks="saddle", lg=.3, bt=.14,bl=.23, hr=.13, sn=.12, snr=.06, sc=.85)),]1101 unmodified lines# ---------------------------------------------------------------- flowerFLOWER_PALETTE = ["red", "yellow", "pink", "purple", "white", "orange"]FLOWER_KIND = [(("rose",), "rose"), (("tulip",), "tulip"), (("daisy", "daisies"), "daisy"), (("sunflower",), "sunflower"),(("lily", "lilies"), "lily"), (("daffodil", "narcissus", "jonquil"), "daffodil")]STEM = (62, 132, 52)LEAF = (72, 148, 56)2 unmodified linesL, h, x, y, rng = ctx.L, inst.h, inst.x, inst.y, inst.rngkind = pick(word_of(inst), FLOWER_KIND, "flower")unit = getattr(cv, "unit", 1.0)default = {"rose": "red", "daisy": "white", "sunflower": "yellow", "lily": "white", "daffodil": "yellow"}.get(kind)col = rgb(inst.color or default or rng.choice(FLOWER_PALETTE), (230, 60, 80))hx, hy = x + h * .04, y - h * .8# rule: thin stems so the bloom owns most of the pixels (keeps the prompt colour dominant)87 unmodified lineslit_ellipse(cv, L, hx + math.cos(a) * R * .58, hy + math.sin(a) * R * .58, R * .45, max(.6 * unit, R * .13), col, rot=a)lit_ellipse(cv, L, hx, hy, R * .32, R * .32, (245, 190, 40) if inst.color != "yellow" else (150, 90, 30))returnif kind == "daffodil":# rule: daffodil = six pointed pale petals around a long orange-yellow trumpet pointing sidewaysR = h * .21for i in range(6):a = i * math.pi / 3 + .3tip = (hx + math.cos(a) * R, hy + math.sin(a) * R)cv.poly([(hx + math.cos(a + .5) * R * .3, hy + math.sin(a + .5) * R * .3), tip,(hx + math.cos(a - .5) * R * .3, hy + math.sin(a - .5) * R * .3)], L.flat(lighter(col, .25), .9))f = -1 if inst.facing == "left" else 1cv.poly([(hx - f * R * .1, hy - R * .22), (hx + f * R * .55, hy - R * .34), (hx + f * R * .55, hy + R * .34),(hx - f * R * .1, hy + R * .22)], L.shade((245, 160, 30), 0, -.3, .8))cv.ellipse(hx + f * R * .55, hy, R * .14, R * .36, L.shade((235, 125, 20), f, 0, .6))return# generic flower: five round petals + centreR = h * .19for k in range(5):5 unmodified lines# ---------------------------------------------------------------- registryconcept("dog", height=.62, aspect=1.3, row="front", setting="field", animal=True, on_top=.72,synonyms=["puppy", "pup", "doggy", "hound", "doggo", "terrier", "poodle", "corgi", "beagle", "husky","dachshund", "wiener dog", "sausage dog", "bulldog", "shiba inu", "shiba", "akita","labradoodle", "goldendoodle"],implied_colors={"labrador": "golden", "retriever": "golden", "golden retriever": "golden", "dalmatian": "white","labrador retriever": "golden"},plurals={"puppy": "puppies"})(draw_dog)15 unmodified linesconcept("ball", height=.3, aspect=1.0, row="front", setting="field", on_top=1.0,synonyms=["sports ball", "soccer ball", "football", "basketball", "beach ball", "beachball", "volleyball", "tennis ball", "baseball"])(draw_ball)concept("flower", height=.45, aspect=.55, row="front", setting="field", on_top=1.0,synonyms=["tulip", "bloom", "blossom", "daffodil", "narcissus", "jonquil"], implied_colors={"rose": "red", "daisy": "white", "sunflower": "yellow", "lily": "white", "daffodil": "yellow"},plurals={"daisy": "daisies", "lily": "lilies"})(draw_flower)
248 unmodified lines249250251252253254381 unmodified lines636637638639640641642248 unmodified linesc = color_of(inst)f = -1 if inst.facing == "left" else 1w = inst.w / 2# rule: banana = thick crescent "smile" (ends up, belly down) with a fat middle tapering to both endsn = 16spine = []381 unmodified linesconcept("bowl", height=.08, aspect=1.9, row="front", setting="table", on_top=.68,synonyms=["soup bowl", "cereal bowl", "salad bowl"], default_color=(236, 234, 228))(draw_bowl)concept("banana", height=.075, aspect=2.1, row="front", setting="table", on_top=.8,synonyms=[], default_color=(245, 210, 50))(draw_banana)concept("apple", height=.085, aspect=1.0, row="front", setting="table", on_top=1.0,synonyms=[], default_color=(200, 35, 40))(draw_apple)concept("orange", height=.08, aspect=1.02, row="front", setting="table", on_top=1.0,248 unmodified lines249250251252253254255256257258259260261262263264265266267268269381 unmodified lines651652653654655656657248 unmodified linesc = color_of(inst)f = -1 if inst.facing == "left" else 1w = inst.w / 2if "peel" in (inst.word or ""):# rule: peeled banana = standing upright, cream flesh on top, the yellow peel split into flaps hanging downr = h * .17cv.poly([(x - r * .9, y - h * .5), (x - r, y - h * .82), (x - r * .4, y - h * 1.0), (x + r * .4, y - h * 1.0),(x + r, y - h * .82), (x + r * .9, y - h * .5)], lambda px, py: L.shade((246, 236, 196), (px - x) / r * .7, -.4, .7))cv.poly([(x - r * .9, y - h * .5), (x - r * .55, y - h * .08), (x + r * .55, y - h * .08), (x + r * .9, y - h * .5)],lambda px, py: L.shade(c, (px - x) / r * .7, -.2, .7))lit_capsule(cv, L, x, y - h * .1, x, y, max(.8, r * .3), (125, 100, 45))for k in (-1, 1): # side flaps curl outward and downcv.poly([(x + k * r * .3, y - h * .55), (x + k * r * 1.0, y - h * .6), (x + k * r * 2.1, y - h * .38),(x + k * r * 2.3, y - h * .22), (x + k * r * 1.6, y - h * .3), (x + k * r * .8, y - h * .42)],L.shade(c, k * .5, -.5, .7))cv.poly([(x - r * .4, y - h * .52), (x + r * .4, y - h * .52), (x + r * .3, y - h * .25), (x - r * .3, y - h * .25)],L.shade(lighter(c, .15), 0, -.3, .8)) # front flapreturn# rule: banana = thick crescent "smile" (ends up, belly down) with a fat middle tapering to both endsn = 16spine = []381 unmodified linesconcept("bowl", height=.08, aspect=1.9, row="front", setting="table", on_top=.68,synonyms=["soup bowl", "cereal bowl", "salad bowl"], default_color=(236, 234, 228))(draw_bowl)concept("banana", height=.075, aspect=2.1, row="front", setting="table", on_top=.8,synonyms=["peeled banana", "half peeled banana", "half-peeled banana"], default_color=(245, 210, 50))(draw_banana)concept("apple", height=.085, aspect=1.0, row="front", setting="table", on_top=1.0,synonyms=[], default_color=(200, 35, 40))(draw_apple)concept("orange", height=.08, aspect=1.02, row="front", setting="table", on_top=1.0,
768 unmodified lines769770771772773774775768 unmodified lines# ================================================================ dishes@concept("noodles", height=.12, aspect=1.6, row="front", setting="table", on_top=1.0,synonyms=["noodle", "ramen", "bowl of noodles", "bowl of ramen", "spaghetti", "pasta", "udon", "pho"],default_color=(205, 45, 40))def draw_noodles(cv, ctx, inst):L, h, x, y = ctx.L, inst.h, inst.x, inst.y768 unmodified lines769770771772773774775768 unmodified lines# ================================================================ dishes@concept("noodles", height=.12, aspect=1.6, row="front", setting="table", on_top=1.0,synonyms=["noodle", "ramen", "bowl of noodles", "bowl of ramen", "spaghetti", "pasta", "udon", "pho", "bowl of pho", "chicken pho", "beef pho", "noodle soup"],default_color=(205, 45, 40))def draw_noodles(cv, ctx, inst):L, h, x, y = ctx.L, inst.h, inst.x, inst.y
915 unmodified lines916917918919920921922915 unmodified lines# ---------------------------------------------------------------- registryconcept("chair", height=.9, aspect=.62, row="front", setting="room", on_top=.53, default_color=(150, 95, 55),synonyms=["armchair", "stool", "dining chair", "office chair"])(draw_chair)concept("couch", height=.85, aspect=2.4, row="front", setting="room", on_top=.5, default_color=(90, 120, 155),synonyms=["sofa", "settee", "loveseat", "love seat", "divan"])(draw_couch)concept("bed", height=.75, aspect=2.0, row="front", setting="room", on_top=.5,915 unmodified lines916917918919920921922915 unmodified lines# ---------------------------------------------------------------- registryconcept("chair", height=.9, aspect=.62, row="front", setting="room", on_top=.53, default_color=(150, 95, 55),synonyms=["stool", "dining chair", "office chair"])(draw_chair)concept("couch", height=.85, aspect=2.4, row="front", setting="room", on_top=.5, default_color=(90, 120, 155),synonyms=["sofa", "settee", "loveseat", "love seat", "divan"])(draw_couch)concept("bed", height=.75, aspect=2.0, row="front", setting="room", on_top=.5,
336 unmodified lines3373383393403413421088 unmodified lines143114321433143414351436143790 unmodified lines1528152915301531153215331534336 unmodified linesL, x, y, w, h = ctx.L, inst.x, inst.y, inst.w, inst.hc = color_of(inst)rng = __import__("random").Random(inst.k * 31 + 7)# rule: branching coral = a recursive fork of thick round-tipped branches spreading up and out, with polyp dotssegs = []1088 unmodified linesdefault_color=(246, 214, 190), synonyms=["shell", "sea shell", "scallop shell", "conch", "conch shell", "clam shell"],natural_colors={"pink": (245, 175, 175), "white": (246, 240, 228)})(draw_seashell)concept("coral", height=.6, aspect=1.1, row="front", setting="underwater", on_top=.8,default_color=(242, 110, 120), synonyms=["coral reef", "reef coral", "branch coral"],plurals={"coral": "corals"})(draw_coral)concept("bee", height=.2, aspect=1.25, row="sky", setting="field", animal=True, flying=True, shadow=False,default_color=(246, 196, 40), synonyms=["bumblebee", "bumble bee", "honeybee", "honey bee", "wasp"],90 unmodified linesdefault_color=(246, 120, 30), synonyms=["road cone", "safety cone", "pylon cone"],natural_colors={"orange": (246, 120, 30)})(draw_traffic_cone)concept("wind turbine", height=30.0, aspect=.62, row="back", setting="field",default_color=(240, 242, 244), synonyms=["windturbine", "wind generator", "wind farm turbine"])(draw_wind_turbine)concept("treehouse", height=7.0, aspect=.95, row="back", setting="field", on_top=.8,default_color=(176, 120, 66), synonyms=["tree house", "tree fort"])(draw_treehouse)concept("pirate ship", height=14.0, aspect=1.15, row="mid", setting="water", on_top=.32, shadow=False,336 unmodified lines3373383393403413423433443453463473483493503513523533543553563571088 unmodified lines144614471448144914501451145290 unmodified lines1543154415451546154715481549336 unmodified linesL, x, y, w, h = ctx.L, inst.x, inst.y, inst.w, inst.hc = color_of(inst)rng = __import__("random").Random(inst.k * 31 + 7)if "brain" in (getattr(inst, "word", "") or ""):# rule: brain coral = a low round dome covered in meandering maze-like groovesbc = color_of(inst) if inst.color else (205, 170, 110)cx, cy, rx, ry = x, y - h * .38, w * .46, h * .4lit_ellipse(cv, L, cx, cy, rx, ry, bc)cv.poly(quad(x - rx, cy, x + rx, y), L.shade(scale(bc, .8), 0, .3, .8))cv.ellipse(cx, y - h * .02, rx, h * .06, scale(bc, .7))groove = scale(bc, .55)for k in range(7):yy = cy - ry * .75 + k * ry * .26half = rx * math.sqrt(max(0, 1 - ((yy - cy) / ry) ** 2)) * .9 if yy < cy else rx * .9pts = [(cx - half + 2 * half * i / 14, yy + math.sin(i * 1.4 + k * 2.1) * ry * .09) for i in range(15)]for a, b in zip(pts, pts[1:]):cv.capsule(a[0], a[1], b[0], b[1], max(.4, U(cv) * .45), groove)return# rule: branching coral = a recursive fork of thick round-tipped branches spreading up and out, with polyp dotssegs = []1088 unmodified linesdefault_color=(246, 214, 190), synonyms=["shell", "sea shell", "scallop shell", "conch", "conch shell", "clam shell"],natural_colors={"pink": (245, 175, 175), "white": (246, 240, 228)})(draw_seashell)concept("coral", height=.6, aspect=1.1, row="front", setting="underwater", on_top=.8,default_color=(242, 110, 120), synonyms=["coral reef", "reef coral", "branch coral", "brain coral"],plurals={"coral": "corals"})(draw_coral)concept("bee", height=.2, aspect=1.25, row="sky", setting="field", animal=True, flying=True, shadow=False,default_color=(246, 196, 40), synonyms=["bumblebee", "bumble bee", "honeybee", "honey bee", "wasp"],90 unmodified linesdefault_color=(246, 120, 30), synonyms=["road cone", "safety cone", "pylon cone"],natural_colors={"orange": (246, 120, 30)})(draw_traffic_cone)concept("wind turbine", height=30.0, aspect=.62, row="back", setting="field",default_color=(240, 242, 244), synonyms=["windturbine", "wind generator", "wind farm turbine", "modern windmill", "modern windmills"])(draw_wind_turbine)concept("treehouse", height=7.0, aspect=.95, row="back", setting="field", on_top=.8,default_color=(176, 120, 66), synonyms=["tree house", "tree fort"])(draw_treehouse)concept("pirate ship", height=14.0, aspect=1.15, row="mid", setting="water", on_top=.32, shadow=False,
1348 unmodified lines134913501351135213531354135513561357135813591348 unmodified lines@concept("sign", height=1.9, aspect=.75, row="front", setting="street",synonyms=["signpost", "signboard", "wooden sign", "road sign", "warning sign", "street sign", "traffic sign","placard", "notice board", "sign post"], default_color=(235, 225, 200))def draw_sign(cv, ctx, inst):L, x, y, h, w = ctx.L, inst.x, inst.y, inst.h, inst.wword = inst.word or ""t = lw(cv, w * .04)if word.startswith(("road sign", "warning sign", "traffic sign")) or inst.color in ("yellow", "orange"):# rule: a yellow (or orange) sign is a warning sign: drawn as the diamond# rule: a road warning sign = yellow diamond with a black border on a grey pole1348 unmodified lines1349135013511352135313541355135613571358135913601361136213631364136513661367136813691348 unmodified lines@concept("sign", height=1.9, aspect=.75, row="front", setting="street",synonyms=["signpost", "signboard", "wooden sign", "road sign", "warning sign", "street sign", "traffic sign","placard", "notice board", "sign post", "yield sign", "give way sign"], default_color=(235, 225, 200))def draw_sign(cv, ctx, inst):L, x, y, h, w = ctx.L, inst.x, inst.y, inst.h, inst.wword = inst.word or ""t = lw(cv, w * .04)if word.startswith(("yield", "give way")):# rule: yield sign = point-DOWN triangle, thick red border around a white centre, on a grey polec = color_of(inst, (205, 30, 35))cv.capsule(x, y, x, y - h * .55, t, STEEL)top, R = y - h * .98, w * .5tri = lambda k: [(x - R * k, top + (1 - k) * R * .58), (x + R * k, top + (1 - k) * R * .58), (x, top + R * 1.62 - (1 - k) * R * 1.0)]cv.poly(tri(1.0), INK)cv.poly(tri(.93), L.shade(c, 0, 0, 1))cv.poly(tri(.5), (246, 244, 240))returnif word.startswith(("road sign", "warning sign", "traffic sign")) or inst.color in ("yellow", "orange"):# rule: a yellow (or orange) sign is a warning sign: drawn as the diamond# rule: a road warning sign = yellow diamond with a black border on a grey pole
186 unmodified lines187188189190191192193186 unmodified lines@concept("t shirt", height=.72, aspect=1.05, row="front", setting="studio",synonyms=["t-shirt", "tshirt", "tee shirt", "tee", "shirt", "sweatshirt", "hoodie", "hooded sweatshirt", "sweater","jumper", "jersey", "polo shirt", "long sleeve shirt", "pullover", "crewneck", "t shirts"],plurals={"tee": "tees"}, default_color=(235, 235, 232))def draw_tshirt(cv, ctx, inst):L, x, y, h, w = ctx.L, inst.x, inst.y, inst.h, inst.w186 unmodified lines187188189190191192193186 unmodified lines@concept("t shirt", height=.72, aspect=1.05, row="front", setting="studio",synonyms=["t-shirt", "tshirt", "tee shirt", "tee", "shirt", "sweatshirt", "hoodie", "hooded sweatshirt", "sweater","jumper", "jersey", "polo shirt", "long sleeve shirt", "pullover", "crewneck", "t shirts", "turtleneck", "turtleneck sweater"],plurals={"tee": "tees"}, default_color=(235, 235, 232))def draw_tshirt(cv, ctx, inst):L, x, y, h, w = ctx.L, inst.x, inst.y, inst.h, inst.w
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474"""Misc wave 8: nouns from the PartiPrompts train split (round 2 sample) that had no concept or a wrong stand-in:armchair, lily pad, black hole, spiral galaxy, infinity symbol, pedestal, obelisk, podium, chalkboard, Greek temple,go-kart. Each is the one silhouette that names it, in 2-4 big colour masses."""from ..kit import *from .objects4 import U, lw, rrect, quad, facing, night, outline, arc_pts, cyl_shade
INK = (26, 24, 28)WOOD = (150, 98, 54)DWOOD = (96, 60, 32)STONE = (196, 190, 178)GOLD = (232, 186, 60)
# ================================================================ furniture@concept("armchair", height=.95, aspect=1.05, row="front", setting="room", on_top=.48, synonyms=["arm chair", "easy chair", "club chair", "wingback chair", "wing chair", "recliner"], default_color=(150, 60, 55))def draw_armchair(cv, ctx, inst): """Upholstered armchair, front view: tall padded back, two fat rolled arms, a thick seat cushion, short legs.""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y c = color_of(inst) leg = h * .1 seat_y = y - h * .42 # back: tall rounded slab (rule: the high padded back above the arms is what separates armchair from chair) cv.poly(rrect(x - w * .36, y - h, x + w * .36, seat_y, w * .14), lambda px, py: L.shade(c, (px - x) / w * .6, -.4, .75)) for k in (-1, 1): # button tufts cv.ellipse(x + k * w * .12, y - h * .74, max(.6, w * .02), max(.6, w * .02), scale(c, .62)) cv.ellipse(x, y - h * .62, max(.6, w * .02), max(.6, w * .02), scale(c, .62)) # seat cushion cv.poly(rrect(x - w * .34, seat_y - h * .1, x + w * .34, seat_y + h * .08, h * .05), L.shade(lighter(c, .12), 0, -.8, .6)) # base / skirt cv.poly(quad(x - w * .44, seat_y + h * .06, x + w * .44, y - leg), L.shade(scale(c, .85), 0, .2, .8)) # rule: rolled arms = fat vertical pads either side with a round scroll on top for k in (-1, 1): ax = x + k * w * .38 cv.poly(rrect(ax - w * .11, seat_y - h * .2, ax + w * .11, y - leg, w * .05), lambda px, py, k=k: L.shade(c, k * .6, -.2, .7)) lit_ellipse(cv, L, ax, seat_y - h * .2, w * .12, h * .07, lighter(c, .08)) for k in (-1, 1): cv.poly(quad(x + k * w * .4 - w * .03, y - leg, x + k * w * .4 + w * .03, y), DWOOD)
@concept("podium", height=1.15, aspect=.62, row="front", setting="room", on_top=1.0, synonyms=["lectern", "speaker podium", "pulpit", "speaking podium"], default_color=(120, 74, 40))def draw_podium(cv, ctx, inst): """Lectern: a tapering wooden stand with a slanted reading top and a microphone on a gooseneck.""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y c = color_of(inst) f = facing(inst) top = y - h * .86 # rule: lectern = trapezoid body wider at the top, a slanted desk lid overhanging it cv.poly([(x - w * .3, y), (x + w * .3, y), (x + w * .4, top), (x - w * .4, top)], lambda px, py: L.shade(c, (px - x) / w * .8, -.1, .8)) cv.poly(quad(x - w * .34, y - h * .04, x + w * .34, y), scale(c, .6)) cv.poly([(x - w * .5, top + h * .02), (x + w * .5, top + h * .02), (x + w * .46, top - h * .07), (x - w * .46, top - h * .07)], L.shade(lighter(c, .15), 0, -1, .5)) # panel inset + emblem disc cv.poly(quad(x - w * .22, top + h * .12, x + w * .22, y - h * .14), L.shade(scale(c, .8), 0, 0, 1)) cv.ellipse(x, top + h * .3, w * .1, w * .1, GOLD) # rule: gooseneck microphone rising from the lid toward the speaker side mx = x + f * w * .2 cv.capsule(mx, top - h * .06, mx - f * w * .05, top - h * .18, max(.5, U(cv) * .5), (50, 50, 55)) lit_ellipse(cv, L, mx - f * w * .06, top - h * .21, w * .055, w * .055, (40, 40, 45))
@concept("chalkboard", height=1.6, aspect=1.5, row="front", setting="room", on_top=1.0, synonyms=["blackboard", "chalk board", "black board", "greenboard", "classroom board", "whiteboard", "white board"], default_color=(38, 72, 56))def draw_chalkboard(cv, ctx, inst): """Chalkboard on a wooden easel frame: big dark slate in a wood border, chalk squiggles and a chalk tray.""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y white = "white" in (inst.word or "") c = color_of(inst, (238, 240, 242) if white else None) ink = (60, 90, 170) if white else (236, 236, 228) b0, b1 = y - h, y - h * .28 # legs for k in (-1, 1): cv.capsule(x + k * w * .4, b1, x + k * w * .44, y, max(.8, w * .02), DWOOD) cv.poly(quad(x - w * .5, b0, x + w * .5, b1), L.shade(WOOD, 0, -.3, .8)) m = w * .035 cv.poly(quad(x - w * .5 + m, b0 + m, x + w * .5 - m, b1 - m), lambda px, py: mix(c, scale(c, .78), (py - b0) / (b1 - b0))) # rule: chalk scribbles = a few hand-drawn wavy strokes, a sum-like row and a circle (no letters) r = max(.5, U(cv) * .45) rng = inst.rng for row in range(3): yy = b0 + (b1 - b0) * (.22 + row * .2) x0 = x - w * .38 n = 3 + row for seg in range(n): xs = x0 + seg * w * .2 pts = [(xs + w * .14 * t / 6, yy + math.sin(t * 1.7 + row + seg) * h * .025) for t in range(7)] for a, bb in zip(pts, pts[1:]): cv.capsule(a[0], a[1], bb[0], bb[1], r, ink, alpha=.85) if xs + w * .2 > x + w * .38: break pts = arc_pts(x + w * .28, b0 + (b1 - b0) * .72, w * .07, w * .07, 0, 2 * math.pi, 16) outline(cv, pts, r, ink, alpha=.85) # chalk tray cv.poly(quad(x - w * .46, b1 - m * .3, x + w * .46, b1 + m * .5), L.shade(DWOOD, 0, -1, .5)) cv.capsule(x - w * .2, b1 - m * .2, x - w * .14, b1 - m * .2, max(.5, m * .25), (245, 245, 240))
# ================================================================ water / space / symbols@concept("lily pad", height=.12, aspect=3.0, row="front", setting="water", on_top=.5, synonyms=["lilypad", "lily pad leaf", "water lily", "waterlily", "lotus leaf"], default_color=(70, 150, 60))def draw_lily_pad(cv, ctx, inst): """Floating lily pads: flat green ovals each with a V notch, one carrying a pink water-lily bloom.""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y c = color_of(inst) rng = inst.rng pads = [(0, 0, 1.0), (-.32, -.25, .62), (.33, -.18, .7)] # rule: pads are drawn back to front: smaller pads higher = farther away on the water for dx, dy, s in sorted(pads, key=lambda p: p[1]): px, py = x + dx * w, y - h * .45 + dy * h rx, ry = w * .26 * s, h * .42 * s ang0 = rng.uniform(-.8, .8) - math.pi / 2 pts = [(px, py)] + [(px + math.cos(a) * rx, py + math.sin(a) * ry) for a in [ang0 + .32 + i * (2 * math.pi - .64) / 20 for i in range(21)]] cv.ellipse(px, py + ry * .25, rx * 1.02, ry * .9, (30, 60, 70), alpha=.35) # shadow on the water cv.poly(pts, lambda qx, qy, px=px, rx=rx: L.shade(c, (qx - px) / rx * .4, -.8, .6)) for k in range(5): # radial veins a = ang0 + .6 + k * 1.1 cv.capsule(px, py, px + math.cos(a) * rx * .8, py + math.sin(a) * ry * .8, max(.3, U(cv) * .3), scale(c, .78)) if "lily" in (inst.word or "") and "pad" not in (inst.word or "") or inst.k == 0: # rule: one pink water-lily bloom of pointed petals sits on the biggest pad bx, by = x + w * .05, y - h * .62 for i in range(8): a = math.pi + i * math.pi / 7 tip = (bx + math.cos(a) * h * .5, by + math.sin(a) * h * .55) cv.poly([(bx - h * .08, by), tip, (bx + h * .08, by)], L.flat((245, 160, 190), .7 + .3 * math.sin(a))) cv.ellipse(bx, by - h * .05, h * .1, h * .06, (250, 210, 70))
@concept("black hole", height=3.0, aspect=1.6, row="sky", setting="space", flying=True, shadow=False, synonyms=["blackhole", "event horizon", "supermassive black hole", "singularity"], default_color=(250, 160, 60))def draw_black_hole(cv, ctx, inst): """Black hole: a pure black disc ringed by a bright photon ring, crossed by a glowing orange accretion disc.""" h, w, x, y = inst.h, inst.w, inst.x, inst.y c = color_of(inst) cx, cy = x, y - h * .5 R = h * .26 # rule: soft outer glow first, then the far half of the accretion disc arching OVER the hole (gravitational lensing) for k, a in ((2.3, .12), (1.8, .2), (1.45, .35)): cv.ellipse(cx, cy, R * k, R * k, mix(c, (255, 255, 230), .3), alpha=a) cv.ellipse(cx, cy, w * .5, h * .15, mix(c, (120, 30, 10), .35), alpha=.85) cv.ellipse(cx, cy, w * .44, h * .1, c) cv.ellipse(cx, cy, R * 1.12, R * 1.12, (255, 236, 190)) # photon ring cv.ellipse(cx, cy, R, R, (2, 2, 4)) # near half of the disc passes in front of the hole cv.poly([(cx - w * .5, cy)] + [(cx + w * .5 * math.cos(t), cy + h * .15 * math.sin(t)) for t in [math.pi - i * math.pi / 20 for i in range(21)]] + [(cx + w * .4 * math.cos(t), cy + h * .06 * math.sin(t)) for t in [i * math.pi / 20 for i in range(21)]], lambda px, py: mix((255, 240, 200), c, min(1, abs(px - cx) / (w * .45))))
@concept("spiral galaxy", height=6.0, aspect=1.4, row="sky", setting="space", flying=True, shadow=False, synonyms=["milky way", "spiral galaxies", "andromeda galaxy", "nebula"], default_color=(170, 140, 230))def draw_spiral_galaxy(cv, ctx, inst): """Spiral galaxy: bright yellow-white core with two glowing star-dusted arms wound around it, seen tilted.""" h, w, x, y = inst.h, inst.w, inst.x, inst.y c = color_of(inst) cx, cy = x, y - h * .5 rng = inst.rng tilt = .55 # rule: arms = two logarithmic spirals of overlapping soft dots, fading outward; core drawn last on top for arm in (0, math.pi): for i in range(70): t = i / 70 a = arm + t * 3.6 * math.pi / 1.4 r = w * (.04 + .44 * t) px, py = cx + math.cos(a) * r, cy + math.sin(a) * r * tilt s = h * (.11 - .07 * t) cv.ellipse(px, py, s, s * .8, mix((255, 250, 235), c, t), alpha=.5 * (1 - t * .6)) for _ in range(60): a, r = rng.uniform(0, 2 * math.pi), w * .5 * rng.random() ** .7 cv.ellipse(cx + math.cos(a) * r, cy + math.sin(a) * r * tilt, max(.5, U(cv) * .5), max(.5, U(cv) * .5), (255, 255, 250)) for k, a in ((.2, .4), (.13, .7), (.07, 1.0)): cv.ellipse(cx, cy, w * k, w * k * tilt * 1.1, (255, 240, 200), alpha=a)
@concept("infinity symbol", height=.5, aspect=2.1, row="front", setting="studio", shadow=True, synonyms=["infinity", "infinity sign", "lemniscate", "infinity loop"], default_color=(60, 110, 210))def draw_infinity(cv, ctx, inst): """Infinity sign: a thick figure-eight lying on its side (lemniscate) as a shaded tube.""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y c = color_of(inst) cx, cy = x, y - h * .5 pts = [] n = 80 for i in range(n + 1): t = i * 2 * math.pi / n d = 1 + math.sin(t) ** 2 pts.append((cx + w * .46 * math.cos(t) / d, cy + h * .9 * math.sin(t) * math.cos(t) / d)) r = h * .12 # rule: draw the tube in two passes so one strand visibly crosses over the other at the centre for (ax, ay), (bx, by) in zip(pts, pts[1:]): cv.capsule(ax, ay, bx, by, r * 1.15, scale(c, .45)) for i, ((ax, ay), (bx, by)) in enumerate(zip(pts, pts[1:])): cv.capsule(ax, ay, bx, by, r, L.shade(c, 0, -.4 if ay < cy else .3, .8)) # the over-strand k0 = n // 4 - 5 seg = list(zip(pts[k0:k0 + 10], pts[k0 + 1:k0 + 11])) for (ax, ay), (bx, by) in seg: cv.capsule(ax, ay, bx, by, r * 1.15, scale(c, .45)) for (ax, ay), (bx, by) in seg: cv.capsule(ax, ay, bx, by, r, L.shade(c, 0, -.2, .85)) for (ax, ay), (bx, by) in zip(pts[3:n // 4], pts[4:n // 4 + 1]): # highlight cv.capsule(ax, ay - r * .4, bx, by - r * .4, r * .25, lighter(c, .45), alpha=.6)
# ================================================================ monuments@concept("pedestal", height=1.2, aspect=.9, row="front", setting="studio", on_top=1.0, synonyms=["plinth", "stone pedestal", "marble pedestal", "statue base", "empty pedestal"], default_color=STONE)def draw_pedestal(cv, ctx, inst): """Pedestal: a square stone block with a projecting cap slab and a stepped base, front-lit.""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y c = color_of(inst) # rule: plinth = three stacked slabs, wide-narrow-wide; side faces darker than the front d = w * .1 lit_box(cv, L, x - w * .48, y - h * .14, x + w * .48 - d, y, d, scale(c, .92)) lit_box(cv, L, x - w * .36, y - h * .82, x + w * .36 - d, y - h * .14, d, c) lit_box(cv, L, x - w * .48, y - h, x + w * .48 - d, y - h * .82, d, lighter(c, .08)) cv.poly(quad(x - w * .24, y - h * .7, x + w * .24 - d, y - h * .26), L.shade(scale(c, .9), 0, 0, 1)) # inset panel
@concept("obelisk", height=20.0, aspect=.2, row="back", setting="desert", on_top=1.0, synonyms=["egyptian obelisk", "stone obelisk", "monolith"], default_color=(214, 184, 130))def draw_obelisk(cv, ctx, inst): """Obelisk: a tall slender four-sided stone shaft tapering up to a small pyramid tip, on a low base.""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y c = hazed(ctx, inst, color_of(inst)) base = h * .05 cv.poly(quad(x - w * .5, y - base, x + w * .5, y), L.shade(scale(c, .85), 0, -.3, .8)) sb, st = w * .36, w * .22 shaft_top = y - h * .9 # rule: two visible faces (lit + shadow) meeting at a centre edge make the square shaft read cv.poly([(x - sb, y - base), (x, y - base), (x, shaft_top), (x - st, shaft_top)], L.shade(c, -.7, 0, .7)) cv.poly([(x, y - base), (x + sb, y - base), (x + st, shaft_top), (x, shaft_top)], L.shade(c, .7, 0, .7)) cv.poly([(x - st, shaft_top), (x, y - h), (x, shaft_top)], L.shade(GOLD, -.6, -.4, .7)) cv.poly([(x, shaft_top), (x, y - h), (x + st, shaft_top)], L.shade(GOLD, .6, -.4, .7)) for k in range(6): # carved glyph marks down the face yy = shaft_top + (y - base - shaft_top) * (.1 + k * .13) cv.capsule(x - st * .7, yy, x - st * .25, yy, max(.4, U(cv) * .4), scale(c, .6))
@concept("greek temple", height=14.0, aspect=1.6, row="back", setting="field", on_top=1.0, synonyms=["parthenon", "the parthenon", "acropolis", "ancient temple", "roman temple", "greek ruins"], default_color=(232, 226, 210))def draw_greek_temple(cv, ctx, inst): """Greek temple front: stepped base, a row of fluted columns, a plain beam and a low triangular pediment.""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y c = hazed(ctx, inst, color_of(inst)) sh = hazed(ctx, inst, scale(c, .62)) # rule: three steps (stylobate), each narrower for k in range(3): cv.poly(quad(x - w * (.5 - k * .02), y - h * (k + 1) * .045, x + w * (.5 - k * .02), y - h * k * .045), L.shade(c, 0, -.5 if k % 2 else .1, .8)) col_b, col_t = y - h * .135, y - h * .7 n = 8 span = w * .88 cw = span / n * .55 cv.poly(quad(x - span / 2, col_t, x + span / 2, col_b), sh) # dark cella behind the colonnade for i in range(n): cx = x - span / 2 + span * (i + .5) / n cv.poly(quad(cx - cw / 2, col_t, cx + cw / 2, col_b), cyl_shade(L, c, cx, cw / 2)) if cw > 3: cv.capsule(cx, col_t + h * .02, cx, col_b - h * .02, max(.3, cw * .06), scale(c, .8)) # flute cv.poly(quad(cx - cw * .62, col_t - h * .03, cx + cw * .62, col_t), c) # capital cv.poly(quad(x - w * .47, col_t - h * .14, x + w * .47, col_t - h * .02), L.shade(c, 0, .2, .9)) # entablature cv.poly(quad(x - w * .47, col_t - h * .1, x + w * .47, col_t - h * .08), sh, alpha=.5) # rule: low wide pediment triangle with a shadowed tympanum cv.poly([(x - w * .49, col_t - h * .14), (x + w * .49, col_t - h * .14), (x, y - h)], c) cv.poly([(x - w * .4, col_t - h * .155), (x + w * .4, col_t - h * .155), (x, y - h * .96)], scale(c, .82))
# ================================================================ vehicles@concept("go kart", height=.65, aspect=2.0, row="front", setting="street", on_top=.6, synonyms=["go-kart", "gokart", "go cart", "kart", "karting car"], default_color=(230, 60, 40))def draw_go_kart(cv, ctx, inst): """Go-kart: a low flat chassis with four fat exposed wheels, a seat, a steering wheel and a front nose bumper.""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y f = facing(inst) X = lambda d: x + f * d c = color_of(inst) r = h * .24 tire = (32, 32, 35) # rule: far wheels first (offset up), then the chassis, then the near wheels: four wheels read as a kart for d in (-w * .3, w * .32): cv.ellipse(X(d) + f * w * .03, y - r - h * .06, r * .9, r * .9, scale(tire, .8)) cv.poly([(X(-w * .44), y - r * 1.1), (X(w * .38), y - r * 1.1), (X(w * .5), y - r * 1.5), (X(w * .48), y - r * 2.0), (X(w * .2), y - r * 2.1), (X(-w * .44), y - r * 1.7)], lambda px, py: L.shade(c, 0, -.5, .7)) cv.poly(rrect(X(-w * .28) - w * .07, y - h * .82, X(-w * .28) + w * .07, y - r * 1.6, w * .03), (40, 40, 46)) # seat back cv.capsule(X(w * .02), y - r * 1.9, X(w * .1), y - h * .7, max(.6, U(cv) * .6), (50, 50, 55)) # steering column cv.ellipse(X(w * .1), y - h * .72, w * .05, h * .08, (40, 40, 46)) cv.poly(quad(X(-w * .5), y - h * .55, X(-w * .44), y - r * 1.1), (60, 60, 64)) # rear bumper / engine for d in (-w * .3, w * .32): cv.ellipse(X(d), y - r, r, r, tire) lit_ellipse(cv, L, X(d), y - r, r * .5, r * .5, (200, 200, 205))
# ================================================================ props / shapes@concept("boxing ring", height=1.6, aspect=1.9, row="mid", setting="room", on_top=.4, synonyms=["wrestling ring", "boxing arena"], default_color=(40, 80, 170))def draw_boxing_ring(cv, ctx, inst): """Boxing ring: raised square canvas platform with a skirt, four corner posts and three rows of ropes.""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y c = color_of(inst) deck = y - h * .3 back = deck - h * .18 # rule: platform seen from slightly above: lighter canvas floor (trapezoid) over a coloured skirt cv.poly([(x - w * .5, deck), (x + w * .5, deck), (x + w * .4, back), (x - w * .4, back)], L.shade((228, 224, 214), 0, -1, .5)) cv.poly(quad(x - w * .5, deck, x + w * .5, y), L.shade(c, 0, .2, .85)) posts = [(x - w * .4, back), (x + w * .4, back), (x - w * .5, deck), (x + w * .5, deck)] ph = h * .62 rope_cols = [(220, 40, 40), (245, 245, 240), (40, 80, 200)] for i, (px, py) in enumerate(posts[:2]): # far posts + far ropes cv.capsule(px, py, px, py - ph * .8, max(.8, w * .012), (200, 200, 205)) for k, rc in enumerate(rope_cols): t = (k + 1) / 3.6 cv.capsule(posts[0][0], back - ph * .8 * t, posts[1][0], back - ph * .8 * t, max(.4, U(cv) * .45), rc) for s_ in (0, 1): # side ropes run from the far post to the near post cv.capsule(posts[s_][0], back - ph * .8 * t, posts[s_ + 2][0], deck - ph * t, max(.4, U(cv) * .45), rc) for px, py in posts[2:]: cv.capsule(px, py, px, py - ph, max(1, w * .016), (210, 210, 215)) cv.ellipse(px, py - ph * .6, w * .02, h * .05, (220, 40, 40)) # corner pad for k, rc in enumerate(rope_cols): t = (k + 1) / 3.6 cv.capsule(posts[2][0], deck - ph * t, posts[3][0], deck - ph * t, max(.5, U(cv) * .55), rc)
@concept("crystal ball", height=.3, aspect=.85, row="front", setting="table", on_top=1.0, synonyms=["crystal orb", "fortune teller ball", "glass orb", "magic orb", "scrying orb"], default_color=(170, 200, 245))def draw_crystal_ball(cv, ctx, inst): """Crystal ball: a big glowing translucent sphere with a bright highlight, sitting on a dark carved stand.""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y c = color_of(inst) R = min(w * .48, h * .38) cy = y - h * .24 - R # stand: flared base cv.poly([(x - w * .42, y), (x + w * .42, y), (x + w * .26, y - h * .26), (x - w * .26, y - h * .26)], L.shade((70, 45, 30), 0, -.3, .8)) cv.poly(quad(x - w * .44, y - h * .05, x + w * .44, y), (50, 32, 22)) # rule: glass orb = soft radial gradient (bright centre glow -> deeper rim), a white window highlight and a glow halo cv.ellipse(x, cy, R * 1.25, R * 1.25, lighter(c, .3), alpha=.25) cv.ellipse(x, cy, R, R, lambda px, py: mix(lighter(c, .55), scale(c, .7), min(1, math.hypot(px - x, py - cy) / R))) cv.ellipse(x - R * .1, cy + R * .2, R * .45, R * .3, (255, 255, 255), alpha=.18) cv.ellipse(x - R * .38, cy - R * .38, R * .22, R * .16, (255, 255, 255), rot=-.6) outline(cv, arc_pts(x, cy, R, R, 0, 2 * math.pi, 28), max(.4, U(cv) * .4), scale(c, .5))
@concept("swirl", height=.7, aspect=1.0, row="front", setting="studio", shadow=False, synonyms=["spiral", "swirly line", "whorl"], default_color=(240, 190, 40))def draw_swirl(cv, ctx, inst): """Swirl: a thick tapering line winding outward from the centre (Archimedean spiral), drawn flat.""" h, w, x, y = inst.h, inst.w, inst.x, inst.y c = color_of(inst) cx, cy = x, y - h * .5 pts = [] n = 90 # rule: three full turns, the stroke thickening as it unwinds so the centre stays readable for i in range(n + 1): t = i / n a = t * 3 * 2 * math.pi r = h * .46 * t pts.append((cx + math.cos(a) * r, cy + math.sin(a) * r, t)) for (ax, ay, t), (bx, by, _) in zip(pts, pts[1:]): cv.capsule(ax, ay, bx, by, max(.8, h * (.015 + .035 * t)) * 1.3, scale(c, .55)) for (ax, ay, t), (bx, by, _) in zip(pts, pts[1:]): cv.capsule(ax, ay, bx, by, max(.7, h * (.015 + .035 * t)), c)
@concept("dashed line", height=.12, aspect=5.0, row="front", setting="studio", shadow=False, synonyms=["dotted line", "broken line", "dash line"], default_color=(50, 100, 220))def draw_dashed_line(cv, ctx, inst): """Dashed line: a straight row of evenly spaced thick rounded dashes.""" h, w, x, y = inst.h, inst.w, inst.x, inst.y c = color_of(inst) dotted = "dot" in (inst.word or "") n = 7 r = h * (.28 if dotted else .14) for i in range(n): x0 = x - w * .5 + w * i / n + r if dotted: cv.ellipse(x0 + w / n * .3, y - h * .5, r, r, c) else: cv.capsule(x0, y - h * .5, x0 + w / n * .62 - 2 * r, y - h * .5, r, c)
@concept("water tower", height=25.0, aspect=.6, row="back", setting="field", on_top=1.0, synonyms=["watertower", "water tank tower", "elevated water tank"], default_color=(200, 205, 210))def draw_water_tower(cv, ctx, inst): """Water tower: a big round tank with a conical cap held high on four splayed steel legs with cross-bracing.""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y c = hazed(ctx, inst, color_of(inst)) steel = hazed(ctx, inst, (120, 125, 132)) tank_b, tank_t = y - h * .52, y - h * .85 r = max(.7, w * .03) # rule: four legs splay outward from under the tank to the ground; X braces between them legs = [(-.42, -.22), (-.14, -.08), (.14, .08), (.42, .22)] for gx, tx in legs: cv.capsule(x + w * gx, y, x + w * tx * 1.6, tank_b, r, steel) for k in range(3): y0 = y - (y - tank_b) * k / 3 y1 = y - (y - tank_b) * (k + 1) / 3 f0, f1 = .42 - .2 * k / 3, .42 - .2 * (k + 1) / 3 cv.capsule(x - w * f0, y0, x + w * f1, y1, r * .6, steel) cv.capsule(x + w * f0, y0, x - w * f1, y1, r * .6, steel) # tank: cylinder with a rounded bottom, then the cone roof rx = w * .45 cv.poly(quad(x - rx, tank_t, x + rx, tank_b), cyl_shade(L, c, x, rx)) cv.ellipse(x, tank_b, rx, h * .05, cyl_shade(L, scale(c, .85), x, rx)) cv.poly([(x - rx * 1.04, tank_t), (x + rx * 1.04, tank_t), (x, y - h)], cyl_shade(L, lighter(c, .08), x, rx)) cv.poly(quad(x - rx, tank_b - h * .06, x + rx, tank_b - h * .03), cyl_shade(L, scale(c, .7), x, rx)) # catwalk band
@concept("poster", height=.9, aspect=.72, row="front", setting="studio", on_top=1.0, synonyms=["propaganda poster", "movie poster", "wall poster", "vintage poster", "travel poster", "placard poster"], default_color=(205, 40, 40))def draw_poster(cv, ctx, inst): """Poster: a tall paper sheet with a bold sunburst, a heroic silhouette and blank title bands (no letters).""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y c = color_of(inst) paper = (238, 226, 196) x0, x1, y0, y1 = x - w * .5, x + w * .5, y - h, y cv.poly(quad(x0 + w * .03, y0 + h * .02, x1 + w * .03, y1 + h * .015), (40, 36, 34), alpha=.35) # drop shadow cv.poly(quad(x0, y0, x1, y1), paper) m = w * .06 ix0, ix1, iy0, iy1 = x0 + m, x1 - m, y0 + m, y1 - h * .24 cv.poly(quad(ix0, iy0, ix1, iy1), c) # rule: propaganda look = rays fanning from a low point, one big dark silhouette with a raised arm, title bands below cx, cy = x, iy1 for k in range(9): a0 = math.pi + k * math.pi / 9 a1 = a0 + math.pi / 18 R = h pts = [(cx, cy), (cx + math.cos(a0) * R, cy + math.sin(a0) * R), (cx + math.cos(a1) * R, cy + math.sin(a1) * R)] pts = [(min(ix1, max(ix0, px)), min(iy1, max(iy0, py))) for px, py in pts] cv.poly(pts, lighter(c, .25)) ink = (30, 26, 28) hx, hy = x - w * .05, iy1 - (iy1 - iy0) * .62 cv.ellipse(hx, hy, w * .075, w * .085, ink) cv.poly([(hx - w * .16, iy1), (hx - w * .13, hy + w * .12), (hx + w * .12, hy + w * .12), (hx + w * .17, iy1)], ink) cv.capsule(hx + w * .1, hy + w * .14, hx + w * .26, hy - w * .12, max(.8, w * .045), ink) # raised arm cv.ellipse(hx + w * .27, hy - w * .14, w * .05, w * .05, ink) # fist cv.poly(quad(x0 + m, y1 - h * .2, x1 - m, y1 - h * .11), ink) cv.poly(quad(x0 + m * 2, y1 - h * .085, x1 - m * 2, y1 - h * .045), c)
@concept("meal", height=.1, aspect=2.4, row="front", setting="table", on_top=.6, synonyms=["plate of food", "food plate", "dinner", "lunch", "feast", "dish of food", "cooked meal"], default_color=(245, 244, 240))def draw_meal(cv, ctx, inst): """A plate of food: white rimmed plate (seen from slightly above) with a seared steak, green broccoli and a scoop of mashed potato, plus carrot slices: three food colours that read as 'a meal'.""" L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y c = color_of(inst) cy = y - h * .4 rx, ry = w * .5, h * .4 cv.ellipse(x, cy + h * .06, rx, ry, scale(c, .7)) cv.ellipse(x, cy, rx, ry, L.shade(c, 0, -1, .5)) cv.ellipse(x, cy, rx * .74, ry * .72, L.shade(scale(c, .94), 0, -1, .6)) # rule: food heaped ABOVE the plate centre so it stays visible at pixel scale: steak left, potato right, greens front sx = x - rx * .28 lit_ellipse(cv, L, sx, cy - h * .12, rx * .36, h * .22, (120, 62, 36), rot=-.15) for k in range(3): # grill marks gx = sx - rx * .18 + k * rx * .14 cv.capsule(gx, cy - h * .26, gx + rx * .1, cy - h * .0, max(.4, U(cv) * .45), (60, 30, 18)) # mashed potato: a low lumpy mound (three overlapping blobs), not an egg for dx, dy, s in ((-.08, 0, .8), (.08, 0, .8), (0, -.12, .7)): lit_ellipse(cv, L, x + rx * (.3 + dx), cy - h * (.14 - dy), rx * .14 * s / .8, h * .2 * s / .8, (240, 228, 180)) cv.ellipse(x + rx * .3, cy - h * .3, rx * .06, h * .07, (250, 210, 80)) # butter pat for k in range(3): # broccoli florets bx = x + rx * (-.05 + k * .12) cv.capsule(bx, cy + h * .14, bx, cy - h * .02, max(.6, rx * .025), (140, 190, 90)) lit_ellipse(cv, L, bx, cy - h * .08, rx * .09, h * .16, (60, 140, 50)) for k in range(3): # carrot coins lit_ellipse(cv, L, x + rx * (.45 - k * .08), cy + h * .12 + k * h * .02, rx * .06, h * .07, (240, 130, 40))730 unmodified lines731732733734735736737738739601 unmodified lines1341134213431344134513461347730 unmodified lineskind, dflt = "fedora", (95, 90, 88)elif "bowler" in word or "derby" in word:kind, dflt = "bowler", (35, 33, 36)else:kind, dflt = "top", (34, 32, 38)c = color_of(inst, dflt)band = (190, 40, 45) if sum(c) < 200 else scale(c, .35)if kind == "sun":band = (200, 70, 90) if inst.color is None else contrast(c)601 unmodified linessynonyms=["party balloon", "helium balloon", "toy balloon"])(draw_balloon)concept("hat", height=.25, aspect=1.3, row="front", setting="table", on_top=1.0, default_color=(34, 32, 38),synonyms=["top hat", "cowboy hat", "stetson", "sun hat", "sunhat", "straw hat", "beach hat", "witch hat","wizard hat", "fedora", "trilby", "panama hat", "bowler hat", "derby hat"])(draw_hat)concept("shoe", height=.12, aspect=2.4, row="front", setting="room", on_top=1.0, default_color=(50, 100, 195),synonyms=["sneaker", "running shoe", "tennis shoe", "gym shoe", "dress shoe", "loafer", "oxford shoe"])(draw_shoe)concept("boot", height=.3, aspect=.95, row="front", setting="room", on_top=1.0, default_color=(120, 74, 40),730 unmodified lines731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765601 unmodified lines13671368136913701371137213731374730 unmodified lineskind, dflt = "fedora", (95, 90, 88)elif "bowler" in word or "derby" in word:kind, dflt = "bowler", (35, 33, 36)elif "cap" in word or "baseball" in word:kind, dflt = "cap", (40, 80, 170)elif "beret" in word:kind, dflt = "beret", (34, 32, 38)else:kind, dflt = "top", (34, 32, 38)c = color_of(inst, dflt)if kind == "cap":# rule: baseball cap = round low dome + a wide flat bill sticking out toward the facing side, button on topf = facing(inst)rx, base = w * .3, y - h * .2cx = x - f * w * .1cv.ellipse(x + f * w * .25, base + h * .06, w * .26, h * .1, L.shade(scale(c, .7), 0, 1, .5)) # bill undersidecv.ellipse(x + f * w * .25, base + h * .03, w * .25, h * .08, L.shade(c, 0, -1, .6)) # bill topdome = arc_pts(cx, base, rx, h * .55, math.pi, 2 * math.pi, 16) + arc_pts(cx, base, rx, h * .08, 0, math.pi, 8)cv.poly(dome, lambda px, py: L.shade(c, (px - cx) / rx * .7, -.6, .7))for k in (-.33, .33): # rule: panel seams sell the cap crowncv.capsule(cx + rx * k, base - h * .03, cx + rx * k * .4, base - h * .48, max(.3, U(cv) * .35), scale(c, .72))cv.ellipse(cx, base - h * .55, w * .035, h * .04, scale(c, .7))returnif kind == "beret":# rule: beret = wide soft flat disc slouched to one side with a tiny stalk on topf = facing(inst)cy = y - h * .35cv.ellipse(x - f * w * .06, cy, w * .46, h * .28, L.shade(c, 0, -.8, .6), rot=-f * .18)cv.ellipse(x - f * w * .06, cy + h * .08, w * .4, h * .16, L.shade(scale(c, .75), 0, .5, .6), rot=-f * .18)cv.poly(quad(x - w * .3, cy + h * .14, x + w * .3, cy + h * .26), scale(c, .6))cv.capsule(x - f * w * .06, cy - h * .26, x - f * w * .04, cy - h * .4, max(.4, w * .03), scale(c, .7))returnband = (190, 40, 45) if sum(c) < 200 else scale(c, .35)if kind == "sun":band = (200, 70, 90) if inst.color is None else contrast(c)601 unmodified linessynonyms=["party balloon", "helium balloon", "toy balloon"])(draw_balloon)concept("hat", height=.25, aspect=1.3, row="front", setting="table", on_top=1.0, default_color=(34, 32, 38),synonyms=["top hat", "cowboy hat", "stetson", "sun hat", "sunhat", "straw hat", "beach hat", "witch hat","wizard hat", "fedora", "trilby", "panama hat", "bowler hat", "derby hat", "baseball cap", "baseball hat","ball cap", "cap", "beret"])(draw_hat)concept("shoe", height=.12, aspect=2.4, row="front", setting="room", on_top=1.0, default_color=(50, 100, 195),synonyms=["sneaker", "running shoe", "tennis shoe", "gym shoe", "dress shoe", "loafer", "oxford shoe"])(draw_shoe)concept("boot", height=.3, aspect=.95, row="front", setting="room", on_top=1.0, default_color=(120, 74, 40),
2144 unmodified lines21452146214721482149215021512144 unmodified lines@concept("chessboard", height=.12, aspect=2.4, row="front", setting="table", on_top=.5,synonyms=["chess board", "chess set", "checkerboard", "checker board", "checkers board", "chess game", "game of chess"],default_color=(90, 58, 36))def draw_chessboard(cv, ctx, inst):L, x, y, h, w = ctx.L, inst.x, inst.y, inst.h, inst.w2144 unmodified lines21452146214721482149215021512144 unmodified lines@concept("chessboard", height=.12, aspect=2.4, row="front", setting="table", on_top=.5,synonyms=["chess board", "chess set", "checkerboard", "checker board", "checkers board", "chess game", "game of chess", "checkers", "game of checkers", "draughts"],default_color=(90, 58, 36))def draw_chessboard(cv, ctx, inst):L, x, y, h, w = ctx.L, inst.x, inst.y, inst.h, inst.w
69 unmodified lines70717273747514 unmodified lines90919293949510 unmodified lines10610710810911011169 unmodified lines"student": dict(sleeves=None, backpack=True),"athlete": dict(top=(215, 50, 50), bottom=(30, 40, 90), sleeves=False, shorts=True, hat="headband",shoes=WHITE, main="top", stripes="jersey"),"dancer": dict(top=(245, 160, 195), bottom=(250, 205, 215), sleeves=False, dress="tutu", hair="bun",arms="up", shoes=(245, 160, 195), main="top", gender="f"),}14 unmodified lines"student": "student", "schoolboy": "student", "schoolgirl": "student","athlete": "athlete", "runner": "athlete", "jogger": "athlete", "sprinter": "athlete","dancer": "dancer", "ballerina": "dancer", "ballet dancer": "dancer",}# word -> (age, gender)WORD_AGE = {10 unmodified lines"policeman": ("adult", "m"), "policewoman": ("adult", "f"), "fireman": ("adult", "m"),"firewoman": ("adult", "f"), "businessman": ("adult", "m"), "businesswoman": ("adult", "f"),"ballerina": ("adult", "f"),}_IRREG = {"men": "man", "women": "woman", "children": "child", "people": "person", "ladies": "lady","policemen": "policeman", "policewomen": "policewoman", "firemen": "fireman", "firewomen": "firewoman",69 unmodified lines7071727374757677787980818214 unmodified lines97989910010110210310410 unmodified lines11511611711811912012112212312412512669 unmodified lines"student": dict(sleeves=None, backpack=True),"athlete": dict(top=(215, 50, 50), bottom=(30, 40, 90), sleeves=False, shorts=True, hat="headband",shoes=WHITE, main="top", stripes="jersey"),# rule: superheroes = their two-colour suit + cape; the suit carries the prompt colour"superman": dict(top=(35, 75, 190), bottom=(35, 75, 190), sleeves=True, cape=(210, 30, 40), belt="red",boots=True, shoes=(210, 30, 40), main="top", gender="m", hair_col=BLACK),"spiderman": dict(top=(210, 30, 40), bottom=(35, 70, 180), sleeves=True, boots=True, shoes=(210, 30, 40),main="top", gender="m"),"batman": dict(top=(60, 60, 70), bottom=(60, 60, 70), sleeves=True, cape=(28, 28, 34), belt=True,boots=True, shoes=BLACK, main="top", gender="m"),"dancer": dict(top=(245, 160, 195), bottom=(250, 205, 215), sleeves=False, dress="tutu", hair="bun",arms="up", shoes=(245, 160, 195), main="top", gender="f"),}14 unmodified lines"student": "student", "schoolboy": "student", "schoolgirl": "student","athlete": "athlete", "runner": "athlete", "jogger": "athlete", "sprinter": "athlete","dancer": "dancer", "ballerina": "dancer", "ballet dancer": "dancer","politician": "business", "senator": "business", "mayor": "business","superman": "superman", "spiderman": "spiderman", "spider man": "spiderman", "batman": "batman",}# word -> (age, gender)WORD_AGE = {10 unmodified lines"policeman": ("adult", "m"), "policewoman": ("adult", "f"), "fireman": ("adult", "m"),"firewoman": ("adult", "f"), "businessman": ("adult", "m"), "businesswoman": ("adult", "f"),"ballerina": ("adult", "f"),# rule: family words carry age + gender ("a father and a son" = a man and a boy)"father": ("adult", "m"), "dad": ("adult", "m"), "daddy": ("adult", "m"), "husband": ("adult", "m"),"mother": ("adult", "f"), "mom": ("adult", "f"), "mum": ("adult", "f"), "wife": ("adult", "f"),"son": ("child", "m"), "daughter": ("child", "f"), "grandson": ("child", "m"), "granddaughter": ("child", "f"),"politician": ("adult", None), "senator": ("adult", None), "mayor": ("adult", None),"superman": ("adult", "m"), "spiderman": ("adult", "m"), "spider man": ("adult", "m"), "batman": ("adult", "m"),}_IRREG = {"men": "man", "women": "woman", "children": "child", "people": "person", "ladies": "lady","policemen": "policeman", "policewomen": "policewoman", "firemen": "fireman", "firewomen": "firewoman",
109 unmodified lines11011111211311411511631 unmodified lines148149150151152153109 unmodified lines# ---------------------------------------------------------------- motorcycle@concept("motorcycle", height=1.15, aspect=1.85, row="front", setting="street",synonyms=["motorbike", "motor bike", "scooter", "moped", "dirt bike", "chopper", "motor cycle"],default_color=(200, 40, 40))def draw_motorcycle(cv, ctx, inst):L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y31 unmodified linesseat = [(X(-w * .06), y - h * .74), (X(-w * .1), y - h * .82), (X(-w * .34), y - h * .82), (X(-w * .38), y - h * .74)]cv.poly(seat, L.shade((35, 32, 32), 0, -.5, .8))cv.capsule(X(-w * .02), y - h * .72, X(w * .22), y - h * .74, max(.6, h * .02), (255, 255, 255), alpha=.35)# handlebar + headlightcv.capsule(X(w * .3), y - h * .85, X(w * .2), y - h * .98, h * .035, (40, 40, 44))hl = (X(w * .36), y - h * .78)109 unmodified lines11011111211311411511631 unmodified lines148149150151152153154155156157158159160161162163164109 unmodified lines# ---------------------------------------------------------------- motorcycle@concept("motorcycle", height=1.15, aspect=1.85, row="front", setting="street",synonyms=["motorbike", "motor bike", "scooter", "moped", "dirt bike", "chopper", "motor cycle", "sport bike", "sportbike", "sports bike", "superbike"],default_color=(200, 40, 40))def draw_motorcycle(cv, ctx, inst):L, h, w, x, y = ctx.L, inst.h, inst.w, inst.x, inst.y31 unmodified linesseat = [(X(-w * .06), y - h * .74), (X(-w * .1), y - h * .82), (X(-w * .34), y - h * .82), (X(-w * .38), y - h * .74)]cv.poly(seat, L.shade((35, 32, 32), 0, -.5, .8))cv.capsule(X(-w * .02), y - h * .72, X(w * .22), y - h * .74, max(.6, h * .02), (255, 255, 255), alpha=.35)if any(k in (inst.word or "") for k in ("sport", "superbike")):# rule: sport bike = a full wedge fairing in body colour hiding the engine, a tinted windscreen and a raised tailfair = [(X(-w * .14), y - h * .25), (X(w * .16), y - h * .22), (X(w * .42), y - h * .62), (X(w * .36), y - h * .86),(X(w * .22), y - h * .8), (X(-w * .05), y - h * .58)]cv.poly(fair, vgrad(L, paint, y - h * .86, y - h * .22))cv.poly([(X(w * .36), y - h * .86), (X(w * .24), y - h * 1.0), (X(w * .18), y - h * .82)], (70, 80, 100))cv.capsule(X(-w * .06), y - h * .48, X(w * .14), y - h * .46, max(.6, h * .02), (245, 245, 240)) # livery stripecv.poly([(X(-w * .25), y - h * .74), (X(-w * .48), y - h * .9), (X(-w * .46), y - h * .78)], vgrad(L, paint, y - h * .9, y - h * .74))hl = (X(w * .39), y - h * .7)cv.ellipse(hl[0], hl[1], h * .05, h * .035, LAMP)return# handlebar + headlightcv.capsule(X(w * .3), y - h * .85, X(w * .2), y - h * .98, h * .035, (40, 40, 44))hl = (X(w * .36), y - h * .78)
83 unmodified lines84858687888933 unmodified lines12312412512612712812972 unmodified lines202203204205206207208102 unmodified lines311312313314315316280 unmodified lines59759859960060160260383 unmodified linesdef layout(scene, W, H, rng, trace):focal = float(H)scene["place"] = choose_place(scene, trace)if scene["place"] == "beach" and scene["entities"] and all(CONCEPTS[e["concept"]]["setting"] == "underwater" for e in scene["entities"]):scene["place"] = "underwater" # rule: only sea creatures + "ocean/sea" = under the seatrace.append("layout: only sea creatures -> underwater")33 unmodified linesside=e.get("side"), depth=e.get("depth"), color_explicit=e.get("color_explicit", True),hair=e.get("hair"), beard=e.get("beard"), expression=e.get("expression"),rng=random.Random(rng.random()), bound=None, rel=None, haze=0.0, place=place))y0 = H * HORIZON.get(place, .5)if scene.get("camera") == "high": # rule: seen from above = high horizon, more groundy0 = H * .22elif scene.get("camera") == "low": # rule: from below = low horizon, subject towers72 unmodified lines# anything else is just nearbyWEARABLE = {"tie", "hat", "crown", "sunglasses", "backpack", "scarf", "helmet", "shoe", "boot"}CONTAIN = {"box", "basket", "bowl", "cup", "car", "boat", "bed", "bucket", "jar", "truck", "bus", "train","shopping cart", "wheelbarrow", "aquarium", "bathtub", "sleeping bag", "wheelchair", "chair", "couch"}if oc in WEARABLE:for it in insts:if it.ent == o:102 unmodified linesimport os_E = dict(kv.split("=") for kv in os.environ.get("PYDRAW_EXP", "").split(",") if "=" in kv)target_px = H * float(_E.get("subj", .52)) / (1 + .3 * (n_subj - 1))if scene.get("distance") == "far": # rule: "in the distance" = small and fartarget_px *= .4280 unmodified linestrace.append("layout: %s sits on %s at y=%.0f" % (it.concept, it.bound.concept, it.y))elif it.rel in ("behind", "in_front_of") and it.bound is not None and hasattr(it.bound, "x"):b = it.boundit.x = b.x + (b.w * .3 + it.w * .25) * (1 if it.k % 2 == 0 else -1)for s, rel, o in order:A = [it for it in insts if it.ent == s and hasattr(it, "x")]B = [it for it in insts if it.ent == o and hasattr(it, "x")]83 unmodified lines848586878889909192939495969733 unmodified lines13113213313413513613772 unmodified lines210211212213214215216217102 unmodified lines320321322323324325326280 unmodified lines60760860961061161261361461561661761861983 unmodified linesdef layout(scene, W, H, rng, trace):focal = float(H)scene["place"] = choose_place(scene, trace)if scene["place"] in ("mountains", "field", "forest", "farm", "park", "savanna") and any(CONCEPTS[e["concept"]]["setting"] in ("water", "underwater") and CONCEPTS[e["concept"]]["animal"] for e in scene["entities"]):trace.append("layout: sea animal on land -> water (with %s behind)" % scene["place"])scene["place"] = "water" # rule: a whale near a mountain is in the water, not on grassfv = scene.get("vary", {}).get("field_variant")if scene["place"] == "field" and fv:scene["place"] = fv # rule (variation): an unnamed field may be a park, a farm or a mountain meadowtrace.append("vary: field -> %s" % fv)if scene["place"] == "beach" and scene["entities"] and all(CONCEPTS[e["concept"]]["setting"] == "underwater" for e in scene["entities"]):scene["place"] = "underwater" # rule: only sea creatures + "ocean/sea" = under the seatrace.append("layout: only sea creatures -> underwater")33 unmodified linesside=e.get("side"), depth=e.get("depth"), color_explicit=e.get("color_explicit", True),hair=e.get("hair"), beard=e.get("beard"), expression=e.get("expression"),rng=random.Random(rng.random()), bound=None, rel=None, haze=0.0, place=place))y0 = H * (HORIZON.get(place, .5) + scene.get("vary", {}).get("horizon_dy", 0))if scene.get("camera") == "high": # rule: seen from above = high horizon, more groundy0 = H * .22elif scene.get("camera") == "low": # rule: from below = low horizon, subject towers72 unmodified lines# anything else is just nearbyWEARABLE = {"tie", "hat", "crown", "sunglasses", "backpack", "scarf", "helmet", "shoe", "boot"}CONTAIN = {"box", "basket", "bowl", "cup", "car", "boat", "bed", "bucket", "jar", "truck", "bus", "train","shopping cart", "wheelbarrow", "aquarium", "bathtub", "sleeping bag", "wheelchair", "chair", "couch","hammock", "boxing ring", "tent", "bed", "rowboat", "canoe", "pickup truck"}if oc in WEARABLE:for it in insts:if it.ent == o:102 unmodified linesimport os_E = dict(kv.split("=") for kv in os.environ.get("PYDRAW_EXP", "").split(",") if "=" in kv)target_px = H * float(_E.get("subj", .52)) / (1 + .3 * (n_subj - 1))target_px *= scene.get("vary", {}).get("size_k", 1.0)if scene.get("distance") == "far": # rule: "in the distance" = small and fartarget_px *= .4280 unmodified linestrace.append("layout: %s sits on %s at y=%.0f" % (it.concept, it.bound.concept, it.y))elif it.rel in ("behind", "in_front_of") and it.bound is not None and hasattr(it.bound, "x"):b = it.boundsib = [o for o in ground if o.bound is b and o.rel == it.rel]if len(sib) > 1: # rule: several things in front of / behind one thing spread out in a rowj = sib.index(it)span = sum(o.w for o in sib) * 1.1it.x = b.x - span / 2 + (j + .5) * span / len(sib)else:it.x = b.x + (b.w * .3 + it.w * .25) * (1 if it.k % 2 == 0 else -1)for s, rel, o in order:A = [it for it in insts if it.ent == s and hasattr(it, "x")]B = [it for it in insts if it.ent == o and hasattr(it, "x")]
105 unmodified lines106107108109110111105 unmodified lines"dollhouse": ("house", "pink"), "doll house": ("house", "pink"), "chemtrail": ("airplane", "white"), "contrail": ("airplane", "white"),"sandpiper": ("bird", "brown"), "boba": ("juice", "brown"),"bubble tea": ("juice", "brown"), "iced tea": ("juice", "brown"), "wind farm": ("wind turbine", None),}105 unmodified lines106107108109110111112113114115116117105 unmodified lines"dollhouse": ("house", "pink"), "doll house": ("house", "pink"), "chemtrail": ("airplane", "white"), "contrail": ("airplane", "white"),"sandpiper": ("bird", "brown"), "boba": ("juice", "brown"),"bubble tea": ("juice", "brown"), "iced tea": ("juice", "brown"), "wind farm": ("wind turbine", None),# wave 8 (parti train round 2)"squirrell": ("squirrel", None), "squirel": ("squirrel", None), "tennis": ("tennis racket", None),"carnival": ("ferris wheel", None), "funfair": ("ferris wheel", None), "fairground": ("ferris wheel", None),"amusement park": ("ferris wheel", None), "theme park": ("ferris wheel", None), "love": ("heart", "red"),"spam": ("soda can", "blue"), "drop top": ("car", "red"), "mailbag": ("handbag", "brown"), "mail bag": ("handbag", "brown"),"speech": ("podium", None), "team": ("person", None), "road trip": ("car", None), "food": ("meal", None),}
123456789101112131415161718192021222324252627282930313233343536373839404142434445"""Dev tool: render one concept in a standard set of prompts and tile them into a sheet.
python -m pydraw.preview fork out/fork.png # pixel style python -m pydraw.preview fork out/fork.png --smooth python -m pydraw.preview fork out/fork.png --prompts "a fork on a table" "three forks""""import sys, argparsefrom . import plot, CONCEPTS
def main(): ap = argparse.ArgumentParser() ap.add_argument("concept") ap.add_argument("out") ap.add_argument("--smooth", action="store_true") ap.add_argument("--prompts", nargs="*") a = ap.parse_args() c = a.concept if c not in CONCEPTS: sys.exit("unknown concept %r; known: %s" % (c, ", ".join(sorted(CONCEPTS)))) pl = c + ("es" if c.endswith(("s", "sh", "ch", "x")) else "s") prompts = a.prompts or ["a photo of a %s" % c, "a photo of a red %s" % c, "a photo of a blue %s" % c, "a photo of three %s" % pl, "a %s at night" % c, "a photo of a dog left of a %s" % c, "a photo of a purple %s and a yellow %s" % (c, "cup" if "cup" in CONCEPTS else "ball"), "a photo of a %s above a %s" % (c, "car")] from PIL import Image ims = [] for i, p in enumerate(prompts): img = plot(p, seed=i, size=256, style="smooth" if a.smooth else "pixel") im = Image.new("RGB", (img.width, img.height)) im.putdata([px for row in img.pixels for px in row]) ims.append(im) unk = img.scene.get("unknown") print("%-55s %s" % (p, ("UNKNOWN: %s" % unk) if unk else "")) cols = 4 rows = (len(ims) + cols - 1) // cols sheet = Image.new("RGB", (256 * cols, 256 * rows), (255, 255, 255)) for i, im in enumerate(ims): sheet.paste(im, ((i % cols) * 256, (i // cols) * 256)) sheet.save(a.out) print("wrote", a.out)
if __name__ == "__main__": main()127 unmodified lines128129130131132133134135283 unmodified lines419420421422423424127 unmodified lines"painting": "oil", "drawing": "sketch", "doodle": "sketch", "crayon": "pastel", "chalk": "pastel"}POSES = {"flying": "flying", "sitting": "sitting", "running": "running", "sleeping": "sleeping", "perched": "perched","standing": "standing", "lying": "lying", "jumping": "jumping", "walking": "walking", "floating": "floating","parked": "standing", "sailing": "floating", "resting": "lying", "laying": "lying", "napping": "sleeping","lounging": "lying", "asleep": "sleeping", "curled": "sleeping", "seated": "sitting", "crouching": "sitting","leaping": "jumping", "jumps": "jumping", "hopping": "jumping", "bouncing": "jumping"}FACING = {"left": "left", "right": "right"}283 unmodified linesQUANT = {"herd": 4, "group": 3, "flock": 5, "pack": 4, "bunch": 4, "lot": 6, "lots": 6, "pile": 4, "stack": 3,"row": 4, "crowd": 5, "family": 3, "pair": 2, "couple": 2, "dozen": 8, "handful": 3, "school": 5,"swarm": 6, "line": 4, "set": 3, "number": 4, "collection": 4, "fleet": 4, "team": 4, "litter": 4}if t in QUANT and i + 1 < n and toks[i + 1] == "of":nxt_hit, _ = match_noun(toks, i + 2)if not (t == "pair" and nxt_hit and nxt_hit[0] in ("skis", "sunglasses", "scissors", "shoe", "boot")):127 unmodified lines128129130131132133134135283 unmodified lines419420421422423424425426427428429430431432433434435127 unmodified lines"painting": "oil", "drawing": "sketch", "doodle": "sketch", "crayon": "pastel", "chalk": "pastel"}POSES = {"flying": "flying", "sitting": "sitting", "running": "running", "sleeping": "sleeping", "perched": "perched","standing": "standing", "lying": "lying", "jumping": "jumping", "walking": "walking", "floating": "flying", "hovering": "flying", "levitating": "flying", "soaring": "flying","parked": "standing", "sailing": "floating", "airborne": "flying", "resting": "lying", "laying": "lying", "napping": "sleeping","lounging": "lying", "asleep": "sleeping", "curled": "sleeping", "seated": "sitting", "crouching": "sitting","leaping": "jumping", "jumps": "jumping", "hopping": "jumping", "bouncing": "jumping"}FACING = {"left": "left", "right": "right"}283 unmodified linesQUANT = {"herd": 4, "group": 3, "flock": 5, "pack": 4, "bunch": 4, "lot": 6, "lots": 6, "pile": 4, "stack": 3,"row": 4, "crowd": 5, "family": 3, "pair": 2, "couple": 2, "dozen": 8, "handful": 3, "school": 5,"swarm": 6, "line": 4, "set": 3, "number": 4, "collection": 4, "fleet": 4, "team": 4, "litter": 4}if t in ("family", "crowd", "team", "couple", "group") and i + 2 < n and toks[i + 1] == "of" and (toks[i + 2] in NUMBERS or toks[i + 2].isdigit()) \and "person" in CONCEPTS:# rule: "a family of four" = four people (the number belongs to the group, not to the next noun)cnt = NUMBERS.get(toks[i + 2]) or min(12, int(toks[i + 2]) if toks[i + 2].isdigit() else 3)scene["entities"].append({"concept": "person", "word": "person", "count": cnt, "color": None, "shade": 1.0,"size": 1.0, "pose": None, "facing": None, "color_explicit": False})trace.append("understand: '%s of %s' -> %d people" % (t, toks[i + 2], cnt))mods = {}i += 3last_noun_end = icontinueif t in QUANT and i + 1 < n and toks[i + 1] == "of":nxt_hit, _ = match_noun(toks, i + 2)if not (t == "pair" and nxt_hit and nxt_hit[0] in ("skis", "sunglasses", "scissors", "shoe", "boot")):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990"""Variation rules: vary what the prompt leaves open, never what it pins down.Different seeds then give different breeds, times of day, settings, framings and colour moods for the same prompt."""
VARIANTS = { "dog": ["dog", "dog", "corgi", "husky", "dalmatian", "poodle", "beagle", "golden retriever", "dachshund", "bulldog", "terrier"], "cat": ["cat", "cat", "kitten", "siamese"], "tree": ["tree", "tree", "birch", "oak", "maple", "cherry blossom", "willow", "apple tree"], "house": ["house", "house", "cottage", "cabin"], "car": ["car", "car", "car", "sports car", "jeep", "convertible", "vintage car"], "flower": ["flower", "rose", "tulip", "daisy", "sunflower", "lily"], "bird": ["bird", "bird", "robin", "sparrow", "bluebird", "cardinal", "seagull"], "ball": ["ball", "soccer ball", "basketball", "beach ball", "tennis ball"], "horse": ["horse", "horse", "pony"], "boat": ["boat", "boat", "sailboat", "rowboat", "canoe"],}# objects whose colour is arbitrary in real life: an unnamed colour may vary per seed (not colour-checked)VARY_COLOR = { "car": ["red", "blue", "white", "black", "silver", "green", "yellow", "orange"], "couch": ["blue", "red", "green", "gray", "brown", "yellow", "beige", "teal"], "chair": ["brown", "red", "blue", "green", "white", "black"], "bed": ["blue", "white", "red", "green", "pink", "yellow"], "umbrella": ["red", "blue", "yellow", "green", "purple", "black", "pink"], "ball": ["red", "blue", "yellow", "green", "orange", "white"], "cup": ["white", "red", "blue", "yellow", "green", "black"], "bicycle": ["red", "blue", "green", "yellow", "black", "orange", "white"], "motorcycle": ["red", "black", "blue", "silver", "orange"], "truck": ["red", "blue", "white", "green", "yellow", "orange"], "boat": ["red", "blue", "white", "green", "yellow"], "kite": ["red", "blue", "yellow", "green", "purple", "orange"], "balloon": ["red", "blue", "yellow", "green", "pink", "purple", "orange"], "backpack": ["red", "blue", "green", "yellow", "black", "purple"], "suitcase": ["red", "blue", "black", "green", "silver", "orange"], "vase": ["blue", "white", "red", "green", "yellow", "purple"], "bowl": ["white", "blue", "red", "green", "yellow"], "hat": ["red", "blue", "black", "brown", "green"], "tent": ["orange", "red", "blue", "green", "yellow"], "skateboard": ["red", "blue", "green", "yellow", "black", "orange"],}OUTDOOR = {"field", "park", "farm", "mountains", "forest", "beach", "snow", "desert", "savanna", "water", "street", "sky", "jungle"}
def vary(scene, trace, rng, strength=1.0): """Decide the open choices up front (before layout) and record them in the scene.""" if strength <= 0: return import os off = set(os.environ.get("PYDRAW_VARYOFF", "").split(",")) # dev-only ablation: v,c,t,s,p,f,m said = " ".join(trace) explicit_time = "time=" in said explicit_place = "place=" in said or scene.get("place") is not None explicit_season = "season=" in said v = {} # rule: variants for generic nouns with no colour / variant word ("a dog" may be a corgi on another seed) for e in scene["entities"]: opts = VARIANTS.get(e["concept"]) color_ok = e["concept"] in ("car", "house", "boat", "ball", "flower") # variants whose look doesn't fight a named colour if "v" not in off and opts and e["word"] in (e["concept"], e["concept"] + "s") and (not e.get("color") or color_ok) and not e.get("material") and rng.random() < .7 * strength: w = rng.choice(opts) if w != e["concept"]: e["word"] = w trace.append("vary: %s drawn as %s" % (e["concept"], w)) for e in scene["entities"]: opts = VARY_COLOR.get(e["concept"]) if "c" not in off and opts and not e.get("color") and not e.get("material") and rng.random() < .75 * strength: e["color"] = rng.choice(opts) e["color_explicit"] = False trace.append("vary: %s coloured %s" % (e["concept"], e["color"])) # rule: if the prompt names a colour, lighting stays neutral daylight (golden hour and colour moods tint named colours) named_colour = any(e.get("color") and e.get("color_explicit", True) for e in scene["entities"]) # rule: time of day, only if the prompt names none (mostly day, sometimes golden hour) if "t" not in off and not named_colour and not explicit_time and scene.get("style") not in ("neon", "silhouette") and rng.random() < .25 * strength: v["time"] = "sunset" # rule: season, only outdoors and only if unnamed if "s" not in off and not explicit_season and rng.random() < .15 * strength: v["season"] = "autumn" # rule: setting variant for an unnamed outdoor place (decided after the layout picks "field") if "p" not in off and not explicit_place: r = rng.random() v["field_variant"] = "park" if r < .2 * strength else "farm" if r < .3 * strength else "mountains" if r < .42 * strength else None # rule: composition jitter: subject size, horizon height, colour mood v["size_k"] = 1 + rng.uniform(-.12, .14) * strength * ("f" not in off) v["horizon_dy"] = rng.uniform(-.04, .04) * strength * ("f" not in off) r = rng.random() v["mood"] = "neutral" if (named_colour or "m" in off) else "warm" if r < .2 * strength else "cool" if r < .33 * strength else "vivid" if r < .46 * strength else "neutral" scene["vary"] = v if v.get("time"): scene["time"] = v["time"] if v.get("season"): scene["season"] = v["season"] trace.append("vary: %s" % ", ".join("%s=%s" % (k, (round(x, 2) if isinstance(x, float) else x)) for k, x in v.items() if x is not None))app.py+24-6
pydraw/__init__.py+8-3
pydraw/compose.py+10
pydraw/concepts/animals2.py+1-1
pydraw/concepts/core.py+24-4
pydraw/concepts/food.py+16-1
pydraw/concepts/food2.py+1-1
pydraw/concepts/indoor.py+1-1
pydraw/concepts/misc3.py+17-2
pydraw/concepts/misc5.py+11-1
pydraw/concepts/misc7.py+1-1
pydraw/concepts/misc8.pyAdded+474
pydraw/concepts/objects2.py+28-1
pydraw/concepts/objects4.py+1-1
pydraw/concepts/people.py+15
pydraw/concepts/vehicles.py+12-1
pydraw/layout.py+19-3
pydraw/lexicon.py+6
pydraw/preview.pyAdded+45
pydraw/understanding.py+13-2
pydraw/variation.pyAdded+90