Turtle Graphics Code Samples - 2

 
Turtle Graphics Code Samples with output- 2

No Name Code Output
1 Traingle import turtle

painter = turtle.Turtle()
painter.pensize(8)
painter.pencolor("blue")
for i in range(3):
    painter.forward(100)
    painter.left(120)
turtle.done()
2 Rectangle import turtle

painter = turtle.Turtle()
painter.pensize(8)
painter.pencolor("red")
for i in range(4):
    painter.forward(150)
    painter.left(90)
turtle.done()
3 Pentagon import turtle

painter = turtle.Turtle()
painter.pensize(8)
painter.pencolor("blue")
for i in range(5):
    painter.forward(100)
    painter.left(72)
turtle.done()
4 Hexagon import turtle

painter = turtle.Turtle()
painter.pensize(8)
painter.pencolor("blue")
for i in range(6):
    painter.forward(100)
    painter.left(60)
turtle.done()
5 Spiral Star import turtle

spiral = turtle.Turtle()
turtle.ht()
for i in range(20):
    spiral.forward(i * 10)
    spiral.right(144)
 
turtle.done()
6 Star1 from turtle import *
color('red', 'yellow')
begin_fill()
while True:
    forward(200)
    left(170)
    if abs(pos()) < 1:
        break
end_fill()
done()
7 Circle import turtle

painter = turtle.Turtle(shape="turtle")

painter.penup()
painter.setposition(-120, 0)
painter.pendown()
painter.pensize(5)
painter.circle(80)

turtle.done()
8 Filled Circle import turtle as painter

painter.speed('normal')
painter.up()
painter.goto(0,-150)
painter.down()
# default pen width is 1
painter.width(2)
# draw a solid blue circle
painter.color('blue')
painter.begin_fill()
painter.circle(100)
painter.end_fill()
# adust center of semi circles
painter.up()
painter.done()