Tag Archives: awesome design using python turtle

RACE track animation with python turtle

Race track Animation in python turtle 🐢

Introduction

Turtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed by Wally Feurzeig, Seymour Papert and Cynthia Solomon in 1967.

Turtle is a special feathers of Python. Using Turtle, we can easily draw in a drawing board.First we import the turtle module. Then create a window, next we create turtle object and using turtle method we can draw in the drawing board.

Follow us on

Code

# required modules

from turtle import *

from random import randint

# classic shape turtle

speed(0)
penup()

goto(-140, 140)

# racing track

for step in range(15):

write(step, align =’center’)

right(90)

for num in range(8):

penup()

forward(10)

pendown()

forward(10)

penup()

backward(160)

left(90)

forward(40)

# first player details

player_1 = Turtle()

player_1.color(‘red’)

player_1.shape(‘turtle’)

# first player proceeds to racing track
player_1.penup()

player_1.goto(-160, 100)
player_1.pendown()

# 360 degree turn

for turn in range(10):

player_1.right(36)

# second player details

player_2 = Turtle()

player_2.color(‘blue’)

player_2.shape(‘turtle’)

# second player enters in the racing track
player_2.penup()

player_2.goto(-160, 70)
player_2.pendown()

# 360 degree turn

for turn in range(72):

player_2.left(5)

# third player details

player_3 = Turtle()

player_3.shape(‘turtle’)

player_3.color(‘green’)

# third player enters in the racing track
player_3.penup()

player_3.goto(-160, 40)
player_3.pendown()

# 360 degree turn

for turn in range(60):

player_3.right(6)

# fourth player details

player_4 = Turtle()

player_4.shape(‘turtle’)

player_4.color(‘orange’)

# fourth player enters in the racing track
player_4.penup()

player_4.goto(-160, 10)
player_4.pendown()

# 360 degree turn

for turn in range(30):

player_4.left(12)

# turtles run at random speeds

for turn in range(100):

player_1.forward(randint(1, 10))

player_2.forward(randint(1, 10))

player_3.forward(randint(1, 10))

player_4.forward(randint(1, 10))

Output

Follow us on

Download as file 🔻

Drawing awesome design with python turtle

Python turtle design – small twinches

Introduction

Turtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed by Wally Feurzeig, Seymour Papert and Cynthia Solomon in 1967.

Turtle is a special feathers of Python. Using Turtle, we can easily draw in a drawing board.First we import the turtle module. Then create a window, next we create turtle object and using turtle method we can draw in the drawing board.

Follow us on

Code

#…..54:30……#
#………………..#
import turtle as tu
roo = tu.Turtle() # Turtle object
wn = tu.Screen() # Screen Object
wn.bgcolor(“black”) # Screen Bg color
wn.title(“Fractal Tree Pattern”)
roo.left(90) # moving the turtle 90 degrees towards left
roo.speed(20) # setting the speed of the turtle

def draw(l): # recursive function taking length ‘l’ as argument
if (l < 10):
return
else:

roo.pensize(2) # Setting Pensize
roo.pencolor(“yellow”) # Setting Pencolor as yellow
roo.forward(l) # moving turtle forward by ‘l’
roo.left(30) # moving the turtle 30 degrees towards left
draw(3 * l / 4) # drawing a fractal on the left of the turtle object ‘roo’ with 3/4th of its length
roo.right(60) # moving the turtle 60 degrees towards right
draw(3 * l / 4) # drawing a fractal on the right of the turtle object ‘roo’ with 3/4th of its length
roo.left(30) # moving the turtle 30 degrees towards left
roo.pensize(2)
roo.backward(l) # returning the turtle back to its original psition

draw(20) # drawing 20 times

roo.right(90)
roo.speed(2000)

# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(2)
roo.pencolor(“magenta”) # magenta
roo.forward(l)
roo.left(30)
draw(3 * l / 4)
roo.right(60)
draw(3 * l / 4)
roo.left(30)
roo.pensize(2)
roo.backward(l)

draw(20)

roo.left(270)
roo.speed(2000)

# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(2)
roo.pencolor(“red”) # red
roo.forward(l)
roo.left(30)
draw(3 * l / 4)
roo.right(60)
draw(3 * l / 4)
roo.left(30)
roo.pensize(2)
roo.backward(l)

draw(20)

roo.right(90)
roo.speed(2000)

# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(2)
roo.pencolor(‘#FFF8DC’) # white
roo.forward(l)
roo.left(30)
draw(3 * l / 4)
roo.right(60)
draw(3 * l / 4)
roo.left(30)
roo.pensize(2)
roo.backward(l)

draw(20)

########################################################

def draw(l):
if (l < 10):
return
else:

roo.pensize(3)
roo.pencolor(“lightgreen”) # lightgreen
roo.forward(l)
roo.left(30)
draw(4 * l / 5)
roo.right(60)
draw(4 * l / 5)
roo.left(30)
roo.pensize(3)
roo.backward(l)

draw(40)

roo.right(90)
roo.speed(2000)

# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(3)
roo.pencolor(“red”) # red
roo.forward(l)
roo.left(30)
draw(4 * l / 5)
roo.right(60)
draw(4 * l / 5)
roo.left(30)
roo.pensize(3)
roo.backward(l)

draw(40)

roo.left(270)
roo.speed(2000)

# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(3)
roo.pencolor(“yellow”) # yellow
roo.forward(l)
roo.left(30)
draw(4 * l / 5)
roo.right(60)
draw(4 * l / 5)
roo.left(30)
roo.pensize(3)
roo.backward(l)

draw(40)

roo.right(90)
roo.speed(2000)

# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(3)
roo.pencolor(‘#FFF8DC’) # white
roo.forward(l)
roo.left(30)
draw(4 * l / 5)
roo.right(60)
draw(4 * l / 5)
roo.left(30)
roo.pensize(3)
roo.backward(l)

draw(40)

########################################################
def draw(l):
if (l < 10):
return
else:

roo.pensize(2)
roo.pencolor(“cyan”) # cyan
roo.forward(l)
roo.left(30)
draw(6 * l / 7)
roo.right(60)
draw(6 * l / 7)
roo.left(30)
roo.pensize(2)
roo.backward(l)

draw(60)

roo.right(90)
roo.speed(2000)

# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(2)
roo.pencolor(“yellow”) # yellow
roo.forward(l)
roo.left(30)
draw(6 * l / 7)
roo.right(60)
draw(6 * l / 7)
roo.left(30)
roo.pensize(2)
roo.backward(l)

draw(60)

roo.left(270)
roo.speed(2000)

# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(2)
roo.pencolor(“magenta”) # magenta
roo.forward(l)
roo.left(30)
draw(6 * l / 7)
roo.right(60)
draw(6 * l / 7)
roo.left(30)
roo.pensize(2)
roo.backward(l)

draw(60)

roo.right(90)
roo.speed(2000)

# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(2)
roo.pencolor(‘#FFF8DC’) # white
roo.forward(l)
roo.left(30)
draw(6 * l / 7)
roo.right(60)
draw(6 * l / 7)
roo.left(30)
roo.pensize(2)
roo.backward(l)

draw(60)
wn.exitonclick()

Output

Follow us on

Download as file 🔻