Write a program that draws a star as shown my code I made a
Write a program that draws a star as shown
my code: I made a star but need to modify accordingly to the given instructions.
import turtle
turtle.goto(75,250)
turtle.goto(150,0)
turtle.goto(-50,150)
turtle.goto(200,150)
turtle.goto(0,0)
turtle.done()
Solution
When you are doing turtle.goto(x, y) - you are drawing a line from current position to coordinates (x, y). Assuming that the starting position is (0, 0), the program becomes following:
import turtle
drawLine(0, 0, 75, 250)
drawLine(75, 250, 150, 0)
drawLine(150, 0, -50, 150)
drawLine(-50, 150, 200, 150)
drawLine(200, 150, 0, 0)
turtle.done()
Where the definition of drawLine would be:
def drawLine(x1, y1, x2, y2, color=\"black\", size=1):
turtle.penup() # Stop drawing
turtle.setpos(x1, y1) # Set the current position for the turtle
turtle.pencolor(color) # Set the pen color
turtle.pensize(size) # Set the pen size
turtle.pendown() # Start drawing
turtle.goto(x2, y2) # Draw a line till point x2, y2
