generated from mwc/project_drawing
Compare commits
7 Commits
b517a3a9e4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a53ed6364 | ||
|
|
9c2c2ed520 | ||
|
|
d90372e0b6 | ||
|
|
a420d01510 | ||
|
|
3b61659fde | ||
|
|
8172fd547a | ||
|
|
e25b34d11a |
BIN
Fireworks.gif
Normal file
BIN
Fireworks.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 MiB |
27
README.md
27
README.md
@@ -1,3 +1,30 @@
|
|||||||
|
# (Drawing project)
|
||||||
|
|
||||||
|
(
|
||||||
|
Halloween Theme
|
||||||
|
|
||||||
|
A spider descends from its web, then expands rapidly to fill the entire screen before bursting like a firework
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
(1. Draw the spider web with the spider
|
||||||
|
2. Make the spider descend.
|
||||||
|
3. Rise up the spider and make it bigger
|
||||||
|
4. At some point, add change it to firework effect
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
## Planning
|
||||||
|
|
||||||
|
(1. Draw the spider web with the spider
|
||||||
|
2. Make the spider descend.
|
||||||
|
3. Rise up the spider and make it bigger
|
||||||
|
4. At some point, add change it to firework effect )
|
||||||
# Grace Proposal of Drawing Program for LAI 676
|
# Grace Proposal of Drawing Program for LAI 676
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|||||||
BIN
__pycache__/spider.cpython-310.pyc
Normal file
BIN
__pycache__/spider.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/spider.cpython-312.pyc
Normal file
BIN
__pycache__/spider.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/spiderall.cpython-310.pyc
Normal file
BIN
__pycache__/spiderall.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/spidermov.cpython-310.pyc
Normal file
BIN
__pycache__/spidermov.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/spiderweb.cpython-310.pyc
Normal file
BIN
__pycache__/spiderweb.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/spiderweb.cpython-312.pyc
Normal file
BIN
__pycache__/spiderweb.cpython-312.pyc
Normal file
Binary file not shown.
34
drawing.py
34
drawing.py
@@ -1,7 +1,35 @@
|
|||||||
# drawing.py
|
# drawing.py
|
||||||
# ----------
|
# ----------Not sure if I sumbmit it right or not
|
||||||
# By ____(you)___________
|
# By ____Grace__________
|
||||||
#
|
#
|
||||||
# (Briefly describe what this program does.)
|
# (Halloween Theme with Spider exploding)
|
||||||
|
|
||||||
|
|
||||||
from turtle import *
|
from turtle import *
|
||||||
|
from superturtle import *
|
||||||
|
from superturtle.movement import *
|
||||||
|
from spider 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)
|
||||||
|
|
||||||
|
|
||||||
|
# Setup
|
||||||
|
setup(width=800, height=800)
|
||||||
|
tracer(0) # Disable automatic screen updates for smooth animation
|
||||||
|
|
||||||
|
# Draw the entire scene
|
||||||
|
draw_scene(300)
|
||||||
BIN
spider.gif
Normal file
BIN
spider.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 569 KiB |
65
spider.py
Normal file
65
spider.py
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
from turtle import *
|
||||||
|
from superturtle import *
|
||||||
|
from superturtle.movement import *
|
||||||
|
|
||||||
|
from turtle import *
|
||||||
|
|
||||||
|
def draw_circle(radius, x, y, color=None):
|
||||||
|
"Draw a circle with the given radius at the (x, y) position. Optionally fill with color."
|
||||||
|
penup()
|
||||||
|
goto(x, y - radius) # Move to the correct start point
|
||||||
|
pendown()
|
||||||
|
|
||||||
|
if color:
|
||||||
|
fillcolor(color) # Set the fill color
|
||||||
|
begin_fill() # Start filling the circle with color
|
||||||
|
|
||||||
|
circle(radius) # Draw the circle
|
||||||
|
|
||||||
|
if color:
|
||||||
|
end_fill() # End the filling
|
||||||
|
|
||||||
|
def draw_spider(radius):
|
||||||
|
|
||||||
|
# Step 1: Draw the big circle (spider body) on top of the small circle
|
||||||
|
draw_circle(radius, 30, 60, color="grey")
|
||||||
|
|
||||||
|
# Step 2: Draw the small circle (spider head)
|
||||||
|
draw_circle(20, 30, 0, color="black")
|
||||||
|
|
||||||
|
# Step 3: Draw legs on big circle
|
||||||
|
draw_legs(radius, 30, 60)
|
||||||
|
|
||||||
|
def draw_legs(radius, x, y):
|
||||||
|
"Draws legs starting from the perimeter of the big circle (spider's body)"
|
||||||
|
leg_length = 50 # Length of the legs
|
||||||
|
pensize(4)
|
||||||
|
|
||||||
|
# Draw legs at equal angles from the top of the big circle
|
||||||
|
angles = [-60, -30, 0, 30, 150, 180, 210, 240] # Angles for legs (top-left, top-right, and bottom)
|
||||||
|
|
||||||
|
for angle in angles:
|
||||||
|
penup()
|
||||||
|
goto(x, y) # Go to the center of the big circle
|
||||||
|
setheading(angle) # Set the heading to the desired angle
|
||||||
|
forward(radius) # Move forward to the perimeter of the big circle
|
||||||
|
pendown()
|
||||||
|
forward(leg_length) # Draw the leg
|
||||||
|
penup()
|
||||||
|
backward(leg_length) # Move back to the perimeter of the big circle
|
||||||
|
|
||||||
|
def draw_connection_line(y):
|
||||||
|
"Draw a line from the top of the big circle (head) to the center of the small circle (body)"
|
||||||
|
penup()
|
||||||
|
goto(30, 400)
|
||||||
|
pendown()
|
||||||
|
goto(30, y) # Draw a line to the center of the small circle (spider's body)
|
||||||
|
penup()
|
||||||
|
goto(0, 0)
|
||||||
|
|
||||||
|
# Draw the spider
|
||||||
|
# draw_spider()
|
||||||
|
# draw_connection_line()
|
||||||
|
# hideturtle()
|
||||||
|
# done()
|
||||||
|
|
||||||
121
spiderall.py
Normal file
121
spiderall.py
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
from turtle import *
|
||||||
|
from superturtle import *
|
||||||
|
from superturtle.movement import *
|
||||||
|
|
||||||
|
segment_positions = []
|
||||||
|
def draw_web_line(side_length):
|
||||||
|
global segment_positions
|
||||||
|
fly(-350, 350)
|
||||||
|
for side in range(5):
|
||||||
|
draw_segmented_line(side_length)
|
||||||
|
right(22.5)
|
||||||
|
fly(-350, 350)
|
||||||
|
#right(22.5)
|
||||||
|
|
||||||
|
def draw_segmented_line(side_length):
|
||||||
|
"Draws a line with 4 equal segments and marks the points"
|
||||||
|
segment_length = side_length / 4
|
||||||
|
line_segments = []
|
||||||
|
for segment in range(4):
|
||||||
|
forward(segment_length)
|
||||||
|
mark_point() # Mark the points at each segment
|
||||||
|
line_segments.append(pos())
|
||||||
|
segment_positions.append(line_segments)
|
||||||
|
|
||||||
|
|
||||||
|
def mark_point():
|
||||||
|
"Marks a point at the current location"
|
||||||
|
dot(5, "black") # Draw a dot to mark the segment points
|
||||||
|
|
||||||
|
def connect_segments():
|
||||||
|
"Connects the corresponding segment points of adjacent lines"
|
||||||
|
global segment_positions
|
||||||
|
for i in range(4): # Iterate over the 4 segments
|
||||||
|
for j in range(5): # Iterate over the 5 lines
|
||||||
|
next_j = (j + 1) % 5 # To wrap around to the first line after the fifth
|
||||||
|
# Skip connections if either segment is near the x-axis or y-axis
|
||||||
|
if segment_positions[j][i][0] == -350 or segment_positions[next_j][i][1] == 350:
|
||||||
|
continue
|
||||||
|
|
||||||
|
penup()
|
||||||
|
goto(segment_positions[j][i]) # Go to the current segment
|
||||||
|
pendown()
|
||||||
|
goto(segment_positions[next_j][i]) # Draw a line to the next segment
|
||||||
|
|
||||||
|
# Main function to draw the web
|
||||||
|
def draw_web(side_length):
|
||||||
|
draw_web_line(side_length)
|
||||||
|
connect_segments()
|
||||||
|
|
||||||
|
|
||||||
|
# Draw the web lines
|
||||||
|
# draw_web(300)
|
||||||
|
# hideturtle()
|
||||||
|
# done()
|
||||||
|
|
||||||
|
def draw_circle(radius, x, y, color=None):
|
||||||
|
"Draw a circle with the given radius at the (x, y) position. Optionally fill with color."
|
||||||
|
penup()
|
||||||
|
goto(x, y - radius) # Move to the correct start point
|
||||||
|
pendown()
|
||||||
|
|
||||||
|
if color:
|
||||||
|
fillcolor(color) # Set the fill color
|
||||||
|
begin_fill() # Start filling the circle with color
|
||||||
|
|
||||||
|
circle(radius) # Draw the circle
|
||||||
|
|
||||||
|
if color:
|
||||||
|
end_fill() # End the filling
|
||||||
|
|
||||||
|
def draw_spider():
|
||||||
|
|
||||||
|
|
||||||
|
# Step 1: Draw the big circle (spider body) on top of the small circle
|
||||||
|
draw_circle(60, 30, 60, color="grey")
|
||||||
|
|
||||||
|
# Step 2: Draw the small circle (spider head)
|
||||||
|
draw_circle(30, 30, 0, color="black")
|
||||||
|
|
||||||
|
# Step 3: Draw legs on big circle
|
||||||
|
draw_legs(60, 30, 60)
|
||||||
|
|
||||||
|
def draw_legs(radius, x, y):
|
||||||
|
"Draws legs starting from the perimeter of the big circle (spider's body)"
|
||||||
|
leg_length = 50 # Length of the legs
|
||||||
|
pensize(4)
|
||||||
|
|
||||||
|
# Draw legs at equal angles from the top of the big circle
|
||||||
|
angles = [-60, -30, 0, 30, 150, 180, 210, 240] # Angles for legs (top-left, top-right, and bottom)
|
||||||
|
|
||||||
|
for angle in angles:
|
||||||
|
penup()
|
||||||
|
goto(x, y) # Go to the center of the big circle
|
||||||
|
setheading(angle) # Set the heading to the desired angle
|
||||||
|
forward(radius) # Move forward to the perimeter of the big circle
|
||||||
|
pendown()
|
||||||
|
forward(leg_length) # Draw the leg
|
||||||
|
penup()
|
||||||
|
backward(leg_length) # Move back to the perimeter of the big circle
|
||||||
|
|
||||||
|
def draw_connection_line():
|
||||||
|
"Draw a line from the top of the big circle (head) to the center of the small circle (body)"
|
||||||
|
penup()
|
||||||
|
goto(30, 400)
|
||||||
|
pendown()
|
||||||
|
goto(30, 120) # Draw a line to the center of the small circle (spider's body)
|
||||||
|
penup()
|
||||||
|
goto(0, 0)
|
||||||
|
|
||||||
|
def drawing(side_length):
|
||||||
|
draw_web(side_length)
|
||||||
|
penup()
|
||||||
|
goto(0, 0)
|
||||||
|
setheading(0)
|
||||||
|
pendown()
|
||||||
|
draw_spider()
|
||||||
|
draw_connection_line()
|
||||||
|
hideturtle()
|
||||||
|
done()
|
||||||
|
|
||||||
|
drawing(300)
|
||||||
80
spidermov.py
Normal file
80
spidermov.py
Normal file
@@ -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)
|
||||||
55
spiderweb.py
Normal file
55
spiderweb.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
from turtle import *
|
||||||
|
from superturtle import *
|
||||||
|
from superturtle.movement import *
|
||||||
|
|
||||||
|
segment_positions = []
|
||||||
|
def draw_web_line(side_length):
|
||||||
|
global segment_positions
|
||||||
|
fly(-350, 350)
|
||||||
|
for side in range(5):
|
||||||
|
draw_segmented_line(side_length)
|
||||||
|
right(22.5)
|
||||||
|
fly(-350, 350)
|
||||||
|
#right(22.5)
|
||||||
|
|
||||||
|
def draw_segmented_line(side_length):
|
||||||
|
"Draws a line with 4 equal segments and marks the points"
|
||||||
|
segment_length = side_length / 4
|
||||||
|
line_segments = []
|
||||||
|
for segment in range(4):
|
||||||
|
forward(segment_length)
|
||||||
|
mark_point() # Mark the points at each segment
|
||||||
|
line_segments.append(pos())
|
||||||
|
segment_positions.append(line_segments)
|
||||||
|
|
||||||
|
|
||||||
|
def mark_point():
|
||||||
|
"Marks a point at the current location"
|
||||||
|
dot(5, "black") # Draw a dot to mark the segment points
|
||||||
|
|
||||||
|
def connect_segments():
|
||||||
|
"Connects the corresponding segment points of adjacent lines"
|
||||||
|
global segment_positions
|
||||||
|
for i in range(4): # Iterate over the 4 segments
|
||||||
|
for j in range(5): # Iterate over the 5 lines
|
||||||
|
next_j = (j + 1) % 5 # To wrap around to the first line after the fifth
|
||||||
|
# Skip connections if either segment is near the x-axis or y-axis
|
||||||
|
if segment_positions[j][i][0] == -350 or segment_positions[next_j][i][1] == 350:
|
||||||
|
continue
|
||||||
|
|
||||||
|
penup()
|
||||||
|
goto(segment_positions[j][i]) # Go to the current segment
|
||||||
|
pendown()
|
||||||
|
goto(segment_positions[next_j][i]) # Draw a line to the next segment
|
||||||
|
|
||||||
|
# Main function to draw the web
|
||||||
|
def draw_web(side_length):
|
||||||
|
draw_web_line(side_length)
|
||||||
|
connect_segments()
|
||||||
|
|
||||||
|
|
||||||
|
# Draw the web lines
|
||||||
|
# draw_web(300)
|
||||||
|
# hideturtle()
|
||||||
|
# done()
|
||||||
|
|
||||||
Reference in New Issue
Block a user