Turtle graphics

  1. import turtle
    import random
    #”canvas= c”
    c=turtle.Screen()
    c.bgcolor(“red”)
    sm=turtle.Turtle()
    sm.pencolor(“white”)
    def random_turtlegraphics():
    for s in range(100):
    angle=random.randint(1,90)
    distance=random.randint(0, 100)
    sm.forward(distance)
    sm.backward(distance)
    sm.right(angle)
    random_turtlegraphics()

 

In this program I wrote codes that creates a star looking image .To do this I imported random module to get random numbers for the length and angle.Then I created screen and assigned that to canvas variable. I also created the turtle and assigned that to variable name sm. I used pencolor for the color of turtle and for the screen I used bgcolor which changes background color or color of the screen. Then I made a function and wrote all the codes that helps to chose randomly the angle and distance.Then I wrote codes to go forward and come back or return same length as it went forward. Then I used random module to get random angle only toward right. At last, I called the function.