Drawing with Code: When Robots Hold Pens

Watch patterns emerge from simple commands

1

Meet Your Drawing Robot

This robot has a pen attached. You control it with simple commands: forward to move and turn to rotate. The pen draws a line wherever the robot goes!

forward(distance)
Move forward by the given number of pixels
turn(angle)
Turn right by the given degrees
pen_down()
Lower the pen to start drawing
pen_up()
Lift the pen to move without drawing
Your Code 🤖 Ready
Drawing Canvas
Try This
Change the distances and angles. What happens if you use 60° instead of 90°? Or make the sides different lengths?
2

The Power of Loops

Typing the same commands over and over is tedious. Loops let you repeat commands automatically. A square is just "forward, turn" repeated 4 times!

With Loops Only 4 lines!
Result
Turn Angle = 360° ÷ Number of Sides
A triangle turns 120° (360÷3), a square turns 90° (360÷4), a hexagon turns 60° (360÷6)... A circle is just a polygon with LOTS of tiny sides!
3

The Magic of Stars

What if we turn MORE than the polygon angle? When we "skip" points, stars appear! A 5-pointed star uses 144° (that's 360° × 2 ÷ 5).

144°
5-Pointed Star
360° × 2 ÷ 5 = 144°

The "2" means we skip 2 points each time!

Star Code
Your Star
Math Magic
The formula is: turn angle = 360° × skip ÷ points. When skip=1, you get a polygon. When skip≥2, you get stars!
4

Spirals from Simple Rules

What if the distance GROWS each time? Instead of forward(100) every time, we increase it: 10, 15, 20, 25... This creates beautiful spirals!

Spiral Code
Spiral Result

Small Angle = Smooth Curves

Turn by small amounts (like 5° or 10°) to get smooth, flowing spirals.

Large Angle = Angular Patterns

Turn by 90° or 120° to get geometric, stepped spirals.

5

Add Color & Style

Use pen_color("red") to change colors. Lift the pen with pen_up() to move without drawing, then pen_down() to start again!

pen_color("color")
Change pen color (red, blue, green, etc.)
pen_width(size)
Change line thickness (1-10)
Colorful Code
Colorful Canvas
6

Your Creation Studio

Now it's your turn! Use everything you've learned to create your own masterpiece. Start from scratch or remix one of the inspiring patterns below.

Your Masterpiece
Your Art
Real Robots!
The Robotics Simulator uses these exact same commands. Your drawing code can control a physics-simulated robot with a real pen!

Code Artist!

You've discovered how simple commands create complex art. Loops turn repetition into beauty, and angles unlock infinite patterns!

0
Commands Run
0
Shapes Drawn
0
Time Creating

Forward & Turn

Just two commands can draw any polygon!

Loops = Power

Repeat commands to create complex patterns from simple rules.

Angles = Shapes

360/n gives you the turn angle for any n-sided shape.

Stars from Math

Turn by 144° (or 360×2/5) and you get a perfect star!

Spirals from Growth

Increase the distance each step and spirals appear.

Pen Control

Lift the pen to move without drawing - create gaps and jumps.

Ready to Create?

Put your new knowledge into practice!

More Discoveries

Suggest a Correction