Hacked By AnonymousFox

Current Path : /usr/lib64/python3.8/__pycache__/
Upload File :
Current File : //usr/lib64/python3.8/__pycache__/turtle.cpython-38.pyc

U

e5dd1�O@s6dZdZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZddl
mZddlmZddd	d
ddd
ddg	Zddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.gZd/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}gOZd~dgZeeeed�gZdd0d3d@dMdQdUd[d]dbdcdedfdqdvdydzgZd�d�d�d�ddd�d�d�d�d�d�d�d�d�d�d�d�d�d�d��Zd�d��Zd�d��Zzee�Wnek
�r
ed��YnXGd�d�de�Zd�d��Zd�d��Zd�Zd�d�d��Z Gd�d�dej!�Z"e e"ej#d��Gd�d��d�ej$�Z%ej#Z#Gd�d��d�e&�Z'Gd�d��d�e�Z(Gd�d��d�e�Z)Gd�d�de&�Z*Gd�d��d�e&�Z+Gd�d�de'�Z,Gd�d��d�e&�Z-Gd�d��d�e&�Z.Gd�d��d�e&�Z/Gd�d
�d
e.e-�Z0e0Z1d�d	�Z2Gd�d��d�e,�Z3Gd�d�de0�Z4e4Z5d�d�d~�Z6d�d��Z7ed�Z8ze8d�k�rre7e8�Wn@e9k
�r�ed�e8�Yn"ek
�r�ed�e8�YnXd�d��Z:d�dÄZ;d�dńZ<d�Z=d�dȄZ>e>ee3d�d�e<�e>ee4d�d�e;�e?Z@eAd�k�r2d�dτZBd�dфZCd�dӄZDeC�eD�eE�dS)�a�

Turtle graphics is a popular way for introducing programming to
kids. It was part of the original Logo programming language developed
by Wally Feurzig and Seymour Papert in 1966.

Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an ``import turtle``, give it
the command turtle.forward(15), and it moves (on-screen!) 15 pixels in
the direction it is facing, drawing a line as it moves. Give it the
command turtle.right(25), and it rotates in-place 25 degrees clockwise.

By combining together these and similar commands, intricate shapes and
pictures can easily be drawn.

----- turtle.py

This module is an extended reimplementation of turtle.py from the
Python standard distribution up to Python 2.5. (See: http://www.python.org)

It tries to keep the merits of turtle.py and to be (nearly) 100%
compatible with it. This means in the first place to enable the
learning programmer to use all the commands, classes and methods
interactively when using the module from within IDLE run with
the -n switch.

Roughly it has the following features added:

- Better animation of the turtle movements, especially of turning the
  turtle. So the turtles can more easily be used as a visual feedback
  instrument by the (beginning) programmer.

- Different turtle shapes, gif-images as turtle shapes, user defined
  and user controllable turtle shapes, among them compound
  (multicolored) shapes. Turtle shapes can be stretched and tilted, which
  makes turtles very versatile geometrical objects.

- Fine control over turtle movement and screen updates via delay(),
  and enhanced tracer() and speed() methods.

- Aliases for the most commonly used commands, like fd for forward etc.,
  following the early Logo traditions. This reduces the boring work of
  typing long sequences of commands, which often occur in a natural way
  when kids try to program fancy pictures on their first encounter with
  turtle graphics.

- Turtles now have an undo()-method with configurable undo-buffer.

- Some simple commands/methods for creating event driven programs
  (mouse-, key-, timer-events). Especially useful for programming games.

- A scrollable Canvas class. The default scrollable Canvas can be
  extended interactively as needed while playing around with the turtle(s).

- A TurtleScreen class with methods controlling background color or
  background image, window and canvas size and other properties of the
  TurtleScreen.

- There is a method, setworldcoordinates(), to install a user defined
  coordinate-system for the TurtleScreen.

- The implementation uses a 2-vector class named Vec2D, derived from tuple.
  This class is public, so it can be imported by the application programmer,
  which makes certain types of computations very natural and compact.

- Appearance of the TurtleScreen and the Turtles at startup/import can be
  configured by means of a turtle.cfg configuration file.
  The default configuration mimics the appearance of the old turtle module.

- If configured appropriately the module reads in docstrings from a docstring
  dictionary in some different language, supplied separately  and replaces
  the English ones by those read in. There is a utility function
  write_docstringdict() to write a dictionary with the original (English)
  docstrings to disc, so it can serve as a template for translations.

Behind the scenes there are some features included with possible
extensions in mind. These will be commented and documented elsewhere.

z-turtle 1.1b- - for Python 3.1   -  4. 5. 2009�N)�isfile�split�join)�deepcopy)�simpledialog�ScrolledCanvas�TurtleScreen�Screen�	RawTurtle�Turtle�RawPen�Pen�Shape�Vec2D�addshape�bgcolor�bgpic�bye�clearscreen�	colormode�delay�exitonclick�	getcanvas�	getshapes�listen�mainloop�mode�numinput�onkey�
onkeypress�onkeyrelease�
onscreenclick�ontimer�register_shape�resetscreen�
screensize�setup�setworldcoordinates�	textinput�title�tracer�turtles�update�
window_height�window_width�back�backward�
begin_fill�
begin_poly�bk�circle�clear�
clearstamp�clearstamps�clone�color�degrees�distance�dot�down�end_fill�end_poly�fd�	fillcolor�filling�forward�get_poly�getpen�	getscreen�
get_shapepoly�	getturtle�goto�heading�
hideturtle�home�ht�isdown�	isvisible�left�lt�onclick�ondrag�	onrelease�pd�pen�pencolor�pendown�pensize�penup�pos�position�pu�radians�right�reset�
resizemode�rt�seth�
setheading�setpos�setposition�settiltangle�
setundobuffer�setx�sety�shape�	shapesize�shapetransform�shearfactor�
showturtle�speed�st�stamp�tilt�	tiltangle�towards�
turtlesize�undo�undobufferentries�up�width�write�xcor�ycor�write_docstringdict�done�
Terminator��?g�?i�i,�standard��?�
i��classic�black�noresizeTZenglish�turtle�screenzPython Turtle GraphicsF)rz�height�	canvwidth�
canvheight�	leftright�	topbottomrrr�undobuffersizerkrWrAra�visible�language�
exampleturtle�
examplescreenr)�
using_IDLEc	Cs�t|d��}|��}W5QRXi}|D]�}|��}|r&|�d�rBq&z|�d�\}}Wn(tk
r|td||f�Yq&YnX|��}|��}|dkr�t|�}n4zd|kr�t|�}nt	|�}Wntk
r�YnX|||<q&|S)z/Convert content of config-file into dictionary.�r�#�=zBad line in config-file %s:
%s)�True�False�Nonez''z""�.)
�open�	readlines�strip�
startswithr�
ValueError�print�eval�float�int)�filename�fZcfglines�cfgdict�line�key�value�r��/usr/lib64/python3.8/turtle.py�config_dict�s0



r�cCs�d}i}i}t|�rt|�}d|kr0d|d}ztt�\}}t||�}Wntk
rbd}YnXt|�rtt|�}t�|�t�|�dS)a@Read config-files, change configuration-dict accordingly.

    If there is a turtle.cfg file in the current working directory,
    read it from there. If this contains an importconfig-value,
    say 'myway', construct filename turtle_mayway.cfg else use
    turtle.cfg and read it from the import-directory, where
    turtle.py is located.
    Update configuration dictionary first according to config-file,
    in the import directory, then according to config-file in the
    current working directory.
    If no config-file is found, the default configuration is used.
    z
turtle.cfgZimportconfigz
turtle_%s.cfg�N)rr�r�__file__r�	Exception�_CFGr,)r�Zdefault_cfgZcfgdict1Zcfgdict2�head�tailZ	cfg_file2r�r�r��
readconfig�s 


r�z"No configfile read, reason unknownc@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)ra�A 2 dimensional vector class, used as a helper class
    for implementing turtle graphics.
    May be useful for turtle graphics programs also.
    Derived from tuple, so a vector is a tuple!

    Provides (for a, b vectors, k number):
       a+b vector addition
       a-b vector subtraction
       a*b inner product
       k*a and a*k multiplication with scalar
       |a| absolute value of a
       a.rotate(angle) rotation
    cCst�|||f�S�N)�tuple�__new__)�cls�x�yr�r�r�r��sz
Vec2D.__new__cCs"t|d|d|d|d�S�Nr��r��self�otherr�r�r��__add__�sz
Vec2D.__add__cCsDt|t�r*|d|d|d|dSt|d||d|�Sr�)�
isinstancerr�r�r�r��__mul__�s
 z
Vec2D.__mul__cCs2t|t�st|t�r.t|d||d|�StSr�)r�r�r�r�NotImplementedr�r�r�r��__rmul__szVec2D.__rmul__cCs"t|d|d|d|d�Sr�r�r�r�r�r��__sub__sz
Vec2D.__sub__cCst|d|d�Sr�r��r�r�r�r��__neg__sz
Vec2D.__neg__cCs|dd|dddS)Nr�r�r�r�r�r�r�r��__abs__
sz
Vec2D.__abs__cCsjt|d|d�}|tjd}t�|�t�|�}}t|d||d||d||d|�S)z.rotate self counterclockwise by angle
        r�r��f@)r�math�pi�cos�sin)r��angleZperp�c�sr�r�r��rotateszVec2D.rotatecCs|d|dfSr�r�r�r�r�r��__getnewargs__szVec2D.__getnewargs__cCsd|S)Nz(%.2f,%.2f)r�r�r�r�r��__repr__szVec2D.__repr__N)�__name__�
__module__�__qualname__�__doc__r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�s
cCsTt|j�}|��|D]}t||�q|j��D]\}}t|�tjkr0|||<q0dS)�#helper function for Scrolled CanvasN)	�list�	__bases__�reverse�__methodDict�__dict__�items�type�types�FunctionType)r��_dictZbaseListZ_superr�r�r�r�r�r�!s
r�cCsi}t||�|��S)r�)r��keys)r�r�r�r�r��	__methods+s
r�zTdef %(method)s(self, *args, **kw): return self.%(attribute)s.%(method)s(*args, **kw)r�cCs�i}t||�i}t|�}|��D]B}|dd�dksd|dd�dksd||ksd||krXq"||||<q"|��D]D\}}	||	d�}
t|t�r�t||d�}t||
�t|||
|�qndS)Nr��_���)�method�func)r�Z	attribute)	r�r�r�r�r��str�__stringBody�exec�setattr)Z	fromClassZtoClassZtoPartZexcludeZ_dict_1r�ZmfcZexr�r��dZ
execStringr�r�r��__forwardmethods5s
0

�
r�c@sdeZdZdZddd�Zddd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)rz�Modeled after the scrolled canvas class from Grayons's Tkinter book.

    Used as the default canvas, which pops up automatically when
    using turtle graphics functions or the Turtle class.
    ���^�Xc
Cs0tjj||||d�|��|_|||_|_|||_|_d|_	tj
||||j	tjdd�|_tj
||jjtjd�|_tj
||jjd�|_|jj|jj|jjd�|jdd	dd
�|jdd	dd
�|jjd	|d	ddd	d	dd�|jjd	|d	dd	d	d	dd�|jjd	|d	d	dd	d	dd�|��|j�d
|j�dS)N)rzr��whiter�)rzr��bgZreliefZborderwidth)�commandZorient)r�)ZxscrollcommandZyscrollcommandrr�)ZweightZminsize�news�ZpadxZin_Zpady�row�columnZrowspanZ
columnspanZstickyz<Configure>)�TK�Frame�__init__�winfo_toplevelZ_rootwindowrzr�r�r�r��CanvasZSUNKEN�_canvasZ	ScrollbarZxviewZ
HORIZONTAL�hscrollZyview�vscrollZ	configure�setZrowconfigureZcolumnconfigure�gridr`�bind�onResize)r��masterrzr�r�r�r�r�r�r�PsN

������zScrolledCanvas.__init__NcCs�|r
||_|r||_|r||_|jj||jd|jd|jd|jdfd�|j�d|j|jd|j�|j�d|j|jd|j�|�	�dS)z<Adjust canvas and scrollbars according to given canvas size.r�)r��scrollregionr��N)
r�r�r�r�config�xview_movetorz�yview_movetor��
adjustScrolls�r�r�r�r�r�r�r�r`is&����zScrolledCanvas.resetc
Cs�|j��}|j��}|j�d|j||j�|j�d|j||j�||jks`||jkr�|jjd|ddddddd�|j	jd|ddddddd�n|j�
�|j	�
�dS)zA Adjust scrollbars according to window- and canvas-size.
        r�r�rr�r�N)r�winfo_width�winfo_heightrr�rr�rrrZgrid_forget)r��cwidth�cheightr�r�r�r
{s&

��
zScrolledCanvas.adjustScrollscCs|��dS)zself-explanatoryN)r
)r��eventr�r�r�r�szScrolledCanvas.onResizecGs|jj|�S��@ 'forward' method, which canvas itself has inherited...
        )r�bbox�r��argsr�r�r�r�szScrolledCanvas.bboxcOs|jj||�Sr)r�cget�r�r�kwargsr�r�r�r�szScrolledCanvas.cgetcOs|jj||�dS�rN)rr
rr�r�r�r
�szScrolledCanvas.configcOs|jj||�dSr)rrrr�r�r�r�szScrolledCanvas.bindcOs|jj||�dSr)r�unbindrr�r�r�r�szScrolledCanvas.unbindcCs|j��dSr)r�focus_forcer�r�r�r�r�szScrolledCanvas.focus_force)r�r�r�r�)NNN)r�r�r�r�r�r`r
rrrr
rrrr�r�r�r�rJs�

