04-June-2022
Source :
vim basic_turtle.py
from turtle import * # or import separate Screen and Turtle classes
import time # to call sleep
s=Screen()
t=Turtle()
# Change color and color mode of screen and pen
s.colormode(1.0) # 1.0 is default, for color names as string
s.bgcolor('gray')
s.colormode(255)
t.color((10,72,85)) # Set rgb color to pen/turtle
# Cursor shape
t.shape('circle')
time.sleep(1)
t.shape('arrow')
time.sleep(1)
t.shape('turtle')
time.sleep(1)
t.shape('classic')
# Draw a circle
t.up()
t.setpos(-200,100)
t.down()
t.circle(15)
# hide cursor
t.ht()
# Draw custom shape & fill color
def draw_square(side):
for i in range(4):
t.forward(side)
t.left(90)
t.up()
t.setpos(-100, 100)
t.down()
t.fillcolor('green') # Set fill color
t.begin_fill()
draw_square(50)
t.end_fill()
t.up()
# Navigate back to home.
t.home()
def draw_circle(direction):
for i in range(72):
if(direction == 1):
t.left(5)
else:
t.right(5)
t.forward(5)
for j in range(2):
t.down()
draw_circle(j % 2)
t.up()
#t.forward(50)
t.down()
time.sleep(15)