B °-_ò0ãO@s6dZdZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z ddl mZddlmZddd d d d d ddg Zddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.gZd/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}gOZd~dgZeeeed€gZdd0d3d@dMdQdUd[d]dbdcdedfdqdvdydzgZdd‚dƒd„ddd…d†d‡dˆd‰dŠdŠd‹dŒddŽddd‘d’œZd“d”„Zd•d–„Zy eeƒWnek r ed—ƒYnXGd˜d„deƒZd™dš„Zd›dœ„ZdZdÔ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 „d e0ƒZ4e4Z5dÕdºd~„Z6d»d¼„Z7ed½Z8ye8dkrre7e8ƒWn@e9k r”ed¾e8ƒYn"ek r´ed¿e8ƒYnXdÀdÁ„Z:dÂdÄZ;dÄdÅ„Ze>ee3dÉdÊe<ƒe>ee4dËdÌe;ƒe?Z@eAdÍkr2dÎ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Ú Terminatorgà?gè?ii,Ústandardgð?é ièÚclassicÚblackÚnoresizeTZenglishÚturtleÚscreenzPython Turtle GraphicsF)rzÚheightÚ canvwidthÚ canvheightÚ leftrightÚ topbottomrrrÚundobuffersizerkrWrAraÚvisibleÚlanguageÚ exampleturtleÚ examplescreenr)Ú using_IDLEc Csät|dƒ}| ¡}WdQRXi}x¼|D]´}| ¡}|r(| d¡rDq(y| d¡\}}Wn&tk r|td||fƒw(YnX| ¡}| ¡}|dkr t|ƒ}n4yd|kr´t|ƒ}nt |ƒ}Wntk rÒYnX|||<q(W|S)z/Convert content of config-file into dictionary.ÚrNú#ú=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/lib/python3.7/turtle.pyÚ config_dict«s0      r«cCsŒd}i}i}t|ƒrt|ƒ}d|kr0d|d}yttƒ\}}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¥Z default_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„Z dd„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|ƒS)Nrr¸)Ú isinstancer)r¹rºr©r©rªÚ__mul__þs  z Vec2D.__mul__cCs2t|tƒst|tƒr.t|d||d|ƒSdS)Nrr¸)r¼r¢r¡r)r¹rºr©r©rªÚ__rmul__szVec2D.__rmul__cCs"t|d|d|d|dƒS)Nrr¸)r)r¹rºr©r©rªÚ__sub__sz Vec2D.__sub__cCst|d |d ƒS)Nrr¸)r)r¹r©r©rªÚ__neg__sz Vec2D.__neg__cCs|dd|dddS)Nrér¸gà?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¸rg€f@)rÚmathÚpiÚcosÚsin)r¹ÚangleZperpÚcÚsr©r©rªÚrotate sz Vec2D.rotatecCs|d|dfS)Nrr¸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 cCs\t|jƒ}| ¡x|D]}t||ƒqWx,|j ¡D]\}}t|ƒtjkr6|||<q6WdS)z#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)z#helper function for Scrolled Canvas)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|ƒ}xN| ¡D]B}|dd…dksf|dd…dksf||ksf||krZq$||||<q$WxP| ¡D]D\}} || dœ} t|tƒržt||dœ} t| | ƒt||| |ƒqtWdS)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ªÚ__forwardmethods4s 0   ræc@sdeZdZdZddd„Zddd „Zd d „Zd d „Zdd„Zdd„Z dd„Z dd„Z dd„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 tj dd|_ tj ||j jtjd|_tj ||j jd|_|j j|jj|jjd|jdd dd |jdd dd |j jd |d ddd d d d |jjd |d dd d d d d |jjd |d d dd d d d | ¡|j d |j¡dS)N)rzrˆÚwhiterÁ)rzrˆÚbgZreliefZ borderwidth)ÚcommandZorient)rì)ZxscrollcommandZyscrollcommandrr¸)ZweightZminsizeÚnews)ÚpadxÚin_ÚpadyÚrowÚcolumnÚrowspanÚ columnspanÚstickyz )ÚTKÚFrameÚ__init__Úwinfo_toplevelZ _rootwindowrzrˆr‰rŠrëÚCanvasZSUNKENÚ_canvasZ ScrollbarZxviewZ HORIZONTALÚhscrollZyviewÚvscrollZ configureÚsetZ rowconfigureZcolumnconfigureÚgridr`ÚbindÚonResize)r¹Zmasterrzrˆr‰rŠr©r©rªrøOs,      zScrolledCanvas.__init__NcCs¢|r ||_|r||_|r||_|jj||j d|j d|jd|jdfd|j d|j|jd|j¡|j d|j|jd|j¡|  ¡dS)z„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. cCstjddd}| ¡|S)z$return a blank image object r¸)rzrˆ)röÚ PhotoImageÚblank)Zimgr©r©rªÚ _blankimageÒszTurtleScreenBase._blankimagecCs tj|dS)z`return an image object containing the imagedata from a gif-file named filename. )Úfile)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Á)rgð?) Úcvr¼rr‰rŠr¢rrÚxscaleÚyscale)r¹r&ÚwÚhr©r©rªrøás  *zTurtleScreenBase.__init__cCs|jjddddS)zcs:ˆj |j¡ˆjˆj |j¡ ˆj}}ˆ||ƒdS)N)r&Úcanvasxr¶r'Úcanvasyr·r()r r¶r·)Úfunr¹r©rªÚeventfunfsz+TurtleScreenBase._onclick..eventfun)r&Ú tag_unbindÚtag_bind)r¹r8rJÚnumÚaddrKr©)rJr¹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. Nzcs:ˆj |j¡ˆjˆj |j¡ ˆj}}ˆ||ƒdS)N)r&rHr¶r'rIr·r()r r¶r·)rJr¹r©rªrKxsz-TurtleScreenBase._onrelease..eventfun)r&rLrM)r¹r8rJrNrOrKr©)rJr¹rªÚ _onreleasels 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. NzcsTy:ˆj |j¡ˆjˆj |j¡ ˆj}}ˆ||ƒWntk rNYnXdS)N)r&rHr¶r'rIr·r(r®)r r¶r·)rJr¹r©rªrK‹s z*TurtleScreenBase._ondrag..eventfun)r&rLrM)r¹r8rJrNrOrKr©)rJr¹rªÚ_ondrags 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. Nz cs:ˆj |j¡ˆjˆj |j¡ ˆj}}ˆ||ƒdS)N)r&rHr¶r'rIr·r()r r¶r·)rJr¹r©rªrK sz1TurtleScreenBase._onscreenclick..eventfun)r&rr)r¹rJrNrOrKr©)rJr¹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 Nzcs ˆƒdS)Nr©)r )rJr©rªrK­sz0TurtleScreenBase._onkeyrelease..eventfun)r&rr)r¹rJr§rKr©)rJrªÚ _onkeyrelease¦s zTurtleScreenBase._onkeyreleasecsnˆdkr4|dkr |j dd¡qj|j d|d¡n6‡fdd„}|dkrX|j d|¡n|j d||¡dS)zIf 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 z cs ˆƒdS)Nr©)r )rJr©rªrK¼sz.TurtleScreenBase._onkeypress..eventfun)r&rr)r¹rJr§rKr©)rJrªÚ _onkeypress±s zTurtleScreenBase._onkeypresscCs|j ¡dS)z=Set focus on canvas (in order to collect key-events) N)r&r)r¹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_idler;)r¹rJÚtr©r©rªÚ_ontimerÈszTurtleScreenBase._ontimercCs|jjdd|dS)z0Create and return image item on canvas. r)Úimage)r&Z create_image)r¹rYr©r©rªÚ _createimageÐszTurtleScreenBase._createimagecCs<|\}}|j |||j| |jf¡|jj||ddS)zZConfigure image item as to draw image object at position (x,y) on canvas) )rYN)r&r.r'r(Ú itemconfig)r¹r8r[rYr¶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 .)rYN)r&r[Z tag_lower)r¹r8rYr©r©rªÚ _setbgpicÝszTurtleScreenBase._setbgpiccCs |j |¡S)zQReturn 'line' or 'polygon' or 'image' depending on type of item. )r&r×)r¹r8r©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|]}ˆ|ˆ|d f‘qS)r¸r©)Ú.0Úi)r3r©rªú ôsz/TurtleScreenBase._pointlist..rrÁ)r&r.ÚrangeÚlen)r¹r8Úplr©)r3rªÚ _pointlistës zTurtleScreenBase._pointlistcCs|jj||||fddS)N)r)r&r)r¹Úsrx1Úsry1Úsrx2Úsry2r©r©rªÚ_setscrollregion÷sz!TurtleScreenBase._setscrollregionc Cs„|j ¡}xt|D]l}t|j |¡ƒ}g}x@|rh|dd…\}}| ||¡| ||¡|dd…}q*W|jj|f|žŽqWdS)NrÁ)r&Zfind_allrÑr.r-) r¹Z xscalefactorZ yscalefactorrÖr8Z coordinatesZ 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`)r¹r‰rŠrër©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 t ¡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ör)r¹r©r©rªr s zTurtleScreenBase.mainloopcCs t ||¡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:") )rZ askstring)r¹r)Úpromptr©r©rªr(/s zTurtleScreenBase.textinputcCstj|||||dS)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 imput 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 initialvalueZminvalueZmaxvalue)rZaskfloat)r¹r)rnÚ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ÐÚ staticmethodr#r%rør,r4r5r6r9r:r<r>r?rGrPrQrRrSrTrUrVrXrZr\r]r^rerjrkrlrmrr(rr©r©r©rªr ÊsH              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 N)rÍrÎrÏrÐr©r©r©rªrqbsrqc@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ÚpolygonrYz.gifÚcompoundzThere is no shape type %s) r^r¼rÑr³ráÚlowerÚendswithrrr%rqÚ_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() rsz Cannot add component to %s ShapeN)r^rqrvr-)r¹Úpolyrr+r©r©rªÚ addcomponent~s   zShape.addcomponent)N)N)rÍrÎrÏrÐrøryr©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__NcCsH|dkr*x4t|jƒD]}dg|j|<qWn||_dgg||_d|_dS)NrÞ)rbr{r|r})r¹r{r`r©r©rªr`s z Tbuffer.resetcCsF|jdkrB|js0|jd|j|_||j|j<n|j|j |¡dS)Nrr¸)r{r~r}r|r-)r¹r8r©r©rªÚpush¥s  z Tbuffer.pushcCsJ|jdkrF|j|j}|dkr"dSdg|j|j<|jd|j|_|SdS)Nrr¸)r{r|r})r¹r8r©r©rªÚpop¬s  z Tbuffer.popcCs|j|j dg¡S)N)r{r|Úcount)r¹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`rr€r‚rÌr©r©r©rªrz–s   rzc@s"eZdZdZdZedededfdd„Zdd „Zd=d d „Zd d„Z d>dd„Z dd„Z dd„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¸tddƒtddƒtddƒtddƒtddƒtddƒtd| ¡ƒd œ|_d d i|_t ||¡||_||_td |_ g|_ |  ¡t j d kr´| ¡}| ddddd¡| ddddd¡dS)Nrr))iöÿÿÿr)r‚r)rr‚))ré)éþÿÿÿé)rÞr‚)éüÿÿÿé)iùÿÿÿé )i÷ÿÿÿé)iúÿÿÿé)iùÿÿÿr¸)éûÿÿÿéýÿÿÿ)iøÿÿÿiúÿÿÿ)iúÿÿÿiøÿÿÿ)r‡rŒ)riùÿÿÿ)érŒ)éiøÿÿÿ)rŠiúÿÿÿ)r‹r)rˆr¸)rr‹)r‰rŠ)rˆr‰)rŽrˆ)r¸r‚)rÁr†))r‚r)g…ëQ¸#@g¸…ëQ¸@)g®Gáz. @g…ëQ¸…@)g…ëQ¸…@g®Gáz. @)g¸…ëQ¸@g…ëQ¸#@)rr‚)g¸…ëQ¸Àg…ëQ¸#@)g…ëQ¸…Àg®Gáz. @)g®Gáz. Àg…ëQ¸…@)g…ëQ¸#Àg¸…ëQ¸@)iöÿÿÿr)g…ëQ¸#Àg¸…ëQ¸À)g®Gáz. Àg…ëQ¸…À)g…ëQ¸…Àg®Gáz. À)g¸…ëQ¸Àg…ëQ¸#À)g€g$À)g¸…ëQ¸@g…ëQ¸#À)g…ëQ¸…@g®Gáz. À)g®Gáz. @g…ëQ¸…À)g…ëQ¸#@g¸…ëQ¸À))r‚iöÿÿÿ)r‚r‚)iöÿÿÿr‚)iöÿÿÿiöÿÿÿ))r‚g®GázÀ)rgš™™™™'@)iöÿÿÿg®GázÀ))rr)rŒi÷ÿÿÿ)riùÿÿÿ)r‹i÷ÿÿÿrY)Zarrowr†r4ZsquareZtrianglerƒr"Únopicr¬rÚdarwinZwmZ attributesr™z-topmostÚ1Ú0)rr#Ú_shapesÚ_bgpicsr røÚ_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¡xd D]}|  d |¡qRW|  d ¡x.|j d d …D]}| d |¡|  d |¡q€Wd 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¬rr¸rrê)r¸rÁéN)r¯r—r˜r9rZÚ_bgpicÚ _bgpicnameÚ_tracingÚ_updatecounterÚ_turtlesrrRrr™rr Ú_pen)r¹Úbtnr§r©r©rªr5ìs        zTurtleScreen.clearNcCs||dkr|jS| ¡}|dkr*td|ƒ‚||_|dkrp| |j d|j d|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)rr¥rÁgð?) r–rtrqrjr‰rŠr'r(r`)r¹rr©r©rªr s  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¡rmr%r'r(r‰rŠrjrkr,)r¹ZllxZllyZurxZuryZxspanZyspanZwxZwyZ oldxscaleZ oldyscalerfrgrhrir©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))) Nz.gifrYz;Bad arguments for register_shape. Use help(register_shape)rr)rtrurr%rqr¼r³r”)r¹Únamerkr©r©rªr#Ss   zTurtleScreen.register_shapec Cst|ƒdkr|d}t|tƒrD| |¡s0|dkr4|Stdt|ƒƒ‚y|\}}}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: %szbad color arguments: %sgð?cSsg|]}td|ƒ‘qS)gào@)Úround)r_r¶r©r©rªraŒsz*TurtleScreen._colorstr..éÿzbad color sequence: %sz #%02x%02x%02x)rcr¼rár>rqÚ TypeErrorržr˜)r¹r9r“ÚgÚbr©r©rªÚ _colorstrvs   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¢)r_r`)Úcstrr©rªra•sz'TurtleScreen._color..)r¸rr‹rŽcsg|]}dtˆ|dƒ‘qS)r„)r¢)r_r*)r¯r©rªra—sr¸zbad colorstring: %sc3s|]}|ˆjdVqdS)rªN)r˜)r_rÈ)r¹r©rªú šsz&TurtleScreen._color..)rrcrqr³)r¹r¯r3r©)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) Ngð?rª)r˜r¡r¢)r¹Zcmoder©r©rªrœs  zTurtleScreen.colormodecCs(x"|jD]}| |j¡| ¡qWdS)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() [] )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®r?r±)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¢)r¹rr©r©rªrùs zTurtleScreen.delaycCs<tjsdt_t‚|jdkr8|jd7_|j|j;_dS)zIncrement update counter.Trr¸N)rÚ_RUNNINGr€r r¡)r¹r©r©rªÚ _incrementudcs  zTurtleScreen._incrementudccCs@|j}d|_x | ¡D]}| ¡| ¡qW||_| ¡dS)z'Perform a TurtleScreen update. TN)r r+Ú _update_dataÚ _drawturtler:)r¹ÚtracingrWr©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)rm)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¸)rm)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 )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)rS)r¹rJr¤rOr©r©rªrREszTurtleScreen.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-rT)r¹rJr§r©r©rªrVs    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-rU)r¹rJr§r©r©rªrts   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)rV)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)rX)r¹rJrWr©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•r%r]rž)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 ;-) )rl)r¹r‰rŠrër©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¼sD& "' #              c@sTeZdZdZeddƒeddƒeddƒdœZdZdZdZefdd „Z d d „Z dBd d„Z dd„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!dHdd?„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. gð?g)rr¦r¥rrr¸cCsB|j|_|j|_||_d|_| ¡d|_| |¡t  |¡dS)N) ÚDEFAULT_ANGLEOFFSETÚ _angleOffsetÚDEFAULT_ANGLEORIENTÚ _angleOrientr–Ú undobufferr:r²r½r`)r¹rr©r©rªrøòs zTNavigator.__init__cCstddƒ|_tj|j|_dS)zXreset turtle to its initial values Will be overwritten by parent class gN)rÚ _positionr½ÚSTART_ORIENTATIONr–Ú_orient)r¹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'. N)rr¥r¦)rr¦rr¸g@rÞ)r–r¿rÁÚ _fullcircle)r¹rr©r©rªr²s zTNavigator._setmodecCs0||_d||_|jdkr"d|_n |d|_dS)z+Helper function for degrees() and radians()ihrrg@N)rÆÚ _degreesPerAUr–r¿)r¹Ú 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. Dafault 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)rÉ)r¹rÈ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)rÉrÃrÄ)r¹r©r©rªr^4s zTNavigator.radianscCs|j|j|}| |¡dS)z)move turtle forward by specified distanceN)rÃrÅÚ_goto)r¹r;Zender©r©rªÚ_goBszTNavigator._gocCs||j9}|j |¡|_dS)z=Turn turtle counterclockwise by specified angle if angle > 0.N)rÇrÅrÊ)r¹rÇr©r©rªÚ_rotateGs zTNavigator._rotatecCs ||_dS)zmove turtle to position end.N)rÃ)r¹Úendr©r©rªrËLszTNavigator._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ªrCPszTNavigator.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) N)rÌ)r¹r;r©r©rªr/gszTNavigator.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)rÍ)r¹rÇr©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 N)rÍ)r¹rÇr©r©rªrPszTNavigator.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) )rÃ)r¹r©r©rªr[¥s zTNavigator.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 r)rÃ)r¹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¸)rÃ)r¹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)rIrd)r¹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) rN)rËrrÃ)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 Ng€f@r‚g€v@) rr¼r³r½rÃr©rÃÚatan2rÄrÇr¿rÁrÆ)r¹r¶r·r[Úresultr©r©rªruDs       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 g€f@r‚g€v@) rÅr©rÃrÐrÄrÇr¿rÁrÆ)r¹r¶r·rÑr©r©rªrJgs   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 g@N)rJrÁrÆrÍ)r¹Zto_anglerÇZfullr©r©rªrdvszTNavigator.setheadingc Cst|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 ¡| |¡x:t|ƒD].} | |¡| |¡| d ¡| |¡qW| | ¡|d krV|  | | ¡| |¡|jrpd |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@gð?gà?g@g€f@rF)rÂrr~rprÆrÏr¢ÚminrÃrÆrÄrÇÚ_tracerr<rÍrbrÌ) r¹ÚradiusZextentÚstepsrpZfracr)Zw2ÚlZtrZdlr`r©r©rªr4’s>" "         zTNavigator.circlecCsdS)z/dummy method - to be overwritten by child classNr©)r¹rÉr©r©rªrpÓszTNavigator.speedcCsdS)z/dummy method - to be overwritten by child classNr©)r¹Úar­r©r©rªrÕÕszTNavigator._tracercCsdS)z/dummy method - to be overwritten by child classNr©)r¹r³r©r©rªr<×szTNavigator._delay)N)rÊ)N)N)N)NN)r)NN)N).rÍrÎrÏrÐrrÄZ DEFAULT_MODEr¾rÀrør`r²rÉr:r^rÌrÍrËrCr/r_rPr[r|r}rIrLrirjr;rurJrdr4rprÕr<r@r3r0rbrQr\rerfrcr©r©r©rªr½æsX     # # A   r½c@sæeZdZdZedfdd„Zededfdd„Zd.d d „Zd/d d „Zdd„Z dd„Z dd„Z d0dd„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 |¡dS)N)Ú _resizemoderÂrÚÚ_reset)r¹rar©r©rªrøész TPen.__init__rWrAcCsFd|_d|_||_||_d|_d|_d|_d|_d|_d|_ d|_ dS)Nr¸Tr)gð?gð?g)gð?gggð?) Ú_pensizeÚ_shownÚ _pencolorÚ _fillcolorÚ_drawingÚ_speedÚ_stretchfactorÚ _shearfactorÚ_tiltÚ _shapetrafoÚ _outlinewidth)r¹rWrAr©r©rªrÜîsz TPen._resetNcCs.|dkr|jS| ¡}|dkr*|j|ddS)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ÛrtrV)r¹Zrmoder©r©rªraüs zTPen.resizemodecCs|dkr|jS|j|ddS)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|jdddS)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árV)r¹r©r©rªrZ/s z TPen.penupcCs|jr dS|jdddS)zÂPull the pen down -- drawing when moving. Aliases: pendown | pd | down No argument. Example (for a Turtle instance named turtle): >>> turtle.pendown() NT)rX)rárV)r¹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ªrNKs z TPen.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‚rrr¸)ZfastestZfastÚnormalZslowZslowestNgà?g%@)rp)râr¢r©rV)r¹rpZspeedsr©r©rªrpZs z TPen.speedcGs„|rht|ƒ}|dkr"|d}}n"|dkr4|\}}n|dkrD|}}| |¡}| |¡}|j||dn| |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)rcr®rVr±rßrà)r¹rrØZpcolorZfcolorr©r©rªr9€s    z TPen.colorcGs:|r*| |¡}||jkrdS|j|dn | |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¹rr9r©r©rªrW®s   z TPen.pencolorcGs:|r*| |¡}||jkrdS|j|dn | |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¹rr9r©r©rªrAÓs   zTPen.fillcolorcCs|jdddS)zÑMakes the turtle visible. Aliases: showturtle | st No argument. Example (for a Turtle instance named turtle): >>> turtle.hideturtle() >>> turtle.showturtle() T)ÚshownN)rV)r¹r©r©rªro÷s zTPen.showturtlecCs|jdddS)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() F)rëN)rV)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}x|D]}||||<qfW|jr|j d|f¡d}d|kr®|j|dkr®d}d|krêt |dtƒrØ| |df¡|d<|j|dkrêd}d|kr|j|dkrd}|r| ¡d|kr*|d|_d|kr>|d|_d|krR|d|_d|krŠt |dtƒr€| |df¡|d<|d|_d |krž|d |_d |kr²|d |_d |krâ|d }t |ttfƒrÜ||f}||_d |krö|d |_d |kr |d |_ d|kr|d|_d|kr2|d|_ d |ksPd|ksPd |krª|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} ) rërXrWrArYrpraÚ stretchfactorrnr+rsrVFrXTrWrYrArprarìrnr+rërsN)rÞrárßràrÝrârÛrãrärçrår¼Údictr,rÂrr³r®Ú_newLiner¢r¡rÃrÆrÅrær:)r¹rVZpendictZ_pdÚpZ_p_bufr§ZnewLineZsfZscxZscyZshfÚsaÚcar©r©rªrV sŒ/                           zTPen.penTcCsdS)z/dummy method - to be overwritten by child classNr©)r¹ÚusePosr©r©rªrîŸ sz TPen._newLineFcCsdS)z/dummy method - to be overwritten by child classNr©)r¹rZforcedr©r©rªr:¡ sz TPen._updatecCsdS)z/dummy method - to be overwritten by child classNr©)r¹rr©r©rªr±£ sz TPen._colorcCsdS)z/dummy method - to be overwritten by child classNr©)r¹rr©r©rªr®¥ szTPen._colorstr)N)N)N)N)T)TF)rÍrÎrÏrÐr¯rørÜrarYrZrXrNrpr9rWrArorKrOrVrîr:r±r®rzryr]rUr=rqrMr©r©r©rªrÚås8   &.%$    rÚc@s eZdZdZdd„Zdd„ZdS)Ú _TurtleImagez6Helper class: Datatype to store Turtle attributes cCs||_d|_| |¡dS)N)r‡r^Ú _setshape)r¹r‡Ú shapeIndexr©r©rªrøµ sz_TurtleImage.__init__cs|j‰||_|jdkr*ˆj|jkr2nndS|jdkrPˆj|jkrXnndS|jdkrpˆ |j¡n$|jdkr”x|jD]}ˆ |¡q‚Wˆj|j|_|jdkr¸ˆ ¡|_nF|jdkr؈ ˆjdj¡|_n&|jdkrþ‡fdd„ˆj|jDƒ|_dS)NrrrY)rYrrrsr"csg|] }ˆ ¡‘qSr©)r,)r_r8)r‡r©rªraÌ sz*_TurtleImage._setshape..) r‡rõr^r”r9Ú_itemr,rZrv)r¹rõr8r©)r‡rªrôº s&""        z_TurtleImage._setshapeN)rÍrÎrÏrÐrørôr©r©r©rªró± sróc@sØeZdZdZgZdedededfdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„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. NrkrrŽcCs6t|tƒr||_n~t|tƒr:|tjkr2tj |¡||_nVt|ttfƒr„xFtjD]}|j |krP||_PqPWt|ƒ|_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&rqr½rørrÚr¢r5ÚdrawingLineItemrór†Ú_polyÚ _creatingPolyÚ _fillitemÚ _fillpathrÞÚ_hidden_from_screenÚcurrentLineItemrÃÚ currentLinerÖÚ stampItemsÚ_undobuffersizerzrÂr:)r¹ZcanvasrkrrŽ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·r:)r¹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)rÂrz)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)rÂr‚)r¹r©r©rªrx+ s zRawTurtle.undobufferentriescCspd|_|_x|jD]}|j |¡qW|j ¡|_g|_|jrN|j  |j ¡|jg|_|  ¡|  |j ¡dS)zDelete all of pen's drawingsN)rürýrÖr‡r9r5rÿrrár-rÃr7rhr)r¹r8r©r©rªr8 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)rr:)r¹r©r©rªr5F s zRawTurtle.clearcCsF|j ¡|jjdkrdSt|jƒdkrB|j |j|j|j|j¡dS)Nrr¸) r‡rµr¡rcrr6rÿrßrÝ)r¹r©r©rªr¶U s   zRawTurtle._update_datacCs||j}|jdkrdS|jdkrD| ¡| ¡| ¡| |j¡n4| ¡|jdkrxx| ¡D] }| ¡q`W| ¡dS)z&Perform a Turtle-data update. rNr¸) r‡r r¶r·r:r<r—r¡r+)r¹r‡rWr©r©rªr:] 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ªrÕo szRawTurtle._tracercCs |j |¡S)N)r‡r±)r¹rr©r©rªr±„ szRawTurtle._colorcCs |j |¡S)N)r‡r®)r¹rr©r©rªr®‡ szRawTurtle._colorstrc CsÐt|tƒr|Sy|\}}}Wn(ttfk rDtdt|ƒƒ‚YnX|jjdkrldd„|||fDƒ\}}}d|kr€dkr²nn.d|kr˜dkr²nnd|kr°dksÂntdt|ƒƒ‚d|||fS) z,Convert colortriples to hexstrings. zbad color arguments: %sgð?cSsg|]}td|ƒ‘qS)gào@)r©)r_r¶r©r©rªra” sz!RawTurtle._cc..rrªzbad color sequence: %sz #%02x%02x%02x)r¼rár«ržrqr‡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() NrrrYr"rscsg|] }ˆ ¡‘qSr©)r,)r_r8)r‡r©rªra» sz#RawTurtle.clone..)r‡rîrár†rrórõr¢r-r”r^r,rörZrvr5rÿr:)r¹r†ÚqÚttyper©)r‡rª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†rõr‡rrqrôr:)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||ddS)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 zeroré)rarìr+)rãrçrqrV)r¹Z stretch_widZ stretch_lenr+rìr©r©rªrlÜ s "    zRawTurtle.shapesizecCs |dkr|jS|jd|ddS)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 Nré)rarn)rärV)r¹Zshearr©r©rªrn szRawTurtle.shearfactorcCs<| |j|j}|tjddtj}|jd|ddS)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) g€f@rÁré)rarsN)rÇrÁrÃrÄrV)r¹rÇrsr©r©rªrg szRawTurtle.settiltanglecCs>|dkr0|j dtj|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() Ng€f@)rårÃrÄrÁrÇrÆrg)r¹rÇrsr©r©rªrt3 szRawTurtle.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)rgrt)r¹rÇr©r©rªrsM szRawTurtle.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 dddS)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Áré)ra) rærqrÃrÐrÄrÆrÅrãrärårV)r¹Út11Út12Út21Út22Zm11Zm12Zm21Zm22ZalfarðrñZa11Za12Za21Za22r©r©rªrm` s,,(  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. gð?csFg|]>\}}ˆˆ|ˆ|ˆjˆˆ |ˆ|ˆjf‘qSr©)r'r()r_r¶r·)Úe0Úe1Úp0Úp1r‡r©rªra‘ sz(RawTurtle._polytrafo..)r‡rÃrÅrr(r'rÏ)r¹rxÚer©)r rrrr‡rªÚ _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)) rrrsN)r‡r”r†rõr^Ú _getshapepolyrv)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. rérèr¸g@rr…c3s2|]*\}}ˆ|ˆ|ˆ|ˆ|fVqdS)Nr©)r_r¶r·)r r r r r©rªr°° sz*RawTurtle._getshapepoly..)rÛræÚmaxrÝr³)r¹rrrsrØr©)r r r r rªr¥ s  zRawTurtle._getshapepolyc Cs®|j}|j|jj}|j}|jj}|jr.|jdkr.|jdkr.d|_ |j }|dkr´|j dkrfd}n|j dkrx|j }n|j }| | |¡¡}|j|j}}|j|||||ddnx|d krÎ| ||j|¡n^|d krªxÐt||ƒD]D\} \} }}| | | d¡¡} |j| | | |¡| |¡|j ddqäWn||j r:d S|dkrV| |d d d ¡nN|d krz| ||j|jdj ¡n*|d kr¤x|D]} | | d d d ¡qŠWd|_ d S)zpManages the correct rendering of the turtle with respect to its shape, resizemode, stretch and tilt etc.rFrrr…r¸rèT)rr+rzr2rYrsN))rr)rr)rrr¬r")r‡r”r†rõr^rörÞr¡r rþrvrÛrÝrçrrràrßr4r\rÃÚzipr) r¹r‡rkrZtitemÚtshaper)ÚfcÚocr8rxr©r©rªr·² sF           zRawTurtle._drawturtlec Cs\|j}|j|jj}|j}|j}|dkrŽ| ¡}|jdkr@d}n|jdkrR|j}n|j }|  |  |¡¡}|j |j }}|j|||||ddn®|dkr²| d¡}| ||j|¡nŠ|d kr>> turtle.color("blue") >>> turtle.stamp() 13 >>> turtle.fd(50) rrr…r¸rèT)rr+rzr2rYr¬rsrr)r‡r”r†rõr^rvr,rÛrÝrçrrràrßr4rZr\rÃr-r³rrrrÂr) r¹r‡rkrrÚstitemr)rrZelementr8rxr©r©rªrrÚ s>        zRawTurtle.stampcCs¸||jkrHt|tƒr0x&|D]}|j |¡qWn |j |¡|j |¡d|f}|j}||jkrddS|j |¡}|j |¡||j kr˜|j d|j |_ |j  |j d|j dg¡dS)z9does the work for clearstamp() and clearstamps() rrNr¸) rr¼r³r‡r9rºrÂr|Úindexr}r{Úinsert)r¹ÚstampidZsubitemr8Zbufrr©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)rr:)r¹rr©r©rªr6 s zRawTurtle.clearstampcCsb|dkr|jdd…}n&|dkr0|jd|…}n|j|d…}x|D]}| |¡qDW| ¡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)rrr:)r¹r³ZtoDeleter8r©r©rªr7, s zRawTurtle.clearstampsc CsÊ|j|j|jt|jtƒf}|j}d|j|||j|j dd…|  |j¡|j dd…ff}|j rh|j   |¡|j}|jr^|jdkr^||}|d|jd|d|jd}dt|ddd|j|jƒ}|d |} x`td|ƒD]R} | dkrüd } nd } || | |_|jr4| |j||jf|j|j| ¡| ¡qêW|jr^|j|jd d |jd|jrr|j  |¡t|jtƒrŒ|j |¡||_|jr¦|j |¡t|j ƒdkr¾| ¡| ¡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Ágà?rgš™™™™™ñ?gð?TF))rr)rrr¬)rrzé*)rárßrÝr¼rýrÑr‡rÃrÿrrerÖrÂrrâr r'r(r¢rbr6rùr:r-rûrúrcrî) r¹rÎÚgo_modesr‡Z undo_entryÚstartÚdiffÚdiffsqÚnhopsÚdeltar³r2r©r©rªrËH sR    $$       zRawTurtle._gotocs$|\}}}}|\}}}} |\} } } ‰|j‰t|j|ƒdkrDtdƒ| |_| |_| ddgkrbd} n|} ˆj| | | |d‡‡fdd„|jDƒ}x"|D]}ˆ |¡|j  |¡q”W|}|j r ˆj dkr ||}|d ˆj d |dˆj d }dt|dd d |j |j ƒ}|d |}x^td|ƒD]P}|dkrFd}nd}||||_|rxˆ |j||jf|||¡| ¡q2W|r ˆj|jdd|d||_|jràt|jƒd krÈ|j ¡|jgkràd|_d|_| r|jgkrd|_tdƒn|jdk r|j ¡| ¡dS)z)Reverse a _goto. Used for undo() gà?z$undogoto: HALLO-DA-STIMMT-WAS-NICHT!)rrr¬)rrzcs&g|]}|ˆkrˆ |¡dkr|‘qS)r¦)r^)r_r`)rÖr‡r©rªra s z'RawTurtle._undogoto..r¸rrÁrgš™™™™™ñ?gð?TF))rr)rrNzUnwahrscheinlich in _undogoto!)r‡rÏrÃrŸrÿrr6rÖr9rºrâr r'r(r¢rbrùr:rûrcrúr€rý)r¹ÚentryÚoldÚnewr ZcoodataZdrawingZpcZpsrBZcLIZcLrdZusepcZtodeleter`r!r"r#r$r%r³r2r©)rÖr‡rªÚ _undogoto} sb      $$           zRawTurtle._undogotocCs®|jr|j d||jf¡||j9}|j |¡}|jj}|dkrœ|jdkrœd|j}dtt |ƒ|ƒ}d||}x&t |ƒD]}|j |¡|_|  ¡q~W||_|  ¡dS)z&Turns pen clockwise by angle. Úrotr¸rg@gð?N) rÂrrÇrÅrÊr‡r râr¢rÏrbr:)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|jddg|_|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)r2N) rcrr‡r6rÿrßrÝr5rÖr-rÃ)r¹ròr©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¼rýrÑ)r¹r©r©rªrBà s zRawTurtle.fillingcCsX| ¡s"|j ¡|_|j |j¡|jg|_| ¡|j rL|j   d|jf¡|  ¡dS)a Called 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,rürÖr-rÃrýrîrÂrr:)r¹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) rBrcrýr‡r4rüràrÂrr:)r¹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¡Wd| |¡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<rÒTrèrF)r¼rár³r®rÝrrßÚhasattrr‡r-rÃrÖr-rÂrrVr~rarMrXrYrWrC)r¹rr9r8rVr©r©rªr< s:        z RawTurtle.dotcCsB|j |j||||j¡\}}|j |¡|jr>|j d|f¡|S)z)Performs the writing for write() Úwri)r‡rGrÃrßrÖr-rÂr)r¹rErFrDr8rÎr©r©rªrGG s   zRawTurtle._writerP©ÚArialrŠrêcCs`|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) rÒTFN)rÂrr~rGrártr[re)r¹ÚargZmoverFrDrÎr¶r·r©r©rªr{Q 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)rÃrúrû)r¹r©r©rªr2n 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)rû)r¹r©r©rªr?| s zRawTurtle.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)rúr³)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 >>> ts.bgcolor("pink") )r‡)r¹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 >>> turtles() [] r©)r¹r©r©rªrH¦ szRawTurtle.getturtlecCs |j |¡S)zDSet delay value which determines speed of turtle animation. )r‡r)r¹rr©r©rªr<¾ 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‡rPr†rör:)r¹rJr¤rOr©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‡rQr†rör:)r¹rJr¤rOr©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‡rRr†rö)r¹rJr¤rOr©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|d kr|d}d|_ |_ ||jkr(|j |¡|j  |¡n$|d kr(t  ||d¡|j ¡dS) z2Does the main part of the work for undo() Nr*rrrr)r/r<r,))rr)rr)rrr¬)rr+r+rV)rÂrÍrÇr€r6r)r‡r9rÖrºr4rürýrÚrV)r¹ÚactionrwrÇZdegPAUZdummyrr8r©r©rªÚ_undos8            zRawTurtle._undocCsp|jdkrdS|j ¡}|d}|dd…}|dkr`x6|r\| ¡}| |d|dd…¡q6Wn | ||¡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Ò)rÂr€r4)r¹r8r3rwr©r©rªrw&s   zRawTurtle.undo)NN)N)NNN)N)N)NNNN)F)N)T)N)FrPr0)N)r¸N)r¸N)r¸N)9rÍrÎrÏrÐrør¯rør`rhrxrr5r¶r:rÕr±r®rr8rkrlrnrgrtrsrmrrGrr·rrrr6r7rËr)rÍrîrBr1r>r<rGr{r2r?rDrFrHrEr<rRrTrSr4rwrvr©r©r©rªr Ð sp%  (  (   (  (- 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 Ú_screenr÷r©r©r©rªr Is c@sfeZdZdZdZedZdd„Zededededfd d „Zd d „Z d d„Z dd„Z dd„Z dS)r÷Nr)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Œ)r÷Ú_rootrr)Ú_titlerÚ_destroyrûr¯rrrrør&)r¹rzrˆr‰rŠr‹rŒr©r©rªrøWs   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 rNrr¸rÁ)r.r6rrr¼r¡rr,)r¹rzrˆrrr@Zshr©r©rªr&ms   " " 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)r÷r6r)r7)r¹Z titlestringr©r©rªr)•s  z _Screen.titlecCs:|j}|tjkr(dt_dt_dt_dt_dt_| ¡dS)NF) r6r÷r r£r5rûrr´r)r¹Úrootr©r©rªr8¦s z_Screen._destroycCs | ¡dS)z~Shut the turtlegraphics window. Example (for a TurtleScreen instance named screen): >>> screen.bye() N)r8)r¹r©r©rªr°sz _Screen.byecsN‡fdd„}ˆ |¡tdr"dSy 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..exitGracefullyr’Nr)rRr¯rÚAttributeErrorÚexit)r¹r:r©)r¹rªr¸s   z_Screen.exitonclick) rÍrÎrÏr6rûr¯r7rør&r)r8rrr©r©r©rªr÷Qs ' r÷c@s4eZdZdZdZdZedededfdd„ZdS)r zÀ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. NrkrrŽcCs,tjdkrtƒt_tj|tj|||ddS)N)rkrrŽ)r r5r r rø)r¹rkrrŽr©r©rªrøßs   zTurtle.__init__)rÍrÎrÏrÐr£r5r¯rør©r©r©rªr Ös Úturtle_docstringdictc Csþi}x"tD]}d|}t|ƒj||<q Wx"tD]}d|}t|ƒj||<q.Wtd|dƒš}tdd„|Dƒƒ}| d¡x8|dd …D](}| d t|ƒ¡| d ||¡q†W|d }| d t|ƒ¡| d ||¡| d ¡| ¡WdQRXdS)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 .py It is intended to serve as a template for translation of the docstrings into different languages. z_Screen.zTurtle.z%s.pyr)css$|]}| d¡dtkr|VqdS)r™r¸N)rÚ _alias_list)r_r¶r©r©rªr°sz&write_docstringdict..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 Csddd| ¡i}t|ƒ}|j}x@|D]8}y||t|ƒ_Wq$tk rZtd|ƒYq$Xq$WdS)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)srzBad docstring-entry: %sN)rtÚ __import__rCr rÐr®rŸ)ZlangÚmodnameÚmodulerCr§r©r©rªÚread_docstringss rHrzCannot 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ªra;sz"getmethparlist..cSsg|]\}}||‘qSr©r©)r_r2Zdfltr©r©rªra=sÚ*z**z, z(%s))ÚinspectZgetargsÚ__code__Ú __defaults__rcrr-r) ZobZdefTextZcallTextrZvarargsZvarkwZitems2ZrealArgsÚdefaultsZitems1r©r©rªÚgetmethparlist+s&     rNcCsJddl}|dkrdStd}| d|d¡}| d|¡}| d|¡}|S)z>>>>>)ÚobjÚinitr¨Z paramslistZargslist)ÚgetattrrNrŸÚ __func_bodyÚformatrãÚglobalsrÐ) Z functionsrµrYrZZ docreviserDrßZpl1Zpl2Zdefstrr©r©rªÚ_make_global_funcsvs       r_zTurtle._screenzScreen()z Turtle._penzTurtle()Ú__main__cCstƒrtƒntƒdS)N)rNr]rUr©r©r©rªÚ switchpen‹sracCs~tƒtdƒtƒtdƒtƒtdƒxjtdƒD]^}|dkrFtƒx tdƒD]}tdƒt dƒqPW|dkr~t dƒt ƒtƒtd ƒtƒq4Wtd ƒt d ƒtd ƒtƒt dƒtdƒt dƒtdƒt d ƒtƒt dd ƒt dd ƒt dƒx2tdƒD]&}tdƒt dƒtdƒt dƒqWtdƒtƒx2tdƒD]&}tdƒt dƒtdƒt dƒqJWt ƒdS)zDemo of old turtle.py - moduleTédrrÁrŽr§éZZmaroonrr¸r„Fé´Z startstartr!Úredr‹N)r`r*ryr0r=rzrbr1rCrPr9r>r_r{)r`rÝr©r©rªÚdemo1‘sX    rfcCs^tdƒtƒtdƒttddƒƒtddƒd}tdƒx tdƒD]}tƒt |dƒqDWt dƒxt ƒrtt ƒqfWt ƒtdƒtd ƒd}td ƒtdƒtd ƒx‚td d ƒD]t}|dkrÞtƒtd d|dd|ƒx tdƒD]}t|ƒtdƒqèWtƒ|d7}tdƒttƒddƒq´Wtdƒtƒtdƒtdƒtƒtddƒtdƒtƒx4tdƒD](}t ddƒtdƒtdƒtdƒqrWtƒtdƒtƒtdƒtƒtdƒtƒ}| d¡tƒ}| d¡| d¡|  ¡| d¡| d¡| ¡| dd¡| d¡| ¡| d¡| dd¡| d¡| d¡tt|ƒƒd}xp| |¡dkrÞ| d¡| d ¡| | |¡¡| d¡|d!dkrÒ|  ¡|  ¡tƒ|d7}qpW|j d"d#d$d%| d&¡| d¡d'd(„}t! "d¡xt ƒr4|  ¡|  ¡qW| d¡|j d)d*d+| #|d¡d,S)-zDemo of some new features.r¸rrg@rcér‚zwait a moment...rªZgreenrdr…r„ééxé éFrreZyellowrŽé2r†rèié(rZblueZorangerÁg @g333333ã?r§zCAUGHT! )r1r„Úboldr_)rDrFr„cSstƒtƒdS)N)rr)r»r¼r©r©rªÚbabaszdemo2..babaz Click me!)ZCourierrjrn)rDN)$rprqrYrdrur;rbrbrar4r{rxrwr`rQrrWr1rAr@r>r]rUr9rkrHrar rPryrIr=rrÚtimeZsleeprR)rÖrÝZlaenger`Ztrir†rror©r©rªÚdemo2Æs°                        rq)r©)r=)FrÐZ_verZtkinterrörØrÃrprJršÚos.pathrrrÚcopyrrZ _tg_classesr?r@Z _tg_utilitiesÚ__all__r>r¯r«r²r®rŸr³rrÔrÜrârær÷rrúrrÚobjectr r€rqrrzrr½rÚrór r r r÷r r r~rHZ _LANGUAGEÚ ImportErrorrNrWrXr\r_rrrÍrarfrqrr©r©r©rªÚes                4  c /&.O} "       5c