🟣
Rainbow dot grid
36 colorful dots arranged in a 6×6 grid — nested loops in action.
Sprout· ages 8–1015 minnested for loopsturtle.dotlist indexing
dot_grid.py
520×520
First load pulls ~10 MB of Python. Only happens once — the browser caches it after.
What should the output look like?
A neat grid of 36 colored dots on the canvas.
📖
How this works
Two for loops nested inside each other — the outer counts rows, the inner counts columns. For every (row, col) pair we jump the turtle there and draw a dot. The color is picked from a list using (row + col) % 6, which creates a diagonal rainbow pattern.
Your turn — try these
- 1Change `size = 6` to `size = 10`. What happens?
- 2Change the color rule to `colors[row % 6]` — now each row is one color.
- 3Change `turtle.dot(24, ...)` to `turtle.dot(row * 5 + 10, ...)` — dots grow row by row!