How to draw spiderweb in Python Turtle?

Spiderweb consists of radical and spiral threads. First of all, we will build radical thread and then spiral threads.

#Python program to draw spider web in turtle programming
import turtle

t = turtle.Turtle()
t.speed(0)

#Code for building radical thread
for i in range(6):
  t.forward(150)
  t.backward(150)
  t.right(60)

#Code for building spiral thread
side = 150
for i in range(15):
  t.penup()
  t.goto(0,0)
  t.pendown()
  t.setheading(0)
  t.forward(side)
  t.right(120)
  for j in range(6):
    t.forward(side)
    t.right(60)
  side = side - 10

Output of the above program

Spider web in Python Turtle

Explanation of the above code-

side = 150
for i in range(15):
  t.penup()
  t.goto(0,0)
  t.pendown()
  t.setheading(0)
  t.forward(side)
  t.right(120)
  for j in range(6):
    t.forward(side)
    t.right(60)
  side = side - 10

There are two for loops- Outer for loop will control the building of spiral threads and inner for loop will build a single spiral thread. In each iteration, we will reduce the length of side by 10.

Recommended Posts