-
Notifications
You must be signed in to change notification settings - Fork 0
/
night.py
81 lines (55 loc) · 1.24 KB
/
night.py
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
import turtle
import random
win = turtle.Screen()
win.setup(width=800,height=600)
win.bgcolor('black')
colors = ['red','blue','orange','yellow','magenta','purple','peru','ivory','dark orange']
moon = turtle.Turtle()
moon.hideturtle()
star = turtle.Turtle()
star.speed(0)
star.hideturtle()
text = turtle.Turtle()
text.speed(6)
text.hideturtle()
def draw_moon(pos,color):
x,y = pos
moon.color(color)
moon.begin_fill()
moon.penup()
moon.goto(x,y)
moon.pendown()
moon.circle(50)
moon.end_fill()
def stars(x,y,color,length):
star.color(color)
star.penup()
star.goto(x,y)
star.pendown()
star.begin_fill()
for i in range(5):
star.forward(length)
star.right(144)
star.forward(length)
star.end_fill()
def random_pos():
return random.randint(-390,390), random.randint(-200,290)
def random_length():
return random.randint(5,25)
def write_text(color):
text.color(color)
text.penup()
text.goto(-180,-270)
text.pendown()
style = ('Stencil Std Bold',50,'normal')
text.write('Good Night',font=style,move=True)
draw_moon((-300,170),'white')
draw_moon((-278,183),'black')
while True:
color = random.choice(colors)
x ,y = random_pos()
length = random_length()
stars(x,y,color,length)
write_text(color)
# moon.clear()
turtle.done()