Python Turtle Graphics - Draw Spiral Triangle
2024. 11. 23. 06:53ㆍPython
728x90
반응형
import turtle
colors = ["yellow", "blue", "red"]
c = 0
def spiral_shape(side, angle):
global c
if side > 0:
t.pencolor(colors[c % 3])
c += 1
t.forward(side)
t.right(angle)
spiral_shape(side - 5, angle)
# Window setup
window = turtle.Screen()
window.bgcolor("black")
# Turtle setup
t = turtle.Turtle()
t.shape("classic")
t.reset()
t.pen(speed=0)
# Initial condition
length = 400
turn_by = 121
t.penup()
t.setpos(-length / 2, -length / 2)
t.left(100)
t.pendown()
t.pensize(2)
# Draw
spiral_shape(length, turn_by)
window.exitonclick()
728x90
반응형
'Python' 카테고리의 다른 글
Python - 백준 1422 숫자의 신 (0) | 2024.11.24 |
---|---|
Python - 백준 1267 핸드폰 요금 (0) | 2024.11.23 |
Python - 백준 5355 화성 수학 (2) | 2024.11.18 |
Python - 백준 2539 소음 (0) | 2024.11.18 |
Python - 백준 2476 주사위 게임 (0) | 2024.11.18 |