0% found this document useful (0 votes)
2 views20 pages

Python Turtle Tutorials

The document contains Python turtle graphics tutorials for creating artistic drawings, including a depiction of Radha Krishna and a birthday cake. It provides step-by-step code to set up the turtle environment, draw shapes, and fill colors to create detailed images. The tutorials demonstrate various turtle functions and techniques for drawing complex figures using Python.

Uploaded by

yuktiravi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views20 pages

Python Turtle Tutorials

The document contains Python turtle graphics tutorials for creating artistic drawings, including a depiction of Radha Krishna and a birthday cake. It provides step-by-step code to set up the turtle environment, draw shapes, and fill colors to create detailed images. The tutorials demonstrate various turtle functions and techniques for drawing complex figures using Python.

Uploaded by

yuktiravi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python turtle tutorials

import turtle

#keeping the background color dark blue


[Link]('#ffc233')

#Defining title of program


[Link]("Radhe Krishna")

#Creating turtle screen


screen= [Link]()
#Defining height and width of screen
[Link](650,580)

t1 = [Link]()

#keeping the fasted speed for now, you can keep the speed as needed
#'fastest' : 0
#'fast' : 10
#'normal' : 6
#'slow' : 3
#'slowest' : 1

[Link](4)

#Let's move down and go the position from where we will start to draw
[Link](90)
[Link]()
[Link](180)
[Link](90)
#Now, the turtle is pointing positive x-axis

#Let's keep the pen down and start to draw the base
[Link]()
#Here we have dipped our turtle brush in a shade of blue color
[Link]("#ff99d1")
t1.begin_fill()
[Link](400)
[Link](90)
[Link](100)
[Link](90)
[Link](800)
[Link](90)
[Link](100)
[Link](90)
[Link](400)
t1.end_fill()
#Now, we have drawn the base which is rectangular in shape
#end_fill will fill blue color (selected above), in the shape formed by turtle

#Now, we will start to draw moon,I have selected a very light shade of blue to color moon
[Link]("#CDEEF1")
t1.begin_fill()
[Link](160)
[Link](40)
#this method will draw the moon's border
[Link](250,280)
[Link](40)
[Link](160)
t1.end_fill()
#Now, we have drawn the moon as well as filled color in it

#Now, we will start drawing Radha Krishna


#We will draw Radha on our right side and Krishna on left side
#We will start with Radha
[Link]("#012427")
t1.begin_fill()
#We will start with the duppata
[Link](160)
[Link](130)
[Link](-300,30)
[Link](95)
#This will draw the shoulder
[Link](50,40)
[Link](40)
#This will draw the head
[Link](43)
[Link](80,25)
[Link](50,30)
[Link](10)
[Link](35,28)
#Now, we have completed drawing Radha

#Now, let's draw krishna's turban


[Link](160)
[Link](10,100)
[Link](100)
[Link](10,80)
[Link](20)
[Link](80)
[Link](100,15)
[Link](90)
[Link](6)
[Link](65)
[Link](60,55)

#Following code will draw Krishna's morpankh


[Link](160)
[Link](20,100)
[Link](10)
[Link](-20,25)
[Link](170)
[Link](-20,40)
[Link](10)
[Link](20,80)
#morpankh done

#We will continue to draw rest part of turban


[Link](135)
[Link](60,15)
[Link](70)
[Link](6)

[Link](110)
[Link](9)

[Link](80)
[Link](70,24)

[Link](60)
[Link](65,30)
[Link](-5,110)

#Below lines of code will draw the right hand of Krishna


[Link](5,120)
[Link](90)
[Link](5,60)
[Link](10)
[Link](10,5)
[Link](80)
[Link](15)
[Link](-5,160)
#Now, we will draw the first open finger of right hand
[Link](6)
[Link](2,180)
[Link](6)
[Link](20,30)

#Below lines will draw fingers holding bansuri


