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 Indian flag with python turtle

Indian flag 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

import turtle
from turtle import *
# screen for output
screen = turtle.Screen()
# Defining a turtle Instance
t = turtle.Turtle()
speed(1)
t.pensize(5)
# initially penup()
t.penup()
t.goto(-200, 125)
t.pendown()
# Orange Rectangle
#white rectangle
t.color(“orange”)
t.begin_fill()
t.forward(400)
t.right(90)
t.forward(84)
t.right(90)
t.forward(400)
t.end_fill()
t.left(90)
t.forward(84)
# Green Rectangle
t.color(“green”)
t.begin_fill()
t.forward(84)
t.left(90)
t.forward(400)
t.left(90)
t.forward(84)
t.end_fill()
# Big Blue Circle
t.penup()
t.goto(35, 0)
t.pendown()
t.color(“navy”)
t.begin_fill()
t.circle(35)
t.end_fill()
# Big White Circle
t.penup()
t.goto(30, 0)
t.pendown()
t.color(“white”)
t.begin_fill()
t.circle(30)
t.end_fill()
t.penup()
t.goto(-27, -4)
t.pendown()
# Small Blue Circle
t.color(“navy”)
t.penup()
t.goto(10, 0)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()
#The spokes of the Indian Flag
t.penup()
t.goto(0, 0)
t.pendown()
t.pensize(1)
for i in range(24):
t.forward(30)
t.backward(30)
t.left(15)
t.color(“Brown”)
t.pensize(10)
t.penup()
t.goto(-200,125)
t.right(180)
t.pendown()
t.forward(800)

Output

Follow us on

Download as file 🔻

Technology and programming

Design a site like this with WordPress.com
Get started