728x90
반응형
# 클릭 위치에 6각형, 원형으로 그리기
import turtle as t
import random
t.shape('turtle')
t.speed(4)
color=['blue','green','pink','yellow','red','white']
length=50
n = 6 # int(input())
def draw(x, y):
t.penup()
t.goto(x,y)
t.pendown()
t.color(color[0])
pos1 = []
t.begin_fill() # 색칠할 영역 시작
t.pencolor('black')
for i in range(n): # 6각형 그리기
pos1.append([t.xcor(), t.ycor()])
t.forward(length)
t.right(360 / n) # 360을 n으로 나누어서 외각을 구함
t.end_fill() # 색칠할 영역 끝
t.up()
t.goto(pos1[2][0],pos1[2][1])
t.down()
t.color(color[1])
pos2 = []
t.begin_fill() # 색칠할 영역 시작
t.pencolor('black')
for i in range(n): # 6각형 그리기
pos2.append([t.xcor(), t.ycor()])
t.forward(length)
t.right(360 / n) # 360을 n으로 나누어서 외각을 구함
t.end_fill() # 색칠할 영역 끝
t.up()
t.goto(pos2[4][0],pos2[4][1])
t.down()
t.color(color[2])
pos3 = []
t.begin_fill() # 색칠할 영역 시작
t.pencolor('black')
for i in range(n): # 6각형 그리기
pos3.append([t.xcor(), t.ycor()])
t.forward(length)
t.right(360 / n) # 360을 n으로 나누어서 외각을 구함
t.end_fill() # 색칠할 영역 끝
t.up()
t.goto(pos3[5][0]-length,pos3[5][1])
t.down()
t.color(color[3])
# pos = []
t.begin_fill() # 색칠할 영역 시작
t.pencolor('black')
for i in range(n): # 6각형 그리기
# pos.append([t.xcor(), t.ycor()])
t.forward(length)
t.right(360 / n) # 360을 n으로 나누어서 외각을 구함
t.end_fill() # 색칠할 영역 끝
# 5번째
t.up()
t.goto(pos3[0][0]-(pos3[2][0] - pos3[5][0])-length,pos3[0][1])
t.down()
t.color(color[4])
# pos = []
t.begin_fill() # 색칠할 영역 시작
t.pencolor('black')
for i in range(n): # 6각형 그리기
# pos.append([t.xcor(), t.ycor()])
t.forward(length)
t.right(360 / n) # 360을 n으로 나누어서 외각을 구함
t.end_fill() # 색칠할 영역 끝
# 6번째
t.up()
t.goto(pos1[5][0]-length, pos1[2][1])
t.down()
t.color(color[5])
# pos = []
t.begin_fill() # 색칠할 영역 시작
t.pencolor('black')
for i in range(n): # 6각형 그리기
# pos.append([t.xcor(), t.ycor()])
t.forward(length)
t.right(360 / n) # 360을 n으로 나누어서 외각을 구함
t.end_fill() # 색칠할 영역 끝
t.onscreenclick(draw)
t.listen()
t.done()

728x90
반응형
'프로그램' 카테고리의 다른 글
[파이썬] 터틀 골뱅이 그리기 (0) | 2022.10.30 |
---|---|
[파이썬] Qt5 입력 및 Label Text 변경. Button Click event (0) | 2022.10.27 |
[파이썬] 단순 단어수 Count (collections Counter) (0) | 2022.10.24 |
[파이썬] 리스트 축약( [새값 for 값 in 조건식] ) (0) | 2022.10.24 |
[파이썬] 이진검색 알고리즘(binary search algorithm) (0) | 2022.10.24 |
댓글