[Link](140)
[Link](3,150)
[Link](110)
[Link](4,80)
[Link](2)
[Link](100)

#Here, we will draw second open finger of krishna


[Link](6)
[Link](60)
[Link](9)
[Link](2,180)
[Link](10)
[Link](30)
[Link](15)
#We will now start to draw bansuri
[Link](85)
[Link](40)
[Link](60)
[Link](5,310)
[Link](80)
[Link](3)
[Link](90)

#dor on bansuri
[Link](42)
[Link](30)
[Link](10)
[Link](90)
[Link](20,60)
[Link](95)
[Link](12)
[Link](29)
[Link](42)

#We will draw the rest part of bansuri


[Link](90)
[Link](34)
[Link](85)

#left hand of Krishna


[Link](2)
[Link](60,25)

#Now, we will draw Krishna's duppata


[Link](80)
[Link](10,40)
[Link](45)
[Link](10)
[Link](130)

#Below lines will draw the plates of duppata


[Link](90)
[Link](20)
[Link](90)
[Link](10)
[Link](90)
[Link](10)
[Link](90)
[Link](5)
[Link](90)
[Link](25)

#This will complete drawing duppata


[Link](100)
[Link](120)

[Link](175)
[Link](50,50)

#Now, we will tilt turtle towards required direction and draw Krishna's dhoti
[Link](80)
[Link](110,15)
[Link](75)

#The turtle will now reach to the rectangular base we had drawn in the beginning
[Link](97)
[Link](260)
t1.end_fill()
#At this point, we have completed drawing Radhe Krishna

[Link]()
[Link](90)
[Link](100)
[Link](90)
[Link](420)

#Lets also write their holy name in our drawing


[Link]("#00a606")
[Link]("Radhe Krishna....", font=("Script",45, "bold"))

[Link]()

[Link]()

[Link]
# Importing turtle library to draw "Happt Birthday"
import turtle

# Creating our turtle cursor to draw


my_turtle_cursor = [Link]()

# Creating a separate Canvas to draw "Happy Birthday"


my_turtle_screen = [Link]()

# initializing a variable for co-ordinating


y_coordinate = -125
# Creating a function to draw a circle on top of stick
def draw_circle_on_top_of_stick(fill_color, border_color, x, y, radius):
my_turtle_cursor.penup()
my_turtle_cursor.pensize(3)
# Changing color of our cursor
my_turtle_cursor.color(fill_color)
# Changing fill color of the cursor
my_turtle_cursor.fillcolor(border_color)

my_turtle_cursor.goto(x, y)
my_turtle_cursor.pendown()
my_turtle_cursor.begin_fill()

my_turtle_cursor.circle(radius)

my_turtle_cursor.end_fill()

my_turtle_cursor.getscreen().update()

def draw_candle_for_cake(fill_color, border_color, x, y):


my_turtle_cursor.penup()

# Changing color of our cursor


my_turtle_cursor.color(border_color)
# Changing fill color of the cursor
my_turtle_cursor.fillcolor(fill_color)

my_turtle_cursor.goto(x, y)
my_turtle_cursor.pendown()
my_turtle_cursor.begin_fill()

# Drawing the first side of our Candle


my_turtle_cursor.forward(25)
my_turtle_cursor.left(90)

# Drawing the second side of our Candle


my_turtle_cursor.forward(60)
my_turtle_cursor.left(90)

# Drawing the third side of our Candle


my_turtle_cursor.forward(25)
my_turtle_cursor.left(90)

# Drawing the fourth side of our Candle


my_turtle_cursor.forward(60)
my_turtle_cursor.left(90)

my_turtle_cursor.end_fill()

my_turtle_cursor.getscreen().update()

# Creating a Function to draw stick on the candle


def draw_stick_on_candle(fill_color, x, y, cursor_size):
my_turtle_cursor.penup()

# Changing color of our cursor


my_turtle_cursor.color(fill_color)

# Changing fill color of the cursor


