generated from mwc/project_drawing
spiderweb updated
Initially, I cannot find the left original point to start drawing the spiderweb, i tried to draw a square and define the web in it. Then i found it doesn't work well, so i change my mind to define a start point then draw web line. spiderweb is ready now, i need to draw a spider then.
This commit is contained in:
parent
e25b34d11a
commit
8172fd547a
46
drawing.py
46
drawing.py
|
@ -1,7 +1,49 @@
|
||||||
# drawing.py
|
# drawing.py
|
||||||
# ----------
|
# ----------
|
||||||
# By ____(you)___________
|
# By ____Grace__________
|
||||||
#
|
#
|
||||||
# (Briefly describe what this program does.)
|
# (Halloween Theme with Spider exploding)
|
||||||
|
|
||||||
from turtle import *
|
from turtle import *
|
||||||
|
from superturtle import *
|
||||||
|
|
||||||
|
def draw_web(radius, lines):
|
||||||
|
web_turtle = Turtle()
|
||||||
|
web_turtle.speed(0) # Set the speed to the fastest
|
||||||
|
for _ in range(lines):
|
||||||
|
web_turtle.penup()
|
||||||
|
web_turtle.goto(0, 0)
|
||||||
|
web_turtle.pendown()
|
||||||
|
web_turtle.forward(radius)
|
||||||
|
web_turtle.backward(radius)
|
||||||
|
web_turtle.right(360 / lines)
|
||||||
|
|
||||||
|
def draw_spider(size):
|
||||||
|
spider_turtle = SuperTurtle()
|
||||||
|
spider_turtle.penup()
|
||||||
|
spider_turtle.goto(0, -size * 0.5) # Position the spider at the center bottom of the web
|
||||||
|
spider_turtle.pendown()
|
||||||
|
# Draw the body
|
||||||
|
spider_turtle.begin_fill()
|
||||||
|
spider_turtle.circle(size)
|
||||||
|
spider_turtle.end_fill()
|
||||||
|
# Draw legs
|
||||||
|
angles = [45, 135, 225, 315]
|
||||||
|
for angle in angles:
|
||||||
|
spider_turtle.penup()
|
||||||
|
spider_turtle.goto(0, -size * 0.5)
|
||||||
|
spider_turtle.setheading(angle)
|
||||||
|
spider_turtle.pendown()
|
||||||
|
spider_turtle.forward(size)
|
||||||
|
spider_turtle.backward(size)
|
||||||
|
|
||||||
|
# Setup the screen
|
||||||
|
screen = Screen()
|
||||||
|
screen.bgcolor("white")
|
||||||
|
|
||||||
|
# Draw the web and spider
|
||||||
|
draw_web(100, 12) # radius of 100 and 12 lines
|
||||||
|
draw_spider(20) # spider size of 20
|
||||||
|
|
||||||
|
# Finish up
|
||||||
|
screen.mainloop() # This is better for some environments than turtle.done()
|
|
@ -0,0 +1,54 @@
|
||||||
|
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(400)
|
||||||
|
hideturtle()
|
||||||
|
done()
|
||||||
|
|
Loading…
Reference in New Issue