project_drawing/drawing.py

176 lines
4.3 KiB
Python

# drawing.py
# ----------
# By Hope Wright
#
# a turtle and bubbles will be drawn and animate swimming across the screen
# phase 2 would be to have it start smaller and grow is it swims across the screen to look like it's getting closer
# phase 3 would be to animate the bubbles.
from turtle import *
from superturtle.movement import fly
from superturtle.animation import animate
from superturtle.easing import easeInQuad
import math
import random
def draw_turtle(size):
pencolor("green")
#draw an oval for the shell
height = size*2
width = size*1.5
steps = 100
for i in range(steps + 1):
angle = 2 * math.pi * i / steps
x = (width) * math.cos(angle)
y = (height) * math.sin(angle)
goto(x,y)
#move to top of for head
penup()
left(90)
forward(size*4)
left(90)
forward(size*1.5)
pendown()
#draw a circle for the head
circle(size)
#draw some lines on the shell
penup()
left(90)
forward(size*2)
pendown()
forward(size*4)
right(180)
forward(size*2)
left(90)
forward(size*1.5)
penup()
left(180)
forward(size*1.5)
pendown()
draw_flipper(size, 1)
draw_flipper(size, 4)
def draw_flipper(size, quad):
width = 2.5 * size
height = 1.5 * size
steps = 100 # Number of points to smooth the curve
penup()
if quad == 1:
angle_range = range(0, steps + 1) # Top half
for i in angle_range:
angle = math.pi * i / steps # Only go from 0 to π radians
x = ((width / 2) * math.cos(angle))+(size*2)
y = ((height / 2) * math.sin(angle))+size
if i == angle_range[0]:
goto(x , y )
pendown()
else:
goto(x, y)
forward (size*2.5)
elif quad == 4:
angle_range = range(0, steps + 1) # Top half
for i in angle_range:
angle = math.pi * i / steps # Only go from 0 to π radians
x = ((width / 2) * math.cos(angle))-(size*2)
y = ((height / 2) * math.sin(angle))+size
if i == angle_range[0]:
goto(x , y )
pendown()
else:
goto(x, y)
forward (size*2.5)
elif quad == 3:
angle_range = range(0, steps + 1) # Top half
for i in angle_range:
angle = math.pi * i / steps # Only go from 0 to π radians
x = ((width / 2) * math.cos(angle))-(size*2)
y = ((height / 2) * math.sin(angle))+size
if i == angle_range[0]:
goto(x , y )
pendown()
else:
goto(x, y)
forward (size*2.5)
else:
angle_range = range(0, steps + 1) # Top half
for i in angle_range:
angle = math.pi * i / steps # Only go from 0 to π radians
x = ((width / 2) * math.cos(angle))-(size*2)
y = ((height / 2) * math.sin(angle))+size
if i == angle_range[0]:
goto(x , y )
pendown()
else:
goto(x, y)
forward (size*2.5)
def draw_bubble(b_size):
pencolor("blue")
circle(b_size)
def place_bubbles(number):
#draws bubbles of random sizes and locations in each of the 4 quadrants
for i in range(number):
x = random.random()*400
y = random.random()*200
fly(x,y)
b_size = random.random()*15
draw_bubble(b_size)
for i in range(number):
x = random.random()*400
y = random.random()*200
fly(-x,y)
b_size = random.random()*15
draw_bubble(b_size)
for i in range(number):
x = random.random()*400
y = random.random()*200
fly(x,-y)
b_size = random.random()*15
draw_bubble(b_size)
for i in range(number):
x = random.random()*400
y = random.random()*200
fly(-x,-y)
b_size = random.random()*15
draw_bubble(b_size)
fly(0,0)
"""
#pass the number of bubbles you want in each quadrant (so it will be 4 X what you pass)
for frame in animate(50, loop=False):
x = frame.interpolate(-10, 10)
y = frame.interpolate(20, -10, easing=easeInQuad)
fly(x, y)
place_bubbles(1)
"""
place_bubbles(5)
draw_turtle(20)
done()