728x90
반응형
"무작위로 이동하여 임의의 점에서 삼각형 또는 사각형 또는 오각형 또는 육각형 또는 원"
from turtle import *
from random import *
x, y, radius = 0,0,0
colorList = ['red','yellow','green','orange','blue','violet','tan','brown','navy','cyan']
shapeList = [0, 3, 4, 5, 6] # 도형.
setup(1200, 800)
bgcolor('black')
speed(0)
def draw_circle(r):
circle(radius)
def draw_shape(n, length):
print(n, length)
for i in range(n):
forward(length)
right(int(360/n))
for i in range(30):
x = randint(-500, 500)
y = randint(-400, 300)
radius = randint(80, 130)
length = randint(20, 200) # 도형 변의 길이
penup()
goto(x, y)
penup()
color(choice(colorList))
shape = choice(shapeList) # 도형 선탹
begin_fill()
if shape == 0: # 0이면 원
draw_circle(radius)
else:
draw_shape(shape, length) # 3,4,5,6 각형 및 한변 길이
end_fill()
done()
try:
bye()
except:
print("bye")
728x90
반응형
'프로그램' 카테고리의 다른 글
[파이썬] 문제 : turtle - 도형 color를 딕셔너리에 저장하고 사용하기 (1) | 2023.12.05 |
---|---|
[파이썬] 문제 : 딕셔너리에 이름,전화번호 저장하기 (2) | 2023.12.05 |
[파이썬] 문제 : 경마 게임 코드 (0) | 2023.12.04 |
[파이썬] 문제 : 평균기온을 입력받아 옷차림을 추천 (0) | 2023.12.04 |
[C언어] 학생 구조체 만들기 (2) | 2023.12.03 |
댓글