rc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�_Rootz'Root class for Screen based on Tkinter.cCstj�|�dSr�)r��Tkr�r�r�r�r�r��sz_Root.__init__cCs&t|||||�|_|jjddd�dS)Nr�Zboth)�expand�fill)rrZpack)r�rzr�rrr�r�r��setupcanvas�sz_Root.setupcanvascCs|jSr�)rr�r�r�r��
_getcanvas�sz_Root._getcanvascCs|�d||||f�dS)Nz%dx%d%+d%+d)Zgeometry)r�rzr��startx�startyr�r�r��set_geometry�sz_Root.set_geometrycCs|�d|�dS)NZWM_DELETE_WINDOW)Zwm_protocol)r��destroyr�r�r��	ondestroy�sz_Root.ondestroycCs|��Sr�)Zwinfo_screenwidthr�r�r�r��	win_width�sz_Root.win_widthcCs|��Sr�)Zwinfo_screenheightr�r�r�r��
win_height�sz_Root.win_heightN)r�r�r�r�r�r#r$r'r)r*r+r�r�r�r�r�src@s,eZdZdZdd�Zdd�Zdd�Zdd	�ZdGdd
�Zdd�Z	dHdd�Z
dd�Zdd�Zdd�Z
dd�ZdIdd�Zdd�ZdJdd �ZdKd!d"�ZdLd#d$�ZdMd%d&�Zd'd(�ZdNd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�ZdOd=d>�Z d?d@�Z!dAdB�Z"dCdD�Z#dPdEdF�Z$d
S)Q�TurtleScreenBasez�Provide the basic graphics functionality.
       Interface between Tkinter and turtle.py.

       To port turtle.py to some different graphics toolkit
       a corresponding TurtleScreenBase class has to be implemented.
    cCstjdd|jd�}|��|S)z$return a blank image object
        r�)rzr�r)r��
PhotoImage�cv�blank)r�Zimgr�r�r��_blankimage�szTurtleScreenBase._blankimagecCstj||jd�S)z`return an image object containing the
        imagedata from a gif-file named filename.
        )�filer)r�r-r.)r�r�r�r�r��_image�szTurtleScreenBase._imagecCs�||_t|t�r"|jj}|jj}nJt|j�d��}t|j�d��}|jj|d|d|d|dfd�||_||_d|_|_	dS)Nrzr�r��rr�)
r.r�rr�r�r�rr
�xscale�yscale)r�r.�w�hr�r�r�r��s

*zTurtleScreenBase.__init__cCs|jjdddd�S)z<Create an invisible polygon item on canvas self.cv)
        )rrrrrrr��r"�outline)r.Zcreate_polygonr�r�r�r��_createpoly�szTurtleScreenBase._createpolyNFc
Cs�g}|D]*\}}	|�||j�|�|	|j�q|jj|f|��|dk	r^|jj||d�|dk	rv|jj||d�|dk	r�|jj||d�|r�|j�|�dS)a`Configure polygonitem polyitem according to provided
        arguments:
        coordlist is sequence of coordinates
        fill is filling color
        outline is outline color
        top is a boolean value, which specifies if polyitem
        will be put on top of the canvas' displaylist so it
        will not be covered by other items.
        N�r")r9�rz��appendr4r5r.�coordsZ
itemconfigureZ	tag_raise)
r�Zpolyitem�	coordlistr"r9rz�top�clr�r�r�r�r��	_drawpoly�szTurtleScreenBase._drawpolyc	Cs|jjddddddtjd�S)z9Create an invisible line item on canvas self.cv)
        rr�r�)r"rzZcapstyle)r.Zcreate_liner�ZROUNDr�r�r�r��_createlines�zTurtleScreenBase._createlinec	Cs�|dk	rNg}|D]*\}}|�||j�|�||j�q|jj|f|��|dk	rf|jj||d�|dk	r~|jj||d�|r�|j�|�dS)aQConfigure lineitem according to provided arguments:
        coordlist is sequence of coordinates
        fill is drawing color
        width is width of drawn line.
        top is a boolean value, which specifies if polyitem
        will be put on top of the canvas' displaylist so it
        will not be covered by other items.
        Nr;r<r=)	r�Zlineitemr@r"rzrArBr�r�r�r�r��	_drawlines
zTurtleScreenBase._drawlinecCs|j�|�dS)z]Delete graphics item from canvas.
        If item is"all" delete all graphics items.
        N)r.�delete�r��itemr�r�r��_delete(szTurtleScreenBase._deletecCs|j��dS)z(Redraw graphics items on canvas
        N)r.r,r�r�r�r��_update.szTurtleScreenBase._updatecCs|j�|�dS)z-Delay subsequent canvas actions for delay ms.N)r.�after�r�rr�r�r��_delay3szTurtleScreenBase._delaycCs4z|j�|�}d}Wntjk
r.d}YnX|S)zCCheck if the string color is a legal Tkinter color string.
        TF)r.Z	winfo_rgbr�ZTclError)r�r9Zrgb�okr�r�r��_iscolorstring7s
zTurtleScreenBase._iscolorstringcCs0|dk	r |jj|d�|��n|j�d�SdS)zVSet canvas' backgroundcolor if color is not None,
        else return backgroundcolor.N)r�r�)r.r
rJr)r�r9r�r�r��_bgcolorAs
zTurtleScreenBase._bgcolorcCst|\}}||j}||j}dddd�}|jj|d||||||d�}	|j�|	�\}
}}}
|j��|	|dfS)z�Write txt at pos in canvas with specified font
        and color.
        Return text item and x-coord of right bottom corner
        of text's bounding box.�swr�Zse)rP�centerr_r�)�text�anchorr"�font)r4r5r.Zcreate_textrr,)r�r[�txt�alignrUrWr�r�rTrHZx0Zy0Zx1Zy1r�r�r��_writeJs

�
zTurtleScreenBase._writer�csD�dkr�j�|d|�n$��fdd�}�j�|d|||�dS)z�Bind fun to mouse-click event on turtle.
        fun must be a function with two arguments, the coordinates
        of the clicked point on the canvas.
        num, the number of the mouse-button defaults to 1
        N�<Button-%s>cs:�j�|j��j�j�|j��j}}�||�dSr��r.�canvasxr�r4�canvasyr�r5�rr�r���funr�r�r��eventfunes�z+TurtleScreenBase._onclick.<locals>.eventfun�r.Z
tag_unbindZtag_bind�r�rHr_�num�addr`r�r^r��_onclick\szTurtleScreenBase._onclickcsD�dkr�j�|d|�n$��fdd�}�j�|d|||�dS)agBind fun to mouse-button-release event on turtle.
        fun must be a function with two arguments, the coordinates
        of the point on the canvas where mouse button is released.
        num, the number of the mouse-button defaults to 1

        If a turtle is clicked, first _onclick-event will be performed,
        then _onscreensclick-event.
        Nz<Button%s-ButtonRelease>cs:�j�|j��j�j�|j��j}}�||�dSr�rZr]r^r�r�r`ws�z-TurtleScreenBase._onrelease.<locals>.eventfunrarbr�r^r��
_onreleaseks	�zTurtleScreenBase._onreleasecsD�dkr�j�|d|�n$��fdd�}�j�|d|||�dS)aqBind fun to mouse-move-event (with pressed mouse button) on turtle.
        fun must be a function with two arguments, the coordinates of the
        actual mouse position on the canvas.
        num, the number of the mouse-button defaults to 1

        Every sequence of mouse-move-events on a turtle is preceded by a
        mouse-click event on that turtle.
        Nz<Button%s-Motion>csTz:�j�|j��j�j�|j��j}}�||�Wntk
rNYnXdSr�)r.r[r�r4r\r�r5r�r]r^r�r�r`�s�z*TurtleScreenBase._ondrag.<locals>.eventfunrarbr�r^r��_ondrag~s	zTurtleScreenBase._ondragcs@�dkr�j�d|�n"��fdd�}�j�d|||�dS)aGBind fun to mouse-click event on canvas.
        fun must be a function with two arguments, the coordinates
        of the clicked point on the canvas.
        num, the number of the mouse-button defaults to 1

        If a turtle is clicked, first _onclick-event will be performed,
        then _onscreensclick-event.
        NrYcs:�j�|j��j�j�|j��j}}�||�dSr�rZr]r^r�r�r`�s�z1TurtleScreenBase._onscreenclick.<locals>.eventfun�r.rr)r�r_rcrdr`r�r^r��_onscreenclick�s	zTurtleScreenBase._onscreenclickcs>�dkr|j�d|d�n�fdd�}|j�d||�dS)z`Bind fun to key-release event of key.
        Canvas must have focus. See method listen
        Nz<KeyRelease-%s>cs
��dSr�r��r�r_r�r�r`�sz0TurtleScreenBase._onkeyrelease.<locals>.eventfunrh�r�r_r�r`r�rkr��
_onkeyrelease�szTurtleScreenBase._onkeyreleasecsn�dkr4|dkr |j�dd�qj|j�d|d�n6�fdd�}|dkrX|j�d|�n|j�d||�dS)z�If key is given, bind fun to key-press event of key.
        Otherwise bind fun to any key-press.
        Canvas must have focus. See method listen.
        Nz
<KeyPress>z
<KeyPress-%s>cs
��dSr�r�rjrkr�r�r`�sz.TurtleScreenBase._onkeypress.<locals>.eventfunrhrlr�rkr��_onkeypress�szTurtleScreenBase._onkeypresscCs|j��dS)z=Set focus on canvas (in order to collect key-events)
        N)r.rr�r�r�r��_listen�szTurtleScreenBase._listencCs(|dkr|j�|�n|j�||�dS)z?Install a timer, which calls fun after t milliseconds.
        rN)r.Z
after_idlerK�r�r_�tr�r�r��_ontimer�szTurtleScreenBase._ontimercCs|jjdd|d�S)z0Create and return image item on canvas.
        r��image)r.Zcreate_image)r�rtr�r�r��_createimage�szTurtleScreenBase._createimagecCs<|\}}|j�|||j||jf�|jj||d�dS)zZConfigure image item as to draw image object
        at position (x,y) on canvas)
        rsN)r.r?r4r5�
itemconfig)r�rHr[rtr�r�r�r�r��
_drawimage�s zTurtleScreenBase._drawimagecCs |jj||d�|j�|�dS)z�Configure image item as to draw image object
        at center of canvas. Set item to the first item
        in the displaylist, so it will be drawn below
        any other item .rsN)r.rvZ	tag_lower)r�rHrtr�r�r��	_setbgpic�szTurtleScreenBase._setbgpiccCs|j�|�S)zQReturn 'line' or 'polygon' or 'image' depending on
        type of item.
        )r.r�rGr�r�r��_type�szTurtleScreenBase._typecs.|j�|���fdd�tdt��d�D�}|S)a returns list of coordinate-pairs of points of item
        Example (for insiders):
        >>> from turtle import *
        >>> getscreen()._pointlist(getturtle().turtle._item)
        [(0.0, 9.9999999999999982), (0.0, -9.9999999999999982),
        (9.9999999999999982, 0.0)]
        >>> cs"g|]}�|�|df�qS)r�r���.0�i�rBr�r��
<listcomp>�sz/TurtleScreenBase._pointlist.<locals>.<listcomp>rr�)r.r?�range�len)r�rH�plr�r}r��
_pointlist�szTurtleScreenBase._pointlistcCs|jj||||fd�dS)Nr3)r.r
)r��srx1�sry1�srx2�sry2r�r�r��_setscrollregion�sz!TurtleScreenBase._setscrollregionc	Cs||j��}|D]h}t|j�|��}g}|rd|dd�\}}|�||�|�||�|dd�}q&|jj|f|��qdS)Nr�)r.Zfind_allr�r?r>)	r�ZxscalefactorZyscalefactorr�rHZcoordinatesZnewcoordlistr�r�r�r�r��_rescale�s
zTurtleScreenBase._rescalecCszt|jt�s|j|jfS||kr6|kr6dkrJnn|jj|jjfS|dk	rX||_|dk	rf||_|j�|||�dS)zaResize the canvas the turtles are drawing on. Does
        not alter the drawing window.
        N)r�r.rr�r�r`rr�r�r��_resizes"zTurtleScreenBase._resizecCs@|j��}|dkr|jd}|j��}|dkr8|jd}||fS)z; Return the width and height of the turtle window.
        r�rzr�)r.rr)r�rzr�r�r�r��_window_sizes



zTurtleScreenBase._window_sizecCs|jj��dS)a{Starts event loop - calling Tkinter's mainloop function.

        No argument.

        Must be last statement in a turtle graphics program.
        Must NOT be used if a script is run from within IDLE in -n mode
        (No subprocess) - for interactive use of turtle graphics.

        Example (for a TurtleScreen instance named screen):
        >>> screen.mainloop()

        N)r.Ztkrr�r�r�r�rs
zTurtleScreenBase.mainloopcCstj|||jd�S)a�Pop up a dialog window for input of a string.

        Arguments: title is the title of the dialog window,
        prompt is a text mostly describing what information to input.

        Return the string input
        If the dialog is canceled, return None.

        Example (for a TurtleScreen instance named screen):
        >>> screen.textinput("NIM", "Name of first player:")

        )�parent)rZ	askstringr.)r�r)�promptr�r�r�r(.s
zTurtleScreenBase.textinputcCstj||||||jd�S)a�Pop up a dialog window for input of a number.

        Arguments: title is the title of the dialog window,
        prompt is a text mostly describing what numerical information to input.
        default: default value
        minval: minimum value for input
        maxval: maximum value for input

        The number input must be in the range minval .. maxval if these are
        given. If not, a hint is issued and the dialog remains open for
        correction. Return the number input.
        If the dialog is canceled,  return None.

        Example (for a TurtleScreen instance named screen):
        >>> screen.numinput("Poker", "Your stakes:", 1000, minval=10, maxval=10000)

        )ZinitialvalueZminvalueZmaxvaluer�)rZaskfloatr.)r�r)r��defaultZminvalZmaxvalr�r�r�r=s

�zTurtleScreenBase.numinput)NNNF)NNNF)N)r�N)r�N)r�N)r�N)N)NNN)NNN)%r�r�r�r�r0r2r�r:rCrDrErIrJrMrOrPrXrerfrgrirmrnrorrrurwrxryr�r�r�r�r�rr(rr�r�r�r�r,�sT
�
�


	





r,c@seZdZdZdS)r�z�Will be raised in TurtleScreen.update, if _RUNNING becomes False.

    This stops execution of a turtle graphics script.
    Main purpose: use in the Demo-Viewer turtle.Demo.py.
    N�r�r�r�r�r�r�r�r�r�Ysc@seZdZdZdS)�TurtleGraphicsErrorzSome TurtleGraphics Error
    Nr�r�r�r�r�r�bsr�c@s$eZdZdZddd�Zddd�ZdS)	rz�Data structure modeling shapes.

    attribute _type is one of "polygon", "image", "compound"
    attribute _data is - depending on _type a poygon-tuple,
    an image or a list constructed using the addcomponent method.
    NcCsz||_|dkr"t|t�rpt|�}nN|dkrVt|t�rp|���d�rpt|�rpt�	|�}n|dkrdg}nt
d|��||_dS)N�polygonrt�.gif�compoundzThere is no shape type %s)ryr�r�r�r��lower�endswithrrr2r��_data)r�Ztype_�datar�r�r�r�ns


