Question

In: Computer Science

Draw an American Flag in Python turtle Height A=1 Width B=1.9 Blue C=0.5385 D=0.76 Star Pattern...

Draw an American Flag in Python turtle Height A=1 Width B=1.9 Blue C=0.5385 D=0.76 Star Pattern E=F=0.0538 G=H=0.0633 Strips K=0.0633 L=0.0769

Solutions

Expert Solution

Python code for the problem is provided below, please comment if any doubts:

Note: if the code indentation may lost on copying, then please refer the code screenshot to reconstruct the indentation.

Pyhton code:

import turtle
import time

# create the screen
flagScn = turtle.getscreen()

#set flag background
flagScn.bgcolor("white")

#set cursor properties
cursor = turtle.Turtle()
cursor.speed(1000)
cursor.penup()

#set the ht and wid
#convert incles to mm
height_flag = 1*250
width_of_flag = 1.9*250

#set the starting corodinates
x_co_begin = -237
y_co_begin = 125

#set the stripe sizes
height_red_strp = 0.0769*250
width_red_strp = width_of_flag

#set the size of the star
star_size = 0.0538*250


#function to create the main rectangeke
def main_rect_draw(co_x, co_y, ht, wid, color):
    cursor.goto(co_x,co_y)
    cursor.pendown()
    cursor.color(color)
    cursor.begin_fill()
    cursor.forward(wid)
    cursor.right(90)
    cursor.forward(ht)
    cursor.right(90)
    cursor.forward(wid)
    cursor.right(90)
    cursor.forward(ht)
    cursor.right(90)
    cursor.end_fill()
    cursor.penup()

#function to create the stars
def main_stars(co_x,co_y,color,length) :
    cursor.goto(co_x,co_y)
    cursor.setheading(0)
    cursor.pendown()
    cursor.begin_fill()
    cursor.color(color)
    for turn in range(0,5) :
        cursor.forward(length)
        cursor.right(144)
        cursor.forward(length)
        cursor.right(144)
    cursor.end_fill()
    cursor.penup()


#function to draw the strips
def strips_draw():
    co_x = x_co_begin
    co_y = y_co_begin
    for stripe in range(0,6):
        for color in ["red", "white"]:
            main_rect_draw(co_x, co_y, height_red_strp, width_red_strp, color)
            co_y = co_y - height_red_strp          

    main_rect_draw(co_x, co_y, height_red_strp, width_red_strp, 'red')
    co_y = co_y - height_red_strp


#function to draw the navy square
def navy_square():
    square_height = 0.5385*250;
    square_width = 0.76*250;
    main_rect_draw(x_co_begin, y_co_begin, square_height, square_width, 'navy')

#function to create the main row stars
def main_stars_row():
    gap_between_stars = 30
    gap_between_lines = height_red_strp + 6
    co_y = 112
    for row in range(0,5) :
        co_x = -222
        for star in range (0,6) :
            main_stars(co_x, co_y, 'white', star_size)
            co_x = co_x + gap_between_stars
        co_y = co_y - gap_between_lines

#function to create the pattern row stars
def pattern_stars_row():
    gap_between_stars = 30
    gap_between_lines = height_red_strp + 6
    co_y = 100
    for row in range(0,4) :
        co_x = -206
        for star in range (0,5) :
            main_stars(co_x, co_y, 'white', star_size)
            co_x = co_x + gap_between_stars
        co_y = co_y - gap_between_lines


#draw the flag using the above functions
strips_draw()
navy_square()
main_stars_row()
pattern_stars_row()
cursor.hideturtle()
flagScn.mainloop()

Output:

Code screenshot:


Related Solutions

