generated from mwc/project_drawing
updated spidermov
under the help of ChatGPT (Canvas), I turned the spider with its web to the color splash like a firework The things I could not figure out is how to make it come down from the top and get bigger. I used ChatGPT to generate this code but it didn't work well. I also added arguments in the function to make it connected with others.
This commit is contained in:
parent
9c2c2ed520
commit
6a53ed6364
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
33
drawing.py
33
drawing.py
|
@ -10,19 +10,26 @@ from superturtle import *
|
||||||
from superturtle.movement import *
|
from superturtle.movement import *
|
||||||
from spider import *
|
from spider import *
|
||||||
from spiderweb import *
|
from spiderweb import *
|
||||||
|
from spidermov import *
|
||||||
|
|
||||||
|
# previous codes drawing a spider
|
||||||
|
# def drawing(side_length):
|
||||||
|
# draw_web(side_length)
|
||||||
|
# penup()
|
||||||
|
# goto(0, 0)
|
||||||
|
# setheading(0)
|
||||||
|
# pendown()
|
||||||
|
# draw_spider(300)
|
||||||
|
# draw_connection_line(300)
|
||||||
|
# hideturtle()
|
||||||
|
# done()
|
||||||
|
|
||||||
|
# drawing(300)
|
||||||
|
|
||||||
|
|
||||||
def drawing(side_length):
|
# Setup
|
||||||
draw_web(side_length)
|
setup(width=800, height=800)
|
||||||
penup()
|
tracer(0) # Disable automatic screen updates for smooth animation
|
||||||
goto(0, 0)
|
|
||||||
setheading(0)
|
|
||||||
pendown()
|
|
||||||
draw_spider()
|
|
||||||
draw_connection_line()
|
|
||||||
hideturtle()
|
|
||||||
done()
|
|
||||||
|
|
||||||
drawing(300)
|
# Draw the entire scene
|
||||||
|
draw_scene(300)
|
||||||
|
|
10
spider.py
10
spider.py
|
@ -19,16 +19,16 @@ def draw_circle(radius, x, y, color=None):
|
||||||
if color:
|
if color:
|
||||||
end_fill() # End the filling
|
end_fill() # End the filling
|
||||||
|
|
||||||
def draw_spider():
|
def draw_spider(radius):
|
||||||
|
|
||||||
# Step 1: Draw the big circle (spider body) on top of the small circle
|
# Step 1: Draw the big circle (spider body) on top of the small circle
|
||||||
draw_circle(60, 30, 60, color="grey")
|
draw_circle(radius, 30, 60, color="grey")
|
||||||
|
|
||||||
# Step 2: Draw the small circle (spider head)
|
# Step 2: Draw the small circle (spider head)
|
||||||
draw_circle(20, 30, 0, color="black")
|
draw_circle(20, 30, 0, color="black")
|
||||||
|
|
||||||
# Step 3: Draw legs on big circle
|
# Step 3: Draw legs on big circle
|
||||||
draw_legs(60, 30, 60)
|
draw_legs(radius, 30, 60)
|
||||||
|
|
||||||
def draw_legs(radius, x, y):
|
def draw_legs(radius, x, y):
|
||||||
"Draws legs starting from the perimeter of the big circle (spider's body)"
|
"Draws legs starting from the perimeter of the big circle (spider's body)"
|
||||||
|
@ -48,12 +48,12 @@ def draw_legs(radius, x, y):
|
||||||
penup()
|
penup()
|
||||||
backward(leg_length) # Move back to the perimeter of the big circle
|
backward(leg_length) # Move back to the perimeter of the big circle
|
||||||
|
|
||||||
def draw_connection_line():
|
def draw_connection_line(y):
|
||||||
"Draw a line from the top of the big circle (head) to the center of the small circle (body)"
|
"Draw a line from the top of the big circle (head) to the center of the small circle (body)"
|
||||||
penup()
|
penup()
|
||||||
goto(30, 400)
|
goto(30, 400)
|
||||||
pendown()
|
pendown()
|
||||||
goto(30, 120) # Draw a line to the center of the small circle (spider's body)
|
goto(30, y) # Draw a line to the center of the small circle (spider's body)
|
||||||
penup()
|
penup()
|
||||||
goto(0, 0)
|
goto(0, 0)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
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)
|
Loading…
Reference in New Issue