zShape.__init__cCs:|jdkrtd|j��|dkr$|}|j�|||g�dS)a-Add component to a shape of type compound.

        Arguments: poly is a polygon, i. e. a tuple of number pairs.
        fill is the fillcolor of the component,
        outline is the outline color of the component.

        call (for a Shapeobject namend s):
        --   s.addcomponent(((0,0), (10,10), (-10,10)), "red", "blue")

        Example:
        >>> poly = ((0,0),(10,-5),(0,10),(-10,-5))
        >>> s = Shape("compound")
        >>> s.addcomponent(poly, "red", "blue")
        >>> # .. add more components and then use register_shape()
        r�z Cannot add component to %s ShapeN)ryr�r�r>)r��polyr"r9r�r�r��addcomponent~s
�zShape.addcomponent)N)N)r�r�r�r�r�r�r�r�r�r�rgs
c@sDeZdZdZddd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)�Tbufferz5Ring buffer used as undobuffer for RawTurtle objects.r�cCs$||_dgg||_d|_d|_dS)Nr�F)�bufsize�buffer�ptr�cumulate)r�r�r�r�r�r��szTbuffer.__init__NcCsD|dkr&t|j�D]}dg|j|<qn||_dgg||_d|_dS)Nr�)rr�r�r�)r�r�r|r�r�r�r`�sz
Tbuffer.resetcCsF|jdkrB|js0|jd|j|_||j|j<n|j|j�|�dSr�)r�r�r�r�r>rGr�r�r��push�s

zTbuffer.pushcCsJ|jdkrF|j|j}|dkr"dSdg|j|j<|jd|j|_|SdSr�)r�r�r�rGr�r�r��pop�s
zTbuffer.popcCs|j|j�dg�Sr�)r�r��countr�r�r�r��nr_of_items�szTbuffer.nr_of_itemscCst|j�dt|j�S)N� )r�r�r�r�r�r�r�r��szTbuffer.__repr__)r�)N)
r�r�r�r�r�r`r�r�r�r�r�r�r�r�r��s

	r�c@s"eZdZdZdZedededfdd�Zdd	�Zd=dd�Zd
d�Z	d>dd�Z
dd�Zdd�Zd?dd�Z
dd�Zdd�Zdd�Zd@dd�ZdAdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�ZdBd.d/�Zd0d1�ZdCd2d3�ZdDd4d5�ZdEd7d8�ZdFd9d:�ZdGd;d<�ZeZ eZ!eZ"e
Z#eZ$d
S)Hrz�Provides screen oriented methods like setbg etc.

    Only relies upon the methods of TurtleScreenBase and NOT
    upon components of the underlying graphics toolkit -
    which is Tkinter in this case.
    Trrrc
Cs�t�||�tdd�tdd�tdd�tdd�tdd�tdd�td|���d	�|_d
di|_||_||_td|_	g|_
|��tj
d
kr�|��}|�ddddd�|�ddddd�dS)Nr�)����r�r�r�rr�))r�)����)r�r�)����)����	)����)����)r�r�)������)���r�)r�r�)r�r��rr�)�r�)�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�)��Q�#@���Q�@)�G�z. @��Q��@)r�r�)r�r�r�)���Q��r�)��Q���r�)�G�z. �r�)��Q�#�r�r�)r�r�)r�r�)r�r�)r�r�)g�g$�)r�r�)r�r�)r�r�)r�r�))r�r�)r�r�)r�r�)r�r�))r���G�z�)rg�����'@)r�r�)�rr)r�r�r�)r�r�rt)Zarrowr�r4ZsquareZtriangler�r/�nopicr�r�darwinZwmZ
attributesr�z-topmost�1�0)r,r�rr0�_shapes�_bgpics�_mode�_delayvaluer��
_colormode�_keysr5�sys�platformr�Zcall)r�r.rrrZ
rootwindowr�r�r�r��s&�


zTurtleScreen.__init__cCs�td|_td|_|�d�|�d�|_d|_d|_d|_g|_	|�
d�d	D]}|�d
|�qP|�d
�|j
d
d
�D]}|�d
|�|�d
|�qzd
t_d
S)aqDelete all drawings and all turtles from the TurtleScreen.

        No argument.

        Reset empty TurtleScreen to its initial state: white background,
        no backgroundimage, no eventbindings and tracing on.

        Example (for a TurtleScreen instance named screen):
        >>> screen.clear()

        Note: this method is not available as function.
        rr�allr�r�r�rr�)r�r��N)r�r�r�rIru�_bgpic�
_bgpicname�_tracing�_updatecounter�_turtlesrrRrr�rr�_pen)r��btnr�r�r�r�r5�s 




zTurtleScreen.clearNcCs||dkr|jS|��}|dkr*td|��||_|dkrp|�|jd|jd|jd|jd�d|_|_|��dS)ahSet turtle-mode ('standard', 'logo' or 'world') and perform reset.

        Optional argument:
        mode -- one of the strings 'standard', 'logo' or 'world'

        Mode 'standard' is compatible with turtle.py.
        Mode 'logo' is compatible with most Logo-Turtle-Graphics.
        Mode 'world' uses userdefined 'worldcoordinates'. *Attention*: in
        this mode angles appear distorted if x/y unit-ratio doesn't equal 1.
        If mode is not given, return the current mode.

             Mode      Initial turtle heading     positive angles
         ------------|-------------------------|-------------------
          'standard'    to the right (east)       counterclockwise
            'logo'        upward    (north)         clockwise

        Examples:
        >>> mode('logo')   # resets turtle heading to north
        >>> mode()
        'logo'
        N�r��logo�worldzNo turtle-graphics-mode %s)r�r�r�r�)	r�r�r�r�r�r�r4r5r`�r�rr�r�r�rs�zTurtleScreen.modecCs�|��dkr|�d�t||�}t||�}|��\}}|�|d|d�|j|j}	}
|j||_|j||_||j}||j}|j|}
|j|}|�|||
|�|�	|j|	|j|
�|�
�dS)asSet up a user defined coordinate-system.

        Arguments:
        llx -- a number, x-coordinate of lower left corner of canvas
        lly -- a number, y-coordinate of lower left corner of canvas
        urx -- a number, x-coordinate of upper right corner of canvas
        ury -- a number, y-coordinate of upper right corner of canvas

        Set up user coodinat-system and switch to mode 'world' if necessary.
        This performs a screen.reset. If mode 'world' is already active,
        all drawings are redrawn according to the new coordinates.

        But ATTENTION: in user-defined coordinatesystems angles may appear
        distorted. (see Screen.mode())

        Example (for a TurtleScreen instance named screen):
        >>> screen.setworldcoordinates(-10,-0.5,50,1.5)
        >>> for _ in range(36):
        ...     left(10)
        ...     forward(0.5)
        r��N)rr�r�r%r4r5r�r�r�r�r,)r�ZllxZllyZurxZuryZxspanZyspanZwxZwyZ	oldxscaleZ	oldyscaler�r�r�r�r�r�r�r'-s 



z TurtleScreen.setworldcoordinatescCsT|dkr2|���d�r(td|�|��}qFtd��nt|t�rFtd|�}||j|<dS)a�Adds a turtle shape to TurtleScreen's shapelist.

        Arguments:
        (1) name is the name of a gif-file and shape is None.
            Installs the corresponding image shape.
            !! Image-shapes DO NOT rotate when turning the turtle,
            !! so they do not display the heading of the turtle!
        (2) name is an arbitrary string and shape is a tuple
            of pairs of coordinates. Installs the corresponding
            polygon shape
        (3) name is an arbitrary string and shape is a
            (compound) Shape object. Installs the corresponding
            compound shape.
        To use a shape, you have to issue the command shape(shapename).

        call: register_shape("turtle.gif")
        --or: register_shape("tri", ((0,0), (10,10), (-10,10)))

        Example (for a TurtleScreen instance named screen):
        >>> screen.register_shape("triangle", ((5,-3),(0,5),(-5,-3)))

        Nr�rtz;Bad arguments for register_shape.
Use  help(register_shape)r�)r�r�rr2r�r�r�r�)r��namerkr�r�r�r#Ts


zTurtleScreen.register_shapec	Cst|�dkr|d}t|t�rD|�|�s0|dkr4|Stdt|���z|\}}}Wn(ttfk
rztdt|���YnX|jdkr�dd�|||fD�\}}}d|kr�d	kr�nn.d|kr�d	kr�nnd|kr�d	ks�ntd
t|���d|||fS)aReturn color string corresponding to args.

        Argument may be a string or a tuple of three
        numbers corresponding to actual colormode,
        i.e. in the range 0<=n<=colormode.

        If the argument doesn't represent a color,
        an error is raised.
        r�rr�zbad color string: %s�bad color arguments: %sr�cSsg|]}td|��qS�g�o@��round�r{r�r�r�r�r~�sz*TurtleScreen._colorstr.<locals>.<listcomp>��bad color sequence: %s�
#%02x%02x%02x)r�r�r�rOr��	TypeErrorr�r�)r�r9r��g�br�r�r��	_colorstrws


FzTurtleScreen._colorstrcsx��d�s�St��dkr.�fdd�dD�}n4t��dkrV�fdd��dd�D�}ntd	���t�fd
d�|D��S)Nr�r�cs"g|]}t�||d�d��qS)r�r��r�rz��cstrr�r�r~�sz'TurtleScreen._color.<locals>.<listcomp>)r�r�r�r�csg|]}dt�|d��qS)r�r�)r{r7r�r�r�r~�sr�zbad colorstring: %sc3s|]}|�jdVqdS)r�N)r�)r{r�r�r�r��	<genexpr>�sz&TurtleScreen._color.<locals>.<genexpr>)r�r�r�r�)r�r�rBr�)r�r�r��_color�s
zTurtleScreen._colorcCs8|dkr|jS|dkr"t|�|_n|dkr4t|�|_dS)aqReturn the colormode or set it to 1.0 or 255.

        Optional argument:
        cmode -- one of the values 1.0 or 255

        r, g, b values of colortriples have to be in range 0..cmode.

        Example (for a TurtleScreen instance named screen):
        >>> screen.colormode()
        1.0
        >>> screen.colormode(255)
        >>> pencolor(240,160,80)
        Nr�r�)r�r�r�)r�Zcmoder�r�r�r�szTurtleScreen.colormodecCs$|jD]}|�|j�|��qdS)z�Reset all Turtles on the Screen to their initial state.

        No argument.

        Example (for a TurtleScreen instance named screen):
        >>> screen.reset()
        N)r��_setmoder�r`)r�r�r�r�r�r`�s
zTurtleScreen.resetcCs|jS)z�Return the list of turtles on the screen.

        Example (for a TurtleScreen instance named screen):
        >>> screen.turtles()
        [<turtle.Turtle object at 0x00E11FB0>]
        )r�r�r�r�r�r+�szTurtleScreen.turtlescGs4|r|�|�}nd}|�|�}|dk	r0|�|�}|S)a�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 (for a TurtleScreen instance named screen):
        >>> screen.bgcolor("orange")
        >>> screen.bgcolor()
        'orange'
        >>> screen.bgcolor(0.5,0,0.5)
        >>> screen.bgcolor()
        '#800080'
        N)r�rPr��r�rr9r�r�r�r�s

zTurtleScreen.bgcolorcCsB|dkr|jSt|�|_d|_|dk	r0t|�|_|jr>|��dS)aeTurns turtle animation on/off and set delay for update drawings.

        Optional arguments:
        n -- nonnegative  integer
        delay -- nonnegative  integer

        If n is given, only each n-th regular screen update is really performed.
        (Can be used to accelerate the drawing of complex graphics.)
        Second arguments sets delay value (see RawTurtle.delay())

        Example (for a TurtleScreen instance named screen):
        >>> screen.tracer(8, 25)
        >>> dist = 2
        >>> for i in range(200):
        ...     fd(dist)
        ...     rt(90)
        ...     dist += 2
        Nr)r�r�r�r�r,)r��nrr�r�r�r*�s

zTurtleScreen.tracercCs|dkr|jSt|�|_dS)z� Return or set the drawing delay in milliseconds.

        Optional argument:
        delay -- positive integer

        Example (for a TurtleScreen instance named screen):
        >>> screen.delay(15)
        >>> screen.delay()
        15
        N)r�r�rLr�r�r�r�szTurtleScreen.delaycCs<tjsdt_t�|jdkr8|jd7_|j|j;_dS)zIncrement update counter.Trr�N)r�_RUNNINGr�r�r�r�r�r�r��
_incrementudc	s
zTurtleScreen._incrementudccCs<|j}d|_|��D]}|��|��q||_|��dS)z'Perform a TurtleScreen update.
        TN)r�r+�_update_data�_drawturtlerJ)r��tracingrqr�r�r�r,s
zTurtleScreen.updatecCs|��dS)z� Return the width of the turtle window.

        Example (for a TurtleScreen instance named screen):
        >>> screen.window_width()
        640
        r�r�r�r�r�r�r.szTurtleScreen.window_widthcCs|��dS)z� Return the height of the turtle window.

        Example (for a TurtleScreen instance named screen):
        >>> screen.window_height()
        480
        r�r�r�r�r�r�r-&szTurtleScreen.window_heightcCs|jS)z�Return the Canvas of this TurtleScreen.

        No argument.

        Example (for a Screen instance named screen):
        >>> cv = screen.getcanvas()
        >>> cv
        <turtle.ScrolledCanvas instance at 0x010742D8>
        )r.r�r�r�r�r/s
zTurtleScreen.getcanvascCst|j���S)z�Return a list of names of all currently available turtle shapes.

        No argument.

        Example (for a TurtleScreen instance named screen):
        >>> screen.getshapes()
        ['arrow', 'blank', 'circle', ... , 'turtle']
        )�sortedr�r�r�r�r�r�r;s	zTurtleScreen.getshapesr�cCs|�|||�dS)a�Bind fun to mouse-click event on canvas.

        Arguments:
        fun -- a function with two arguments, the coordinates of the
               clicked point on the canvas.
        btn -- the number of the mouse-button, defaults to 1

        Example (for a TurtleScreen instance named screen)

        >>> screen.onclick(goto)
        >>> # Subsequently clicking into the TurtleScreen will
        >>> # make the turtle move to the clicked point.
        >>> screen.onclick(None)
        N)ri�r�r_r�rdr�r�r�rRFszTurtleScreen.onclickcCsF|dkr ||jkr6|j�|�n||jkr6|j�|�|�||�dS)amBind fun to key-release event of key.

        Arguments:
        fun -- a function with no arguments
        key -- a string: key (e.g. "a") or key-symbol (e.g. "space")

        In order to be able to register key-events, TurtleScreen
        must have focus. (See method listen.)

        Example (for a TurtleScreen instance named screen):

        >>> def f():
        ...     fd(50)
        ...     lt(60)
        ...
        >>> screen.onkey(f, "Up")
        >>> screen.listen()

        Subsequently the turtle can be moved by repeatedly pressing
        the up-arrow key, consequently drawing a hexagon

        N)r��remover>rm�r�r_r�r�r�r�rWs

zTurtleScreen.onkeycCsN|dkr ||jkr>|j�|�n|dk	r>||jkr>|j�|�|�||�dS)aBind fun to key-press event of key if key is given,
        or to any key-press-event if no key is given.

        Arguments:
        fun -- a function with no arguments
        key -- a string: key (e.g. "a") or key-symbol (e.g. "space")

        In order to be able to register key-events, TurtleScreen
        must have focus. (See method listen.)

        Example (for a TurtleScreen instance named screen
        and a Turtle instance named turtle):

        >>> def f():
        ...     fd(50)
        ...     lt(60)
        ...
        >>> screen.onkeypress(f, "Up")
        >>> screen.listen()

        Subsequently the turtle can be moved by repeatedly pressing
        the up-arrow key, or by keeping pressed the up-arrow key.
        consequently drawing a hexagon.
        N)r�r�r>rnr�r�r�r�rus
zTurtleScreen.onkeypresscCs|��dS)aSet focus on TurtleScreen (in order to collect key-events)

        No arguments.
        Dummy arguments are provided in order
        to be able to pass listen to the onclick method.

        Example (for a TurtleScreen instance named screen):
        >>> screen.listen()
        N)ro)r��xdummy�ydummyr�r�r�r�s
zTurtleScreen.listenrcCs|�||�dS)a�Install a timer, which calls fun after t milliseconds.

        Arguments:
        fun -- a function with no arguments.
        t -- a number >= 0

        Example (for a TurtleScreen instance named screen):

        >>> running = True
        >>> def f():
        ...     if running:
        ...             fd(50)
        ...             lt(60)
        ...             screen.ontimer(f, 250)
        ...
        >>> f()   # makes the turtle marching around
        >>> running = False
        N)rrrpr�r�r�r"�szTurtleScreen.ontimercCsF|dkr|jS||jkr(|�|�|j|<|�|j|j|�||_dS)aFSet background image or return name of current backgroundimage.

        Optional argument:
        picname -- a string, name of a gif-file or "nopic".

        If picname is a filename, set the corresponding image as background.
        If picname is "nopic", delete backgroundimage, if present.
        If picname is None, return the filename of the current backgroundimage.

        Example (for a TurtleScreen instance named screen):
        >>> screen.bgpic()
        'nopic'
        >>> screen.bgpic("landscape.gif")
        >>> screen.bgpic()
        'landscape.gif'
        N)r�r�r2rxr�)r�Zpicnamer�r�r�r�s
zTurtleScreen.bgpiccCs|�|||�S)a�Resize the canvas the turtles are drawing on.

        Optional arguments:
        canvwidth -- positive integer, new width of canvas in pixels
        canvheight --  positive integer, new height of canvas in pixels
        bg -- colorstring or color-tuple, new backgroundcolor
        If no arguments are given, return current (canvaswidth, canvasheight)

        Do not alter the drawing window. To observe hidden parts of
        the canvas use the scrollbars. (Can make visible those parts
        of a drawing, which were outside the canvas before!)

        Example (for a Turtle instance named turtle):
        >>> turtle.screensize(2000,1500)
        >>> # e.g. to search for an erroneously escaped turtle ;-)
        )r�rr�r�r�r%�szTurtleScreen.screensize)N)N)N)NN)N)r�N)N)NN)r)N)NNN)%r�r�r�r�r�r�r�r5rr'r#r�r�rr`r+rr*rr�r,r.r-rrrRrrrr"rr%r!r$rrr r�r�r�r�r�sH�
