generated from mwc/project_drawing
Created a skeumorphic TV project. Utilized conditional statements to enable a psuedo button press.
Utilized severl functions for creation of TV and background. This project was extremely interesting. I was thinking of ideas in my mind and I find skeumorphic design interesting. I thought of utilzing a button press to change the channels on the TV. If I have time I may actually draw the channel screens, for now they are just colors. Since turtle has no "button" features, I utilized conditional statements that tracked where the mouse was being clicked. I first thought about using the distance formula of a circle but that seemed like too much. I would love to eventually use the superturle library to animate my tv channels, however I was having issues getting it working. I realize my code could probably be heavily refactored for efficiencies.
This commit is contained in:
parent
791b1d1417
commit
432d4bf74c
193
drawing.py
193
drawing.py
|
@ -1,7 +1,196 @@
|
|||
# drawing.py
|
||||
# ----------
|
||||
# By ____(you)___________
|
||||
# By: Louis Cooper
|
||||
#
|
||||
# (Briefly describe what this program does.)
|
||||
# Draws an animation in turtle.
|
||||
|
||||
from http.client import RemoteDisconnected
|
||||
from turtle import *
|
||||
import random
|
||||
|
||||
pensize(2)
|
||||
|
||||
def fly(x, y): #Utlizes x, y positions to move the turtle
|
||||
penup()
|
||||
goto(x, y)
|
||||
pendown()
|
||||
|
||||
def starting_position(): #sets initial position of the drawing. See fly()
|
||||
penup()
|
||||
fly(-600, -300)
|
||||
pendown()
|
||||
|
||||
starting_position()
|
||||
|
||||
#draws rectange with height / width parameter. There is an optional parameter for corner radius. If corner radius is true then the corners are rounded by 3rd argument value, subtracted from length to maintain consistency.
|
||||
def rectangle(length, height, corner_radius=0):
|
||||
for i in range(2):
|
||||
forward(length - 2 * corner_radius)
|
||||
if corner_radius:
|
||||
circle(corner_radius, 90)
|
||||
else:
|
||||
left(90)
|
||||
forward(height - 2 * corner_radius)
|
||||
if corner_radius:
|
||||
circle(corner_radius, 90)
|
||||
else:
|
||||
left(90)
|
||||
|
||||
def draw_background():
|
||||
speed(0)
|
||||
fillcolor("black")
|
||||
begin_fill()
|
||||
rectangle(500, 600, 0)
|
||||
end_fill()
|
||||
|
||||
draw_background()
|
||||
|
||||
#draws a TV
|
||||
def draw_tv():
|
||||
#outer border
|
||||
fly(-500, -200)
|
||||
fillcolor("#c7b199")
|
||||
begin_fill()
|
||||
rectangle(300, 210, 10)
|
||||
end_fill()
|
||||
|
||||
# Antenna - added
|
||||
color("#C0C0C0")
|
||||
pensize(5)
|
||||
penup()
|
||||
goto(-350, 10) # Positioning the antenna
|
||||
pendown()
|
||||
setheading(30) # Angle for the left part of the antenna
|
||||
forward(100)
|
||||
penup()
|
||||
goto(-350, 10) # Going back to the antenna's root
|
||||
pendown()
|
||||
setheading(150) # Angle for the right part of the antenna
|
||||
forward(100)
|
||||
pensize(2)
|
||||
setheading(0) # Resetting the direction
|
||||
# Antenna Base - added
|
||||
penup()
|
||||
goto(-360, 0) # Positioning the base
|
||||
pendown()
|
||||
fillcolor('#C0C0C0')
|
||||
begin_fill()
|
||||
circle(10)
|
||||
end_fill()
|
||||
color("black")
|
||||
# Antenna Base ends
|
||||
|
||||
#inner screen border
|
||||
fillcolor('#1a1a1a')
|
||||
fly(-490, -186)
|
||||
begin_fill()
|
||||
rectangle(200, 180, 5)
|
||||
end_fill()
|
||||
#inner screen
|
||||
fly(-480, -175)
|
||||
fillcolor("black")
|
||||
begin_fill()
|
||||
rectangle(180, 158, 5)
|
||||
end_fill()
|
||||
#side panel
|
||||
fly(-270, -185)
|
||||
fillcolor('#1a1a1a')
|
||||
begin_fill()
|
||||
rectangle(50, 180, 5)
|
||||
end_fill()
|
||||
#side Panel internal Panel
|
||||
fly(-265, -120)
|
||||
fillcolor("#514640")
|
||||
begin_fill()
|
||||
rectangle(40, 110, 5)
|
||||
end_fill()
|
||||
#dial1
|
||||
fly(-250, -100)
|
||||
fillcolor("#484848")
|
||||
begin_fill()
|
||||
circle(15)
|
||||
end_fill()
|
||||
fillcolor('#1a1a1a')
|
||||
begin_fill()
|
||||
left(15)
|
||||
rectangle(4, 29)
|
||||
right(15)
|
||||
end_fill()
|
||||
#dial2
|
||||
fly(-250, -60)
|
||||
fillcolor("#484848")
|
||||
begin_fill()
|
||||
circle(15)
|
||||
end_fill()
|
||||
fillcolor('#1a1a1a')
|
||||
begin_fill()
|
||||
left(5)
|
||||
rectangle(4, 29)
|
||||
right(5)
|
||||
end_fill()
|
||||
#circle adornments
|
||||
fly(-260, -115)
|
||||
fillcolor("#c7b199")
|
||||
begin_fill()
|
||||
circle(4)
|
||||
fly(-240, -115)
|
||||
fillcolor("#c7b199")
|
||||
circle(4)
|
||||
end_fill()
|
||||
#grill
|
||||
fillcolor("#c7b199")
|
||||
fly(-270, -130)
|
||||
for j in range(12):
|
||||
begin_fill()
|
||||
rectangle(40, 4)
|
||||
end_fill()
|
||||
fly(-270, -130 - (j*5))
|
||||
#Feet
|
||||
fillcolor("tan")
|
||||
fly(-495, -200)
|
||||
begin_fill()
|
||||
rectangle(14, -50)
|
||||
end_fill()
|
||||
fly(-240, -200)
|
||||
begin_fill()
|
||||
rectangle(14, -50)
|
||||
end_fill()
|
||||
|
||||
draw_tv()
|
||||
|
||||
def instructions_text():
|
||||
fly(-540, -290)
|
||||
color("white")
|
||||
write("Click the dials to change the channel", font=("Verdana", 15, "normal"))
|
||||
color("black")
|
||||
|
||||
instructions_text()
|
||||
|
||||
#Checks for clicks inside the roung dials.
|
||||
def detect_circle_click(x_pos, y_pos):
|
||||
if x_pos > -266.0 and x_pos < -235 and y_pos < -30.0 and y_pos > -95: #These are registering as one button, whhy, it doesnt matter for this use case but I should fix
|
||||
nextScreen()
|
||||
elif x_pos > -266.0 and x_pos < -235 and y_pos < -70.0 and y_pos > -99.0:
|
||||
nextScreen()
|
||||
|
||||
def nextScreen():
|
||||
hideturtle()
|
||||
screen_colors = ['white', 'black', 'red', 'green', 'blue', 'cyan', 'yellow', 'magenta',
|
||||
'orange', 'purple', 'pink', 'brown', 'grey', 'gold', 'lime', 'teal',
|
||||
'lavender', 'turquoise', 'tan', 'sky blue', 'salmon', 'olive', 'maroon',
|
||||
'navy', 'aquamarine', 'violet', 'silver', 'plum', 'peach puff', 'orchid',
|
||||
'midnight blue', 'indigo', 'honeydew', 'ghost white', 'fuchsia',
|
||||
'dark violet', 'dark turquoise', 'dark salmon', 'dark red', 'dark orchid',
|
||||
'dark orange', 'dark olive green', 'dark khaki', 'dark goldenrod',
|
||||
'dark cyan', 'dark blue', 'crimson', 'coral', 'chocolate', 'chartreuse',
|
||||
'cadet blue', 'azure', 'aquamarine', 'antique white', 'alice blue']
|
||||
fly(-480, -175)
|
||||
fillcolor(random.choice(screen_colors))
|
||||
setheading(0)
|
||||
begin_fill()
|
||||
rectangle(180, 158, 5)
|
||||
end_fill()
|
||||
|
||||
onscreenclick(detect_circle_click)
|
||||
mainloop() #what does this do?
|
||||
done() #prevents window from closing
|
Loading…
Reference in New Issue