Menu

[Solved]Modify Polygon Program Create Triangle Replace Square Function Call Random Pattern Program Q37078858

Modify the polygon program to create a triangle. Replace thesquare function call in the random pattern program with thetriangles function calls.

def drawPolygon(turtle, vertices): Draws a polygon from a list of vertices The list has the form [(xl, yl), , (xn. yn)1. tur

from turtlegraphics import Turtle random def drawsquare(turtle, X, y, length): Draws a square with the upper-left corner (x,y

def drawPolygon(turtle, vertices): “Draws a polygon from a list of vertices The list has the form [(xl, yl), , (xn. yn)1. turtle.up() (x, y)-verticest-1 turtle.move(x, y) turtle. down() for (x, y) in vertices turtle.move(x, y) from turtlegraphics import Turtle >>> turtle = Turtle ( ) >>>drawPolygon (turtle, (20, 20),(-20,20), (-20, -20)1) from turtlegraphics import Turtle random def drawsquare(turtle, X, y, length): Draws a square with the upper-left corner (x,y) and the given length.* turtle.up) turtle.move(x, y) turtle.setDirection (270) turtle.down() for count in xrange (4): turtle.move(length) turtle.turn (90) def main(): turtleTurtle() # Length of the square length40 # Relative distances to corners of window from center widthturtle.getwidth 2 height -turtle.getHeight) 2 # Black turtle.setColor (0, 0, 0) # Draw in upper-left corner drawSquare (turtle, -width, height, length) # Gray turtle.setColor (127, 127, 127) # Draw in lower-left corner drawSquare (turtle,-width, length- height, length) # First random color turtle.setColor (random.randint(0, 255), random.randint (0, 255), random.randint(0, 255)) # Draw in upper-right corner drawSquare (turtle, width- length, height, length) # Second random color turtle.setColor (random.randint(0, 255), random.randint (0, 255), random.randint(0, 255)) # Draw in lower-right corner drawSquare (turtle, width- length, length – height, length) main() Show transcribed image text def drawPolygon(turtle, vertices): “Draws a polygon from a list of vertices The list has the form [(xl, yl), , (xn. yn)1. turtle.up() (x, y)-verticest-1 turtle.move(x, y) turtle. down() for (x, y) in vertices turtle.move(x, y) from turtlegraphics import Turtle >>> turtle = Turtle ( ) >>>drawPolygon (turtle, (20, 20),(-20,20), (-20, -20)1)
from turtlegraphics import Turtle random def drawsquare(turtle, X, y, length): Draws a square with the upper-left corner (x,y) and the given length.* turtle.up) turtle.move(x, y) turtle.setDirection (270) turtle.down() for count in xrange (4): turtle.move(length) turtle.turn (90) def main(): turtleTurtle() # Length of the square length40 # Relative distances to corners of window from center widthturtle.getwidth 2 height -turtle.getHeight) 2 # Black turtle.setColor (0, 0, 0) # Draw in upper-left corner drawSquare (turtle, -width, height, length) # Gray turtle.setColor (127, 127, 127) # Draw in lower-left corner drawSquare (turtle,-width, length- height, length) # First random color turtle.setColor (random.randint(0, 255), random.randint (0, 255), random.randint(0, 255)) # Draw in upper-right corner drawSquare (turtle, width- length, height, length) # Second random color turtle.setColor (random.randint(0, 255), random.randint (0, 255), random.randint(0, 255)) # Draw in lower-right corner drawSquare (turtle, width- length, length – height, length) main()

Expert Answer


Answer to Modify the polygon program to create a triangle. Replace the square function call in the random pattern program with the… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *