Please solve accordingly, the program is Python. Thank you.
Posted: Tue Jul 05, 2022 10:27 am
Please solve accordingly, the program is Python. Thank you.
Your Task Complete the program below to draw a red carpet with m times n circles of radius 0.5! Notice the default parameter n in the function. circle(r, cx, cy, n-64). The sample output on the right corresponds to m 3 and n = 4 def rectangle (ax, bx, ay, by): 2 3 4 7 ### Hint Code template Code history Creates a rectangle connecting the points (ax, ay), (bx, ay), (bx, by), (ax, by). Terminates the X and Y arrays with None. # return fax, bx, bx. ax ax None 1 Lav av by by. av. Nonel This is a red carpet Expected output
1 def rectangle(ax, bx, ay, by): 2 3 10 11 20 23 23 27 28 29 30 www 31 32 Creates a rectangle connecting the points (ax, ay), (bx, ay), (bx, by), (ax, by). Terminates the X and Y arrays with None. www return [ax, bx, bx, ax, ax, None], [ay, ay, by, by, ay, None] def circle(r, cx, cy, n=64): 11||| Creates a circle with radius r, centered at (cx, cy). The circle will have n-64 edges by default. HI t = ... x = ... Y return x, Y 25 def carpet (m, n): 26 x = list (x) + [None] y list (y) + [None] """Draws a carpet with mxn circles""" X = ... y = #Loop over columns (horizontal direction): for i in rangel).
26 27 28 29 30 31 32| 33 34 35 36 37 38 39 40 41 42 42 43| """Draws a carpet with mxn circles""" 44 Stat 45 * 46 47 X = Y #Loop over columns (horizontal direction): for i in range (...): #Loop over rows (vertical direction): for j in range (...): #Add a circle: sx, sy = ... X += ... y += # Append the outer rectangle: xo, yo = rectangle(....….... .... return x + ..., y + ... 48 # Main program (do not change): 49 import matplotlib.pyplot as plt 50 import numpy as np ... 51 xc, yc 52 plt.axis ("equal") carpet (3, 4) 53 plt.grid() 54 plt.title("This is a red carpet") 55 plt.plot(xc, yc, color="red", lw=3) 56 plt.show()
Your Task Complete the program below to draw a red carpet with m times n circles of radius 0.5! Notice the default parameter n in the function. circle(r, cx, cy, n-64). The sample output on the right corresponds to m 3 and n = 4 def rectangle (ax, bx, ay, by): 2 3 4 7 ### Hint Code template Code history Creates a rectangle connecting the points (ax, ay), (bx, ay), (bx, by), (ax, by). Terminates the X and Y arrays with None. # return fax, bx, bx. ax ax None 1 Lav av by by. av. Nonel This is a red carpet Expected output
1 def rectangle(ax, bx, ay, by): 2 3 10 11 20 23 23 27 28 29 30 www 31 32 Creates a rectangle connecting the points (ax, ay), (bx, ay), (bx, by), (ax, by). Terminates the X and Y arrays with None. www return [ax, bx, bx, ax, ax, None], [ay, ay, by, by, ay, None] def circle(r, cx, cy, n=64): 11||| Creates a circle with radius r, centered at (cx, cy). The circle will have n-64 edges by default. HI t = ... x = ... Y return x, Y 25 def carpet (m, n): 26 x = list (x) + [None] y list (y) + [None] """Draws a carpet with mxn circles""" X = ... y = #Loop over columns (horizontal direction): for i in rangel).
26 27 28 29 30 31 32| 33 34 35 36 37 38 39 40 41 42 42 43| """Draws a carpet with mxn circles""" 44 Stat 45 * 46 47 X = Y #Loop over columns (horizontal direction): for i in range (...): #Loop over rows (vertical direction): for j in range (...): #Add a circle: sx, sy = ... X += ... y += # Append the outer rectangle: xo, yo = rectangle(....….... .... return x + ..., y + ... 48 # Main program (do not change): 49 import matplotlib.pyplot as plt 50 import numpy as np ... 51 xc, yc 52 plt.axis ("equal") carpet (3, 4) 53 plt.grid() 54 plt.title("This is a red carpet") 55 plt.plot(xc, yc, color="red", lw=3) 56 plt.show()