Python Turtle

Python Turtle

  • It is a Python library by which we can create and draw various types of shapes and images.
  • Turtle contains the following methods.
  • This function moves the turtle forward by the specified amount.
  • It takes single parameter.
  • fd() function also works same as forward()
#import turtle library
import  turtle
turtle.forward(160)
turtle.done()


  • This function moves the turtle backward by the specified amount.
  • It takes single parameter.
  • bk() function also works same as backward()
#import turtle library
import  turtle
turtle.backward(160)
turtle.done()


  • This function Turns the turtle clockwise.
  • It takes single parameter as an angle.
  • rt() function also works same as right()
#import turtle library
import  turtle
#move the turtle by 160
turtle.forward(160)
#turns the turtle clockwise by 90 degree
turtle.right(90)
#then moves the turtle by 50
turtle.forward(50)
turtle.done()


  • This function Turns the turtle counter clockwise.
  • It takes single parameter as an angle.
  • lt() function also works same as left()
#import turtle library
import  turtle
#move the turtle by 160
turtle.forward(160)
#turns the turtle counter
#clockwise by 90 degree
turtle.left(90)
#then moves the turtle by 50
turtle.forward(50)
turtle.done()


  • This function changes the color of turtle's pen.
  • It takes two parameter as a color.
#import turtle library
import  turtle
#changing color red to green
turtle.color("red","green")
#move the turtle by 160
turtle.forward(160)
turtle.done()


  • This function is used to set the color of turtle's pen.
  • It takes single parameter as a color.
#import turtle library
import  turtle
#set pencolor to orange
turtle.pencolor("orange")
#move the turtle by 160
turtle.forward(160)
turtle.done()


  • This function is used to set the color of turtle's pen.
  • It takes single parameter as a color.
#import turtle library
import  turtle
#set pencolor to orange
turtle.pencolor("orange")
turtle.pensize(5)
#move the turtle by 160
turtle.forward(160)
turtle.done()


#import turtle library
import  turtle
#set background to black
turtle.bgcolor("black")
#set pencolor to orange
turtle.pencolor("yellow")
#using loop
for i in range(0,4):
    turtle.fd(100)
    turtle.lt(90)
turtle.done()


#import turtle library
import  turtle
#set background to black
turtle.bgcolor("black")
#set pencolor to orange
turtle.pencolor("yellow")
#using loop
for i in range(0,2):
    turtle.fd(100)
    turtle.lt(90)
    turtle.fd(50)
    turtle.lt(90)
turtle.done()


#import turtle library
import  turtle
#set background to black
turtle.bgcolor("black")
#set pencolor to orange
turtle.pencolor("yellow")
#using loop
for i in range(0,360,1):
    turtle.forward(1)
    turtle.left(1)
turtle.done()


#import turtle library
import  turtle
#set background to black
turtle.bgcolor("black")
#set pencolor to orange
turtle.pencolor("yellow")
#using loop
for i in range(0,3):
    turtle.left(120)
    turtle.forward(90)
turtle.done()


#import turtle library
import  turtle
#set background to black
turtle.bgcolor("black")
#set pencolor to orange
turtle.pencolor("yellow")
turtle.color("yellow","green")
#change pen shape
turtle.shape("turtle")
turtle.pensize(2)
#using loop
j=200
for i in range(0,17,1):
    turtle.forward(j)
    j=j-10
    turtle.left(90)

turtle.done()


#import turtle library
import  turtle
#set background to black
turtle.bgcolor("black")
#set pencolor to orange
turtle.pencolor("yellow")
turtle.color("yellow","green")
#change pen shape
turtle.shape("turtle")
turtle.pensize(2)
for i in range(0,6):
    turtle.forward(100)
    turtle.left(60)
turtle.done()


#import turtle library
import  turtle
#set background to black
turtle.bgcolor("black")
#set pencolor to orange
turtle.pencolor("yellow")
turtle.color("yellow","green")
#change pen shape
turtle.shape("turtle")
turtle.pensize(2)
for i in range(5):
    turtle.forward(200)
    turtle.right(144)
turtle.done()


#importing turtle library
from turtle import *
import  turtle
color('orange', 'yellow')
#set backgroud color
turtle.bgcolor("black")
begin_fill()
while True:
    forward(200)
    left(170)
    if abs(pos()) < 1:
        break
end_fill()
done()

 



 

import  turtle
import  time
def myFun():
    colors=["red","blue","green","yellow","orange","brown"]
    t=turtle
    t.pensize(5)
    t.bgcolor('black')
    t.speed(1000)
    for x in range(360):
        t.pencolor(colors[x%len(colors)])
        t.pensize(x/50)
        t.forward(x)
        t.left(59)
myFun()
time.sleep(5)

 


Request:-If you found this post helpful then let me know by your comment and share it with your friend. 

If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other. 

Thanks.😊

Post a Comment

0 Comments