(
"'
#
	

			

 



c@sTeZdZdZedd�edd�edd�d�ZdZdZdZefdd	�Z	d
d�Z
dBd
d�Zdd�ZdCdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�ZdDd*d+�Zd,d-�Zd.d/�Zd0d1�ZdEd2d3�ZdFd4d5�Zd6d7�Zd8d9�Z dGd:d;�Z!dHd<d=�Z"dId>d?�Z#dJd@dA�Z$eZ%eZ&eZ'eZ(eZ)eZ*eZ+eZ,e Z-dS)K�
TNavigatorzRNavigation part of the RawTurtle.
    Implements methods for turtle movement.
    r��)r�r�r�r�rr�cCsB|j|_|j|_||_d|_|��d|_|�|�t�	|�dSr�)
�DEFAULT_ANGLEOFFSET�_angleOffset�DEFAULT_ANGLEORIENT�_angleOrientr��
undobufferr:r�r�r`r�r�r�r�r��s
zTNavigator.__init__cCstdd�|_tj|j|_dS)zXreset turtle to its initial values

        Will be overwritten by parent class
        r�N)r�	_positionr��START_ORIENTATIONr��_orientr�r�r�r�r`�szTNavigator.resetNcCsL|dkr|jS|dkrdS||_|dkr6d|_d|_n|jd|_d|_dS)z:Set turtle-mode to 'standard', 'world' or 'logo'.
        Nr�)r�r�rr��@r�)r�rr�_fullcircler�r�r�r�r�szTNavigator._setmodecCs0||_d||_|jdkr"d|_n
|d|_dS)z+Helper function for degrees() and radians()ihr�rrN)r�
_degreesPerAUr�r�r�Z
fullcircler�r�r��_setDegreesPerAUs


zTNavigator._setDegreesPerAU��v@cCs|�|�dS)a> Set angle measurement units to degrees.

        Optional argument:
        fullcircle -  a number

        Set angle measurement units, i. e. set number
        of 'degrees' for a full circle. Default value is
        360 degrees.

        Example (for a Turtle instance named turtle):
        >>> turtle.left(90)
        >>> turtle.heading()
        90

        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

        N)rr
r�r�r�r:szTNavigator.degreescCs|�dtj�dS)a Set the angle measurement units to radians.

        No arguments.

        Example (for a Turtle instance named turtle):
        >>> turtle.heading()
        90
        >>> turtle.radians()
        >>> turtle.heading()
        1.5707963267948966
        r�N)rr�r�r�r�r�r�r^5szTNavigator.radianscCs|j|j|}|�|�dS)z)move turtle forward by specified distanceN)rr�_goto)r�r;Zender�r�r��_goCszTNavigator._gocCs||j9}|j�|�|_dS)z=Turn turtle counterclockwise by specified angle if angle > 0.N)r	rr��r�r�r�r�r��_rotateHs
zTNavigator._rotatecCs
||_dS)zmove turtle to position end.N�r)r��endr�r�r�r
MszTNavigator._gotocCs|�|�dS)aMove the turtle forward by the specified distance.

        Aliases: forward | fd

        Argument:
        distance -- a number (integer or float)

        Move the turtle forward by the specified distance, in the direction
        the turtle is headed.

        Example (for a Turtle instance named turtle):
        >>> turtle.position()
        (0.00, 0.00)
        >>> turtle.forward(25)
        >>> turtle.position()
        (25.00,0.00)
        >>> turtle.forward(-75)
        >>> turtle.position()
        (-50.00,0.00)
        N�r�r�r;r�r�r�rCQszTNavigator.forwardcCs|�|�dS)a�Move the turtle backward by distance.

        Aliases: back | backward | bk

        Argument:
        distance -- a number

        Move the turtle backward by distance, opposite to the direction the
        turtle is headed. Do not change the turtle's heading.

        Example (for a Turtle instance named turtle):
        >>> turtle.position()
        (0.00, 0.00)
        >>> turtle.backward(30)
        >>> turtle.position()
        (-30.00, 0.00)
        Nrrr�r�r�r/hszTNavigator.backcCs|�|�dS)a�Turn turtle right by angle units.

        Aliases: right | rt

        Argument:
        angle -- a number (integer or float)

        Turn turtle right by angle units. (Units are by default degrees,
        but can be set via the degrees() and radians() functions.)
        Angle orientation depends on mode. (See this.)

        Example (for a Turtle instance named turtle):
        >>> turtle.heading()
        22.0
        >>> turtle.right(45)
        >>> turtle.heading()
        337.0
        N�rrr�r�r�r_|szTNavigator.rightcCs|�|�dS)a�Turn turtle left by angle units.

        Aliases: left | lt

        Argument:
        angle -- a number (integer or float)

        Turn turtle left by angle units. (Units are by default degrees,
        but can be set via the degrees() and radians() functions.)
        Angle orientation depends on mode. (See this.)

        Example (for a Turtle instance named turtle):
        >>> turtle.heading()
        22.0
        >>> turtle.left(45)
        >>> turtle.heading()
        67.0
        Nrrr�r�r�rP�szTNavigator.leftcCs|jS)z�Return the turtle's current location (x,y), as a Vec2D-vector.

        Aliases: pos | position

        No arguments.

        Example (for a Turtle instance named turtle):
        >>> turtle.pos()
        (0.00, 240.00)
        rr�r�r�r�r[�szTNavigator.poscCs
|jdS)z� Return the turtle's x coordinate.

        No arguments.

        Example (for a Turtle instance named turtle):
        >>> reset()
        >>> turtle.left(60)
        >>> turtle.forward(100)
        >>> print turtle.xcor()
        50.0
        rrr�r�r�r�r|�szTNavigator.xcorcCs
|jdS)a	 Return the turtle's y coordinate
        ---
        No arguments.

        Example (for a Turtle instance named turtle):
        >>> reset()
        >>> turtle.left(60)
        >>> turtle.forward(100)
        >>> print turtle.ycor()
        86.6025403784
        r�rr�r�r�r�r}�szTNavigator.ycorcCs,|dkr|�t|��n|�t||��dS)atMove turtle to an absolute position.

        Aliases: setpos | setposition | goto:

        Arguments:
        x -- a number      or     a pair/vector of numbers
        y -- a number             None

        call: goto(x, y)         # two coordinates
        --or: goto((x, y))       # a pair (tuple) of coordinates
        --or: goto(vec)          # e.g. as returned by pos()

        Move turtle to an absolute position. If the pen is down,
        a line will be drawn. The turtle's orientation does not change.

        Example (for a Turtle instance named turtle):
        >>> tp = turtle.pos()
        >>> tp
        (0.00, 0.00)
        >>> turtle.setpos(60,30)
        >>> turtle.pos()
        (60.00,30.00)
        >>> turtle.setpos((20,80))
        >>> turtle.pos()
        (20.00,80.00)
        >>> turtle.setpos(tp)
        >>> turtle.pos()
        (0.00,0.00)
        N)r
r)r�r�r�r�r�r�rI�szTNavigator.gotocCs|�dd�|�d�dS)a$Move turtle to the origin - coordinates (0,0).

        No arguments.

        Move turtle to the origin - coordinates (0,0) and set its
        heading to its start-orientation (which depends on mode).

        Example (for a Turtle instance named turtle):
        >>> turtle.home()
        rN)rIrdr�r�r�r�rL�szTNavigator.homecCs|�t||jd��dS)a�Set the turtle's first coordinate to x

        Argument:
        x -- a number (integer or float)

        Set the turtle's first coordinate to x, leave second coordinate
        unchanged.

        Example (for a Turtle instance named turtle):
        >>> turtle.position()
        (0.00, 240.00)
        >>> turtle.setx(10)
        >>> turtle.position()
        (10.00, 240.00)
        r�N�r
rr)r�r�r�r�r�riszTNavigator.setxcCs|�t|jd|��dS)a�Set the turtle's second coordinate to y

        Argument:
        y -- a number (integer or float)

        Set the turtle's first coordinate to x, second coordinate remains
        unchanged.

        Example (for a Turtle instance named turtle):
        >>> turtle.position()
        (0.00, 40.00)
        >>> turtle.sety(-10)
        >>> turtle.position()
        (0.00, -10.00)
        rNr)r�r�r�r�r�rjszTNavigator.setycCsT|dk	rt||�}t|t�r"|}n$t|t�r6t|�}nt|t�rF|j}t||j�S)a�Return the distance from the turtle to (x,y) in turtle step units.

        Arguments:
        x -- a number   or  a pair/vector of numbers   or   a turtle instance
        y -- a number       None                            None

        call: distance(x, y)         # two coordinates
        --or: distance((x, y))       # a pair (tuple) of coordinates
        --or: distance(vec)          # e.g. as returned by pos()
        --or: distance(mypen)        # where mypen is another turtle

        Example (for a Turtle instance named turtle):
        >>> turtle.pos()
        (0.00, 0.00)
        >>> turtle.distance(30,40)
        50.0
        >>> pen = Turtle()
        >>> pen.forward(77)
        >>> turtle.distance(pen)
        77.0
        N)rr�r�r�r�abs)r�r�r�r[r�r�r�r;%s




zTNavigator.distancecCs�|dk	rt||�}t|t�r"|}n$t|t�r6t|�}nt|t�rF|j}||j\}}tt�||�dtjd�d}||j	}|j
|j||jS)aCReturn the angle of the line from the turtle's position to (x, y).

        Arguments:
        x -- a number   or  a pair/vector of numbers   or   a turtle instance
        y -- a number       None                            None

        call: distance(x, y)         # two coordinates
        --or: distance((x, y))       # a pair (tuple) of coordinates
        --or: distance(vec)          # e.g. as returned by pos()
        --or: distance(mypen)        # where mypen is another turtle

        Return the angle, between the line from turtle-position to position
        specified by x, y and the turtle's start orientation. (Depends on
        modes - "standard" or "logo")

        Example (for a Turtle instance named turtle):
        >>> turtle.pos()
        (10.00, 10.00)
        >>> turtle.towards(0,0)
        225.0
        Nr�r�r)
rr�r�r�rr�r��atan2r�r	rrr)r�r�r�r[�resultr�r�r�ruEs




 
zTNavigator.towardscCsJ|j\}}tt�||�dtjd�d}||j}|j|j||jS)z� Return the turtle's current heading.

        No arguments.

        Example (for a Turtle instance named turtle):
        >>> turtle.left(67)
        >>> turtle.heading()
        67.0
        r�r�r)	rr�r�rr�r	rrr)r�r�r�rr�r�r�rJhs

 
