/ Projects / Halloween Turtle

πŸ•ΈοΈ The Spooky Spiderweb Challenge

Follow the tasks, then check your understanding at the bottom!

Part 1: Understanding Python Turtle 🐒

Method 1: The "Global" Turtle

This method is quick for simple drawings. You import the whole module and call functions like `turtle.forward()`.

import turtle

turtle.forward(100)
turtle.left(90)
turtle.color("red")
turtle.forward(50)

turtle.done()

You are using a single, built-in turtle. This is fine, but can be confusing if you want multiple turtles on the screen.

Method 2: The Turtle "Object" (Instance)

This is the method we use. You create a *new* turtle object (we call ours `t`) from the `turtle.Turtle()` blueprint.

import turtle

# Create a new Turtle object
t = turtle.Turtle() 

t.forward(100)
t.left(90)
t.color("blue")
t.forward(50)

turtle.done()

This is much more powerful. You could create `t2 = turtle.Turtle()` and have a *second* independent turtle!

βš™οΈ Essential Turtle Commands

To complete this challenge, you will be using your Turtle object named `t`. Review these key commands:

Command Purpose
t.speed(0) Sets the turtle to the fastest speed.
t.home() Moves the turtle instantly to the origin (0, 0).
t.setheading(angle) Sets the direction (0=East, 90=North).
t.forward(dist) Moves the turtle forward.
t.backward(dist) Moves the turtle backward.
t.right(angle) Turns the turtle clockwise.
t.penup() Lifts the pen (no drawing).
t.pendown() Lowers the pen (drawing active).

Part A: The Radial Spokes πŸ•ΈοΈ

Task A.1: Define the `draw_spoke` function

Write a function that draws one spoke (a line of length 150), starting and ending at the origin (0, 0).

Task A.2: Use a simple loop to draw the web framework

Use a `for` loop to repeat the `draw_spoke` function 8 times, turning 45Β° each time, to create the radial lines of the web.

Skeleton Code:

import turtle
screen = turtle.Screen()
screen.setup(width=600, height=600)
screen.bgcolor("black") 
t = turtle.Turtle()
t.color("white")
t.pensize(2)
t.speed(0)

# --- FUNCTION DEFINITION AREA ---
def draw_spoke(length):
    """Draws a single line spoke of the web and returns to the center."""
    t.pendown()
    t.forward(length)
    t.backward(length)
    t.penup()

# --- MAIN PROGRAM AREA (Start of the Web) ---

# TODO: Set the number of spokes (N) and calculate the angle (360/N)
N = 8
angle = 360 / N

# TODO: Write a for loop that calls draw_spoke N times
# ... your loop here ...

turtle.done()

Example Solution & Visual:

If you complete Part A correctly, your code for the main program area should look like this, and your output will show 8 spokes.

# --- MAIN PROGRAM AREA (Start of the Web) ---

N = 8
angle = 360 / N

# Loop 8 times
for _ in range(N):
    draw_spoke(150) # Call the function
    t.left(angle)   # Turn ready for the next spoke

t.hideturtle()
turtle.done()
8 spokes of a spiderweb radiating from the center on a black background

Visual Output for Part A

Part B: The Concentric Rings 🎯

Task B.1: Draw the Rings

After your code for Part A, add a new loop to draw 5 concentric rings (circles). The size of the circle depends on the ring number. The web has a max radius of 150. To draw 5 rings, they should be 30 units apart (150 / 5 = 30).

Ring Drawing Logic (Add this *after* your Part A loop):

# --- RING DRAWING AREA (Part B) ---
num_rings = 5
max_radius = 150
step_size = max_radius / num_rings

t.home()
t.setheading(0) # Reset heading

for i in range(num_rings):
    # 1. Calculate the radius for the current ring (i starts at 0)
    current_radius = (i + 1) * step_size

    # 2. Go to the starting point of the circle
    t.penup()
    # TODO: Go home, set heading to 0
    # TODO: Move forward by current_radius
    # TODO: Set heading to 270 (South)
    
    # 3. Draw the circle!
    t.pendown()
    t.circle(current_radius)

# Optional: Draw a spooky spider in the center!
t.dot(20, "orange")

Example Solution & Visual:

Here is the completed code for the rings. This creates the final spiderweb.

# --- RING DRAWING AREA (Part B) ---
num_rings = 5
max_radius = 150
step_size = max_radius / num_rings

t.home()
t.setheading(0) # Reset heading

for i in range(num_rings):
    current_radius = (i + 1) * step_size
    
    t.penup()
    t.goto(0, 0)      # Go home
    t.setheading(0)   # Face East
    t.forward(current_radius) # Move to the circle's edge
    t.setheading(270) # Face South to start the circle
    
    t.pendown()
    t.circle(current_radius) # Draw the ring

t.dot(20, "orange") # Add the spider
t.hideturtle()
turtle.done()
A complete spiderweb with 8 spokes and 5 concentric rings on a black background, with an orange dot in the center

Visual Output for Part B

Part 5: Check Your Understanding 🧠

1. The Angle

If you wanted to draw **6** spokes, what angle would you need to turn by? (360 / 6)

2. Fill in the Blank

To stop the turtle from drawing when it moves, you would use the command `t.____()`.

3. Command Recall

Which single command moves the turtle to (0, 0) and faces it East (heading 0)?

4. True or False?

Click to select the correct answer for the statement:

"t.speed(0) makes the turtle move very slowly."

...

5. Code Logic

If `num_rings = 4` and `max_radius = 200`, what is the radius of the *first* ring? (step_size = 200/4 = 50)

πŸ‘» Extra Activities

If you're finished, try these extensions (not marked):

  • Import `random` and draw a spider at a random `(x, y)` location.
  • Use a list of colors `["red", "orange"]` to make the web flicker.
  • Define a new function `draw_hat()` to draw a witch hat.