프로그램

[파이썬] 터틀(turtle)의 좌표 기준을 변경 (setworldcoordinates)

오디세이99 2023. 7. 16. 19:19
728x90
반응형

기본 좌표

import turtle

# 화면 생성
screen = turtle.Screen()
screen.setup(500, 500)

# turtle 생성
t = turtle.Turtle()
t.hideturtle()

# 예제: 원 그리기
t.pencolor('blue')
t.forward(100)
t.write('+x', font=('Arial', 12, 'normal'))

t.setposition(0,0)
t.pencolor('red')
t.left(180)
t.forward(100)
t.write('-x', font=('Arial', 12, 'normal'))

t.setposition(0,0)
t.pencolor('green')
t.right(90)
t.forward(100)
t.write('+y', font=('Arial', 12, 'normal'))

t.setposition(0,0)
t.pencolor('orange')
t.left(180)
t.forward(100)
t.write('-y', font=('Arial', 12, 'normal'))

# 프로그램 종료
turtle.done()

try:
    turtle.bye()
except:
    print("bye")

 

화면 좌측 상단이 (0, 0)이 되도록 설정

import turtle

# 화면 생성
screen = turtle.Screen()
screen.setup(500, 500)

# 화면 좌측 상단이 (0, 0)이 되도록 설정
screen.setworldcoordinates(0, screen.window_height(), screen.window_width(), 0)

# turtle 생성
t = turtle.Turtle()
t.hideturtle()

# 예제: 원 그리기
t.pencolor('blue')
t.forward(100)
t.write('+x', font=('Arial', 12, 'normal'))

t.setposition(0,0)
t.pencolor('red')
t.left(180)
t.forward(100)
t.write('-x', font=('Arial', 12, 'normal'))

t.setposition(0,0)
t.pencolor('green')
t.right(90)
t.forward(100)
t.write('+y', font=('Arial', 12, 'normal'))

t.setposition(0,0)
t.pencolor('orange')
t.left(180)
t.forward(100)
t.write('-y', font=('Arial', 12, 'normal'))

# 프로그램 종료
turtle.done()

try:
    turtle.bye()
except:
    print("bye")
728x90
반응형