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

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.setheading(90)

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.setheading(-30*i+60)

      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()

Turtle race using python

import turtle

from random import *

from turtle import *

penup()

goto(-140,140)

for sp in range(15): 

  write(sp)

  right(90)

  forward(10)

  pendown()

  forward(150)

  penup()

  backward(160)

  left(90)

  forward(20)

x = Turtle() 

x.color('green') 

x.shape('turtle') 

x.penup() 

x.goto(-160,100) 

x.pendown() 

y = Turtle() 

y.color('red') 

y.shape('turtle') 

y.penup() 

y.goto(-160,80) 

y.pendown() 

turtlee = Turtle() 

turtlee.color('blue') 

turtlee.shape('turtle') 

turtlee.penup() 

turtlee.goto(-160,60) 

turtlee.pendown() 

for turn in range(100): 

  x.forward(randint(1,5)) 

  y.forward(randint(1,5)) 

  turtlee.forward(randint(1,5)) 

turtle.done()

Program to create infinity using turtle

from turtle import *

bgcolor("black")

color("yellow")

speed(11)

right(45)

for i in range(150):

circle(30)

if 7<i<62:

left(5)

if 80<i<133:

right(5)

if i<80:

forward(10)

else:

forward(5)

Generate Captcha Using Python


from captcha.image import ImageCaptcha

image = ImageCaptcha(width = 280, height = 90)

captcha_text = 'python'

data = image.generate(captcha_text)

image.write(captcha_text,'CAPTCHA.png')


Drawing Corona Virus Using Turtle

from turtle import *

color('green')

bgcolor('black')

speed(10)

hideturtle()

b = 0

while b < 200:

right( b)

forward(b * 3)

b = b + 1

PROGRAM TO CREATE INSTAGRAM LOGO IN PYTHON TURTLE

from turtle import  *

speed(5)

def om(x,y):

    penup()

    goto(x,y)

    pendown()

def om1(x,y,f,c,c1,c2):

    color(c)

    om(x,y)

    begin_fill()

    for i in range(4):

        forward(f)

        circle(c1,c2)

    end_fill()

def om2(c,x,y,c1):

    color(c)

    begin_fill()

    om(x, y)

    circle(c1)

    end_fill()


om1(-150,-120,350,"black",20,90)

om1(-110,-70,260,"white",20,90)

om1(-90,-50,220,"black",20,90)

om2("white",20,10,70)

om2("black",20,30,50)

om2("white",110,160,15)


color("black")

om(-120,-180)

write("INSTAGRAM",font=("Helvetica",40,"bold"))

hideturtle()

done()

Plotting Star Using Turtle

import turtle

s = turtle.Turtle()

s.right(75)

s.forward(100)

for i in range(4):

s.right(144)

s.forward(100)

turtle.done()


Colorful Spiral Web Using Turtle Graphics in Python

import turtle

colors = ['red', 'yellow', 'green', 'purple', 'blue', 'orange']

s= turtle.Pen()

s.speed(10)

turtle.bgcolor("black")

for x in range(200):

s.pencolor(colors[x%6]) 

s.width(x/100 + 1) 

s.forward(x) 

s.left(59) 

turtle.done()

s.speed(20)

turtle.bgcolor("black") 

for x in range(200):

s.pencolor(colors[x%6]) 

s.width(x/100 + 1) 

s.forward(x) 

s.left(59) 

turtle.done()