project_drawing/spidermov.py

80 lines
2.8 KiB
Python

from turtle import *
from superturtle import *
from superturtle.movement import *
import time
import random
from spider import draw_circle, draw_legs, draw_connection_line, draw_spider
from spiderweb import draw_web
# Function to simulate the explosion of the spider like a firework
def explode_spider(x, y, radius):
"""Simulates the explosion of the spider like a firework."""
for _ in range(20):
penup()
goto(x, y)
setheading(random.randint(0, 360)) # Random direction
forward(random.randint(radius, radius * 3)) # Random distance
pendown()
dot(10, random.choice(["red", "orange", "yellow", "white"])) # Draw explosion dot
penup()
time.sleep(1)
update() # Update the screen to show the explosion
clear() # Clear the screen after explosion
update()
# Draw rainbow after explosion
draw_rainbow_splash()
# Function to draw a rainbow splash
def draw_rainbow_splash():
"""Draws a rainbow like a splash of colorful dashed and solid lines of different lengths."""
colors = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
penup()
goto(0, 0) # Start from the center of the screen
for color in colors:
for _ in range(2): # Repeat each color two times
setheading(random.randint(0, 360)) # Random direction for each line
pencolor(color)
pensize(2)
length = random.randint(100, 200) # Random length for each line
pendown()
if random.choice([True, False]): # Randomly choose between dashed and solid lines
for _ in range(length // 15): # Create dashed lines
forward(10)
penup()
forward(5)
pendown()
else:
forward(length) # Create solid line
penup()
goto(0, 0) # Return to the center
update() # Update the screen to show the rainbow splash
# Function to draw the entire scene
def draw_scene(side_length):
"""Draws the entire scene with the web, spider, and animation."""
draw_web(side_length) # Draw the web
update() # Update the screen to show the web
time.sleep(1)
penup()
goto(0, 0)
setheading(0)
pendown()
draw_spider(60) # Draw the spider with the specified radius
update() # Update the screen to show the spider
draw_connection_line(120) # Draw the connection line from the top of the screen to the spider
update() # Update the screen to show the connection line
hideturtle()
time.sleep(1)
explode_spider(30, 60, 60) # Explode the spider
done()
# Setup
setup(width=800, height=800)
tracer(0) # Disable automatic screen updates for smooth animation
# Draw the entire scene
draw_scene(300)