my_turtle_cursor.fillcolor(fill_color)
my_turtle_cursor.goto(x, y)
my_turtle_cursor.pensize(cursor_size)
my_turtle_cursor.begin_fill()
my_turtle_cursor.pendown()
my_turtle_cursor.right(90)
my_turtle_cursor.forward(12)
my_turtle_cursor.end_fill()
my_turtle_cursor.getscreen().update()

def write_happy_inside_circle(text_color, x, y):


my_turtle_cursor.penup()
# Changing color of our cursor
my_turtle_cursor.color(text_color)

# Changing fill color of the cursor


my_turtle_cursor.goto(x, y)
my_turtle_cursor.begin_fill()
my_turtle_cursor.pendown()

my_turtle_cursor.write("Happy", font=("sans-serif", 26, "bold"))

my_turtle_cursor.getscreen().update()

def write_birthday_inside_circle(text_color, x, y):


my_turtle_cursor.penup()
# Changing color of our cursor
my_turtle_cursor.color(text_color)

# Changing fill color of the cursor


my_turtle_cursor.goto(x, y)
my_turtle_cursor.begin_fill()
my_turtle_cursor.pendown()

my_turtle_cursor.write("Birthday", font=("sans-serif", 26, "bold"))

my_turtle_cursor.getscreen().update()

def draw_stick(fill_color, border_color, x, y):


my_turtle_cursor.penup()
my_turtle_cursor.pensize(3)

# Changing color of our cursor


my_turtle_cursor.color(border_color)

# Changing fill color of the cursor


my_turtle_cursor.fillcolor(fill_color)
my_turtle_cursor.goto(x, y)
my_turtle_cursor.begin_fill()
my_turtle_cursor.pendown()
my_turtle_cursor.left(180)
my_turtle_cursor.forward(200)
my_turtle_cursor.end_fill()
my_turtle_cursor.getscreen().update()

# Function to draw topping of our cake


def draw_toppings_on_cake(fill_color, border_color, x, y, radius):
my_turtle_cursor.penup()

# Changing color of our cursor


my_turtle_cursor.color(border_color)

# Changing fill color of the cursor


my_turtle_cursor.fillcolor(fill_color)
my_turtle_cursor.goto(x, y)
my_turtle_cursor.pendown()
my_turtle_cursor.begin_fill()

# Drawing a circle using circle function


my_turtle_cursor.forward(10)
my_turtle_cursor.left(90)
my_turtle_cursor.circle(radius, extent = 180)
my_turtle_cursor.left(90)
my_turtle_cursor.forward(10)
my_turtle_cursor.end_fill()
my_turtle_cursor.getscreen().update()

# Creating a Function to draw different layers of a cake


def draw_layer_of_the_cake(fill_color, border_color, cursor_size, x, y, width, height):
my_turtle_cursor.hideturtle()
my_turtle_cursor.penup()

my_turtle_cursor.pensize(cursor_size)
# Changing color of our cursor
my_turtle_cursor.color(border_color)
# Changing fill color of the cursor
my_turtle_cursor.fillcolor(fill_color)
my_turtle_cursor.goto(x, y)
my_turtle_cursor.pendown()

# Starting the cursor to fill color


my_turtle_cursor.begin_fill()

for i in range(2):
my_turtle_cursor.forward(width)
my_turtle_cursor.left(90)
my_turtle_cursor.forward(height)
my_turtle_cursor.left(90)

my_turtle_cursor.end_fill()
my_turtle_cursor.setheading(0)
my_turtle_cursor.getscreen().update()

# Changing the background color of our canvas


my_turtle_screen.bgcolor("#FFFDD0")

# # Creating an empty list of different parts of our cake


parts_of_cake = []
parts_of_cake.append(["#A020F0", "#000000", 3, 30])
parts_of_cake.append(["#55FF55", "#000000", 3, 20])
parts_of_cake.append(["#B87333", "#000000", 3, 60])

