FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python_example/turtle_triangle_recursion.py at main · rheehot/python_example · GitHub
rheehot
/
python_example
Public
forked from
nicecoding1/python_example
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python_example
/
turtle_triangle_recursion.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (43 loc) · 1.37 KB
Breadcrumbs
python_example
/
turtle_triangle_recursion.py
Copy path
File metadata and controls
51 lines (43 loc) · 1.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
from
turtle
import
*
import
math
step
=
int
(
input
(
"삼각형 그리기 재귀함수 반복 횟수 입력: "
))
size
=
400
if
step
<
1
:
min
=
size
elif
step
==
1
:
min
=
size
/
2
else
:
min
=
size
/
(
2
**
step
)
#pf = 0.8660254 # 피타고라스정리: sqrt(3)/2
pf
=
math
.
sqrt
(
3
)
/
2
# r,g,b 색상 만들어 반환하는 함수
def
getRGB
():
r
,
g
,
b
=
0
,
0
,
0
r
=
random
.
random
()
g
=
random
.
random
()
b
=
random
.
random
()
return
(
r
,
g
,
b
)
def
D
(
l
,
x
,
y
):
if
l
>
min
:
# 변의 길이가 최소 길이보다 길면 재귀함수 호출(변 사이즈 반으로 줄여서 호출)
l
=
l
/
2
# 크기를 반으로 줄이고 실행
D
(
l
,
x
,
y
)
# 왼쪽 아래 삼각형
D
(
l
,
x
+
l
,
y
)
# 오른쪽 아래 삼각형
D
(
l
,
x
+
l
/
2
,
y
+
l
*
pf
)
# 위쪽 삼각형
else
:
# 재귀함수 종료
goto
(
x
,
y
);
r
,
g
,
b
=
getRGB
()
color
(
r
,
g
,
b
)
pendown
()
# 선그리기 시작
forward
(
l
);
# l만큼 직진
left
(
120
)
# 120도 좌회선
forward
(
l
);
# l만큼 직진
left
(
120
)
# 120도 좌회전
forward
(
l
)
# l만큼 직진
setheading
(
0
)
# 거북이 방향 초기화
penup
();
# 선그리기 종료
goto
(
x
,
y
)
# 시작 지점으로 이동
penup
()
speed
(
'fastest'
)
#빠르게 그림 그리기
D
(
size
,
-
size
/
2
,
-
size
*
pf
/
2.0
)
goto
(
0
,
0
)
done
()
Back
|
FazBrowse Home
|
New Git URL