Grades K–4: make pixel art with code
In this Hour of Code activity, students design pixel art and train a robot to paint the picture using code. It is free, runs in the browser, and needs no sign-up.
About 9 Dots. 9 Dots is a nonprofit that partners with schools to bring computer science to every student, starting in kindergarten. If you’re interested in bringing 9 Dots to your school, please fill out the form below.
Leading this with a class? Get the facilitation guide
A lesson plan for running the PixelBots activity with your class: timing, discussion questions and tips for helping students who get stuck.
Your hour at a glance
- 10 minWarm-Up
- 8 minLoops Exploration
- 10 minDesign Your Animal
- 22 minCode Your Animal
- 10 minShare & Reflect
Warm-Up: your first 9 Dots challenge
Help PixelBot paint an orange line using step, turn and paint blocks.
Your code blocks
Step
Moves PixelBot forward one square, in the direction it is facing.
Turn right
Turns PixelBot a quarter turn to its right. It stays on the same square.
Turn left
Turns PixelBot a quarter turn to its left. It stays on the same square.
Paint
Colors the square PixelBot is standing on. You choose the color.
How to code in PixelBots



Loops: write it once, repeat it
A loop tells a computer to repeat a sequence. Instead of writing the same code over and over again, write the sequence once inside a loop, and say how many times you’d like the code to repeat.
Read the code out loud: “step, paint, step, paint, step, paint.” Hear it? The same two blocks happen again and again.
1
2
3
Six lines of code to paint three squares.
Put one step and one paint inside a loop block. Then count the repeats you circled and type that number in the loop’s box.
3 repeats
Three lines of code do the same job. Want five squares? Just change 3 to 5.
Solve the warm-up again, this time with a loop
Your challenge: design and code your favorite animal
Great coders plan before they build. Design your picture first, then write the code, then make it shorter with loops.
Use Edit Goal to color your animal on the grid. Start with the big shapes, then add eyes, ears and other details. See how
Use step, turn and paint blocks to tell PixelBot how to paint your design. Go one row at a time and press play often.
Wherever colors and blocks repeat, swap them for a loop. Can you use at least two loops?
Need an idea? Try one of these.
How to design your animal in PixelBots
-
1
Open the drawing grid. Click the Edit Goal button.
-
2
Pick a color. Click the color square at the top left, then choose a color from the menu.
-
3
Paint. With the paintbrush selected, click a square on the grid to paint it. Pick a new color any time.
-
4
Fix a mistake. Click the eraser, then click a square to erase it. To paint again, click the paintbrush.

-
5
Save it. When your animal is done, remember to click Save. Now PixelBot knows what to paint.
Code your animal with PixelBots
Open in a new tabShare & Reflect
Every coder shares their work. Show your project to a partner and tell them how you made it.
Share your project with a partner
Presenter sentence starters
Finish each sentence out loud as you show your project.- “The animal I designed is ________.”
- “I wrote ________ lines of code.”
- “I used ________ loops in my code.”
Want to learn more about 9 Dots?
Tell us a little about yourself and we will follow up with ways to bring computer science to your school or family.