QQuickLab
← All articles

· QuickLab

Turning Blender into a game-art script with Python

How Word Sprout’s flower pots, mascot, 113 flower cards and 3D garden are made with Blender Python scripts: building characters from basic shapes, Freestyle outlines, and exporting meshes for Unity.

Most of the art in Word Sprout comes out of Blender: the six stages of a growing flower pot, Sprout the mascot with a seedling on its head, the 113 flower cards you earn from missions, and the 3D garden you can walk around. Almost none of it was made by hand in Blender’s UI, though. It’s all built by Python scripts and rendered with a single command.

Why scripts

The flower cards made the reason obvious. Model 99 flowers by hand (113 now, with seasonal cards) and changing something as small as the outline thickness means touching all 113. With a script, you change one number and run it again.

Having the source as text matters too. It’s hard to tell what changed in a .blend file, but a Python file shows up as a clean diff. The pot script still saves a .blend file when it finishes, so you can open the result in Blender if you need to.

One command

Blender can run in the background with no window and just execute a script. -b means background, -P means run this Python file, and anything after -- is read by the script itself.

# pot stages, mascot, water drop, app icon
Blender -b -P word_sprout/ArtSource/sprout_art.py

# every flower card, only some numbers, or only the seasonal cards
Blender -b -P word_sprout/ArtSource/flower_cards.py
Blender -b -P word_sprout/ArtSource/flower_cards.py -- 1 42 99
Blender -b -P word_sprout/ArtSource/flower_cards.py -- season
On macOS the Blender binary is /Applications/Blender.app/Contents/MacOS/Blender

Before each image, the script starts from an empty scene with read_factory_settings(use_empty=True). Nothing from the previous image leaks in, so every run produces the same pictures.

A character from basic shapes

Sprout is made of nothing but spheres, cylinders, cones and curve tubes. The body is a slightly squashed sphere, each eye is a flat black sphere with a small white one on top for the sparkle, and the smile is a tube through nine points on a downward arc.

def mascot(z=0.0, s=1.0):
    sphere((0, 0, z), (0.9*s, 0.8*s, 0.82*s), BODY)        # body
    for x in (-0.3, 0.3):                                   # eyes and sparkles
        sphere((x*s, -0.74*s, z+0.12*s), (0.11*s, 0.06*s, 0.15*s), EYE)
        sphere(((x+0.04)*s, -0.8*s, z+0.18*s), (0.035*s, 0.02*s, 0.045*s), WHITE)
    for x in (-0.52, 0.52):                                 # cheeks
        sphere((x*s, -0.66*s, z-0.1*s), (0.13*s, 0.04*s, 0.08*s), CHEEK)
    # smile: a tube through nine points on a downward arc
    pts = []
    for i in range(9):
        t = math.radians(200 + i * 140 / 8)
        pts.append((0.17*s*math.cos(t), -0.79*s, z - 0.06*s + 0.12*s*math.sin(t)))
    tube(pts, 0.028*s, EYE)
The real code, with material arguments trimmed

All the colors are constants at the top of the file: terracotta for the pot, soil, three greens for leaves, pink for petals, and so on. To change a color, you change it there.

One gotcha: colors in Blender materials are in linear color space, so plugging in the sRGB values you’re used to makes everything look washed out. We write the constants in familiar sRGB and convert them to linear when building each material.

The cartoon look: Freestyle outlines

Basic shapes under plain lighting look like plastic toys. The single biggest step toward a hand-drawn feel was Freestyle outlines, drawn in dark brown on silhouettes and borders only.

scene.render.use_freestyle = True
scene.render.line_thickness_mode = "ABSOLUTE"
scene.render.line_thickness = 2.6
lineset = scene.view_layers[0].freestyle_settings.linesets[0]
lineset.select_silhouette = True
lineset.select_border = True
lineset.select_crease = False         # skip inner crease lines
lineset.linestyle.color = srgb(LINE)  # dark brown

The rest of the setup pushes in the same direction.

Swapping into the same frame

All six pot stages are rendered at the same size and position, so the app just swaps images and the pot appears to grow in place.

For the flower cards we built 16 templates, among them daisy, tulip, bell, rose, star, clover and orchid, and each card swaps in its own colors, petal count and decorations to make 99 cards. Every flower has Sprout’s face in the middle (eyes, cheeks, a smile) so they all look like one family. Rarer cards get sparkles, a glow and a crown, and the 14 seasonal cards wear props like a Santa hat, a witch hat, sunglasses or bunny ears. Card numbers and names follow the same order as the list in the game code, so any card can be re-rendered by number.

Exporting meshes for the 3D garden

Word Sprout also has a 3D view where you walk around your own garden with Sprout. The ground, fences, arch, fountain, bench, butterflies, bees and all 113 flowers come from Blender scripts too, but this time the scripts export meshes instead of PNGs.

