Question: Python - Turtle Graphics. American Flag The width (w) of the official American flag is 1.9 times the height (h). The blue rectangular canton (referred

Python - Turtle Graphics.

American Flag The width (w) of the official American flag is 1.9 times the height (h). The blue rectangular canton (referred to as the union) has width 25 w and height 713 h. Write a program that draws an American flag.

I have a working code below, but it fills with black and white. I need help setting it to resemble the true colors, red white and blue. Thanks

import turtle import time import random

def draw_rectangle(length, height): turtle.up() x = -150 y = 150 C = height*(7/13) D = length*(2/5) L = stripe_width = float(round(height/13,1))

## Draw rectangle first. turtle.color(0,0,0) turtle.begin_fill() turtle.setpos(x,y) turtle.down() turtle.forward(length) turtle.right(90) turtle.forward(height) turtle.right(90) turtle.forward(length) turtle.right(90) turtle.forward(height) turtle.end_fill()

## Then draw the stripes. x1 = -150 y1 = 150-L for z in range(13): if z%2 == 0: r = s = t = 0 else: r = s = t = 1 turtle.up() turtle.speed(100) turtle.setpos(x1,y1) turtle.setheading(90) turtle.down() turtle.color(r,s,t) turtle.begin_fill() turtle.forward(L) turtle.right(90) turtle.forward(length) turtle.right(90) turtle.forward(L) turtle.right(90) turtle.forward(length) turtle.end_fill() y1 -= L

## Finally draw the stars rectangle overlapping the stripes, next is stars. x2 = -150+D y2 = 150.5-C turtle.up() turtle.setpos(x2,y2) turtle.down() turtle.color(0,0,0) turtle.begin_fill() turtle.forward(D) turtle.right(90) turtle.forward(C) turtle.right(90) turtle.forward(D) turtle.right(90) turtle.forward(C) turtle.end_fill() turtle.up()

turtle.bye draw_star(-length, height)

def draw_star(l, h): for z in range(50): if z < 7: row = 140 draw_starrows(row) if z < 14: row = row - 20 draw_starrows(row) if z < 21: row = row - 20 draw_starrows(row) if z < 28: row = row - 20 draw_starrows(row) if z < 35: row = row - 20 draw_starrows(row) ## This gets the turtle pen out of the way at the very end. turtle.up() turtle.setpos(-180,100) break

def draw_starrows(row): x = -160 y = 150 for z in range(10): x += 15 turtle.up() turtle.color(1,1,1) turtle.speed(100) turtle.setpos(x,row) turtle.begin_fill() turtle.down() turtle.forward(6.154) turtle.left(144) turtle.forward(6.154) turtle.left(144) turtle.forward(6.154) turtle.left(144) turtle.forward(6.154) turtle.left(144) turtle.forward(6.154) turtle.left(144) turtle.end_fill() turtle.bye

##def get_color(): ## r = g = b = 0 ## color = r = g = b ## return color

def draw_flag(): A = 200 height = int(A) ## length = height*1.9 ## C = height*(7/13) ## D = length*(2/5) ## E = F = union_height/10 ## G = H = union_length/12 ## stripe_width = height/13 ## diameter_star = stripe_width*(4/5) draw_rectangle(height*1.9, height)

draw_flag()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!