zTNavigator.headingcCs>||��|j}|j}||d||d}|�|�dS)a�Set the orientation of the turtle to to_angle.

        Aliases:  setheading | seth

        Argument:
        to_angle -- a number (integer or float)

        Set the orientation of the turtle to to_angle.
        Here are some common directions in degrees:

         standard - mode:          logo-mode:
        -------------------|--------------------
           0 - east                0 - north
          90 - north              90 - east
         180 - west              180 - south
         270 - south             270 - west

        Example (for a Turtle instance named turtle):
        >>> turtle.setheading(90)
        >>> turtle.heading()
        90
        �@N)rJrrr)r�Zto_angler�Zfullr�r�r�rdwszTNavigator.setheadingcCsp|jr|j�dg�d|j_|��}|dkr2|j}|dkrjt|�|j}dttdt|�dd�|�}d||}d	|}d
|t�	|tj
d|j�}|dkr�|||}}}|��}	|�
�}
|dkr�|�dd�n
|�d�|�|�t|�D].}|�|�|�|�|�d�|�|��q|�|�|dk�rR|�|	|
�|�|�|j�rld
|j_dS)a� Draw a circle with given radius.

        Arguments:
        radius -- a number
        extent (optional) -- a number
        steps (optional) -- an integer

        Draw a circle with given radius. The center is radius units left
        of the turtle; extent - an angle - determines which part of the
        circle is drawn. If extent is not given, draw the entire circle.
        If extent is not a full circle, one endpoint of the arc is the
        current pen position. Draw the arc in counterclockwise direction
        if radius is positive, otherwise in clockwise direction. Finally
        the direction of the turtle is changed by the amount of extent.

        As the circle is approximated by an inscribed regular polygon,
        steps determines the number of steps to use. If not given,
        it will be calculated automatically. Maybe used to draw regular
        polygons.

        call: circle(radius)                  # full circle
        --or: circle(radius, extent)          # arc
        --or: circle(radius, extent, steps)
        --or: circle(radius, steps=6)         # 6-sided polygon

        Example (for a Turtle instance named turtle):
        >>> turtle.circle(50)
        >>> turtle.circle(120, 180)  # semicircle
        �seqTNr��g@g�M@r�r�rr�rF)rr�r�rprrr��minr�r�r�r	�_tracerrMrrr)r��radiusZextent�stepsrpZfracr6Zw2�lZtrZdlr|r�r�r�r4�s>""






zTNavigator.circlecCsdS�z/dummy method - to be overwritten by child classNr�)r�r�r�r�r�rp�szTNavigator.speedcCsdSr"r�)r��ar�r�r�r�r�szTNavigator._tracercCsdSr"r�)r�r�r�r�r�rM�szTNavigator._delay)N)r)N)N)N)NN)r)NN)N).r�r�r�r�rrZDEFAULT_MODEr�rr�r`r�rr:r^rrr
rCr/r_rPr[r|r}rIrLrirjr;rurJrdr4rprrMr@r3r0rbrQr\rerfrcr�r�r�r�r��sZ�

	


#
 
#
A


r�c@s�eZdZdZedfdd�Zededfdd�Zd.d
d�Zd/dd
�Zdd�Z	dd�Z
dd�Zd0dd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd1d"d#�Zd2d%d&�Zd3d(d)�Zd*d+�Zd,d-�ZeZe	Ze	Ze
Ze
ZeZeZd	S)4�TPenzFDrawing part of the RawTurtle.
    Implements drawing properties.
    racCs||_d|_t�|�dSr�)�_resizemoderr$�_reset)r�rar�r�r�r��sz
TPen.__init__rWrAcCsFd|_d|_||_||_d|_d|_d|_d|_d|_d|_	d|_
dS)Nr�Tr�)r�r�r�)r�r�r�r�)�_pensize�_shown�	_pencolor�
_fillcolor�_drawing�_speed�_stretchfactor�_shearfactor�_tilt�_shapetrafo�
_outlinewidth)r�rWrAr�r�r�r&�szTPen._resetNcCs.|dkr|jS|��}|dkr*|j|d�dS)azSet resizemode to one of the values: "auto", "user", "noresize".

        (Optional) Argument:
        rmode -- one of the strings "auto", "user", "noresize"

        Different resizemodes have the following effects:
          - "auto" adapts the appearance of the turtle
                   corresponding to the value of pensize.
          - "user" adapts the appearance of the turtle according to the
                   values of stretchfactor and outlinewidth (outline),
                   which are set by shapesize()
          - "noresize" no adaption of the turtle's appearance takes place.
        If no argument is given, return current resizemode.
        resizemode("user") is called by a call of shapesize with arguments.


        Examples (for a Turtle instance named turtle):
        >>> turtle.resizemode("noresize")
        >>> turtle.resizemode()
        'noresize'
        N)�auto�userr��ra)r%r�rV)r�Zrmoder�r�r�ra�s
zTPen.resizemodecCs|dkr|jS|j|d�dS)a!Set or return the line thickness.

        Aliases:  pensize | width

        Argument:
        width -- positive number

        Set the line thickness to width or return it. If resizemode is set
        to "auto" and turtleshape is a polygon, that polygon is drawn with
        the same line thickness. If no argument is given, current pensize
        is returned.

        Example (for a Turtle instance named turtle):
        >>> turtle.pensize()
        1
        >>> turtle.pensize(10)   # from here on lines of width 10 are drawn
        N)rY)r'rV)r�rzr�r�r�rYszTPen.pensizecCs|js
dS|jdd�dS)z�Pull the pen up -- no drawing when moving.

        Aliases: penup | pu | up

        No argument

        Example (for a Turtle instance named turtle):
        >>> turtle.penup()
        NF�rX�r+rVr�r�r�r�rZ0s
z
TPen.penupcCs|jr
dS|jdd�dS)z�Pull the pen down -- drawing when moving.

        Aliases: pendown | pd | down

        No argument.

        Example (for a Turtle instance named turtle):
        >>> turtle.pendown()
        NTr5r6r�r�r�r�rX>s
zTPen.pendowncCs|jS)aReturn True if pen is down, False if it's up.

        No argument.

        Example (for a Turtle instance named turtle):
        >>> turtle.penup()
        >>> turtle.isdown()
        False
        >>> turtle.pendown()
        >>> turtle.isdown()
        True
        )r+r�r�r�r�rNLs
zTPen.isdowncCsjdddddd�}|dkr|jS||kr0||}n*d|krDd	krVnntt|��}nd}|j|d
�dS)a� Return or set the turtle's speed.

        Optional argument:
        speed -- an integer in the range 0..10 or a speedstring (see below)

        Set the turtle's speed to an integer value in the range 0 .. 10.
        If no argument is given: return current speed.

        If input is a number greater than 10 or smaller than 0.5,
        speed is set to 0.
        Speedstrings  are mapped to speedvalues in the following way:
            'fastest' :  0
            'fast'    :  10
            'normal'  :  6
            'slow'    :  3
            'slowest' :  1
        speeds from 1 to 10 enforce increasingly faster animation of
        line drawing and turtle turning.

        Attention:
        speed = 0 : *no* animation takes place. forward/back makes turtle jump
        and likewise left/right make the turtle turn instantly.

        Example (for a Turtle instance named turtle):
        >>> turtle.speed(3)
        rr�r�r�r�)ZfastestZfast�normalZslowZslowestNr�g%@)rp)r,r�r�rV)r�rpZspeedsr�r�r�rp[s
z
TPen.speedcGs�|rht|�}|dkr"|d}}n"|dkr4|\}}n|dkrD|}}|�|�}|�|�}|j||d�n|�|j�|�|j�fSdS)a�Return or set the pencolor and fillcolor.

        Arguments:
        Several input formats are allowed.
        They use 0, 1, 2, or 3 arguments as follows:

        color()
            Return the current pencolor and the current fillcolor
            as a pair of color specification strings as are returned
            by pencolor and fillcolor.
        color(colorstring), color((r,g,b)), color(r,g,b)
            inputs as in pencolor, set both, fillcolor and pencolor,
            to the given value.
        color(colorstring1, colorstring2),
        color((r1,g1,b1), (r2,g2,b2))
            equivalent to pencolor(colorstring1) and fillcolor(colorstring2)
            and analogously, if the other input format is used.

        If turtleshape is a polygon, outline and interior of that polygon
        is drawn with the newly set colors.
        For more info see: pencolor, fillcolor

        Example (for a Turtle instance named turtle):
        >>> turtle.color('red', 'green')
        >>> turtle.color()
        ('red', 'green')
        >>> colormode(255)
        >>> color((40, 80, 120), (160, 200, 240))
        >>> color()
        ('#285078', '#a0c8f0')
        r�rr�r�)rWrAN)r�r�rVr�r)r*)r�rr!ZpcolorZfcolorr�r�r�r9�s 


z
TPen.colorcGs:|r*|�|�}||jkrdS|j|d�n|�|j�SdS)aZ Return or set the pencolor.

        Arguments:
        Four input formats are allowed:
          - pencolor()
            Return the current pencolor as color specification string,
            possibly in hex-number format (see example).
            May be used as input to another color/pencolor/fillcolor call.
          - pencolor(colorstring)
            s is a Tk color specification string, such as "red" or "yellow"
          - pencolor((r, g, b))
            *a tuple* of r, g, and b, which represent, an RGB color,
            and each of r, g, and b are in the range 0..colormode,
            where colormode is either 1.0 or 255
          - pencolor(r, g, b)
            r, g, and b represent an RGB color, and each of r, g, and b
            are in the range 0..colormode

        If turtleshape is a polygon, the outline of that polygon is drawn
        with the newly set pencolor.

        Example (for a Turtle instance named turtle):
        >>> turtle.pencolor('brown')
        >>> tup = (0.2, 0.8, 0.55)
        >>> turtle.pencolor(tup)
        >>> turtle.pencolor()
        '#33cc8c'
        N)rW)r�r)rVr�r�r�r�r�rW�s

z
TPen.pencolorcGs:|r*|�|�}||jkrdS|j|d�n|�|j�SdS)a] Return or set the fillcolor.

        Arguments:
        Four input formats are allowed:
          - fillcolor()
            Return the current fillcolor as color specification string,
            possibly in hex-number format (see example).
            May be used as input to another color/pencolor/fillcolor call.
          - fillcolor(colorstring)
            s is a Tk color specification string, such as "red" or "yellow"
          - fillcolor((r, g, b))
            *a tuple* of r, g, and b, which represent, an RGB color,
            and each of r, g, and b are in the range 0..colormode,
            where colormode is either 1.0 or 255
          - fillcolor(r, g, b)
            r, g, and b represent an RGB color, and each of r, g, and b
            are in the range 0..colormode

        If turtleshape is a polygon, the interior of that polygon is drawn
        with the newly set fillcolor.

        Example (for a Turtle instance named turtle):
        >>> turtle.fillcolor('violet')
        >>> col = turtle.pencolor()
        >>> turtle.fillcolor(col)
        >>> turtle.fillcolor(0, .5, 0)
        N)rA)r�r*rVr�r�r�r�r�rA�s

zTPen.fillcolorcCs|jdd�dS)z�Makes the turtle visible.

        Aliases: showturtle | st

        No argument.

        Example (for a Turtle instance named turtle):
        >>> turtle.hideturtle()
        >>> turtle.showturtle()
        T��shownN�rVr�r�r�r�ro�szTPen.showturtlecCs|jdd�dS)aYMakes the turtle invisible.

        Aliases: hideturtle | ht

        No argument.

        It's a good idea to do this while you're in the
        middle of a complicated drawing, because hiding
        the turtle speeds up the drawing observably.

        Example (for a Turtle instance named turtle):
        >>> turtle.hideturtle()
        Fr8Nr:r�r�r�r�rK	szTPen.hideturtlecCs|jS)z�Return True if the Turtle is shown, False if it's hidden.

        No argument.

        Example (for a Turtle instance named turtle):
        >>> turtle.hideturtle()
        >>> print turtle.isvisible():
        False
        )r(r�r�r�r�rO	s
zTPen.isvisiblecKs�|j|j|j|j|j|j|j|j|j|j	|j
d�}|s>|s>|St|t�rN|}ni}|�
|�i}|D]}||||<qd|jr�|j�d|f�d}d|kr�|j|dkr�d}d|kr�t|dt�r�|�|df�|d<|j|dkr�d}d|k�r|j|dk�rd}|�r|��d|k�r&|d|_d|k�r:|d|_d|k�rN|d|_d|k�r�t|dt��r||�|df�|d<|d|_d	|k�r�|d	|_d
|k�r�|d
|_d|k�r�|d}t|ttf��r�||f}||_d|k�r�|d|_d
|k�r|d
|_	d|k�r|d|_d|k�r.|d|_
d|k�sLd|k�sLd|k�r�|j\}	}
|j}t�|j
�t�|j
�}}
|	|
|
||
||	||
|
||f|_|��dS)aLReturn or set the pen's attributes.

        Arguments:
            pen -- a dictionary with some or all of the below listed keys.
            **pendict -- one or more keyword-arguments with the below
                         listed keys as keywords.

        Return or set the pen's attributes in a 'pen-dictionary'
        with the following key/value pairs:
           "shown"      :   True/False
           "pendown"    :   True/False
           "pencolor"   :   color-string or color-tuple
           "fillcolor"  :   color-string or color-tuple
           "pensize"    :   positive number
           "speed"      :   number in range 0..10
           "resizemode" :   "auto" or "user" or "noresize"
           "stretchfactor": (positive number, positive number)
           "shearfactor":   number
           "outline"    :   positive number
           "tilt"       :   number

        This dictionary can be used as argument for a subsequent
        pen()-call to restore the former pen-state. Moreover one
        or more of these attributes can be provided as keyword-arguments.
        This can be used to set several pen attributes in one statement.


        Examples (for a Turtle instance named turtle):
        >>> turtle.pen(fillcolor="black", pencolor="red", pensize=10)
        >>> turtle.pen()
        {'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
        'pencolor': 'red', 'pendown': True, 'fillcolor': 'black',
        'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
        >>> penstate=turtle.pen()
        >>> turtle.color("yellow","")
        >>> turtle.penup()
        >>> turtle.pen()
        {'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
        'pencolor': 'yellow', 'pendown': False, 'fillcolor': '',
        'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
        >>> p.pen(penstate, fillcolor="green")
        >>> p.pen()
        {'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
        'pencolor': 'red', 'pendown': True, 'fillcolor': 'green',
        'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
        )r9rXrWrArYrpra�
stretchfactorrnr9rsrVFrXTrWrYrArprar;rnr9r9rsN)r(r+r)r*r'r,r%r-r.r1r/r��dictr,rr�r�r��_newLiner�r�r�r�r�r0rJ)r�rVZpendictZ_pd�pZ_p_bufr�ZnewLineZsfZscxZscyZshf�sa�car�r�r�rV!	s�/�

























�zTPen.penTcCsdSr"r��r�ZusePosr�r�r�r=�	sz
TPen._newLineFcCsdSr"r�)r�r�Zforcedr�r�r�rJ�	szTPen._updatecCsdSr"r�rr�r�r�r��	szTPen._colorcCsdSr"r�rr�r�r�r��	szTPen._colorstr)N)N)N)N)T)TF)r�r�r�r�r�r�r&rarYrZrXrNrpr9rWrArorKrOrVr=rJr�r�rzryr]rUr=rqrMr�r�r�r�r$�s:�



&.%$



r$c@s eZdZdZdd�Zdd�ZdS)�_TurtleImagez6Helper class: Datatype to store Turtle attributes
    cCs||_d|_|�|�dSr�)r�ry�	_setshape)r�r��
shapeIndexr�r�r�r��	sz_TurtleImage.__init__cs�|j�||_|jdkr*�j|jkr2nndS|jdkrP�j|jkrXnndS|jdkrp��|j�n |jdkr�|jD]}��|�q��j|j|_|jdkr����|_nF|jdkrԈ��jdj�|_n&|jdkr��fdd��j|jD�|_dS)Nr�rt)rtr�r�r/csg|]}����qSr��r:�r{rH�r�r�r�r~�	sz*_TurtleImage._setshape.<locals>.<listcomp>)	r�rDryr�rI�_itemr:rur�)r�rDrHr�rGr�rC�	s(""







�z_TurtleImage._setshapeN)r�r�r�r�r�rCr�r�r�r�rB�	srBc@s�eZdZdZgZdedededfdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dmdd�Zdd�Zdd�Zdd�Zdd�Zdnd d!�Zdod"d#�Zdpd$d%�Zd&d'�Zdqd(d)�Zd*d+�Zdrd,d-�Zd.d/�Zd0d1�Zdsd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z dtd=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dudFdG�Z%dHdI�Z&dJdK�Z'dLdM�Z(dvdNdO�Z)dPdQ�Z*dwdTdU�Z+dVdW�Z,dXdY�Z-dZd[�Z.d\d]�Z/d^d_�Z0e0Z1dxd`da�Z2dydcdd�Z3dzdedf�Z4d{dgdh�Z5didj�Z6dkdl�Z7eZ8dS)|r
zvAnimation part of the RawTurtle.
    Puts RawTurtle upon a TurtleScreen and provides tools for
    its animation.
    Nrkr�r�cCs4t|t�r||_n|t|t�r:|tjkr2tj�|�||_nTt|ttf�r�tjD]}|j	|krN||_q�qNt|�|_tj�|j�nt
d|��|j}t�||�
��t�|�|j�|�|��|_t||�|_d|_d|_d|_|_||_d|_|��|_|jg|_|jg|_g|_||_t |�|_!|�"�dS)Nzbad canvas argument %sF)#r��_Screenr�rr
�screensr>rr�r.r�r�r�rr$r�rD�drawingLineItemrBr��_poly�
_creatingPoly�	_fillitem�	_fillpathr(�_hidden_from_screen�currentLineItemr�currentLiner��
stampItems�_undobuffersizer�rrJ)r�Zcanvasrkr�r�r�r�r�r�r��	s@











zRawTurtle.__init__cCs0t�|�t�|�|��|��|��dS)a�Delete the turtle's drawings and restore its default values.

        No argument.

        Delete the turtle's drawings from the screen, re-center the turtle
        and set variables to the default values.

        Example (for a Turtle instance named turtle):
        >>> turtle.position()
        (0.00,-22.00)
        >>> turtle.heading()
        100.0
        >>> turtle.reset()
        >>> turtle.position()
        (0.00,0.00)
        >>> turtle.heading()
        0.0
        N)r�r`r$r&�_clearr�rJr�r�r�r�r`
s


zRawTurtle.resetcCs&|dks|dkrd|_n
t|�|_dS)a�Set or disable undobuffer.

        Argument:
        size -- an integer or None

        If size is an integer an empty undobuffer of given size is installed.
        Size gives the maximum number of turtle-actions that can be undone
        by the undo() function.
        If size is None, no undobuffer is present.

        Example (for a Turtle instance named turtle):
        >>> turtle.setundobuffer(42)
        Nr)rr�)r��sizer�r�r�rh
szRawTurtle.setundobuffercCs|jdkrdS|j��S)z�Return count of entries in the undobuffer.

        No argument.

        Example (for a Turtle instance named turtle):
        >>> while undobufferentries():
        ...     undo()
        Nr)rr�r�r�r�r�rx,
s	
zRawTurtle.undobufferentriescCsld|_|_|jD]}|j�|�q|j��|_g|_|jrJ|j�	|j
�|jg|_|��|�|j
�dS)zDelete all of pen's drawingsN)rNrOr�r�rIrDrQrRr+r>rr7rhrTrGr�r�r�rU9
s

zRawTurtle._clearcCs|��|��dS)agDelete the turtle's drawings from the screen. Do not move turtle.

        No arguments.

        Delete the turtle's drawings from the screen. Do not move turtle.
        State and position of the turtle as well as drawings of other
        turtles are not affected.

        Examples (for a Turtle instance named turtle):
        >>> turtle.clear()
        N)rUrJr�r�r�r�r5G
szRawTurtle.clearcCsF|j��|jjdkrdSt|j�dkrB|j�|j|j|j|j�dSr�)	r�r�r�r�rRrErQr)r'r�r�r�r�r�V
s
�zRawTurtle._update_datacCsx|j}|jdkrdS|jdkrD|��|��|��|�|j�n0|��|jdkrt|��D]}|��q^|��dS)z&Perform a Turtle-data update.
        rNr�)	r�r�r�r�rJrMr�r�r+)r�r�rqr�r�r�rJ^
s



zRawTurtle._updatecCs|j�||�S)amTurns turtle animation on/off and set delay for update drawings.

        Optional arguments:
        n -- nonnegative  integer
        delay -- nonnegative  integer

        If n is given, only each n-th regular screen update is really performed.
        (Can be used to accelerate the drawing of complex graphics.)
        Second arguments sets delay value (see RawTurtle.delay())

        Example (for a Turtle instance named turtle):
        >>> turtle.tracer(8, 25)
        >>> dist = 2
        >>> for i in range(200):
        ...     turtle.fd(dist)
        ...     turtle.rt(90)
        ...     dist += 2
        )r�r*)r��flagrr�r�r�rp
szRawTurtle._tracercCs|j�|�Sr�)r�r�rr�r�r�r��
szRawTurtle._colorcCs|j�|�Sr�)r�r�rr�r�r�r��
szRawTurtle._colorstrc	Cs�t|t�r|Sz|\}}}Wn(ttfk
rDtdt|���YnX|jjdkrldd�|||fD�\}}}d|kr�dkr�nn.d|kr�dkr�nnd|kr�dks�ntdt|���d|||fS)	z,Convert colortriples to hexstrings.
        r�r�cSsg|]}td|��qSr�r�r�r�r�r�r~�
sz!RawTurtle._cc.<locals>.<listcomp>rr�r�r�)r�r�r�r�r�r�r�)r�rr�r�r�r�r�r��_cc�
s
Fz
RawTurtle._cccs�|j�|�|j�|j}d|_d|_t|�}�|_||_�|_t�|jj�|_�j�|��j	|jjj
}|dkr����|j_nJ|dkr���
�j	dj�|j_n*|dkrʇfdd��j	|jjjD�|j_���|_|��|S)aCreate and return a clone of the turtle.

        No argument.

        Create and return a clone of the turtle with same position, heading
        and turtle properties.

        Example (for a Turtle instance named mick):
        mick = Turtle()
        joe = mick.clone()
        Nr�rtr/r�csg|]}����qSr�rErFrGr�r�r~�
sz#RawTurtle.clone.<locals>.<listcomp>)r�r=r+r�rrBrDr�r>r�ryr:rHrur�rDrQrJ)r�r��q�ttyper�rGr�r8�
s.
�

zRawTurtle.clonecCsB|dkr|jjS||j��kr*td|��|j�|�|��dS)a�Set turtle shape to shape with given name / return current shapename.

        Optional argument:
        name -- a string, which is a valid shapename

        Set turtle shape to shape with given name or, if name is not given,
        return name of current shape.
        Shape with name must exist in the TurtleScreen's shape dictionary.
        Initially there are the following polygon shapes:
        'arrow', 'turtle', 'circle', 'square', 'triangle', 'classic'.
        To learn about how to deal with shapes see Screen-method register_shape.

        Example (for a Turtle instance named turtle):
        >>> turtle.shape()
        'arrow'
        >>> turtle.shape("turtle")
        >>> turtle.shape()
        'turtle'
        NzThere is no shape named %s)r�rDr�rr�rCrJ)r�r�r�r�r�rk�
szRawTurtle.shapecCs�||kr|krdkr8nn|j\}}|||jfS|dksH|dkrPtd��|dk	rt|dkrj||f}q�||f}n|dk	r�|jd|f}n|j}|dkr�|j}|jd||d�dS)aOSet/return turtle's stretchfactors/outline. Set resizemode to "user".

        Optional arguments:
           stretch_wid : positive number
           stretch_len : positive number
           outline  : positive number

        Return or set the pen's attributes x/y-stretchfactors and/or outline.
        Set resizemode to "user".
        If and only if resizemode is set to "user", the turtle will be displayed
        stretched according to its stretchfactors:
        stretch_wid is stretchfactor perpendicular to orientation
        stretch_len is stretchfactor in direction of turtles orientation.
        outline determines the width of the shapes's outline.

        Examples (for a Turtle instance named turtle):
        >>> turtle.resizemode("user")
        >>> turtle.shapesize(5, 5, 12)
        >>> turtle.shapesize(outline=8)
        Nrz(stretch_wid/stretch_len must not be zeror3)rar;r9)r-r1r�rV)r�Zstretch_widZstretch_lenr9r;r�r�r�rl�
s$"


�zRawTurtle.shapesizecCs |dkr|jS|jd|d�dS)a�Set or return the current shearfactor.

        Optional argument: shear -- number, tangent of the shear angle

        Shear the turtleshape according to the given shearfactor shear,
        which is the tangent of the shear angle. DO NOT change the
        turtle's heading (direction of movement).
        If shear is not given: return the current shearfactor, i. e. the
        tangent of the shear angle, by which lines parallel to the
        heading of the turtle are sheared.

        Examples (for a Turtle instance named turtle):
        >>> turtle.shape("circle")
        >>> turtle.shapesize(5,2)
        >>> turtle.shearfactor(0.5)
        >>> turtle.shearfactor()
        >>> 0.5
        Nr3)rarn)r.rV)r�Zshearr�r�r�rnszRawTurtle.shearfactorcCs<||j|j}|tjddtj}|jd|d�dS)aIRotate the turtleshape to point in the specified direction

        Argument: angle -- number

        Rotate the turtleshape to point in the direction specified by angle,
        regardless of its current tilt-angle. DO NOT change the turtle's
        heading (direction of movement).


        Examples (for a Turtle instance named turtle):
        >>> turtle.shape("circle")
        >>> turtle.shapesize(5,2)
        >>> turtle.settiltangle(45)
        >>> stamp()
        >>> turtle.fd(50)
        >>> turtle.settiltangle(-45)
        >>> stamp()
        >>> turtle.fd(50)
        r�r�r3)rarsN)r	rr�r�rV�r�r�rsr�r�r�rgszRawTurtle.settiltanglecCs>|dkr0|jdtj|j}||j|jS|�|�dS)a�Set or return the current tilt-angle.

        Optional argument: angle -- number

        Rotate the turtleshape to point in the direction specified by angle,
        regardless of its current tilt-angle. DO NOT change the turtle's
        heading (direction of movement).
        If angle is not given: return the current tilt-angle, i. e. the angle
        between the orientation of the turtleshape and the heading of the
        turtle (its direction of movement).

        Deprecated since Python 3.1

        Examples (for a Turtle instance named turtle):
        >>> turtle.shape("circle")
        >>> turtle.shapesize(5,2)
        >>> turtle.tilt(45)
        >>> turtle.tiltangle()
        Nr�)r/r�r�rr	rrgr[r�r�r�rt4szRawTurtle.tiltanglecCs|�||���dS)a�Rotate the turtleshape by angle.

        Argument:
        angle - a number

        Rotate the turtleshape by angle from its current tilt-angle,
        but do NOT change the turtle's heading (direction of movement).

        Examples (for a Turtle instance named turtle):
        >>> turtle.shape("circle")
        >>> turtle.shapesize(5,2)
        >>> turtle.tilt(30)
        >>> turtle.fd(50)
        >>> turtle.tilt(30)
        >>> turtle.fd(50)
        N)rgrtrr�r�r�rsNszRawTurtle.tiltcCs6||kr(|kr(|kr(dkr2nn|jS|j\}}}}|dk	rL|}|dk	rX|}|dk	rd|}|dk	rp|}||||dkr�td��||||f|_t�||�dtj}	t�|	�t�|	�}
}|||
||||
||
||||
|||f\}}
}}||f|_|
||_|	|_	|j
dd�dS)a�Set or return the current transformation matrix of the turtle shape.

        Optional arguments: t11, t12, t21, t22 -- numbers.

        If none of the matrix elements are given, return the transformation
        matrix.
        Otherwise set the given elements and transform the turtleshape
        according to the matrix consisting of first row t11, t12 and
        second row t21, 22.
        Modify stretchfactor, shearfactor and tiltangle according to the
        given matrix.

        Examples (for a Turtle instance named turtle):
        >>> turtle.shape("square")
        >>> turtle.shapesize(4,2)
        >>> turtle.shearfactor(-0.5)
        >>> turtle.shapetransform()
        (4.0, -1.0, -0.0, 2.0)
        Nrz0Bad shape transform matrix: must not be singularr�r3r4)r0r�r�rr�r�r�r-r.r/rV)r��t11�t12�t21�t22Zm11Zm12Zm21Zm22Zalfar?r@Za11Za12Za21Za22r�r�r�rmas0,�

zRawTurtle.shapetransformcs^|j�|j\��|j\��t���j�j�}dt|�|\�������fdd�|D�S)zlComputes transformed polygon shapes from a shape
        according to current position and heading.
        r�csFg|]>\}}��|�|�j��|�|�jf�qSr�)r4r5�r{r�r��Ze0Ze1Zp0Zp1r�r�r�r~�s�z(RawTurtle._polytrafo.<locals>.<listcomp>)r�rrrr5r4r)r�r��er�rar��
_polytrafo�s

�zRawTurtle._polytrafocCs2|jj|jj}|jdkr.|�|j|jdk�SdS)a@Return the current shape polygon as tuple of coordinate pairs.

        No argument.

        Examples (for a Turtle instance named turtle):
        >>> turtle.shape("square")
        >>> turtle.shapetransform(4, -1, 0, 2)
        >>> turtle.get_shapepoly()
        ((50, -20), (30, 20), (-50, 20), (-30, -20))

        r�r�N)r�r�r�rDry�
_getshapepolyr�)r�rkr�r�r�rG�s
zRawTurtle.get_shapepolyFcsx|jdks|r|j\����n>|jdkrNtd|jd�}|dd|f\����n|jdkr\|St����fdd�|D��S)	z`Calculate transformed shape polygon according to resizemode
        and shapetransform.
        r3r2r�g@rr�c3s2|]*\}}�|�|�|�|fVqdSr�r�r`�r\r]r^r_r�r�r��sz*RawTurtle._getshapepoly.<locals>.<genexpr>)r%r0�maxr'r�)r�r�r�r!r�rer�rd�s

zRawTurtle._getshapepolyc	Cs�|j}|j|jj}|j}|jj}|j�r*|jdk�r*|jdk�r*d|_	|j
}|dkr�|jdkrfd}n|jdkrx|j}n|j
}|�|�|��}|j|j}}|j|||||dd�nt|d	kr�|�||j|�nZ|d
k�r�t||�D]D\}	\}
}}|�|�|
d��}
|j|	|
|�|�|�|�|j
dd�q�nx|j	�r6dS|dk�rR|�|dd
d
�nJ|d	k�rv|�||j|jdj
�n&|d
k�r�|D]}	|�|	dd
d
��q�d|_	dS)zpManages the correct rendering of the turtle with respect to
        its shape, resizemode, stretch and tilt etc.rFr�r�r�r2T�r"r9rzrArtr�N�r�r�r�r�r/)r�r�r�rDryrHr(r�r�rPr�r%r'r1rcrdr*r)rCrwr�ziprX)r�r�rkrZZtitem�tshaper6�fc�ocrHr�r�r�r�r��sR 

�
�




�
zRawTurtle._drawturtlec	CsT|j}|j|jj}|j}|j}|dkr�|��}|jdkr@d}n|jdkrR|j}n|j	}|�
|�|��}|j|j
}}|j|||||dd�n�|dkr�|�d�}|�||j|�n�|d	k�r4g}|D]}	|��}
|�|
�q�t|�}t||�D]D\}
\}}}|�
|�|d��}|j|
||�|�|�|�|j	dd�q�|j�|�|j�d
|f�|S)a�Stamp a copy of the turtleshape onto the canvas and return its id.

        No argument.

        Stamp a copy of the turtle shape onto the canvas at the current
        turtle position. Return a stamp_id for that stamp, which can be
        used to delete it by calling clearstamp(stamp_id).

        Example (for a Turtle instance named turtle):
        >>> turtle.color("blue")
        >>> turtle.stamp()
        13
        >>> turtle.fd(50)
        r�r�r�r2Trgrtr�r�rr)r�r�r�rDryr�r:r%r'r1rcrdr*r)rCrurwrr>r�rirXrSrr�)r�r�rkrZrj�stitemr6rkrlZelementrHr�r�r�r�rr�sH

�

�zRawTurtle.stampcCs�||jkrDt|t�r,|D]}|j�|�qn|j�|�|j�|�d|f}|j}||jkr`dS|j�|�}|j�|�||j	kr�|j	d|j
|_	|j�|j	d|j
dg�dS)z9does the work for clearstamp() and clearstamps()
        rrNr�)rSr�r�r�rIr�rr��indexr�r��insert)r��stampidZsubitemrHZbufrnr�r�r��_clearstamps



zRawTurtle._clearstampcCs|�|�|��dS)aDDelete stamp with given stampid

        Argument:
        stampid - an integer, must be return value of previous stamp() call.

        Example (for a Turtle instance named turtle):
        >>> turtle.color("blue")
        >>> astamp = turtle.stamp()
        >>> turtle.fd(50)
        >>> turtle.clearstamp(astamp)
        N)rqrJ)r�rpr�r�r�r6s
zRawTurtle.clearstampcCs^|dkr|jdd�}n&|dkr0|jd|�}n|j|d�}|D]}|�|�qB|��dS)a�Delete all or first/last n of turtle's stamps.

        Optional argument:
        n -- an integer

        If n is None, delete all of pen's stamps,
        else if n > 0 delete first n stamps
        else if n < 0 delete last n stamps.

        Example (for a Turtle instance named turtle):
        >>> for i in range(8):
        ...     turtle.stamp(); turtle.fd(30)
        ...
        >>> turtle.clearstamps(2)
        >>> turtle.clearstamps(-2)
        >>> turtle.clearstamps()
        Nr)rSrqrJ)r�r�ZtoDeleterHr�r�r�r7-szRawTurtle.clearstampsc
Cs�|j|j|jt|jt�f}|j}d|j|||j|j	dd�|�
|j�|jdd�ff}|jrh|j�
|�|j}|j�rZ|jdk�rZ||}|d|jd|d|jd}dt|ddd|j|j�}|d	|}	td|�D]R}
|
dkr�d
}nd}||	|
|_|j�r2|�|j||jf|j|j|�|��q�|j�rZ|j|jdd
|jd�|j�rn|j	�|�t|jt��r�|j�|�||_|j�r�|j�|�t|j	�dk�r�|��|��dS)z�Move the pen to the point end, thereby drawing a line
        if pen is down. All other methods for turtle movement depend
        on this one.
        �goNr�rr�r�r�皙�����?r�TF�r�r�r��r"rz�*)r+r)r'r�rOr�r�rrQrRr�r�rr�r,r�r4r5r�rrErKrJr>rMrLr�r=)r�r�go_modesr�Z
undo_entry�start�diff�diffsq�nhops�deltar�rAr�r�r�r
Isb
�

��$$�

�zRawTurtle._gotocs|\}}}}|\}}}}	|\}
}}�|j�t|j|�dkrDtd�|
|_||_|ddgkrbd}
n|}
�j|
||
|d���fdd�|jD�}|D]}��|�|j�	|�q�|}|j
�r��jdk�r�||}|d	�jd
|d�j
d
}dt|ddd|j
|j
�}|d
|}td|�D]P}|dk�r@d}nd}||||_|�rr��|j||jf|||�|���q,|�r��j|jdd|d�||_|j�r�t|j�d	k�r�|j��|jgk�r�d|_d|_|	�r|jgk�r�d|_td�n|jdk	�r|j��|��dS)z)Reverse a _goto. Used for undo()
        r�z$undogoto: HALLO-DA-STIMMT-WAS-NICHT!r�r�rucs&g|]}|�kr��|�dkr|�qS)r�)ryrz�r�r�r�r�r~�s�z'RawTurtle._undogoto.<locals>.<listcomp>r�rr�r�rsr�TFrtNzUnwahrscheinlich in _undogoto!)r�rrr�rQrRrEr�rIr�r,r�r4r5r�rrKrJrMr�rLr�rO)r��entry�old�newrwZcoodataZdrawingZpcZpsrBZcLIZcLr�ZusepcZtodeleter|rxryrzr{r|r�rAr�r}r��	_undogoto~sl
$$
�
�


zRawTurtle._undogotocCs�|jr|j�d||jf�||j9}|j�|�}|jj}|dkr�|jdkr�d|j}dtt	|�|�}d||}t
|�D]}|j�|�|_|��q|||_|��dS)z&Turns pen clockwise by angle.
        �rotr�rg@r�N)rr�r	rr�r�r�r,r�rrrJ)r�r�Z	neworientr�Zanglevelr r|r�r�r�r�r�s


zRawTurtle._rotateTcCsnt|j�dkrD|j�|j|j|j|j�|j��|_|j�	|j�n|jj|jdd�g|_|rj|j
g|_dS)z�Closes current line item and starts a new one.
           Remark: if current line became too long, animation
           performance (via _drawline) slowed down considerably.
        r�T)rAN)r�rRr�rErQr)r'rDr�r>rrAr�r�r�r=�s�zRawTurtle._newLinecCst|jt�S)aReturn fillstate (True if filling, False else).

        No argument.

        Example (for a Turtle instance named turtle):
        >>> turtle.begin_fill()
        >>> if turtle.filling():
        ...     turtle.pensize(5)
        ... else:
        ...     turtle.pensize(3)
        )r�rOr�r�r�r�r�rB�szRawTurtle.fillingcCsX|��s"|j��|_|j�|j�|jg|_|��|j	rL|j	�
d|jf�|��dS)aCalled just before drawing a shape to be filled.

        No argument.

        Example (for a Turtle instance named turtle):
        >>> turtle.color("black", "red")
        >>> turtle.begin_fill()
        >>> turtle.circle(60)
        >>> turtle.end_fill()
        �	beginfillN)rBr�r:rNr�r>rrOr=rr�rJr�r�r�r�r1�s
zRawTurtle.begin_fillcCs^|��rZt|j�dkrF|jj|j|j|jd�|jrF|j�d|jf�d|_|_|�	�dS)aFill the shape drawn after the call begin_fill().

        No argument.

        Example (for a Turtle instance named turtle):
        >>> turtle.color("black", "red")
        >>> turtle.begin_fill()
        >>> turtle.circle(60)
        >>> turtle.end_fill()
        r�r;�dofillN)
rBr�rOr�rCrNr*rr�rJr�r�r�r�r>
s�zRawTurtle.end_fillc	Gs8|sNt|ttf�r0|�|�}|jt|jd�}qr|j}|sr|jt|jd�}n$|dkrh|jt|jd�}|�|�}t|jd�r�|j�	|j
||�}|j�|�|j
r�|j
�d|f�n�|��}|j
r�|j
�dg�d|j
_z>|��dkr�|��|��|�|�|�|�|�d�W5|�|�X|j
�r4d	|j
_dS)
a�Draw a dot with diameter size, using color.

        Optional arguments:
        size -- an integer >= 1 (if given)
        color -- a colorstring or a numeric color tuple

        Draw a circular dot with diameter size, using color.
        If size is not given, the maximum of pensize+4 and 2*pensize is used.

        Example (for a Turtle instance named turtle):
        >>> turtle.dot()
        >>> turtle.fd(50); turtle.dot(20, "blue"); turtle.fd(50)
        r�N�_dotr<rTr2rF)r�r�r�r�r'rfr)�hasattrr�r�rr�r>rr�rVr�rarMrXrYrWrC)r�rVr9rHrVr�r�r�r<
s:



z
RawTurtle.dotcCsB|j�|j||||j�\}}|j�|�|jr>|j�d|f�|S)z)Performs the writing for write()
        �wri)r�rXrr)r�r>rr�)r�rVrWrUrHrr�r�r�rXH
s�zRawTurtle._writerP��Arialr�r7cCs`|jr|j�dg�d|j_|�t|�|��|�}|rN|��\}}|�||�|jr\d|j_dS)a�Write text at the current turtle position.

        Arguments:
        arg -- info, which is to be written to the TurtleScreen
        move (optional) -- True/False
        align (optional) -- one of the strings "left", "center" or right"
        font (optional) -- a triple (fontname, fontsize, fonttype)

        Write text - the string representation of arg - at the current
        turtle position according to align ("left", "center" or right")
        and with the given font.
        If move is True, the pen is moved to the bottom-right corner
        of the text. By default, move is False.

        Example (for a Turtle instance named turtle):
        >>> turtle.write('Home = ', True, align="center")
        >>> turtle.write((0,0), True)
        rTFN)rr�r�rXr�r�r[re)r��argZmoverWrUrr�r�r�r�r�r{R
szRawTurtle.writecCs|jg|_d|_dS)aStart recording the vertices of a polygon.

        No argument.

        Start recording the vertices of a polygon. Current turtle position
        is first point of polygon.

        Example (for a Turtle instance named turtle):
        >>> turtle.begin_poly()
        TN)rrLrMr�r�r�r�r2o
s
zRawTurtle.begin_polycCs
d|_dS)a7Stop recording the vertices of a polygon.

        No argument.

        Stop recording the vertices of a polygon. Current turtle position is
        last point of polygon. This will be connected with the first point.

        Example (for a Turtle instance named turtle):
        >>> turtle.end_poly()
        FN)rMr�r�r�r�r?}
szRawTurtle.end_polycCs|jdk	rt|j�SdS)z�Return the lastly recorded polygon.

        No argument.

        Example (for a Turtle instance named turtle):
        >>> p = turtle.get_poly()
        >>> turtle.register_shape("myFavouriteShape", p)
        N)rLr�r�r�r�r�rD�
s

zRawTurtle.get_polycCs|jS)a�Return the TurtleScreen object, the turtle is drawing  on.

        No argument.

        Return the TurtleScreen object, the turtle is drawing  on.
        So TurtleScreen-methods can be called for that object.

        Example (for a Turtle instance named turtle):
        >>> ts = turtle.getscreen()
        >>> ts
        <turtle.TurtleScreen object at 0x0106B770>
        >>> ts.bgcolor("pink")
        rGr�r�r�r�rF�
szRawTurtle.getscreencCs|S)aUReturn the Turtleobject itself.

        No argument.

        Only reasonable use: as a function to return the 'anonymous turtle':

        Example:
        >>> pet = getturtle()
        >>> pet.fd(50)
        >>> pet
        <turtle.Turtle object at 0x0187D810>
        >>> turtles()
        [<turtle.Turtle object at 0x0187D810>]
        r�r�r�r�r�rH�
szRawTurtle.getturtlecCs|j�|�S)zDSet delay value which determines speed of turtle animation.
        )r�rrLr�r�r�rM�
szRawTurtle._delayr�cCs"|j�|jj|||�|��dS)a�Bind fun to mouse-click event on this turtle on canvas.

        Arguments:
        fun --  a function with two arguments, to which will be assigned
                the coordinates of the clicked point on the canvas.
        btn --  number of the mouse-button defaults to 1 (left mouse button).
        add --  True or False. If True, new binding will be added, otherwise
                it will replace a former binding.

        Example for the anonymous turtle, i. e. the procedural way:

        >>> def turn(x, y):
        ...     left(360)
        ...
        >>> onclick(turn)  # Now clicking into the turtle will turn it.
        >>> onclick(None)  # event-binding will be removed
        N)r�rer�rHrJr�r�r�r�rR�
