Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.21 KB | None | 0 0
  1. #  File: USFlag.py
  2. #  Description: Draws a US Flag using Turtle graphics.
  3. #  Student's Name: Robert Jurgens
  4. #  Student's UT EID: rdj697
  5. #  Course Name: CS313E
  6. #  Unique Number: 51325
  7. #
  8. #  Date Created: 9/10/2016
  9. #  Date Last Modified: 9/15/2016
  10.  
  11. import turtle
  12. import math
  13.  
  14. ## Initializing turtle...
  15.  
  16. height = eval(input("What is the vertical height of the flag in pixels? : "))
  17. width = 1.9 * height
  18. star_size = height * (((2 * (5 - (5 ** 0.5))) / 4225) ** .5)
  19. screen = turtle.Screen()
  20. screen.setup(width + 200, height + 200, 100, 100)
  21. ttl = turtle.Turtle()
  22. ttl.pu()
  23. ttl.speed(10)
  24. screen.bgcolor("black")
  25.        
  26. def drawFrame(width, height):
  27.  
  28.     ## Draw the frame
  29.    
  30.     ttl.goto(-width/2, height/2)
  31.     ttl.pd()
  32.     for i in range(2):
  33.         ttl.forward(width)
  34.         ttl.right(90)
  35.         ttl.forward(height)
  36.         ttl.right(90)
  37.  
  38. def drawStripes(width, height):
  39.    
  40.     ttl.color("red")
  41.     ttl.fillcolor("red")
  42.     for i in range(13):
  43.         if ttl.pencolor() == "red":
  44.             ttl.begin_fill()
  45.             for i in range(2):
  46.                 ttl.forward(width)
  47.                 ttl.right(90)
  48.                 ttl.forward(height/13)
  49.                 ttl.right(90)
  50.             ttl.end_fill()
  51.             ttl.right(90)
  52.             ttl.forward(height/13)
  53.             ttl.left(90)
  54.             ttl.color("white")
  55.             ttl.fillcolor("white")
  56.         else:
  57.             ttl.begin_fill()
  58.             for i in range(2):
  59.                 ttl.forward(width)
  60.                 ttl.right(90)
  61.                 ttl.forward(height/13)
  62.                 ttl.right(90)
  63.             ttl.end_fill()
  64.             ttl.right(90)
  65.             ttl.forward(height/13)
  66.             ttl.left(90)
  67.             ttl.color("red")
  68.             ttl.fillcolor("red")
  69.            
  70. def drawCanton(width, height):
  71.            
  72.     ## draw the canton
  73.     canton_width = 2/5 * width
  74.     canton_height = 7/13 * height
  75.     ttl.penup()
  76.     ttl.goto(-width/2, height/2)
  77.     ttl.pendown()
  78.     ttl.color("blue")
  79.     ttl.fillcolor("blue")
  80.     for i in range(2):
  81.         ttl.begin_fill()
  82.         ttl.forward(canton_width)
  83.         ttl.right(90)
  84.         ttl.forward(canton_height)
  85.         ttl.right(90)
  86.         ttl.end_fill()
  87.        
  88. def drawStar(width, height):
  89.     ttl.speed(10)
  90.     ttl.color("white")
  91.     ttl.fillcolor("white")
  92.     ttl.begin_fill()
  93.     for i in range(5):
  94.         ttl.forward(star_size)
  95.         ttl.right(144)
  96.     ttl.end_fill()
  97.  
  98. def padStars(width, height):
  99.     horiz_padding = 1/30 * width
  100.     vert_padding = 7/130 * height
  101.     ttl.pu()
  102.     ttl.forward(horiz_padding)
  103.     ttl.right(90)
  104.     ttl.forward(vert_padding)
  105.     ttl.left(162)
  106.     ttl.pd()
  107.    
  108. def main():
  109.     ttl.hideturtle()
  110.     drawFrame(width, height)
  111.     drawStripes(width, height)
  112.     drawCanton(width, height)
  113.     padStars(width, height)
  114.     ttl.penup()
  115.     ttl.left(144)
  116.     ttl.forward(.0117528 * height)
  117.     ttl.right(144)
  118.     ttl.pendown()
  119.     for j in range(5):
  120.         for i in range(6):
  121.             drawStar(width, height)
  122.             ttl.right(72)
  123.             ttl.penup()
  124.             ttl.forward(1/15 * width)
  125.             ttl.left(72)
  126.             ttl.pendown()
  127.         ttl.pu()
  128.         ttl.left(108)
  129.         ttl.forward(6/15 * width)
  130.         ttl.left(90)
  131.         ttl.forward(7/65 * height)
  132.         ttl.left(162)
  133.         ttl.pendown()
  134.     ttl.penup()
  135.     ttl.left(18)
  136.     ttl.forward(63/130 * height)
  137.     ttl.right(90)
  138.     ttl.forward(1/30 * width)
  139.     ttl.left(72)
  140.     for j in range(4):
  141.         for i in range(5):
  142.             drawStar(width, height)
  143.             ttl.right(72)
  144.             ttl.penup()
  145.             ttl.forward(1/15 * width)
  146.             ttl.left(72)
  147.             ttl.pendown()
  148.             ttl.pu()
  149.         ttl.left(108)
  150.         ttl.forward(5/15 * width)
  151.         ttl.left(90)
  152.         ttl.forward(7/65 * height)
  153.         ttl.left(162)
  154.         ttl.pendown()
  155.    
  156. main()
  157. turtle.done()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement