본문 바로가기

PROGRAM/Python

Turtle - Example

import turtle

t1 = turtle.Turtle()
t2 = turtle.Turtle()
t1.shape('turtle')
t2.hideturtle()
t2.pencolor('white')
t2_move =[]
while True:
    direction = input('방향입력(l:left, r:right, q:종료) : ')
    if direction == 'l':
        t1.left(90)
        t1.forward(100)
        t2_move.append('l')
    if direction == 'r':
        t1.right(90)
        t1.forward(100)
        t2_move.append('r')
    if direction == 'q':
        break
    if len(t2_move)==4 and t2_move[0]=='l':
        t2.left(90)
        t2.forward(100)
        del t2_move[0]
    if len(t2_move)==4 and t2_move[0]=='r':
        t2.right(90)
        t2.forward(100)
        del t2_move[0]

print("종료")
turtle.mainloop()
    

'PROGRAM > Python' 카테고리의 다른 글

랜덤뽑기  (0) 2022.09.01
Class / lambda식 등  (0) 2020.09.07
iris.csv 분석  (0) 2020.07.31
jupyter notebook을 tistory에 적용하기  (0) 2020.07.30
class -sample  (0) 2020.04.29