Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # File: USFlag.py
- # Description: Draws a US Flag using Turtle graphics.
- # Student's Name: Robert Jurgens
- # Student's UT EID: rdj697
- # Course Name: CS313E
- # Unique Number: 51325
- #
- # Date Created: 9/10/2016
- # Date Last Modified: 9/15/2016
- import turtle
- import math
- ## Initializing turtle...
- height = eval(input("What is the vertical height of the flag in pixels? : "))
- width = 1.9 * height
- star_size = height * (((2 * (5 - (5 ** 0.5))) / 4225) ** .5)
- screen = turtle.Screen()
- screen.setup(width + 200, height + 200, 100, 100)
- ttl = turtle.Turtle()
- ttl.pu()
- ttl.speed(10)
- screen.bgcolor("black")
- def drawFrame(width, height):
- ## Draw the frame
- ttl.goto(-width/2, height/2)
- ttl.pd()
- for i in range(2):
- ttl.forward(width)
- ttl.right(90)
- ttl.forward(height)
- ttl.right(90)
- def drawStripes(width, height):
- ttl.color("red")
- ttl.fillcolor("red")
- for i in range(13):
- if ttl.pencolor() == "red":
- ttl.begin_fill()
- for i in range(2):
- ttl.forward(width)
- ttl.right(90)
- ttl.forward(height/13)
- ttl.right(90)
- ttl.end_fill()
- ttl.right(90)
- ttl.forward(height/13)
- ttl.left(90)
- ttl.color("white")
- ttl.fillcolor("white")
- else:
- ttl.begin_fill()
- for i in range(2):
- ttl.forward(width)
- ttl.right(90)
- ttl.forward(height/13)
- ttl.right(90)
- ttl.end_fill()
- ttl.right(90)
- ttl.forward(height/13)
- ttl.left(90)
- ttl.color("red")
- ttl.fillcolor("red")
- def drawCanton(width, height):
- ## draw the canton
- canton_width = 2/5 * width
- canton_height = 7/13 * height
- ttl.penup()
- ttl.goto(-width/2, height/2)
- ttl.pendown()
- ttl.color("blue")
- ttl.fillcolor("blue")
- for i in range(2):
- ttl.begin_fill()
- ttl.forward(canton_width)
- ttl.right(90)
- ttl.forward(canton_height)
- ttl.right(90)
- ttl.end_fill()
- def drawStar(width, height):
- ttl.speed(10)
- ttl.color("white")
- ttl.fillcolor("white")
- ttl.begin_fill()
- for i in range(5):
- ttl.forward(star_size)
- ttl.right(144)
- ttl.end_fill()
- def padStars(width, height):
- horiz_padding = 1/30 * width
- vert_padding = 7/130 * height
- ttl.pu()
- ttl.forward(horiz_padding)
- ttl.right(90)
- ttl.forward(vert_padding)
- ttl.left(162)
- ttl.pd()
- def main():
- ttl.hideturtle()
- drawFrame(width, height)
- drawStripes(width, height)
- drawCanton(width, height)
- padStars(width, height)
- ttl.penup()
- ttl.left(144)
- ttl.forward(.0117528 * height)
- ttl.right(144)
- ttl.pendown()
- for j in range(5):
- for i in range(6):
- drawStar(width, height)
- ttl.right(72)
- ttl.penup()
- ttl.forward(1/15 * width)
- ttl.left(72)
- ttl.pendown()
- ttl.pu()
- ttl.left(108)
- ttl.forward(6/15 * width)
- ttl.left(90)
- ttl.forward(7/65 * height)
- ttl.left(162)
- ttl.pendown()
- ttl.penup()
- ttl.left(18)
- ttl.forward(63/130 * height)
- ttl.right(90)
- ttl.forward(1/30 * width)
- ttl.left(72)
- for j in range(4):
- for i in range(5):
- drawStar(width, height)
- ttl.right(72)
- ttl.penup()
- ttl.forward(1/15 * width)
- ttl.left(72)
- ttl.pendown()
- ttl.pu()
- ttl.left(108)
- ttl.forward(5/15 * width)
- ttl.left(90)
- ttl.forward(7/65 * height)
- ttl.left(162)
- ttl.pendown()
- main()
- turtle.done()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement