ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Python/Turtle] 7. Help and configuration, Turtledemo
    코딩/Python 2022. 12. 20. 01:22
    728x90

    Help and configuration

    How to use help

    Screen 및 Turtle 클래스의 공개 메서드는 docstring을 통해 광범위하게 문서화. 따라서 Python 도움말 기능을 통해 온라인 도움말로 사용.

    • IDLE을 사용하는 경우 툴팁에 함수/메서드 호출에 입력된 docstring의 서명과 첫 번째 줄이 표시.
    • 메서드 또는 함수에서 help()를 호출하면 docstring이 표시.
    help(Screen.bgcolor)
    Help on method bgcolor in module turtle:
    
    bgcolor(self, *args) unbound turtle.Screen method
        Set or return backgroundcolor of the TurtleScreen.
    
        Arguments (if given): a color string or three numbers
        in the range 0..colormode or a 3-tuple of such numbers.
    
    
          >>> screen.bgcolor("orange")
          >>> screen.bgcolor()
          "orange"
          >>> screen.bgcolor(0.5,0,0.5)
          >>> screen.bgcolor()
          "#800080"
    
    help(Turtle.penup)
    Help on method penup in module turtle:
    
    penup(self) unbound turtle.Turtle method
        Pull the pen up -- no drawing when moving.
    
        Aliases: penup | pu | up
    
        No argument
    
        >>> turtle.penup()
    • 메서드에서 파생된 함수의 docstring은 다음과 같은 수정된 형식을 갖는다.
    help(bgcolor)
    Help on function bgcolor in module turtle:
    
    bgcolor(*args)
        Set or return backgroundcolor of the TurtleScreen.
    
        Arguments (if given): a color string or three numbers
        in the range 0..colormode or a 3-tuple of such numbers.
    
        Example::
    
          >>> bgcolor("orange")
          >>> bgcolor()
          "orange"
          >>> bgcolor(0.5,0,0.5)
          >>> bgcolor()
          "#800080"
    
    help(penup)
    Help on function penup in module turtle:
    
    penup()
        Pull the pen up -- no drawing when moving.
    
        Aliases: penup | pu | up
    
        No argument
    
        Example:
        >>> penup()

    이러한 수정된 docstring은 가져오기 시간에 메서드에서 파생된 함수 정의와 함께 자동으로 생성.

    Translation of docstrings into different languages

    키가 메서드 이름이고 값이 Screen 및 Turtle 클래스의 공개 메서드 독스트링인 사전을 만드는 유틸리티가 있다.

    모국어로 된 온라인 도움말과 함께 거북이를 사용하려면 독스트링을 번역하고 결과 파일을 예를 들어 다음과 같이 저장해야 한다. turtle_docstringdict_german.py.

    turtle.cfg 파일에 적절한 항목이 있으면 가져올 때 이 사전을 읽어 원본 영어 docstring을 대체.

    이 글을 쓰는 시점에 독일어와 이탈리아어로 된 docstring 사전이 있다. (요청사항은 glingl@aon.at)

    turtle.write_docstringdict(filename='turtle_docstringdict')

    filename – a string, used as filename

    지정된 파일 이름으로 Python 스크립트에 docstring-dictionary를 만들고 쓴다. 이 함수는 명시적으로 호출해야 한다(터틀 그래픽 클래스에서 사용하지 않음). docstring 사전은 Python 스크립트 filename.py에 기록. 독스트링을 다른 언어로 번역하기 위한 템플릿 역할을 하기 위한 것.

    How to configure Screen and Turtles

    내장된 기본 구성은 최상의 호환성을 유지하기 위해 이전 거북이 모듈의 모양과 동작을 모방.

    이 모듈의 기능을 더 잘 반영하거나 필요에 더 잘 맞는 다른 구성을 사용하려는 경우. 강의실에서 사용하기 위해 가져올 때 읽을 구성 파일 turtle.cfg를 준비하고 해당 설정에 따라 구성을 수정.

    기본 제공 구성은 다음 turtle.cfg에 해당.

    width = 0.5
    height = 0.75
    leftright = None
    topbottom = None
    canvwidth = 400
    canvheight = 300
    mode = standard
    colormode = 1.0
    delay = 10
    undobuffersize = 1000
    shape = classic
    pencolor = black
    fillcolor = black
    resizemode = noresize
    visible = True
    language = english
    exampleturtle = turtle
    examplescreen = screen
    title = Python Turtle Graphics
    using_IDLE = False

    선택한 항목에 대한 간단한 설명:

    • 처음 네 줄은 Screen.setup() 메서드의 인수에 해당.
    • 5행과 6행은 Screen.screensize() 메서드의 인수에 해당.
    • 모양은 기본 제공 모양(예: 화살표, 거북이 등) 중 하나. 자세한 내용은 help(shape)를 사용.
    • 채우기 색상을 사용하지 않으려면(즉, 거북이를 투명하게 만들려면) fillcolor = ""를 작성(그러나 비어 있지 않은 모든 문자열은 cfg 파일에 따옴표가 있어서는 안 된다).
    • 거북이의 상태를 반영하려면 resizemode = auto를 사용.
    • 예를 들어 설정하면 언어 = 이탈리아어 docstringdict turtle_docstringdict_italian.py는 가져올 때 로드(가져오기 경로에 있는 경우, 예를 들어 거북이와 같은 디렉터리에 있음).
    • 항목 exampleturtle 및 examplescreen은 독스트링에서 발생하는 이러한 개체의 이름을 정의. method-docstring을 function-docstring으로 변환하면 docstring에서 이러한 이름이 삭제.
    • using_IDLE: 정기적으로 IDLE 및 해당 -n 스위치를 사용하는 경우 True로 설정("하위 프로세스 없음"). 이렇게 하면 exitonclick()이 메인 루프에 들어가는 것을 방지.

    거북이가 저장된 디렉토리에 turtle.cfg 파일이 있고 현재 작업 디렉토리에 추가 파일이 있을 수 있다. 후자는 첫 번째 설정을 무시.

    Lib/turtledemo 디렉토리에는 turtle.cfg 파일이 포함. 예제로 공부하고 데모를 실행할 때 그 효과를 확인할 수 있다(데모 뷰어 내에서가 아닌 것이 좋다).

    turtledemo — Demo scripts

    turtledemo 패키지에는 데모 스크립트 세트가 포함. 이러한 스크립트는 다음과 같이 제공된 데모 뷰어를 사용하여 실행.

    python -m turtledemo

    또는 데모 스크립트를 개별적으로 실행. 예를 들어,

    python -m turtledemo.bytedesign

    turtledemo 패키지 디렉토리에는 다음이 포함.

    • 스크립트의 소스 코드를 보고 동시에 실행하는 데 사용할 수 있는 데모 뷰어 main.py.
    • 거북이 모듈의 다양한 기능을 보여주는 여러 스크립트. 예제는 예제 메뉴를 통해 액세스. 독립 실행형으로도 실행.
    • 이러한 파일을 작성하고 사용하는 방법에 대한 예제 역할을 하는 turtle.cfg 파일.

    데모 스크립트:

    Name Description Features
    bytedesign complex classical turtle graphics pattern tracer(), delay, update()
    chaos graphs Verhulst dynamics, shows that computer’s computations can generate results sometimes against the common sense expectations world coordinates
    clock analog clock showing time of your computer turtles as clock’s hands, ontimer
    colormixer experiment with r, g, b ondrag()
    forest 3 breadth-first trees randomization
    fractalcurves Hilbert & Koch curves recursion
    lindenmayer ethnomathematics (indian kolams) L-System
    minimal_hanoi Towers of Hanoi Rectangular Turtles as Hanoi discs (shape, shapesize)
    nim play the classical nim game with three heaps of sticks against the computer. turtles as nimsticks, event driven (mouse, keyboard)
    paint super minimalistic drawing program onclick()
    peace elementary turtle: appearance and animation
    penrose aperiodic tiling with kites and darts stamp()
    planet_and_moon simulation of gravitational system compound shapes, Vec2D
    round_dance dancing turtles rotating pairwise in opposite direction compound shapes, clone shapesize, tilt, get_shapepoly, update
    sorting_animate visual demonstration of different sorting methods simple alignment, randomization
    tree a (graphical) breadth first tree (using generators) clone()
    two_canvases simple design turtles on two canvases
    wikipedia a pattern from the wikipedia article on turtle graphics clone(), undo()
    yinyang another elementary example circle()
    728x90

    댓글

Designed by Tistory.