These models use plain single-color materials with no textures, so a much simpler format than FBX does the job: a small binary file with a position, normal and color per vertex, followed by a list of triangles. The file starts with the four bytes WSG1 so the Unity side can check it’s reading the right format.

with open(path, "wb") as out:
    out.write(b"WSG1")
    out.write(struct.pack("<ii", len(vertices), len(triangles)))
    for v in vertices:   # position 3 + normal 3 (float) + color RGBA (byte)
        out.write(struct.pack("<6f4B", *v))
    out.write(struct.pack("<%di" % len(triangles), *triangles))

Two conversions happen on the way out. Blender is Z-up and Unity is Y-up, so each vertex swaps y and z; that flips the handedness, so the triangle winding is reversed too (0, 1, 2 becomes 0, 2, 1). Skip that and the models render inside out. Material colors are also converted from Blender’s linear values back to sRGB for the vertex colors.

Since this has to run on phones, the garden versions are re-exported with spheres and cylinders cut down to 12 segments. The same flower definitions produce smooth shapes for the cards and light ones for the garden. On the Unity side, only planted flowers are built, there’s one material per color, and shadows are a single disc on the ground. Flowers rarely change, so GARDEN_ONLY=visit skips them and rebuilds just the garden props.

Keeping sources and outputs apart

Python scripts and .blend sources live in ArtSource/, and the PNGs and meshes the game reads live in Assets/Resources/. Game code only ever reads the outputs; the sources are only for regenerating them. The docstring at the top of each script says what it produces and how to run it again.

Blender isn’t the only tool in our asset rules: Krita is there for 2D concepts and textures, and PureRef for mood boards comparing references and colors. We don’t copy characters or art from other works, though. Word Sprout’s flowers use real flower names, but every shape and card design is our own.

At the other end, browser games like K-Claw Machine skip Blender entirely and build the shop and plush toys from basic shapes and textures drawn in code. We tend to pick whatever is lightest for each game. For how the Unity projects themselves are built in code, see Making mobile puzzle games in Unity.

Related articles

Seven habits that win more Klondike solitaire games

Dig the tallest hidden column first, empty a column only when a King is ready, and scan the board before you draw. Klondike tips from building Pinegold.

Read →

How we promise “every deal is solvable”: card game solvers and difficulty

Random shuffles include unwinnable deals. How Lantern Cells and Pinegold use a solver to pick deals, measure difficulty and order 120 levels.

Read →

Stuck at FreeCell? Five habits that save your free cells

FreeCell is a game of planning, not luck. The supermove formula, why an empty column beats free cells, and the order of play we learned while building Lantern Cells.

Read →

Seven rules we set while building apps for two-year-olds: Dodam Play and Color Wiggle

Ads, sound, praise, failure and parent locks: the principles behind our upcoming toddler learning app and kids coloring app.

Read →

Amortizing vs equal principal vs interest-only: the interest gap on a 100,000 loan

Same loan, same 4.5% rate, same 30 years, yet total interest ranges from about 67,700 to 135,000 depending on how you repay. How each method works and how to choose.

Read →

What we learned building 42 web tools that run entirely in your browser

Removing modulo bias from random numbers, a metronome that never drifts, line diffs with LCS and Markdown that scripts cannot sneak into: the small techniques behind QuickLab’s free tools.

Read →

The arithmetic is right—so why is the puzzle wrong? A Math Lattice guide

Worked examples for crossing equations, practical solving tips, and ways to play with children and older adults—without overstating school or brain-health benefits.

Read →

Stuck on a line puzzle? Leave a route for the other colors

Practical Lumen Lanes tips for tight passages and connection order, ways to play with family, and what brain-health research does—and does not—tell us.

Read →

Studying English words with Word Sprout: a tour of every feature, with screenshots

From snapping a school word list to flash cards, multiple choice, matching pairs, spelling, dictation, tests and an exam date. A screen-by-screen look at Word Sprout’s learning features and why each one is there.

Read →

Making mobile puzzle games in Unity, with no scenes or prefabs

How we build Pour Parade, Math Lattice and Munchling Meadow in Unity: how we pick an engine, a project built entirely in code, tests that run without Unity, and where AdMob and Hindi text tripped us up.

Read →

Stuck on a color sort puzzle? Start by saving the empty bottle

Why pour-and-sort puzzles suddenly jam up in later levels, and how to get through them with fewer moves, using Pour Parade as the example.

Read →

We put four games on Google Play

The four games MandooHai Studio has released on Google Play so far, and a few things we try to stick to when making them.

Read →

A week before the word test, 15 minutes a day is enough

Instead of cramming the night before, spend 15 minutes a day for a week. A day-by-day plan for a child’s English word test.

Read →

Spaced repetition and the Leitner box: for kids who forget yesterday’s words

Why words your child knew last night are gone by morning, and how to try the Leitner system, five boxes that decide when to review, at home.

Read →