Learning LibraryDigital Art LibraryKids

Drawing shapes: stamp stars and flowers

Drawing in code is like using stamps. Each shape — a star, a flower — knows how to draw itself. You just say where to put it, and what color and size.

The big idea

You draw by calling a shape and telling it where to go on the canvas.

See it in code

1Start simple

A shape is like a stamp. You say star, give it the screen, and tell it where. Here we stamp one star in the center:

python
from art import Canvas, star

screen = Canvas.create()
Canvas.fill(screen)

star(screen, 250, 250, size=100)
Run it — one star, stamped where you asked:
A single yellow star stamped in the center of a dark canvas.

The star drew itself. You only picked the spot and the size.

2A step further

Now use two different stamps. A star and a flower, side by side. Each shape knows how to draw itself:

python
from art import Canvas, star, flower

screen = Canvas.create()
Canvas.fill(screen)

star(screen, 170, 250, size=90)
flower(screen, 330, 250, size=90)
Run it — a star and a flower, in their own spots:
A yellow star on the left and a pink flower on the right of a dark canvas.

Two shapes, two spots. Change an x and one moves — the other stays put.

3In our world

Now stamp a few. Two stars and a flower, each in its own spot, each its own size and color. The shapes handle all the tricky drawing math for us:

python
from art import Canvas, star, flower

screen = Canvas.create()
Canvas.fill(screen)

star(screen, 150, 150, size=80)
flower(screen, 350, 150, size=80)
star(screen, 250, 350, size=100, color=(120, 220, 130))
Run it — three shapes, stamped where you asked:
A yellow star and a pink flower near the top of a dark canvas, and a larger green star below them.

Three lines, three shapes. Each one drew itself once we said where. Change an x, y, size, or color, and that shape moves or changes — the rest stay put.

The same idea, everywhere

All drawing works this way: you place shapes on a surface. Games stamp ships and coins, apps stamp buttons and icons, maps stamp pins. Learn to place a few shapes and you can build a whole scene.

Try it yourself

Add a third star of your own in an empty spot. Then make one shape much bigger with size=180, and give another a color like (255, 105, 160).

The common mistake

Forgetting the screen. Every shape needs to know which canvas to draw on, so screen always comes first: star(screen, ...). Leave it out and the shape has nowhere to appear.

What it unlocks

Placing shapes builds on the canvas and coordinates, and grows into composition and generative art.