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
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:
from art import Canvas, star
screen = Canvas.create()
Canvas.fill(screen)
star(screen, 250, 250, size=100)
The star drew itself. You only picked the spot and the size.
Now use two different stamps. A star and a flower, side by side. Each shape knows how to draw itself:
from art import Canvas, star, flower
screen = Canvas.create()
Canvas.fill(screen)
star(screen, 170, 250, size=90)
flower(screen, 330, 250, size=90)
Two shapes, two spots. Change an x and one moves — the other stays put.
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:
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))
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.
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.