ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Python/Turtle] 3. Methods/Turtle state & Settings for measurement
    코딩/Python 2022. 12. 19. 21:36
    728x90

    빨리가기
    position() / towards() / xcor() / ycor() / heading() / distance() / degrees() / radians()

    Methods of RawTurtle/Turtle

    Turtle's state

    turtle.position() / turtle.pos()

    거북이의 현재 위치를 (x,y) (Vec2D vector)로 반환.

    turtle.pos()
    (440.00,-0.00)

    turtle.towards(x, y=None)

    x – a number or a pair/vector of numbers or a turtle instance
    y – a number if x is a number, else None

    거북이 위치에서 (x,y)로 지정된 위치까지의 선, 벡터 또는 다른 거북이 사이의 각도를 반환.
    "표준"/"세계" 또는 "로고" 모드에 따른 거북이의 시작 방향에 따라 다르다.

    turtle.goto(10, 10)
    turtle.towards(0,0)

    turtle.xcor()

    거북이의 x 좌표 반환

    turtle.home()
    turtle.left(50)
    turtle.forward(100)
    print(round(turtle.xcor(), 5))

    turtle.ycor()

    거북이의 y 좌표 반환

    turtle.home()
    turtle.left(60)
    turtle.forward(100)
    print(round(turtle.ycor(), 5))

    turtle.heading()

    거북이의 현재 방향을 반환

    turtle.home()
    turtle.left(67)
    turtle.heading()

    turtle.distance(x, y=None)

    x – a number or a pair/vector of numbers or a turtle instance
    y – a number if x is a number, else None

    거북이에서 (x,y)까지의 거리, 주어진 벡터 또는 주어진 다른 거북이까지의 거리를 거북이 스텝 단위로 반환.

    turtle.home()
    turtle.distance(30,40)
    turtle.distance((30,40))
    joe = Turtle()
    joe.forward(77)
    turtle.distance(joe)

    Settings for measurement

    turtle.degrees(fullcircle=360.0)

    각도 측정 단위를 설정. 완전한 원의 "도" 수를 설정. 기본값 360

    turtle.home()
    turtle.left(90)
    turtle.heading()
    # 90.0
    ''' Change angle measurement unit to grad (also known as gon,
    grade, or gradian and equals 1/100-th of the right angle.) '''
    
    turtle.degrees(400.0)
    turtle.heading()
    # 100.0
    turtle.degrees(360)
    turtle.heading()
    # 90.0

    turtle.radians()

    각도 측정 단위를 라디안으로 설정. 도(2*math.pi)와 같다.

    turtle.home()
    turtle.left(90)
    turtle.heading()
    90.0
    turtle.radians()
    turtle.heading()
    1.5707963267948966

    Turtle state 2

    Visibility

    *turtle.hideturtle() / turtle.ht() *

    거북이를 숨긴다. 거북이를 숨기면 눈에 띄게 그리기 속도가 빨라지므로 복잡한 그림을 그리는 도중에 이 작업을 수행하는 것이 좋다.

    turtle.hideturtle()

    turtle.showturtle() / turtle.st()

    거북이를 보이게 한다.

    turtle.showturtle()

    turtle.isvisible()

    Turtle이 표시되면 True를 반환, 숨겨져 있으면 False를 반환.

    turtle.hideturtle()
    turtle.isvisible()
    turtle.showturtle()
    turtle.isvisible()

    Appearance

    turtle.shape(name=None)

    거북이 모양을 주어진 이름을 가진 모양으로 설정하거나, 이름이 주어지지 않으면 현재 모양의 이름을 반환. 이름이 있는 모양은 TurtleScreen의 shape dictionary에 존재해야 한다. 처음에는 "화살표", "거북이", "원", "사각형", "삼각형", "클래식"과 같은 다각형 모양이 있다. 모양을 다루는 방법에 대해 알아보려면 Screen 메서드 register_shape()를 참조.

    turtle.shape()
    'classic'
    turtle.shape("turtle")
    turtle.shape()
    'turtle'

    turtle.resizemode(rmode=None)

    rmode – “auto”, “user”, “noresize”

    resizemode를 "auto", "user", "noresize" 값 중 하나로 설정. rmode가 제공되지 않으면 현재 resizemode를 반환.

    • "자동": pensize 값에 해당하는 거북이 모양을 조정.
    • “user”: shapesize()에 의해 설정된 stretchfactor 및 outlinewidth(outline) 값에 따라 거북이의 모양을 조정.
    • "noresize": 거북이 모양이 조정되지 않는다.

    resizemode("user")는 인수와 함께 사용될 때 shapesize()에 의해 호출.

    turtle.resizemode()
    'noresize'
    turtle.resizemode("auto")
    turtle.resizemode()
    'auto'

    turtle.shapesize(stretch_wid=None, stretch_len=None, outline=None) / turtle.turtlesize(stretch_wid=None, stretch_len=None, outline=None)

    펜의 속성 x/y-stretchfactors 및/또는 외곽선을 반환하거나 설정. 크기 조정 모드를 "사용자"로 설정. resizemode가 "user"로 설정된 경우에만 거북이가 stretchfactors에 따라 늘어난다. stretch_wid는 방향에 수직인 stretchfactor이고 stretch_len은 방향 방향의 stretchfactor이며 outline은 도형의 외곽선 너비를 결정.

    turtle.shapesize()
    (1.0, 1.0, 1)
    turtle.resizemode("user")
    turtle.shapesize(5, 5, 12)
    turtle.shapesize()
    (5, 5, 12)
    turtle.shapesize(outline=8)
    turtle.shapesize()
    (5, 5, 8)

    turtle.shearfactor(shear=None)

    현재 전단 인자를 설정하거나 반환. 전단 각도의 탄젠트인 주어진 전단 계수 전단에 따라 거북이 모양을 전단. 거북이의 방향(이동 방향)을 변경하지 않는다. 전단이 제공되지 않은 경우: 현재 전단 계수, 거북이의 방향에 평행한 선이 전단되는 전단 각도의 탄젠트를 반환

    turtle.shape("circle")
    turtle.shapesize(5,2)
    turtle.shearfactor(0.5)
    turtle.shearfactor()
     0.5

    turtle.tilt(angle)

    거북이 모양을 현재 기울기 각도에서 각도만큼 회전하지만 거북이의 방향(이동 방향)은 변경하지 않는다.

    turtle.reset()
    turtle.shape("circle")
    turtle.shapesize(5,2)
    turtle.tilt(30)
    turtle.fd(50)
    turtle.tilt(30)
    turtle.fd(50)

    turtle.tiltangle(angle=None)

    현재 기울기 각도를 설정하거나 반환. 각도가 주어지면 현재 기울기 각도에 관계없이 거북이 모양이 각도로 지정된 방향을 가리키도록 회전. 거북이의 방향(이동 방향)을 변경하지 않는다. 각도가 제공되지 않으면: 현재 기울기 각도, 거북이 모양의 방향과 거북이의 방향(이동 방향) 사이의 각도를 반환합니다.

    turtle.reset()
    turtle.shape("circle")
    turtle.shapesize(5,2)
    turtle.tilt(45)
    turtle.tiltangle()
    45.0

    turtle.shapetransform(t11=None, t12=None, t21=None, t22=None)

    거북이 모양의 현재 변환 행렬을 설정하거나 반환.
    행렬 요소가 제공되지 않으면 변환 행렬을 4개 요소의 튜플로 반환. 그렇지 않으면 주어진 요소를 설정하고 첫 번째 행 t11, t12 및 두 번째 행 t21, t22로 구성된 행렬에 따라 거북이 모양을 변형. 결정자 t11 * t22 - t12 * t21은 0이 아니어야 한다. 그렇지 않으면 오류가 발생. 주어진 행렬에 따라 stretchfactor, shearfactor 및 tiltangle을 수정.

    turtle = Turtle()
    turtle.shape("square")
    turtle.shapesize(4,2)
    turtle.shearfactor(-0.5)
    turtle.shapetransform()
    (4.0, -1.0, -0.0, 2.0)

    turtle.get_shapepoly()

    현재 모양 다각형을 좌표 쌍의 튜플로 반환. 이는 복합 모양의 새 모양 또는 구성 요소를 정의하는 데 사용

    turtle.shape("square")
    turtle.shapetransform(4, -1, 0, 2)
    turtle.get_shapepoly()
    ((50, -20), (30, 20), (-50, 20), (-30, -20))
    728x90

    댓글

Designed by Tistory.