Monday, January 28, 2019

Turtle Graphics Code Samples - 1

NoNameCodeOutput
1Right Turnfrom turtle import *
forward(100)
right(90)
forward(100)

2Left Turnfrom turtle import *
forward(100)
left(90)
forward(100)

3Squarefrom turtle import *
forward(100)
left(90)
forward(100)
left(90)
forward(100)

left(90)
forward(100)

4Angle Rays#angles
from turtle import *
for angle in range(0, 360, 15):
    setheading(angle)
    forward(100)
    write(str(angle) + '°')
    backward(100)

5Purple Squareimport turtle
turtle.fillcolor('purple')
turtle.pensize(10)
turtle.pencolor('black')

turtle.begin_fill()
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.end_fill()
turtle.done()

No comments:

Post a Comment