szRawTurtle.onclickcCs"|j�|jj|||�|��dS)a�Bind fun to mouse-button-release event on this turtle on canvas.

        Arguments:
        fun -- a function with two arguments, to which will be assigned
                the coordinates of the clicked point on the canvas.
        btn --  number of the mouse-button defaults to 1 (left mouse button).

        Example (for a MyTurtle instance named joe):
        >>> class MyTurtle(Turtle):
        ...     def glow(self,x,y):
        ...             self.fillcolor("red")
        ...     def unglow(self,x,y):
        ...             self.fillcolor("")
        ...
        >>> joe = MyTurtle()
        >>> joe.onclick(joe.glow)
        >>> joe.onrelease(joe.unglow)

        Clicking on joe turns fillcolor red, unclicking turns it to
        transparent.
        N)r�rfr�rHrJr�r�r�r�rT�
szRawTurtle.onreleasecCs|j�|jj|||�dS)a�Bind fun to mouse-move event on this turtle on canvas.

        Arguments:
        fun -- a function with two arguments, to which will be assigned
               the coordinates of the clicked point on the canvas.
        btn -- number of the mouse-button defaults to 1 (left mouse button).

        Every sequence of mouse-move-events on a turtle is preceded by a
        mouse-click event on that turtle.

        Example (for a Turtle instance named turtle):
        >>> turtle.ondrag(turtle.goto)

        Subsequently clicking and dragging a Turtle will move it
        across the screen thereby producing handdrawings (if pen is
        down).
        N)r�rgr�rHr�r�r�r�rS�
szRawTurtle.ondragcCs,|jdkrdS|dkr@|\}}|�|||j�|j��}n�|dkr\|d}|�|�n�|dkrp|�|�n�|dkr�|d}|j�|�|j�	|�n�|dkr�|d}|jj
|dd	d	d
�nh|dk�r|d}d|_|_||jk�r(|j�|�|j�	|�n$|dk�r(t
�||d�|j��dS)
z2Does the main part of the work for undo()
        Nr�rrrrr)r�r<r�rhr�r8r�rV)rrr	r�r6r�r�rIr�r�rCrNrOr$rV)r��actionr�r�ZdegPAUZdummyrmrHr�r�r��_undos<

�

zRawTurtle._undocCsl|jdkrdS|j��}|d}|dd�}|dkr\|rh|��}|�|d|dd��q4n|�||�dS)a�undo (repeatedly) the last turtle action.

        No argument.

        undo (repeatedly) the last turtle action.
        Number of available undo actions is determined by the size of
        the undobuffer.

        Example (for a Turtle instance named turtle):
        >>> for i in range(4):
        ...     turtle.fd(50); turtle.lt(80)
        ...
        >>> for i in range(8):
        ...     turtle.undo()
        ...
        Nrr�r)rr�r�)r�rHr�r�r�r�r�rw's

zRawTurtle.undo)NN)N)NNN)N)N)NNNN)F)N)T)N)FrPr�)N)r�N)r�N)r�N)9r�r�r�r�rJr�r�r`rhrxrUr5r�rJrr�r�rXr8rkrlrnrgrtrsrmrcrGrdr�rrrqr6r7r
r�rr=rBr1r>r<rXr{r2r?rDrFrHrErMrRrTrSr�rwrvr�r�r�r�r
�	sr�
(

(

(


(

(-
5A

0







 cCstjdkrt�t_tjS)z�Return the singleton screen object.
    If none exists at the moment, create a new one and return it,
    else return the existing one.N)r�_screenrIr�r�r�r�r	Js
c@sfeZdZdZdZedZdd�Zededededfd	d
�Zdd�Z	d
d�Z
dd�Zdd�ZdS)rINr)cCs�tjdkr4t�t_|_|j�tj�|j�|j�tjdkr�td}td}td}td}td}td}|j�	||||�|j�
�t_t�|tj�|�
||||�dS)Nrzr�r�r�r�r�)rI�_rootrr)�_titler)�_destroyrr�r#r$rr�r&)r�rzr�r�r�r�r�r�r�r�r�Xs

z_Screen.__init__rzr�r�r�cCs�t|jd�sdS|j��}|j��}t|t�rNd|krBdkrNnn||}|dkrb||d}t|t�r�d|kr�dkr�nn||}|dkr�||d}|j�||||�|��dS)a Set the size and position of the main window.

        Arguments:
        width: as integer a size in pixels, as float a fraction of the screen.
          Default is 50% of screen.
        height: as integer the height in pixels, as float a fraction of the
          screen. Default is 75% of screen.
        startx: if positive, starting position in pixels from the left
          edge of the screen, if negative from the right edge
          Default, startx=None is to center window horizontally.
        starty: if positive, starting position in pixels from the top
          edge of the screen, if negative from the bottom edge
          Default, starty=None is to center window vertically.

        Examples (for a Screen instance named screen):
        >>> screen.setup (width=200, height=200, startx=0, starty=0)

        sets window to 200x200 pixels, in upper left of screen

        >>> screen.setup(width=.75, height=0.5, startx=None, starty=None)

        sets window to 75% of screen by 50% of screen and centers
        r'Nrr�r�)r�r�r*r+r�r�r'r,)r�rzr�r%r&rQZshr�r�r�r&ns

""z
_Screen.setupcCs tjdk	rtj�|�|t_dS)aqSet title of turtle-window

        Argument:
        titlestring -- a string, to appear in the titlebar of the
                       turtle graphics window.

        This is a method of Screen-class. Not available for TurtleScreen-
        objects.

        Example (for a Screen instance named screen):
        >>> screen.title("Welcome to the turtle-zoo!")
        N)rIr�r)r�)r�Ztitlestringr�r�r�r)�s
z
_Screen.titlecCs:|j}|tjkr(dt_dt_dt_dt_dt_|��dS)NF)	r�rIrr�r�rrr�r()r��rootr�r�r�r��s
z_Screen._destroycCs|��dS)z~Shut the turtlegraphics window.

        Example (for a TurtleScreen instance named screen):
        >>> screen.bye()
        N)r�r�r�r�r�r�sz_Screen.byecsN�fdd�}��|�tdr"dSz
t�Wntk
rHtd�YnXdS)alGo into mainloop until the mouse is clicked.

        No arguments.

        Bind bye() method to mouseclick on TurtleScreen.
        If "using_IDLE" - value in configuration dictionary is False
        (default value), enter mainloop.
        If IDLE with -n switch (no subprocess) is used, this value should be
        set to True in turtle.cfg. In this case IDLE's mainloop
        is active also for the client script.

        This is a method of the Screen-class and not available for
        TurtleScreen instances.

        Example (for a Screen instance named screen):
        >>> screen.exitonclick()

        cs���dS)z&Screen.bye() with two dummy-parametersN)r)r�r�r�r�r��exitGracefully�sz+_Screen.exitonclick.<locals>.exitGracefullyr�Nr)rRr�r�AttributeError�exit)r�r�r�r�r�r�s

z_Screen.exitonclick)
r�r�r�r�rr�r�r�r&r)r�rrr�r�r�r�rIRs�
(
rIc@s4eZdZdZdZdZedededfdd�ZdS)rz�RawTurtle auto-creating (scrolled) canvas.

    When a Turtle object is created or a function derived from some
    Turtle method is called a TurtleScreen object is automatically created.
    Nrkr�r�cCs,tjdkrt�t_tj|tj|||d�dS)N)rkr�r�)rr�r	r
r�)r�rkr�r�r�r�r�r��s

�zTurtle.__init__)r�r�r�r�r�r�r�r�r�r�r�r�r�s��turtle_docstringdictc	Cs�i}tD]}d|}t|�j||<qtD]}d|}t|�j||<q(td|d���}tdd�|D��}|�d�|dd	�D](}|�d
t|��|�d||�q||d	}|�d
t|��|�d||�|�d
�|��W5QRXdS)a�Create and write docstring-dictionary to file.

    Optional argument:
    filename -- a string, used as filename
                default value is turtle_docstringdict

    Has to be called explicitly, (not used by the turtle-graphics classes)
    The docstring dictionary will be written to the Python script <filname>.py
    It is intended to serve as a template for translation of the docstrings
    into different languages.
    z_Screen.zTurtle.z%s.pyr6css$|]}|�d�dtkr|VqdS)r�r�N)r�_alias_listr�r�r�r�r�s�z&write_docstringdict.<locals>.<genexpr>zdocsdict = {

Nr�z%s :
z        """%s
""",

z        """%s
"""

z}
)	�_tg_screen_functionsr�r��_tg_turtle_functionsr�r�r{�repr�close)r��docsdict�
methodnamer�r�r�r�r�r�r~�s$

c	Cs`dd|��i}t|�}|j}|D]8}z||t|�_Wq"tk
rXtd|�Yq"Xq"dS)z�Read in docstrings from lang-specific docstring dictionary.

    Transfer docstrings, translated to lang, from a dictionary-file
    to the methods of classes Screen and Turtle and - in revised form -
    to the corresponding functions.
    z!turtle_docstringdict_%(language)sr�zBad docstring-entry: %sN)r��
__import__r�r�r�r�r�)Zlang�modname�moduler�r�r�r�r��read_docstringssr�r�zCannot find docsdict forz;Unknown Error when trying to import %s-docstring-dictionaryc
Cs�d}}t�|j�\}}}|dd�}|dd�}|jp:g}dd�|D�}dgt|�t|�|}dd�t||�D�}	|dk	r�|	�d|�|�d|�|dk	r�|	�d|�|�d|�d	�|	�}d
|}d	�|�}d
|}||fS)a?Get strings describing the arguments for the given object

    Returns a pair of strings representing function parameter lists
    including parenthesis.  The first string is suitable for use in
    function definition and the second is suitable for use in function
    call.  The "self" parameter is not included.
    r�r�NcSsg|]}d|f�qS)z=%rr�)r{r�r�r�r�r~<sz"getmethparlist.<locals>.<listcomp>cSsg|]\}}||�qSr�r�)r{r�Zdfltr�r�r�r~>s�*z**z, z(%s))�inspectZgetargs�__code__�__defaults__r�rir>r)
ZobZdefTextZcallTextrZvarargsZvarkwZitems2ZrealArgs�defaultsZitems1r�r�r��getmethparlist,s&


r�cCsJddl}|dkrdStd}|�d|d�}|�d|�}|�d|�}|S)z<To reduce docstrings from RawTurtle class for functions
    rNr��%s.r�� \(.+ %s\):�:��rer��replace�compile�sub)�docstrr�Z
turtlename�	newdocstr�parexpr�r�r��_turtle_docreviseKsr�cCsJddl}|dkrdStd}|�d|d�}|�d|�}|�d|�}|S)z?To reduce docstrings from TurtleScreen class for functions
    rNr�r�r�r�r�r�)r�r�Z
screennamer�r�r�r�r��_screen_docreviseWsr�ardef {name}{paramslist}:
    if {obj} is None:
        if not TurtleScreen._RUNNING:
            TurtleScreen._RUNNING = True
            raise Terminator
        {obj} = {init}
    try:
        return {obj}.{name}{argslist}
    except TK.TclError:
        if not TurtleScreen._RUNNING:
            TurtleScreen._RUNNING = True
            raise Terminator
        raise
c
Csl|D]b}t||�}t|�\}}|dkr4td||�qtj|||||d�}	t|	t��||j�t�|_qdS)Nr�z>>>>>>)�obj�initr�Z
paramslistZargslist)�getattrr�r��__func_body�formatr��globalsr�)
Z	functionsr�r�r�Z	docreviser�r�Zpl1Zpl2Zdefstrr�r�r��_make_global_funcsws

�r�zTurtle._screenzScreen()zTurtle._penzTurtle()�__main__cCst�rt�nt�dSr�)rNr]rUr�r�r�r��	switchpen�sr�cCslt�td�t�td�t�td�td�D]Z}|dkrDt�td�D]}td�t	d�qL|dkrxt
d�t�t�td	�t�q2td
�t
d�td�t�td�td�td�td�td
�t�t
dd
�t
dd
�t
d�td�D]$}td�t	d�td�td�q�td�t�td�D]&}td�t	d�td�td��q:t�dS)zDemo of old turtle.py - moduleT�dr�r�r�r��ZZmaroonr	r�r�F�Z
startstartrx�redr�N)r`r*ryr0r=rzrr1rCrPr9r>r_r{)r|r�r�r�r��demo1�sX



r�cCsBtd�t�td�ttdd��tdd�d}td�td�D]}t�t	|d�qBt
d�t�rnt�q`t
�td�td	�d}td
�td�td�tdd
�D]p}|dkr�t�td	d|dd|�td�D]}t|�td�q�t�|d7}td�tt�dd�q�td�t�td�td�t�tdd�td�t�td�D](}t	dd�td�td�td��q`t�td�t�td�t�td�t�}|�d�t�}|�d�|�d�|�
�|�d�|�d�|��|�dd�|�d�|��|�d�|�dd�|�d�|�d�tt|��d}|�|�dk�r�|�d�|�d �|�|�|��|�d�|d!dk�r�|� �|� �t�|d7}�qZ|j
d"d#d$d%�|�d&�|�d�d'd(�}t!�"d�t��r|��|���q�|�d�|j
d)d*d+�|�#|d�d,S)-zDemo of some new features.r�r�rrr��r�zwait a moment...r�Zgreenr�r�r���x��Fr	r�Zyellowr��2r�r2i�(r�ZblueZoranger�g@g333333�?r�zCAUGHT! )r�r��boldr_)rUrWr�cSst�t�dSr�)rr)r�r�r�r�r��babaszdemo2.<locals>.babaz  Click me!)ZCourierr�r�)rUN)$rprqrYrdrur;rbrr�r4r{rxrwr`rQrrWr1rAr@r>r]rUr9rkrHrarrPryrIr=rr�time�sleeprR)rr�Zlaenger|Ztrir�r�r�r�r�r��demo2�s�


















r�)r�)r�)Fr�Z_verZtkinterr�r�r�r�r�r�Zos.pathrrr�copyrrZ_tg_classesr�r�Z
_tg_utilities�__all__r�r�r�r�r�r�r�rr�r�r�r�r�rr�r r�objectr,r�r�rr�rr�r$rBr
rr	rIrr
r~r�Z	_LANGUAGE�ImportErrorr�r�r�r�r�rrr�r�r�r�rr�r�r�r��<module>s�N��
�

����5
�
c	/&/O}
"
���
5c

Hacked By AnonymousFox1.0, Coded By AnonymousFox