-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdraw_star_line.py
More file actions
51 lines (36 loc) · 809 Bytes
/
draw_star_line.py
File metadata and controls
51 lines (36 loc) · 809 Bytes
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
import turtle
import random
screen = turtle.Screen()
screen.screensize(500, 500)
t = turtle.Turtle()
t.shape("turtle")
def getrgb():
r, g, b = 0, 0, 0
r = random.random()
g = random.random()
b = random.random()
return (r, g, b)
def star(length):
r, g, b = getrgb()
t.pendown()
t.begin_fill()
t.color(r, g, b)
for i in range(5):
t.forward(length)
t.right(144)
t.end_fill()
t.penup()
def drawline(x, y):
t.pendown()
t.goto(x, y)
s = turtle.textinput("입력", "별의 개수를 입력하시오: ")
num = int(s)
for n in range(num):
x = random.randrange(-300, 300)
y = random.randrange(-300, 300)
t.up()
t.goto(x,y)
t.down()
star(random.randint(100, 200))
t.screen.onclick(drawline)
turtle.mainloop()