## Blog Pages

Showing posts with label turtle. Show all posts
Showing posts with label turtle. Show all posts

### memory game

from random import *

from turtle import *

screen = Screen()

screen.bgcolor("yellow")

def Square(x, y):

up()

goto(x, y)

down()

color('white', 'red')

begin_fill()

for count in range(4):

forward(50)

left(90)

end_fill()

def numbers(x, y):

return int((x + 200) // 50 + ((y + 200) // 50) * 8)

def Coordinates(count):

return (count % 8) * 50 - 200, (count // 8) * 50 - 200

def click(x, y):

spot = numbers(x, y)

mark = state['mark']

if mark is None or mark == spot or tiles[mark] != tiles[spot]:

state['mark'] = spot

else:

hide[spot] = False

hide[mark] = False

state['mark'] = None

def draw():

clear()

goto(0, 0)

stamp()

for count in range(64):

if hide[count]:

x, y = Coordinates(count)

Square(x, y)

mark = state['mark']

if mark is not None and hide[mark]:

x, y = Coordinates(mark)

up()

goto(x + 2, y)

color('white')

write(tiles[mark], font=('Arial', 30, 'normal'))

update()

ontimer(draw, 10)

tiles = list(range(32)) * 2

state = {'mark': None}

hide = [True] * 64

shuffle(tiles)

tracer(False)

onscreenclick(click)

draw()

done()

### Turtle moving circle

import turtle

def moving_object(move):

move.fillcolor('Purple')

move.begin_fill()

move.circle(10)

move.end_fill()

if __name__ == "__main__" :

screen = turtle.Screen()

screen.setup(600,600)

# screen background color

screen.bgcolor('white')

screen.tracer(0)

move = turtle.Turtle()

move.color('Purple')

move.speed(0)

move.width(2)

move.hideturtle()

move.penup()

move.goto(-250, 0)

move.pendown()

while True :

move.clear()

moving_object(move)

screen.update()

move.forward(0.5)

### Python Logo Using Turtle in Python

import turtle

turtle_cursor = turtle.Turtle()

turtle_screen = turtle.Screen()

def pause():

turtle_cursor.speed(2)

for i in range(100):

turtle_cursor.left(90)

def upper_dot_of_python_logo():

turtle_cursor.penup()

turtle_cursor.right(90)

turtle_cursor.forward(160)

turtle_cursor.left(90)

turtle_cursor.forward(70)

turtle_cursor.pencolor("white")

turtle_cursor.dot(35)

def second_position():

turtle_cursor.penup()

turtle_cursor.forward(20)

turtle_cursor.right(90)

turtle_cursor.forward(10)

turtle_cursor.right(90)

turtle_cursor.pendown()

def half():

turtle_cursor.forward(50)

draw_side_curve_of_python_logo()

turtle_cursor.forward(90)

draw_first_left_curve_of_python_logo()

turtle_cursor.forward(40)

turtle_cursor.left(90)

turtle_cursor.forward(80)

turtle_cursor.right(90)

turtle_cursor.forward(10)

turtle_cursor.right(90)

turtle_cursor.forward(120)

draw_second_left_curve_of_python_logo()

turtle_cursor.forward(30)

turtle_cursor.left(90)

turtle_cursor.forward(50)

draw_right_curve_of_python_logo()

turtle_cursor.forward(40)

turtle_cursor.end_fill()

def lower_dot_of_python_logo():

turtle_cursor.left(90)

turtle_cursor.penup()

turtle_cursor.forward(310)

turtle_cursor.left(90)

turtle_cursor.forward(120)

turtle_cursor.pendown()

turtle_cursor.dot(35)

def draw_first_left_curve_of_python_logo():

draw_side_curve_of_python_logo()

turtle_cursor.forward(80)

draw_side_curve_of_python_logo()

def draw_second_left_curve_of_python_logo():

draw_side_curve_of_python_logo()

turtle_cursor.forward(90)

draw_side_curve_of_python_logo()

def draw_side_curve_of_python_logo():

for i in range(90):

turtle_cursor.left(1)

turtle_cursor.forward(1)

def draw_right_curve_of_python_logo():

for i in range(90):

turtle_cursor.right(1)

turtle_cursor.forward(1)

turtle_cursor.pensize(2)

turtle_cursor.speed(10)

turtle_cursor.pensize(2)

turtle_cursor.pencolor("black")

turtle_screen.bgcolor("white")

turtle_cursor.fillcolor("#306998")

turtle_cursor.begin_fill()

half()

turtle_cursor.end_fill()

second_position()

turtle_cursor.fillcolor("#FFD43B")

turtle_cursor.begin_fill()

half()

turtle_cursor.end_fill()

upper_dot_of_python_logo()

lower_dot_of_python_logo()

pause

### Spiral Square Mania with Turtle

import turtle as t

pen = t.Turtle()

pen.color("cyan")

pen.speed(0)

colors = ["green","black","orange","navy","green","black","orange","navy"]

def draw_square(color):

for side in range(4):

pen.forward(100)

pen.right(90)

for side in range(4):

pen.forward(50)

pen.right(90)

pen.penup()

pen.back(40)

pen.pendown()

for color in colors:

pen.color(color)

draw_square(color)

pen.forward(50)

pen.left(45)

pen.hideturtle()

t.done()

### Chess-Board using Turtle

import turtle

sc = turtle.Screen()

cb = turtle.Turtle()

def draw():

for i in range(4):

cb.forward(30)

cb.left(90)

cb.forward(30)

if __name__ == "__main__":

sc.setup(400, 600)

cb.speed(100)

for i in range(8):

cb.up()

cb.setpos(-100, 30 * i)

cb.down()

for j in range(8):

if (i + j) % 2 == 0:

col = 'black'

else:

col = 'white'

cb.fillcolor(col)

cb.begin_fill()

draw()

cb.end_fill()

cb.hideturtle()

turtle.done()

### Hexagons Turtle

import turtle

from random import randint

x = 20

y = 20

turtle.speed(100)

turtle.colormode(255)

def move(l, a):

turtle.right(a)

turtle.forward(l)

def hex():

turtle.pendown()

turtle.color( randint(0,255),randint(0,255),randint(0,255) )

turtle.begin_fill()

for i in range(6):

move(x,-60)

turtle.end_fill()

turtle.penup()

turtle.penup()

for z in range (y):

if z == 0:

hex()

move(x,-60)

move(x,-60)

move(x,-60)

move(0,180)

for i in range (6):

move(0,60)

for j in range (z+1):

hex()

move(x,-60)

move(x,60)

move(-x,0)

move(-x,60)

move(x,-120)

move(0,60)

turtle.exitonclick()

### Google Drive Logo Using Turtle

import turtle as t

t.hideturtle()

t.Screen().bgcolor("Black")

t.pencolor("white")

t.pensize(0)

t.begin_fill()

t.fillcolor('#4688F4')

t.forward(170)

t.left(60)

t.forward(50)

t.left(120)

t.forward(220)

t.left(120)

t.forward(50)

t.end_fill()

t.begin_fill()

t.fillcolor('#1FA463')

t.left(120)

t.forward(200)

t.left(120)

t.forward(50)

t.left(60)

t.forward(150)

t.left(60)

t.forward(50)

t.end_fill()

t.penup()

t.left(120)

t.forward(200)

t.left(120)

t.forward(50)

t.pendown()

t.begin_fill()

t.fillcolor('#FFD048')

t.left(125)

t.forward(160)

t.left(55)

t.forward(53)

t.left(126)

t.forward(163)

t.end_fill()

t.done()

### Javascript logo using turtle

import turtle

t=turtle.Turtle()

t.penup()

t.goto(-20,-70)

t.color("#F0DB4F","#F0DB4F")

t.begin_fill()

t.pendown()

t.left(165)

t.forward(100)

t.right(70)

t.forward(220)

t.forward(229)

t.penup()

t.goto(-20,-70)

t.pendown()

t.left(15)

t.forward(100)

t.left(70)

t.forward(229)

t.end_fill()

t.penup()

t.goto(-35,-20)

t.color("white","white")

t.pendown()

t.begin_fill()

t.forward(150)

t.left(90)

t.forward(20)

t.left(90)

t.forward(130)

t.left(75)

t.forward(40)

t.left(110)

t.forward(20)

t.penup()

t.goto(-35,-20)

t.left(75)

t.pendown()

t.forward(60)

t.end_fill()

t.penup()

t.color("yellow","yellow")

t.goto(-20,-55)

t.pendown()

t.begin_fill()

t.forward(215)

t.right(90)

t.forward(100)

t.right(95)

t.forward(195)

t.left(90)

t.end_fill()

t.penup()

t.color("white","white")

t.pensize(2)

t.goto(-10,-20)

t.begin_fill()

t.left(15)

t.pendown()

t.forward(65)

t.left(70)

t.forward(70)

t.left(90)

t.left(15)

t.forward(50)

t.right(100)

t.forward(50)

t.right(90)

t.forward(50)

t.left(85)

t.forward(20)

t.left(95)

t.forward(70)

t.left(90)

t.forward(90)

t.left(100)

t.forward(50)

t.right(105)

t.forward(37)

t.right(75)

t.forward(50)

t.left(85)

t.forward(20)

t.end_fill()

t.hideturtle()

turtle.done()

### Google Drive Logo Using Python Turtle

import turtle as t

t.hideturtle()

t.Screen().bgcolor("Black")

t.pencolor("white")

t.pensize(0)

t.begin_fill()

t.fillcolor('#4688F4')

t.forward(170)

t.left(60)

t.forward(50)

t.left(120)

t.forward(220)

t.left(120)

t.forward(50)

t.end_fill()

t.begin_fill()

t.fillcolor('#1FA463')

t.left(120)

t.forward(200)

t.left(120)

t.forward(50)

t.left(60)

t.forward(150)

t.left(60)

t.forward(50)

t.end_fill()

t.penup()

t.left(120)

t.forward(200)

t.left(120)

t.forward(50)

t.pendown()

t.begin_fill()

t.fillcolor('#FFD048')

t.left(125)

t.forward(160)

t.left(55)

t.forward(53)

t.left(126)

t.forward(163)

t.end_fill()

t.done()

### Draw Spider web using Python Turtle

import turtle as t

t.speed(2)

for i in range(6):

t.forward(150)

t.backward(150)

t.right(60)

side = 50

t.fillcolor("Orange")

t.begin_fill()

for i in range(15):

t.penup()

t.goto(0, 0)

t.pendown()

t.forward(side)

t.right(120)

for j in range(6):

t.forward(side-2)

t.right(60)

side = side - 10

t.end_fill()

turtle.done()

### Spotify logo using python turtle

import turtle as t

t.Screen().bgcolor("Black")

t.speed(15)

t.begin_fill()

t.fillcolor('#1DB954')

t.pencolor("#1DB954")

t.pensize(0)

t.circle(100)

t.end_fill()

t.penup()

t.goto(40,50)

t.pendown()

t.left(150)

t.forward(0)

t.pensize(15)

t.pencolor('black')

t.circle(80,60)

t.penup()

t.goto(50,85)

t.pendown()

t.pensize(17)

t.right(60)

t.forward(0)

t.circle(100,60)

t.penup()

t.goto(60,120)

t.pendown()

t.pensize(20)

t.right(60)

t.forward(0)

t.circle(120,60)

t.penup()

t.goto(130, 55)

t.pendown()

t.color("#1DB954")

t.write("Spotify", font=("Arial", 60, "bold"))

t.done()

### FB logo using turtle

from turtle import *

speed(10)

color("#0270d6")

Screen().bgcolor('black')

penup()

goto(0, 150)

pendown()

begin_fill()

forward(150)

circle(-50, 90)

forward(300)

circle(-50, 90)

forward(300)

circle(-50, 90)

forward(300)

circle(-50, 90)

forward(150)

end_fill()

color("white")

penup()

goto(140, 80)

pendown()

begin_fill()

right(180)

forward(50)

circle(80, 90)

forward(50)

right(90)

forward(80)

left(90)

forward(40)

left(90)

forward(80)

right(90)

forward(160)

left(90)

forward(55)

left(90)

forward(160)

right(90)

forward(70)

left(80)

forward(45)

left(100)

forward(80)

right(90)

forward(40)

circle(-40, 90)

forward(40)

left(90)

forward(45)

end_fill()

hideturtle()

done()

### Design with turtle

import turtle

turtle.speed(0)

turtle.bgcolor("black")

for i in range(15):

for colours in ("red", "magenta", "yellow", "orange", "blue", "green", "purple"):

turtle.color(colours)

turtle.pensize(3)

turtle.left(4)

turtle.forward(200)

turtle.left(90)

turtle.forward(200)

turtle.left(90)

turtle.forward(200)

turtle.left(90)

turtle.forward(200)

turtle.left(90)

### Draw Among Us Character with Turtle

import turtle

color1 =  'yellow'

color2 = ''

color3 = 'skyblue'

color4 = ''

s = turtle.getscreen()

t = turtle.Turtle()

def x():

t.pensize(20)

t.fillcolor(color1)

t.begin_fill()

t.right(90)

t.forward(50)

t.right(180)

t.circle(40, -180)

t.right(180)

t.forward(200)

t.right(180)

t.circle(100, -180)

t.backward(20)

t.left(15)

t.circle(500, -20)

t.backward(20)

t.circle(40, -180)

t.left(7)

t.backward(50)

t.up()

t.left(90)

t.forward(10)

t.right(90)

t.down()

t.right(240)

t.circle(50, -70)

t.end_fill()

def glass():

t.up()

t.right(230)

t.forward(100)

t.left(90)

t.forward(20)

t.right(90)

t.down()

t.fillcolor(color3)

t.begin_fill()

t.right(150)

t.circle(90, -55)

t.right(180)

t.forward(1)

t.right(180)

t.circle(10, -65)

t.right(180)

t.forward(110)

t.right(180)

t.circle(50, -190)

t.right(170)

t.forward(80)

t.right(180)

t.circle(45, -30)

t.end_fill()

def y():

t.up()

t.right(60)

t.forward(100)

t.right(90)

t.forward(75)

t.fillcolor(color1)

t.begin_fill()

t.down()

t.forward(30)

t.right(255)

t.circle(300, -30)

t.right(260)

t.forward(30)

t.end_fill()

x()

glass()

y()

turtle.done()

### Colored Hexagons Turtle

import turtle

from random import randint

x = 20

y = 20

turtle.speed(300)

turtle.colormode(255)

def move(l, a):

turtle.right(a)

turtle.forward(l)

def hex():

turtle.pendown()

turtle.color( randint(0,255),randint(0,255),randint(0,255) )

turtle.begin_fill()

for i in range(6):

move(x,-60)

turtle.end_fill()

turtle.penup()

turtle.penup()

for color in range (y):

if color == 0:

hex()

move(x,-60)

move(x,-60)

move(x,-60)

move(0,180)

for i in range (6):

move(0,60)

for j in range (color+1):

hex()

move(x,-60)

move(x,60)

move(-x,0)

move(-x,60)

move(x,-120)

move(0,60)

turtle.exitonclick()

### Square Mania

import turtle as t

pen = t.Turtle()

pen.color("cyan")

pen.speed(0)

colors = ["green","black","orange","navy","green","black","orange","navy"]

def draw_square(color):

for side in range(4):

pen.forward(100)

pen.right(90)

for side in range(4):

pen.forward(50)

pen.right(90)

pen.penup()

pen.back(40)

pen.pendown()

for color in colors:

pen.color(color)

draw_square(color)

pen.forward(50)

pen.left(45)

pen.hideturtle()

t.done()

### Turtle 3D cubes

import turtle

screen=turtle.Screen()

screen.setup(800,800)

trtl = turtle.Turtle()

screen.title("3-D CUBES")

trtl.penup()

trtl.setposition(0,0)

trtl.color('red')

def hexagon():

for i in range(6):

trtl.fd(50)

trtl.rt(60)

i = 1

while i < 7:

trtl.pendown()

hexagon()

trtl.right(60)

i = i + 1

### Spinner Game

from turtle import *

state = {'turn': 0}

def spinner():

clear()

angle = state['turn']/10

right(angle)

forward(100)

dot(120, 'red')

back(100)

right(120)

forward(100)

dot(120, 'green')

back(100)

right(120)

forward(100)

dot(120, 'blue')

back(100)

right(120)

update()

def animate():

if state['turn']>0:

state['turn']-=1

spinner()

ontimer(animate, 20)

def flick():

state['turn']+=10

setup(420, 420, 370, 0)

hideturtle()

tracer(False)

width(20)

onkey(flick, 'space')

listen()

animate()

done()

### Side look emoji using turtle

import turtle

my_pen = turtle.Turtle()

my_pen.color("#ffdd00")

my_pen.begin_fill()

my_pen.circle(100)

my_pen.fillcolor("#ffdd00")

my_pen.end_fill()

my_pen.home()

my_pen.goto(-40, 100)

my_pen.color("#555555")

my_pen.begin_fill()

my_pen.circle(15)

my_pen.color("#ffffff")

my_pen.end_fill()

my_pen.penup()

my_pen.goto(-48, 110)

my_pen.pendown()

my_pen.color("Black")

my_pen.begin_fill()

my_pen.circle(5)

my_pen.end_fill()

my_pen.penup()

my_pen.goto(40, 100)

my_pen.pendown()

my_pen.color("#555555")

my_pen.begin_fill()

my_pen.circle(15)

my_pen.color("#ffffff")

my_pen.end_fill()

my_pen.penup()

my_pen.goto(32, 110)

my_pen.pendown()

my_pen.color("Black")

my_pen.begin_fill()

my_pen.circle(5)

my_pen.end_fill()

my_pen.penup()

my_pen.goto(-20, 50)

my_pen.pendown()

my_pen.pensize(10)

my_pen.forward(40)

turtle.done()

### A clock dial using turtle

import turtle

screen=turtle.Screen()

trtl=turtle.Turtle()

screen.setup(620,620)

screen.bgcolor('black')

clr=['red','green','blue','yellow','purple']

trtl.pensize(4)

trtl.shape('turtle')

trtl.penup()

trtl.pencolor('red')

m=0

for i in range(12):

m=m+1

trtl.penup()

trtl.forward(150)

trtl.pendown()

trtl.forward(25)

trtl.penup()

trtl.forward(20)

trtl.write(str(m),align="center",font=("Arial", 12, "normal"))

if m==12:

m=0

trtl.home()

trtl.home()

trtl.setpos(0,-250)

trtl.pendown()

trtl.pensize(10)

trtl.pencolor('blue')

trtl.circle(250)

trtl.penup()

trtl.setpos(150,-270)

trtl.pendown()

trtl.ht()