# Draw The American Flag # print("This program is used to draw the american flag.") print("You can enter the height you want it to be drawn.") print("Then the program will start drawing the American flag") print("with all the correct dimensions based off the height.") print("The dimesion of 150 draws the given picture.") print(' '*50) import turtle # imports turtle program turtle.shape("turtle") # changes turtle shape to a turtle turtle.speed(100) # changes the speed of the turtle def draw_star(size,color): # 1st required define function turtle.pendown() # define function used to draw a five point star turtle.color(color) turtle.begin_fill() turtle.left(70) turtle.forward(size) turtle.right(140) turtle.forward(size) turtle.left(70) for i in range(4): turtle.forward(size) turtle.right(135) turtle.forward(size) turtle.left(60) turtle.end_fill() def draw_star_5(size,color,s_h_s): # define function that draws five stars in a row draw_star(size,color) turtle_star_move_5(s_h_s) draw_star(size,color) turtle_star_move_5(s_h_s) draw_star(size,color) turtle_star_move_5(s_h_s) draw_star(size,color) turtle_star_move_5(s_h_s) draw_star(size,color) turtle.penup() def draw_star_6(size,color,s_h_s): # define function that draws six stars in a row draw_star(size,color) turtle_star_move_6(s_h_s) draw_star(size,color) turtle_star_move_6(s_h_s) draw_star(size,color) turtle_star_move_6(s_h_s) draw_star(size,color) turtle_star_move_6(s_h_s) draw_star(size,color) turtle_star_move_6(s_h_s) draw_star(size,color) turtle.penup() def get_color(color): if color == "red": # 2nd required define function r = float(.689) # define function that will draw colors: g = float(.132) # "red","blue","white", and else("black") b = float(.203) return (r,g,b) elif color == "blue": r = float(.234) g = float(.233) b = float(.430) return (r,g,b) elif color == "white": r = int(1) g = int(1) b = int(1) return (r,g,b) else: r = int(0) g = int(0) b = int(0) return(r,g,b) def draw_rectangle(length,height,color): # 3rd required define function turtle.color(color) # define function that draws the stripes of the flag turtle.begin_fill() turtle.forward(length) turtle.left(90) turtle.forward(height) turtle.left(90) turtle.forward(length) turtle.left(90) turtle.forward(height) turtle.end_fill() turtle.penup() def flag_outline(length,height,h_stripe): # define function used to draw the black flag outline turtle_move(0,13*h_stripe) # The position to start drawing flag outline turtle.forward(length) turtle.left(90) turtle.forward(height) turtle.left(90) turtle.forward(length) turtle.left(90) turtle.forward(height) def turtle_move(x,y): # define function used to move turtle to different locations turtle.penup() turtle.goto(x,y) turtle.left(90) turtle.pendown() def turtle_star_move(s_h_s): # define function used to place first star in original position turtle.penup() turtle.forward(s_h_s) turtle.left(90) turtle.forward(s_h_s) def turtle_mover(x,y,s_h_s): # define function used to move turtle to original position to turtle.goto(x,y) # to start drawing row of six or five stars turtle.right(60) turtle.forward(s_h_s) turtle.pendown() def turtle_star_move_5(s_h_s): # define function used to move turtle for turtle.penup() # the spacing when drawing five stars in a row turtle.right(60) turtle.forward((17/7)*s_h_s) # spacing in between stars turtle.pendown() def turtle_star_move_6(s_h_s): # define function used to move turtle for turtle.penup() # the spacing when drawing six stars in a row turtle.right(60) turtle.forward((17/7)*s_h_s) # spacing in between stars turtle.pendown() def draw_flag(height): # 4th required define function height_1 = height l = 1.9*height_1 # length of flag h_union = (7/13)*height_1 # height of blue field of stars l_union = (2/5)*l # length of blue field of stars s_h_s = h_union/10 # height spacing of stars s_l_s = l_union/12 # width spacing of stars h_stripe = height_1/13 # height of the stripes s_size = (1/5)*h_stripe # star size l_stripe = (3/5)*l # short stripes next to blue field r = get_color("red") # define r as selected "red" color b = get_color("blue") # define b as selected "blue" color w = get_color("white") # define w as selected "white" color draw_rectangle(l,h_stripe,r) # beginning of using the define functions to draw american flag turtle_move(0,2*h_stripe) draw_rectangle(l,h_stripe,r) turtle_move(0,4*h_stripe) draw_rectangle(l,h_stripe,r) turtle_move(l_union,6*h_stripe) draw_rectangle(l_stripe,h_stripe,r) turtle_move(l_union,8*h_stripe) draw_rectangle(l_stripe,h_stripe,r) turtle_move(l_union,10*h_stripe) draw_rectangle(l_stripe,h_stripe,r) turtle_move(l_union,12*h_stripe) draw_rectangle(l_stripe,h_stripe,r) turtle_move(l_union,13*h_stripe) draw_rectangle(-l_union,-h_union,b) flag_outline(l,-height,h_stripe) turtle_star_move(s_h_s) draw_star_6(s_size,w,s_h_s) turtle_mover(0,11*h_stripe,s_h_s) draw_star_6(s_size,w,s_h_s) turtle_mover(0,9.6*h_stripe,s_h_s) draw_star_6(s_size,w,s_h_s) turtle_mover(0,8.2*h_stripe,s_h_s) draw_star_6(s_size,w,s_h_s) turtle_mover(0,6.8*h_stripe,s_h_s) draw_star_6(s_size,w,s_h_s) turtle_mover(1.2*s_h_s,11.7*h_stripe,s_h_s) draw_star_5(s_size,w,s_h_s) turtle_mover(1.2*s_h_s,10.3*h_stripe,s_h_s) draw_star_5(s_size,w,s_h_s) turtle_mover(1.2*s_h_s,8.9*h_stripe,s_h_s) draw_star_5(s_size,w,s_h_s) turtle_mover(1.2*s_h_s,7.5*h_stripe,s_h_s) draw_star_5(s_size,w,s_h_s) turtle.penup() turtle.goto(-20,0) # moves turtle out of flag # end of using the define functions to draw american flag draw_flag(float(input("Enter the height for the flag to be drawn:")))