forked from anuragrana/Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindia_flag_turtle.py
More file actions
106 lines (89 loc) · 2.67 KB
/
india_flag_turtle.py
File metadata and controls
106 lines (89 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#
# Python script to wish Merry Christmas using turtle.
# Author - https://www.pythoncircle.com
#
import turtle
import time
# create a screen
screen = turtle.getscreen()
# set background color of screen
screen.bgcolor("#b3daff")
# set tile of screen
screen.title("Indian Flag - https://www.pythoncircle.com")
# "Yesterday is history, tomorrow is a mystery,
# but today is a gift. That is why it is called the present.”
# — Oogway to Po, under the peach tree, Kung Fu Panda Movie
oogway = turtle.Turtle()
# set the cursor/turtle speed. Higher value, faster is the turtle
oogway.speed(100)
oogway.penup()
# decide the shape of cursor/turtle
oogway.shape("turtle")
# flag height to width ratio is 2:3
flag_height = 300
flag_width = 450
# starting points
# start from the first quardant, half of flag width and half of flag height
start_x = -225
start_y = 150
# For saffron, white and green stripes. each strip width will be flag_height/3 = 100
stripe_height = flag_height/3
stripe_width = flag_width
# Radius of Ashok Chakra, half of white stripe
chakra_radius = stripe_height / 2
def draw_fill_rectangle(x, y, height, width, color):
oogway.goto(x,y)
oogway.pendown()
oogway.color(color)
oogway.begin_fill()
oogway.forward(width)
oogway.right(90)
oogway.forward(height)
oogway.right(90)
oogway.forward(width)
oogway.right(90)
oogway.forward(height)
oogway.right(90)
oogway.end_fill()
oogway.penup()
# this function is used to create 3 stripes
def draw_stripes():
x = start_x
y = start_y
# we need to draw total 3 stripes, 1 saffron, 1 white and 1 green
draw_fill_rectangle(x, y, stripe_height, stripe_width, "#FF9933")
# decrease value of y by stripe_height
y = y - stripe_height
# create middle white stripe
draw_fill_rectangle(x, y, stripe_height, stripe_width, "white")
y = y - stripe_height
# create last green stripe
draw_fill_rectangle(x, y, stripe_height, stripe_width, '#138808')
y = y - stripe_height
def draw_chakra():
oogway.speed(1)
oogway.goto(0,0)
color = "#000080" # navy blue
oogway.penup()
oogway.color(color)
oogway.fillcolor(color)
oogway.goto(0, 0 - chakra_radius)
oogway.pendown()
oogway.circle(chakra_radius)
# draw 24 spikes in chakra
for _ in range(24):
oogway.penup()
oogway.goto(0,0)
oogway.left(15)
oogway.pendown()
oogway.forward(chakra_radius)
# start after 5 seconds.
time.sleep(0)
# draw 3 stripes
draw_stripes()
# draw squares to hold stars
draw_chakra()
# hide the cursor/turtle
oogway.hideturtle()
# keep holding the screen until closed manually
screen.mainloop()