# drawing an plate for our cake using draw_layer_of_the_cake() function


draw_layer_of_the_cake("#FFC0CB", "#000000", 3, -220, y_coordinate - 70, 400, 10)

# Drawing different parts of our cake


for parts in parts_of_cake:
draw_layer_of_the_cake(parts[0], parts[1], parts[2], -135, y_coordinate - 60, 240, parts[3])
y_coordinate += parts[3]
# drawing top topping of our cake
draw_toppings_on_cake("#C20067", "#000000", -120, y_coordinate - 60, 10)
draw_toppings_on_cake("#FFFF00", "#000000", -80, y_coordinate - 60, 10)
draw_toppings_on_cake("#FF0000", "#000000", 25, y_coordinate - 60, 10)
draw_toppings_on_cake("#0000FF", "#000000", 59, y_coordinate - 60, 10)

# drawing middle topping of our cakes


draw_toppings_on_cake("#FFA500", "#000000", -135, y_coordinate - 80, 10)
draw_toppings_on_cake("#E4E6EB", "#000000", -135, y_coordinate - 100, 10)
draw_toppings_on_cake("#FFA500", "#000000", -135, y_coordinate - 120, 10)
draw_toppings_on_cake("#181A18", "#000000", -80, y_coordinate - 80, 10)
draw_toppings_on_cake("#0000FF", "#000000", -65, y_coordinate - 110, 10)
draw_toppings_on_cake("#FFD700", "#000000", -95, y_coordinate - 140, 10)
draw_toppings_on_cake("#181A18", "#000000", 10, y_coordinate - 80, 10)
draw_toppings_on_cake("#E4E6EB", "#000000", -20, y_coordinate - 110, 10)
draw_toppings_on_cake("#181418", "#000000", 35, y_coordinate - 140, 10)
draw_toppings_on_cake("#FFA500", "#000000", 75, y_coordinate - 80, 10)
draw_toppings_on_cake("#E4E6EB", "#000000", 75, y_coordinate - 110, 10)
draw_toppings_on_cake("#FFD700", "#000000", 75, y_coordinate - 140, 10)

# Drawing candle on of our cake using draw_candle_for_cake() function


draw_candle_for_cake("#FFF44F", "#000000", -40, y_coordinate - 60)

# Drawing stick on top og uou candle


draw_stick_on_candle("#181A18", -26, y_coordinate + 15, 7)

# Drawing a stick for writing Happy Birthday


draw_stick("#181A18", "#181A18", 0, y_coordinate - 60)

# Drawing a circle on top of stick


draw_circle_on_top_of_stick("#181A18", "#FFFDD0", 100, y_coordinate + 235, 100)

# Writing "Happy" inside of our circle


write_happy_inside_circle("#000000", -70, y_coordinate + 240)

# Writing "Birthday" inside of our circle


write_birthday_inside_circle("#000000", -80, y_coordinate + 190)

# Calling done function at the end


[Link]()
from turtle import *

# Doraemon with Python Turtle


def ankur(x, y):
penup()
goto(x, y)
pendown()

def aankha():
fillcolor("#ffffff")
begin_fill()

tracer(False)
a = 2.5
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a -= 0.05
lt(3)
fd(a)
else:
a += 0.05
lt(3)
fd(a)
tracer(True)
end_fill()

def daari():
ankur(-32, 135)
seth(165)
fd(60)

ankur(-32, 125)
seth(180)
fd(60)

ankur(-32, 115)
seth(193)
fd(60)

ankur(37, 135)
seth(15)
fd(60)

ankur(37, 125)
seth(0)
fd(60)

ankur(37, 115)
seth(-13)
fd(60)

def mukh():
ankur(5, 148)
seth(270)
fd(100)
seth(0)
circle(120, 50)
seth(230)
circle(-120, 100)

def muflar():
fillcolor('#e70010')
begin_fill()
seth(0)
fd(200)
circle(-5, 90)
fd(10)
circle(-5, 90)
fd(207)
circle(-5, 90)
fd(10)
circle(-5, 90)
end_fill()

def nak():
ankur(-10, 158)
seth(315)
fillcolor('#e70010')
begin_fill()
circle(20)
end_fill()

def black_aankha():
seth(0)
ankur(-20, 195)
fillcolor('#000000')
begin_fill()
circle(13)
end_fill()

pensize(6)
ankur(20, 205)
seth(75)
circle(-10, 150)
pensize(3)

ankur(-17, 200)
seth(0)
fillcolor('#ffffff')
begin_fill()
circle(5)
end_fill()
ankur(0, 0)

def face():
fd(183)
lt(45)
fillcolor('#ffffff')
begin_fill()
circle(120, 100)
seth(180)
# print(pos())
fd(121)
pendown()
seth(215)
circle(120, 100)
end_fill()
ankur(63.56, 218.24)
seth(90)
aankha()
seth(180)
penup()
fd(60)
pendown()
seth(90)
aankha()
penup()
seth(180)
fd(64)

def taauko():
penup()
circle(150, 40)
pendown()
fillcolor('#00a0de')
begin_fill()
circle(150, 280)
end_fill()

def Doraemon():
taauko()

muflar()

face()

nak()

mukh()

daari()
ankur(0, 0)

seth(0)
penup()
circle(150, 50)
pendown()
seth(30)
fd(40)
seth(70)
circle(-30, 270)

fillcolor('#00a0de')
begin_fill()

seth(230)
fd(80)
seth(90)
circle(1000, 1)
seth(-89)
circle(-1000, 10)

# print(pos())

seth(180)
fd(70)
seth(90)
circle(30, 180)
seth(180)
fd(70)

# print(pos())
seth(100)
circle(-1000, 9)

seth(-86)
circle(1000, 2)
seth(230)
fd(40)

# print(pos())

circle(-30, 230)
seth(45)
fd(81)
seth(0)
fd(203)
circle(5, 90)
fd(10)
circle(5, 90)
fd(7)
seth(40)
circle(150, 10)
seth(30)
fd(40)
end_fill()

seth(70)
fillcolor('#ffffff')
begin_fill()
circle(-30)
end_fill()

ankur(103.74, -182.59)
seth(0)
fillcolor('#ffffff')
begin_fill()
fd(15)
circle(-15, 180)
fd(90)
circle(-15, 180)
fd(10)
end_fill()

ankur(-96.26, -182.59)
seth(180)
fillcolor('#ffffff')
begin_fill()
fd(15)
circle(15, 180)
fd(90)
circle(15, 180)
fd(10)
end_fill()

ankur(-133.97, -91.81)
seth(50)
fillcolor('#ffffff')
begin_fill()
circle(30)
end_fill()
# Doraemon with Python Turtle

ankur(-103.42, 15.09)
seth(0)
fd(38)
seth(230)
begin_fill()
circle(90, 260)
end_fill()

ankur(5, -40)
seth(0)
fd(70)
seth(-90)
circle(-70, 180)
seth(0)
fd(70)

ankur(-103.42, 15.09)
fd(90)
seth(70)
fillcolor('#ffd200')
# print(pos())
begin_fill()
circle(-20)
end_fill()
seth(170)
fillcolor('#ffd200')
begin_fill()
circle(-2, 180)
seth(10)
circle(-100, 22)
circle(-2, 180)
seth(180 - 10)
circle(100, 22)
end_fill()
goto(-13.42, 15.09)
seth(250)
circle(20, 110)
seth(90)
fd(15)
dot(10)
ankur(0, -150)
black_aankha()

if __name__ == '__main__':
screensize(800, 600, "#f0f0f0")
pensize(3)
speed(9)
Doraemon()
ankur(100, -300)
write('by Ankur Gajurel', font=("Bradley Hand ITC", 30, "bold"))
mainloop()

You might also like