this is a python code: QUESTION 1: Input floating point numbers for a, b, c, d...
this is a python code: QUESTION 1: Input floating point numbers for a, b, c, d and e. calculate the following and display the result.  Mathematical expression ab means a * b in programming context. QUESTION 2: You are sleep expert for a baby that is having struggle sleeping every night. You are to ask the mother of the child "How many oz of milk the child drank ?" Based on the amount of milk, you will have to determine...
The colour of copper sulphide is (a) Blue (b) Black (c) Red (d) Green
The colour of copper sulphide is________. (a) Blue(b) Black(c) Red(d) Green
Part 1: answer (a), (b), (c), and (d). Part 2: answer (a), (b), (c), and (d)....
Part 1: answer (a), (b), (c), and (d). Part 2: answer (a), (b), (c), and (d). Godspeed, and good luck!!! CC11 Cookie Creations Natalie and her friend Curtis Lesperance decide that they can benefit from joining Cookie Creations and Curtis’s coffee shop. In the first part of this problem, they come to you with questions about setting up a corporation for their new business. In the second part of the problem, they want your help in preparing financial information following...
3. Let A = D + 1, B = D − 3, C = D +...
3. Let A = D + 1, B = D − 3, C = D + x, where D = dx. Calculate the differential operators AB, BC, CA and their effect on y(x) = e^3x
1. A quantity index: a,b,c, or d? and Price Index: a,b,c, or d? a. holds prices...
1. A quantity index: a,b,c, or d? and Price Index: a,b,c, or d? a. holds prices constant and allows quantities to vary b. holds quantities constant and allows prices to vary c. allows both prices and quantities to vary d. holds both prices and quantities constant
6. The coolest stars are those whose color is a. blue b. red c. yellow d....
6. The coolest stars are those whose color is a. blue b. red c. yellow d. white 7. A pulsar is a powerful source of radio (and sometimes light) waves thought to be coming from a. rapidly spinning white dwarf stars b. supernovas c. spinning stars composed primarily of neutrons d. ordinary stars like our Sun which happen to be more energetic than the average 8. The existence of "black holes" has been a. verified by actual astronomical observations b....
1. Evaluate: (a+b)/(c-d) + 9/(a+d) when a=5, b=3, c=8, d=4 a. 6 b. 3 c. 15/2...
1. Evaluate: (a+b)/(c-d) + 9/(a+d) when a=5, b=3, c=8, d=4 a. 6 b. 3 c. 15/2 d. 17/13 2. Solve for x: 5(x+3) = 35 a. 2 b. 7 c. 4 d. -4 3. Acid rain occurs primarily as a result of a. operating a nuclear power plant b. burning coal or oil containing sulfur c. by-products created by operating an oil refinery d. the use of Freon and other refrigerants 4. The "ozone holes" at the polar region arise...
#Python Given a dictionary gradeCounts = { "A": 8, "D": 3, "B": 15, "F": 2, "C":...
#Python Given a dictionary gradeCounts = { "A": 8, "D": 3, "B": 15, "F": 2, "C": 6 } write the Python statement(s) to print: a) all the keys. b) all the values. c) all the key and value pairs. d) all of the key and value pairs in key order. e) the average value. f) a chart similar to the following in which each row contains a key followed by a number of asterisks equal to the key’s data value....
Astronomy question. Which star is coolest? a. M8 V b. K1 I c. A7 III d....
Astronomy question. Which star is coolest? a. M8 V b. K1 I c. A7 III d. B3 V
1. Find the missing value A, B, C, D
Refer to the table below.QuantityVariable Cost (in dollars)Fixed Costs (in dollars)Total Costs (in dollars)Average Variable Costs (in dollars per unit)Average Total Costs (in dollars per unit)Marginal Costs (in dollars per unit)00A40------1154055155515235407517.537.520360401002033.3254904013022.532.530512540165C33356B40D26.633.3351. Find the missing value A, B, C, D2. Continue to refer to this table. If the firm produces 5 units that it sells for $40.00 each, what will its profits or losses equal?Select one:a. losses equal $75b. losses equal $35c. profits equal $75d. profits equal $353. Continue to refer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT