Saturday, 11 November 2023

Happy Diwali using Python Turtle

 


import turtle

s = turtle.Screen()

t = turtle.Turtle()

def move_to(x,y):

    t.penup()

    t.goto(x,y)

    t.pendown()

def draw_rectangle(a,b):

    t.begin_fill()

    t.forward(a)

    t.left(90)

    t.forward(b)

    t.left(90)

    t.forward(a)

    t.left(90)

    t.forward(b)

    t.end_fill()

    t.speed(10)

t.color("red")

move_to(-500,200)

draw_rectangle(10,100)

move_to(-490,250)

t.left(90)

draw_rectangle(80,10)

move_to(-410,200)

t.left(90)

draw_rectangle(10,100)

move_to(-380,200)

t.left(60)

t.color("yellow")

draw_rectangle(10,122)

move_to(-275,198)

t.left(145)

draw_rectangle(10,110)

move_to(-350,230)

t.left(335)

draw_rectangle(10,63)

move_to(-240,198)

t.left(270)

t.color("green")

draw_rectangle(100,10)

move_to(-240,288)

draw_rectangle(50,10)

move_to(-190,288)

draw_rectangle(40,10)

move_to(-190,248)

draw_rectangle(50,10)

move_to(-160,198)

t.color("violet")

draw_rectangle(100,10)

move_to(-160,288)

draw_rectangle(50,10)

move_to(-110,288)

draw_rectangle(40,10)

move_to(-110,248)

draw_rectangle(50,10)

move_to(-80,198)

t.left(320)

t.color("orange")

draw_rectangle(120,10)

move_to(-100,295)

draw_rectangle(68,10)

move_to(-500,80)

t.left(40)

t.color("blue")

draw_rectangle(100,10)

t.left(180)

move_to(-490,70)

draw_rectangle(50,10)

t.left(90)

t.fd(50)

t.right(90)

draw_rectangle(80,10)

t.left(90)

t.fd(80)

t.left(270)

draw_rectangle(50,10)

move_to(-400,80)

t.left(180)

t.color("pink")

draw_rectangle(100,10)

move_to(-220,70)

t.left(60)

t.color("brown")

draw_rectangle(100,10)

t.left(300)

move_to(-370,70)

t.right(152)

draw_rectangle(100,10)

t.left(152)

move_to(-290,10)

t.right(45)

draw_rectangle(40,10)

t.right(3)

draw_rectangle(40,10)

move_to(-200,-15)

t.left(200)

t.color("darkgreen")

draw_rectangle(10,110)

move_to(-95,-20)

t.left(145)

draw_rectangle(10,114)

move_to(-175,25)

t.left(333)

draw_rectangle(10,63)

move_to(-70,79)

t.left(90)

t.color("skyblue")

draw_rectangle(101,10)

move_to(-60,-22)

t.left(180)

draw_rectangle(80,10)

move_to(50,-22)

t.left(180)

t.color("black")

draw_rectangle(100,10)

move_to(300,150)

t.color("red")

angle=0

for i in range(20):

    t.fd(50)

    move_to(300,150)

    angle+=18

    t.left(angle)

move_to(450,150)

t.color("blue")

angle=0

for i in range(20):

    t.fd(50)

    angle+=18

    t.left(angle)

    move_to(450,150)

move_to(375,300)

t.color("green")

angle=0

for i in range(20):

    t.fd(50)

    angle+=18

    t.left(angle)

    move_to(375,300)

move_to(375,-300)

t.color("black")

angle=0

for i in range(20):

    t.fd(50)

    angle+=18

    t.left(angle)

    move_to(375,-300)

move_to(150,-150)

t.color("violet")

angle=0

for i in range(20):

    t.fd(50)

    angle+=18

    t.left(angle)

    move_to(150,-150)

move_to(450,-150)

t.color("brown")

angle=0

for i in range(20):

    t.fd(50)

    angle+=18

    t.left(angle)

    move_to(450,-150)

move_to(-200,-300)

t.color("green")

angle=0

for i in range(20):

    t.fd(50)

    angle+=18

    t.left(angle)

    move_to(-200,-300)

move_to(125,0)

t.color("yellow")

angle=0

for i in range(20):

    t.fd(50)

    angle+=18

    t.left(angle)

    move_to(125,0)

t.color("pink")

angle=0

move_to(-100,-200)

for i in range(20):

    t.fd(50)

    angle+=18

    t.left(angle)

    move_to(-100,-200)

t.color("lightgreen")

angle=0

move_to(300,0)

for i in range(20):

    t.fd(50)

    angle+=18

    t.left(angle)

    move_to(300,0)

t.color("skyblue")

angle=0

move_to(-500,-240)

for i in range(20):

    t.fd(50)

    angle+=18

    t.left(angle)

    move_to(-500,-240)

t.color("orange")

angle=0

move_to(-350,-170)

for i in range(20):

    t.fd(50)

    angle+=18

    t.left(angle)

    move_to(-350,-170)

t.color("black")

angle=0

move_to(500,20)

for i in range(20):

    t.fd(50)

    angle+=18

    t.left(angle)

    move_to(500,20)

    #clcoding.com

0 Comments:

Post a Comment

Popular Posts

Categories

AI (33) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (146) C (77) C# (12) C++ (82) Course (67) Coursera (198) Cybersecurity (24) data management (11) Data Science (106) Data Strucures (8) Deep Learning (13) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (21) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (46) Meta (18) MICHIGAN (5) microsoft (4) Nvidia (1) Pandas (3) PHP (20) Projects (29) Python (893) Python Coding Challenge (285) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (42) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses