انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Python: home
0. Lab tour1
1. The start5
2. Variables and input5
3. Conditions5
4. Loops5
5. Lists4
6. Functions4
7. Drawing with the turtle3
8. The project: the guess-the-number game3
9. Strings in depth1
10. Dictionaries (dict)3
11. Randomness and errors3
12. Classes and objects (class)2
13. Pro drawing and charts3
14. The final project: the quiz game2

A coloured star

Section 7: Drawing with the turtleLesson 7.2 · ⏱ 8 min
🐍 A star of 36 lines
import turtle
t = turtle.Turtle()
t.speed(0)
colors = ["red", "orange", "gold", "green", "blue", "purple"]
for i in range(36):
    t.color(colors[i % 6])
    t.forward(180)
    t.left(170)
The turtle drawing in Robo Python🐍 Open the code in Robo Python ↗

📌 Another example: a five-pointed star

We turn 144 degrees five times.

🐍 A five-pointed star
import turtle
t = turtle.Turtle()
t.color("orange")
t.pensize(3)
for i in range(5):
    t.forward(180)
    t.right(144)
🐍 Open the code in Robo Python ↗
In Robo Python
In Robo Python
✍️ Practise
Try the lesson's examples here: copy the code, change it, and click ▶ Run.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

A small red star (100).

👀 Show the solution
🐍 Solution
import turtle
t = turtle.Turtle()
t.color("red")
for i in range(5):
    t.forward(100)
    t.right(144)
🐍 Open the code in Robo Python ↗
In Robo Python
In Robo Python

Result: a red star.

Medium

A star whose colours change with every side.

👀 Show the solution
🐍 Solution
import turtle
t = turtle.Turtle()
colors = ["red", "orange", "gold", "green", "blue"]
t.pensize(4)
for i in range(5):
    t.color(colors[i])
    t.forward(160)
    t.right(144)
🐍 Open the code in Robo Python ↗
In Robo Python
In Robo Python

Result: every side in a colour.

Hard

Three stars in different sizes (a star(size) function).

👀 Show the solution
🐍 Solution
import turtle
t = turtle.Turtle()
def star(size):
    for i in range(5):
        t.forward(size)
        t.right(144)

t.speed(0)
for size, x in [(60, -150), (100, -40), (140, 90)]:
    t.penup()
    t.goto(x, 0)
    t.pendown()
    star(size)
🐍 Open the code in Robo Python ↗
In Robo Python
In Robo Python

Result: three stars getting bigger.

Finished the lesson? Mark it so your progress counts.