Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325
 mŽŒY1ãO@sdZdZddlZddlZddlZddlZddlZddlZddl 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;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}gOZd~dgZeeeed€gZdd0d3d@dMdQdUd[d]dbdcdedfdqdvdydzgZdzd�d‚dƒd„d…d†d‡dˆdd‰dddŠdd‹ddŒd�dŽdkd�dWd�dAd�dad‘d’d“d”d•d–d—d˜d™d)dšd›dœiZd�dž„ZdŸd „ZyeeƒWnek r'ed¡ƒYnXGd¢d„deƒZd£d¤„Zd¥d¦„Zd§d¨Zfd©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”Z8ye8d•kre7e8ƒ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Ökr d×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à?Úheightgè?Ú canvwidthi�Ú canvheighti,Ú leftrightÚ topbottomÚstandardgð?é ÚundobuffersizeièÚclassicÚblackÚnoresizeÚvisibleTÚlanguageÚenglishÚ exampleturtleÚturtleÚ examplescreenÚscreenzPython Turtle GraphicsÚ using_IDLEFcCs't|dƒ�}|jƒ}WdQRXi}xõ|D]í}|jƒ}| s2|jdƒr]q2y|jdƒ\}}Wn)tk r¡td||fƒw2YnX|jƒ}|jƒ}|d krÕt|ƒ}n@y+d |krót|ƒ}n t |ƒ}Wntk rYnX|||)Ú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__Nc CsÐ|r||_|r||_|r-||_|jjd|d|j d|j d|jd|jdfƒ|jjd|j|jd|jƒ|jjd|j|jd|jƒ|j ƒdS)z„Z!d?d@„Z"dAdB„Z#dCdD„Z$d d d dEdF„Z%d S)GÚ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. cCs&tjddddƒ}|jƒ|S)z$return a blank image object rzr»r�)röÚ PhotoImageÚblank)Zimgr¬r¬r­Ú _blankimageÒs zTurtleScreenBase._blankimagecCstjd|ƒS)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ƒr3|jj}|jj}nat|jjdƒƒ}t|jjdƒƒ}|jjd| d| d|d|dfƒ||_||_d|_|_ dS)Nrzr�rrÄgð?) Úcvr¿rr‚rƒr¥rrÚxscaleÚyscale)r¼r'ÚwÚhr¬r¬r­røás  1  zTurtleScreenBase.__init__cCs|jjdddddƒS)zy|jj|ƒ}d}Wntjk r9d}YnX|S)zCCheck if the string color is a legal Tkinter color string. TF)r'Z winfo_rgbröZTclError)r¼r9ZrgbÚokr¬r¬r­Ú_iscolorstring8s   zTurtleScreenBase._iscolorstringcCs@|dk r,|jjd|ƒ|jƒn|jjdƒSdS)zVSet canvas' backgroundcolor if color is not None, else return backgroundcolor.Nrì)r'rr;r)r¼r9r¬r¬r­Ú_bgcolorBs  zTurtleScreenBase._bgcolorc Cs­|\}}||j}||j}ddddddi}|jj|d| d|d ||d |d |ƒ} |jj| ƒ\} } } } |jjƒ| | 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.rPÚswÚcenterrÌr_Zser»ÚtextÚanchorrÚfont)r(r)r'Z create_textr r,)r¼r[ÚtxtÚalignrErWr¹rºrDr9Zx0Zy0Zx1Zy1r¬r¬r­Ú_writeKs   ' zTurtleScreenBase._writer»cs\ˆdkr&ˆjj|d|ƒn2‡‡fdd†}ˆjj|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 Nz csKˆjj|jƒˆjˆjj|jƒ ˆj}}ˆ||ƒdS)N)r'Úcanvasxr¹r(Úcanvasyrºr))r r¹rº)Úfunr¼r¬r­Úeventfunfs!z+TurtleScreenBase._onclick..eventfun)r'Ú tag_unbindÚtag_bind)r¼r9rKÚnumÚaddrLr¬)rKr¼r­Ú_onclick]s zTurtleScreenBase._onclickcs\ˆdkr&ˆjj|d|ƒn2‡‡fdd†}ˆjj|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. NzcsKˆjj|jƒˆjˆjj|jƒ ˆj}}ˆ||ƒdS)N)r'rIr¹r(rJrºr))r r¹rº)rKr¼r¬r­rLxs!z-TurtleScreenBase._onrelease..eventfun)r'rMrN)r¼r9rKrOrPrLr¬)rKr¼r­Ú _onreleasels zTurtleScreenBase._onreleasecs\ˆdkr&ˆjj|d|ƒn2‡‡fdd†}ˆjj|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. Nzc sdyKˆjj|jƒˆjˆjj|jƒ ˆj}}ˆ||ƒWntk r_YnXdS)N)r'rIr¹r(rJrºr)r±)r r¹rº)rKr¼r¬r­rL‹s ! z*TurtleScreenBase._ondrag..eventfun)r'rMrN)r¼r9rKrOrPrLr¬)rKr¼r­Ú_ondrags zTurtleScreenBase._ondragcsVˆdkr#ˆjjd|ƒn/‡‡fdd†}ˆjjd|||ƒ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 csKˆjj|jƒˆjˆjj|jƒ ˆj}}ˆ||ƒdS)N)r'rIr¹r(rJrºr))r r¹rº)rKr¼r¬r­rL s!z1TurtleScreenBase._onscreenclick..eventfun)r'rr)r¼rKrOrPrLr¬)rKr¼r­Ú_onscreenclick”s zTurtleScreenBase._onscreenclickcsSˆdkr&|jjd|dƒn)‡fdd†}|jjd||ƒdS)z`Bind fun to key-release event of key. Canvas must have focus. See method listen Nzcs ˆƒdS)Nr¬)r )rKr¬r­rL­sz0TurtleScreenBase._onkeyrelease..eventfun)r'rr)r¼rKrªrLr¬)rKr­Ú _onkeyrelease¦s zTurtleScreenBase._onkeyreleasecs—ˆdkrH|dkr.|jjddƒq“|jjd|dƒnK‡fdd†}|dkr||jjd|ƒn|jjd||ƒ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 z cs ˆƒdS)Nr¬)r )rKr¬r­rL¼sz.TurtleScreenBase._onkeypress..eventfun)r'rr)r¼rKrªrLr¬)rKr­Ú _onkeypress±s   zTurtleScreenBase._onkeypresscCs|jjƒdS)z=Set focus on canvas (in order to collect key-events) N)r'r)r¼r¬r¬r­Ú_listenÃszTurtleScreenBase._listencCs6|dkr|jj|ƒn|jj||ƒdS)z?Install a timer, which calls fun after t milliseconds. rN)r'Z after_idler<)r¼rKÚtr¬r¬r­Ú_ontimerÈs zTurtleScreenBase._ontimercCs|jjddd|ƒS)z0Create and return image item on canvas. rÚimage)r'Z create_image)r¼rZr¬r¬r­Ú _createimageÐszTurtleScreenBase._createimagecCsN|\}}|jj|||j| |jfƒ|jj|d|ƒdS)zZConfigure image item as to draw image object at position (x,y) on canvas) rZN)r'r/r(r)Ú itemconfig)r¼r9r[rZr¹rºr¬r¬r­Ú _drawimageÕs (zTurtleScreenBase._drawimagecCs*|jj|d|ƒ|jj|ƒ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 .rZN)r'r\Z tag_lower)r¼r9rZr¬r¬r­Ú _setbgpicÝszTurtleScreenBase._setbgpiccCs|jj|ƒS)zQReturn 'line' or 'polygon' or 'image' depending on type of item. )r'rÚ)r¼r9r¬r¬r­Ú_typeåszTurtleScreenBase._typecsA|jj|ƒ‰‡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)r4r¬r­ú ôs z/TurtleScreenBase._pointlist..rrÄ)r'r/ÚrangeÚlen)r¼r9Úplr¬)r4r­Ú _pointlistës+zTurtleScreenBase._pointlistcCs#|jjd||||fƒdS)Nr)r'r)r¼Úsrx1Úsry1Úsrx2Úsry2r¬r¬r­Ú_setscrollregion÷sz!TurtleScreenBase._setscrollregionc Csª|jjƒ}x”|D]Œ}t|jj|ƒƒ}g}xR|rŽ|dd…\}}|j||ƒ|j||ƒ|dd…}q=W|jj||ŒqWdS)NrÄ)r'Zfind_allrÔr/r.) r¼Z xscalefactorZ yscalefactorrÙr9Z coordinatesZ newcoordlistr¹rºr¬r¬r­Ú_rescaleús  zTurtleScreenBase._rescalecCs£t|jtƒs"|j|jfS||koD|koDdknr_|jj|jjfS|dk rt||_|dk r‰||_|jj|||ƒ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._resizecCsZ|jjƒ}|dkr(|jd}|jjƒ}|dkrP|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_sizecCstjƒ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.mainloopcCstj||ƒ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.textinputc Cs"tj||d|d|d|ƒ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 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 initialvalueZminvalueÚmaxvalue)rZaskfloat)r¼r)roÚdefaultZminvalZmaxvalr¬r¬r­r>szTurtleScreenBase.numinput)&rÐrÑrÒrÓÚ staticmethodr$r&rør-r5r6r7r:r;r=r?r@rHrQrRrSrTrUrVrWrYr[r]r^r_rfrkrlrmrnrr(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€Ys c@seZdZdZdS)ÚTurtleGraphicsErrorzSome TurtleGraphics Error N)rÐrÑrÒrÓr¬r¬r¬r­rsbs rsc@s4eZdZdZddd„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. NcCs³||_|dkr3t|tƒr¦t|ƒ}ns|dkr�t|tƒr¦|jƒjdƒr¦t|ƒr¦tj |ƒ}n%|dkr–g}nt d|ƒ‚||_ dS)NÚpolygonrZz.gifÚcompoundzThere is no shape type %s) r_r¿rÔr¶räÚlowerÚendswithrrr&rsÚ_data)r¼Ztype_Údatar¬r¬r­røns   !  zShape.__init__cCsQ|jdkr"td|jƒ‚|dkr4|}|jj|||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() ruz Cannot add component to %s ShapeN)r_rsrxr.)r¼Úpolyrr,r¬r¬r­Ú addcomponent~s   zShape.addcomponent)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‡cCs2||_dgg||_d|_d|_dS)Nr»Frã)ÚbufsizeÚbufferÚptrÚcumulate)r¼r}r¬r¬r­rø˜s  zTbuffer.__init__NcCsb|dkr9xFt|jƒD]}dg|j|>> screen.clear() Note: this method is not available as function. rrÚallr¯r”r»rrërÄrŽN)r»rÄrŽ)r²rrr:r[Ú_bgpicÚ _bgpicnameÚ_tracingÚ_updatecounterÚ_turtlesrrRrrrr Ú_pen)r¼Úbtnrªr¬r¬r­r5ìs          zTurtleScreen.clearNcCs¢|dkr|jS|jƒ}|dkr;td|ƒ‚||_|d kr”|j|j d|j d|jd|jdƒd|_|_|jƒ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' Nr†ÚlogoÚworldzNo turtle-graphics-mode %srÄgð?)r†rr)r†r) rrvrsrkr‚rƒr(r)r`)r¼rr¬r¬r­r s     zTurtleScreen.modecCs|jƒdkr|jdƒt||ƒ}t||ƒ}|jƒ\}}|j|d|dƒ|j|j} } |j||_|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¤rnr%r(r)r‚rƒrkrlr,)r¼ZllxZllyZurxZuryZxspanZyspanZwxZwyZ oldxscaleZ oldyscalergrhrirjr¬r¬r­r',s     z TurtleScreen.setworldcoordinatescCs~|dkrO|jƒjdƒr<td|j|ƒƒ}qmtddƒ‚nt|tƒrmtd|ƒ}||j|>> screen.register_shape("triangle", ((5,-3),(0,5),(-5,-3))) Nz.gifrZz"Bad arguments for register_shape. zUse help(register_shape)rt)rvrwrr&rsr¿r¶rÿ)r¼Únamerkr¬r¬r­r#Ss  zTurtleScreen.register_shapec CsSt|ƒdkr|d}t|tƒr`|j|ƒsF|dkrJ|Stdt|ƒƒ‚y|\}}}Wn.ttfk r£tdt|ƒƒ‚YnX|jdkrØdd„|||fDƒ\}}}d|koïd kno)d|ko d kno)d|ko'd knsBtd 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ð?cSs g|]}td|ƒ‘qS)gào@)Úround)r`r¹r¬r¬r­rbŒs z*TurtleScreen._colorstr..éÿzbad color sequence: %sz #%02x%02x%02x)rdr¿rär?rsÚ TypeErrorr¡r)r¼r9r”ÚgÚbr¬r¬r­Ú _colorstrvs  %TzTurtleScreen._colorstrcs¦ˆjdƒsˆStˆƒdkrA‡fdd†d Dƒ}nHtˆƒdkry‡fd d†ˆdd…Dƒ}ntd ˆƒ‚t‡fd d†|DƒƒS) Nr•r‰cs-g|]#}tˆ||d…dƒ‘qS)rÄr†)r¥)r`ra)Úcstrr¬r­rb•s z'TurtleScreen._color..r»rŽr�rˆcs'g|]}dtˆ|dƒ‘qS)r†)r¥)r`r+)rr¬r­rb—s zbad colorstring: %scs!g|]}|ˆjd‘qS)r)r)r`rË)r¼r¬r­rbšs )r»rŽr�)r rdrsr¶)r¼rr4r¬)rr¼r­Ú_color‘s&zTurtleScreen._colorcCsP|dkr|jS|dkr1t|ƒ|_n|dkrLt|ƒ|_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)rr¤r¥)r¼Zcmoder¬r¬r­rœs    zTurtleScreen.colormodecCs2x+|jD] }|j|jƒ|jƒq WdS)z®Reset all Turtles on the Screen to their initial state. No argument. Example (for a TurtleScreen instance named screen): >>> screen.reset() N)r Ú_setmoderr`)r¼r�r¬r¬r­r`±szTurtleScreen.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.turtlescGsL|r|j|ƒ}nd}|j|ƒ}|dk rH|j|ƒ}|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)rr@r)r¼rr9r¬r¬r­rÆs zTurtleScreen.bgcolorcCs]|dkr|jSt|ƒ|_d|_|dk rFt|ƒ|_|jrY|jƒ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 rr,)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)rr¥)r¼rr¬r¬r­rùs zTurtleScreen.delaycCsLtjsdt_t‚|jdkrH|jd7_|j|j;_dS)zIncrement update counter.Trr»N)rÚ_RUNNINGr€r r )r¼r¬r¬r­Ú _incrementudcs   zTurtleScreen._incrementudccCsT|j}d|_x(|jƒD]}|jƒ|jƒqW||_|jƒdS)z'Perform a TurtleScreen update. TN)r r+Ú _update_dataÚ _drawturtler;)r¼ÚtracingrXr¬r¬r­r,s    zTurtleScreen.updatecCs|jƒdS)z› Return the width of the turtle window. Example (for a TurtleScreen instance named screen): >>> screen.window_width() 640 r)rn)r¼r¬r¬r­r.szTurtleScreen.window_widthcCs|jƒdS)z� Return the height of the turtle window. Example (for a TurtleScreen instance named screen): >>> screen.window_height() 480 r»)rn)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|jjƒƒ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|j|||ƒ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. num -- 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)rT)r¼rKrrPr¬r¬r­rREszTurtleScreen.onclickcCsa|dkr.||jkrM|jj|ƒn||jkrM|jj|ƒ|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.rU)r¼rKrªr¬r¬r­rVs  zTurtleScreen.onkeycCsm|dkr.||jkrY|jj|ƒn+|dk rY||jkrY|jj|ƒ|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)rr$r.rV)r¼rKrªr¬r¬r­rts  zTurtleScreen.onkeypresscCs|jƒ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)rW)r¼ÚxdummyÚydummyr¬r¬r­r”s zTurtleScreen.listenrcCs|j||ƒ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)rY)r¼rKrXr¬r¬r­r" szTurtleScreen.ontimercCs_|dkr|jS||jkr8|j|ƒ|j|<|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 rr&r^r )r¼Zpicnamer¬r¬r­rµs  zTurtleScreen.bgpiccCs|j|||ƒ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 ;-) )rm)r¼r‚rƒrìr¬r¬r­r%ÍszTurtleScreen.screensize)%rÐrÑrÒrÓrr²rør5rr'r#rrrr`r+rr*rrr,r.r-rrrRrrrr"rr%r!r$rrr r¬r¬r¬r­r¼sD & " '#       c@seZdZdZdeddƒdeddƒdeddƒiZdZdZdZed d „Z d d „Z d dd„Z dd„Z ddd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd d+d,„Zd-d.„Zd/d0„Zd1d2„Zd d3d4„Zd d5d6„Zd7d8„Zd9d:„Z d d d;d<„Z!dd=d>„Z"d d d?d@„Z#d dAdB„Z$eZ%eZ&eZ'eZ(eZ)eZ*eZ+eZ,e Z-d S)CÚ TNavigatorzRNavigation part of the RawTurtle. Implements methods for turtle movement. r†gð?grrrr»cCs[|j|_|j|_||_d|_|jƒd|_|j|ƒtj |ƒdS)N) ÚDEFAULT_ANGLEOFFSETÚ _angleOffsetÚDEFAULT_ANGLEORIENTÚ _angleOrientrÚ undobufferr:rr'r`)r¼rr¬r¬r­røòs       zTNavigator.__init__cCs)tddƒ|_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`üszTNavigator.resetNcCsj|dkr|jS|dkr#dS||_|d krMd|_d|_n|jd|_d |_dS) z:Set turtle-mode to 'standard', 'world' or 'logo'. Nr†rrrr»g@)r†rr)r†rrã)rr)r+Ú _fullcircle)r¼rr¬r¬r­rs      zTNavigator._setmodecCsB||_d||_|jdkr1d|_n |d|_dS)z+Helper function for degrees() and radians()ihr†rg@N)r0Ú _degreesPerAUrr))r¼Ú fullcircler¬r¬r­Ú_setDegreesPerAUs    zTNavigator._setDegreesPerAUg€v@cCs|j|ƒ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)r3)r¼r2r¬r¬r­r:szTNavigator.degreescCs|jdtjƒ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)r3rÆrÇ)r¼r¬r¬r­r^4s zTNavigator.radianscCs%|j|j|}|j|ƒdS)z)move turtle forward by specified distanceN)r-r/Ú_goto)r¼r;Zender¬r¬r­Ú_goBszTNavigator._gocCs&||j9}|jj|ƒ|_dS)z=Turn turtle counterclockwise by specified angle if angle > 0.N)r1r/rÍ)r¼rÊr¬r¬r­Ú_rotateGs zTNavigator._rotatecCs ||_dS)zmove turtle to position end.N)r-)r¼Úendr¬r¬r­r4LszTNavigator._gotocCs|j|ƒ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)r5)r¼r;r¬r¬r­rCPszTNavigator.forwardcCs|j| ƒ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)r5)r¼r;r¬r¬r­r/gszTNavigator.backcCs|j| ƒ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)r6)r¼rÊr¬r¬r­r_{szTNavigator.rightcCs|j|ƒ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)r6)r¼rÊr¬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) )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"|jt|Œƒn|jt||ƒƒ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)r4r)r¼r¹rºr¬r¬r­rIÏs zTNavigator.gotocCs!|jddƒ|jdƒ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!|jt||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)r4rr-)r¼r¹r¬r¬r­riszTNavigator.setxcCs!|jt|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)r4rr-)r¼rºr¬r¬r­rjszTNavigator.setycCsz|dk rt||ƒ}t|tƒr3|}n6t|tƒrQt|Œ}nt|tƒri|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ƒr3|}n6t|tƒrQt|Œ}nt|tƒri|j}||j\}}ttj||ƒ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-rrÆÚatan2rÇr1r)r+r0)r¼r¹rºr[Úresultr¬r¬r­ruDs   * zTNavigator.towardscCs_|j\}}ttj||ƒ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/rrÆr9rÇr1r)r+r0)r¼r¹rºr:r¬r¬r­rJgs * zTNavigator.headingcCsK||jƒ|j}|j}||d||d}|j|ƒ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+r0r6)r¼Zto_anglerÊÚfullr¬r¬r­rdvs zTNavigator.setheadingc Csã|jr(|jjdgƒd|j_|jƒ}|dkrI|j}|dkr“t|ƒ|j}dttdt|ƒddƒ|ƒ}d||}d |}d |tj |tj d |j ƒ}|d kr÷| | | }}}|j ƒ} |j ƒ} |d kr.|j d d ƒn |jd ƒ|j|ƒxHt|ƒD]:} |j|ƒ|j|ƒ|jd ƒ|j|ƒqUW|j| ƒ|d kr½|j | | ƒ|j|ƒ|jrßd |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,r�r€rpr0r8r¥ÚminrÆrÉrÇr1Ú_tracerr=r6rcr5) r¼ÚradiusZextentÚstepsrpZfracr*Zw2ÚlÚtrZdlrar¬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¼Úarr¬r¬r­r?ÕszTNavigator._tracercCsdS)z/dummy method - to be overwritten by child classNr¬)r¼rr¬r¬r­r=×szTNavigator._delay).rÐrÑrÒrÓrr.Z DEFAULT_MODEr(r*rør`rr3r:r^r5r6r4rCr/r_rPr[r|r}rIrLrirjr;rurJrdr4rpr?r=r@r3r0rbrQr\rerfrcr¬r¬r¬r­r'æsX             #    #  Ar'c@sNeZdZdZeddd„Zededdd„Zd d d „Zd d d „Zdd„Z dd„Z dd„Z d dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zd d!„Zd d"d#„Zd$d%d&„Zd$d'd(d)„Zd*d+„Zd,d-„ZeZe Ze Ze Ze ZeZeZd S).ÚTPenzFDrawing part of the RawTurtle. Implements drawing properties. racCs#||_d|_tj|ƒdS)N)Ú _resizemoder,rEÚ_reset)r¼rar¬r¬r­røés  z TPen.__init__rWrAcCsgd|_d|_||_||_d|_d|_d|_d|_d|_d|_ d|_ dS)Nr»TrŽçð?ç)rHrH)rHrIrIrH) Ú_pensizeÚ_shownÚ _pencolorÚ _fillcolorÚ_drawingÚ_speedÚ_stretchfactorÚ _shearfactorÚ_tiltÚ _shapetrafoÚ _outlinewidth)r¼rWrAr¬r¬r­rGîs          z TPen._resetNcCs?|dkr|jS|jƒ}|dkr;|jd|ƒ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)rUrVr‹)rFrvrV)r¼Zrmoder¬r¬r­raüs    zTPen.resizemodecCs'|dkr|jS|jd|ƒ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 NrY)rJrV)r¼rzr¬r¬r­rYs z 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() NrXF)rNrV)r¼r¬r¬r­rZ/s 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() NrXT)rNrV)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 )rN)r¼r¬r¬r­rNKs z TPen.isdownc Cs›ddddddddd d i}|d kr7|jS||krP||}n7d |kogd knr�tt|ƒƒ}nd}|jd|ƒd S)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) ZfastestrÚfastr‡ÚnormalrŒZslowrŽZslowestr»Ngà?g%@rp)rOr¥rrV)r¼rpZspeedsr¬r¬r­rpZs$   z TPen.speedcGs½|r—t|ƒ}|dkr/|d}}n1|dkrJ|\}}n|dkr`|}}|j|ƒ}|j|ƒ}|jd|d|ƒn"|j|jƒ|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 mor 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)rdrrVrrLrM)r¼rrBZpcolorZfcolorr¬r¬r­r9€s      z TPen.colorcGsO|r;|j|ƒ}||jkr(dS|jd|ƒn|j|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' NrW)rrLrVr)r¼rr9r¬r¬r­rW®s z TPen.pencolorcGsO|r;|j|ƒ}||jkr(dS|jd|ƒn|j|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) NrA)rrMrVr)r¼rr9r¬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() ÚshownTN)rV)r¼r¬r¬r­ro÷s zTPen.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() rYFN)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 )rK)r¼r¬r¬r­rO s zTPen.isvisiblecKs¦d|jd|jd|jd|jd|jd|jd|jd|jd |jd |j d |j i }|pr|sy|St |t ƒr‘|}ni}|j |ƒi}x|D]}||||>> 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} rYrXrWrArYrpraÚ stretchfactorrnr,rsrVFTN)rKrNrLrMrJrOrFrPrQrTrRr¿Údictr,r,r�r¶rÚ_newLiner¥r¤rÆrÉrÈrSr;)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¼rƒZforcedr¬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)rÐrÑrÒrÓr²rørGrarYrZrXrNrpr9rWrArorKrOrVr\r;rrrzryr]rUr=rqrMr¬r¬r¬r­rEås8     & . % $    rEc@s.eZdZdZdd„Zdd„ZdS)Ú _TurtleImagez6Helper class: Datatype to store Turtle attributes cCs#||_d|_|j|ƒdS)N)r’r_Ú _setshape)r¼r’Ú shapeIndexr¬r¬r­røµ s  z_TurtleImage.__init__csY|j‰||_|jdko6ˆj|jknr?dS|jdkocˆj|jknrldS|jdkrŽˆj|jƒn0|jdkr¾x|jD]}ˆj|ƒq§Wˆj|j|_|jdkròˆjƒ|_nc|jdkr ˆjˆjdjƒ|_n5|jdkrU‡fdd†ˆj|jDƒ|_dS)NrtrZrur#csg|]}ˆjƒ‘qSr¬)r-)r`r9)r’r¬r­rbÌ s z*_TurtleImage._setshape..)rZrt) r’rcr_rÿr:Ú_itemr-r[rx)r¼rcr9r¬)r’r­rbº s&  ))z_TurtleImage._setshapeN)rÐrÑrÒrÓrørbr¬r¬r¬r­ra± s  rac@sÚeZdZdZgZdedededdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dddd„Zdd„Zdd„Zdd„Zdd„Zdd d!„Zdddd"d#„Zdd$d%„Zd&d'„Zdd(d)„Zd*d+„Zddddd,d-„Zd.d/„Zd0d1„Zd2d3d4„Zd5d6„Zd7d8„Zd9d:„Zd;d<„Z dd=d>„Z!d?d@„Z"dAdB„Z#dCdD„Z$dEdFdG„Z%dHdI„Z&dJdK„Z'dLdM„Z(ddNdO„Z)dPdQ„Z*d2dRdodVdW„Z+dXdY„Z,dZd[„Z-d\d]„Z.d^d_„Z/d`da„Z0e0Z1ddbdc„Z2ddddedf„Z3ddddgdh„Z4ddddidj„Z5dkdl„Z6dmdn„Z7eZ8dS)pr zvAnimation part of the RawTurtle. Puts RawTurtle upon a TurtleScreen and provides tools for its animation. NrkrˆrŒcCs¹t|tƒr||_n±t|tƒrU|tjkrItjj|ƒ||_nwt|ttfƒr¼x_tjD]}|j |krt||_PqtWt|ƒ|_tjj|jƒnt d|ƒ‚|j}t j ||j ƒƒtj |ƒ|jj|ƒ|jƒ|_t||ƒ|_d|_d|_d|_|_||_d|_|jƒ|_|jg|_|jg|_g|_||_t |ƒ|_!|j"ƒdS)Nzbad canvas argument %sF)#r¿Ú_Screenr’rr Úscreensr.rrúr'rsr'rørrEr r6ÚdrawingLineItemrar�Ú_polyÚ _creatingPolyÚ _fillitemÚ _fillpathrKÚ_hidden_from_screenÚcurrentLineItemr-Ú currentLinerÙÚ stampItemsÚ_undobuffersizer|r,r;)r¼ZcanvasrkrˆrŒr’r¬r¬r­rø× s@           zRawTurtle.__init__cCs<tj|ƒtj|ƒ|jƒ|jƒ|jƒ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`rErGÚ_clearr!r;)r¼r¬r¬r­r`ÿ s     zRawTurtle.resetcCs7|dks|dkr$d|_nt|ƒ|_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,r|)r¼Úsizer¬r¬r­rh s zRawTurtle.setundobuffercCs |jdkrdS|jjƒ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.undobufferentriescCs˜d|_|_x!|jD]}|jj|ƒqW|jjƒ|_g|_|jrk|jj |j ƒ|jg|_|j ƒ|j |j ƒdS)zDelete all of pen's drawingsN)rjrkrÙr’r:r6rmrnrNr.r-r7rhrp)r¼r9r¬r¬r­rq8 s   zRawTurtle._clearcCs|jƒ|jƒ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)rqr;)r¼r¬r¬r­r5F s zRawTurtle.clearcCsa|jjƒ|jjdkr#dSt|jƒdkr]|jj|j|j|j|jƒdS)Nrr») r’rr rdrnr7rmrLrJ)r¼r¬r¬r­r U s  zRawTurtle._update_datacCs¤|j}|jdkrdS|jdkr\|jƒ|jƒ|jƒ|j|jƒnD|jƒ|jdkr x|jƒD]}|jƒq‚W|jƒdS)z&Perform a Turtle-data update. rNr») r’r r r!r;r=rr r+)r¼r’rXr¬r¬r­r;] s     zRawTurtle._updatecCs|jj||ƒ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|jj|ƒS)N)r’r)r¼rr¬r¬r­r„ szRawTurtle._colorcCs|jj|ƒS)N)r’r)r¼rr¬r¬r­r‡ szRawTurtle._colorstrc Cs t|tƒr|Sy|\}}}Wn.ttfk rVtdt|ƒƒ‚YnX|jjdkrŽdd„|||fDƒ\}}}d|ko¥dknoßd|koÁdknoßd|koÝdknsøtdt|ƒƒ‚d|||fS) z,Convert colortriples to hexstrings. zbad color arguments: %sgð?cSs g|]}td|ƒ‘qS)gào@)r)r`r¹r¬r¬r­rb” s z!RawTurtle._cc..rrzbad color sequence: %sz #%02x%02x%02x)r¿rärr¡rsr’r)r¼rr”rrr¬r¬r­Ú_ccŠ s%Tz RawTurtle._cccs@|j‰|j|jƒ|j}d|_d|_t|ƒ}ˆ|_||_ˆ|_tˆ|jjƒ|_ˆjj|ƒˆj |jjj }|dkrºˆj ƒ|j_ ni|dkrèˆj ˆj djƒ|j_ n;|dkr#‡fdd†ˆj |jjjDƒ|j_ ˆjƒ|_|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() NrtrZr#rucsg|]}ˆjƒ‘qSr¬)r-)r`r9)r’r¬r­rb» s z#RawTurtle.clone..)r’r\rNr�rrarcr r.rÿr_r-rdr[rxr6rmr;)r¼r�ÚqÚttyper¬)r’r­r8™ s,          "   zRawTurtle.clonecCsY|dkr|jjS||jjƒkr;td|ƒ‚|jj|ƒ|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�rcr’rrsrbr;)r¼rr¬r¬r­rkÁ s   zRawTurtle.shapecCs||ko"|ko"dknrF|j\}}|||jfS|dks^|dkrjtdƒ‚|dk r |dkr‘||f}qË||f}n+|dk rÂ|jd|f}n |j}|dkrà|j}|jddd|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 zerorarVrZr,)rPrTrsrV)r¼Z stretch_widZ stretch_lenr,rZr¬r¬r­rlÜ s '       zRawTurtle.shapesizecCs-|dkr|jS|jddd|ƒ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 NrarVrn)rQrV)r¼Zshearr¬r¬r­rn s zRawTurtle.shearfactorcCsK| |j|j}|tjddtj}|jddd|ƒ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) g€f@rÄrarVrsN)r1r+rÆrÇrV)r¼rÊrsr¬r¬r­rg szRawTurtle.settiltanglecCsK|dkr:|j dtj|j}||j|jS|j|ƒ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@)rRrÆrÇr+r1r0rg)r¼rÊrsr¬r¬r­rt3 s zRawTurtle.tiltanglecCs|j||jƒƒ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.tiltcCs“||ko-|ko-|ko-dknr9|jS|j\}}}}|dk r`|}|dk rr|}|dk r„|}|dk r–|}||||dkrºtdƒ‚||||f|_tj| |ƒdtj} tj| ƒtj| ƒ} } | || || || || || || || |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ÄrarV) rSrsrÆr9rÇrÉrÈrPrQrRrV)r¼Út11Út12Út21Út22Zm11Zm12Zm21Zm22Zalfar^r_Za11Za12Za21Za22r¬r¬r­rm` s,2     0  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ð?csQg|]G\}}ˆˆ|ˆ|ˆjˆˆ |ˆ|ˆjf‘qSr¬)r(r))r`r¹rº)Úe0Úe1Úp0Úp1r’r¬r­rb‘ s z(RawTurtle._polytrafo..)r’r-r/rr)r(r8)r¼rzÚer¬)r{r|r}r~r’r­Ú _polytrafoˆ s zRawTurtle._polytrafocCsE|jj|jj}|jdkrA|j|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)) rtruN)r’rÿr�rcr_Ú _getshapepolyrx)r¼rkr¬r¬r­rG” s zRawTurtle.get_shapepolyFcs¬|jdks|r-|j\‰‰‰‰nY|jdkrstd|jdƒ}|dd|f\‰‰‰‰n|jdkr†|St‡‡‡‡fdd†|DƒƒS) z`Calculate transformed shape polygon according to resizemode and shapetransform. rVrUr»g@rr‹cs:g|]0\}}ˆ|ˆ|ˆ|ˆ|f‘qSr¬r¬)r`r¹rº)rwrxryrzr¬r­rb° s z+RawTurtle._getshapepoly..)rFrSÚmaxrJr¶)r¼rtrurBr¬)rwrxryrzr­r�¥ s!zRawTurtle._getshapepolyc Cs^|j}|j|jj}|j}|jj}|jr½|jdkr½|jdkr½d|_ |j }|dkr|j dkrŽd}n$|j dkr©|j }n |j }|j|j|ƒƒ}|j|j}}|j||d|d|d |d d ƒqZ|d kr-|j||j|ƒqZ|d krZxt||ƒD]m\} \} }}|j|j| d ƒƒ} |j| | d|j|ƒd|j|ƒd |j d d ƒqIWn�|j rÊdS|dkrï|j|dddƒnb|d kr|j||j|jdj ƒn3|d krQx$|D]} |j| dddƒq1Wd |_ dS)zpManages the correct rendering of the turtle with respect to its shape, resizemode, stretch and tilt etc.rFrtr‹r»rUrr,rzr3TrZruNr¯r#©rr©rr©rr)rƒr„r…©rr©rr©rr)r†r‡rˆ)r’rÿr�rcr_rdrKr r rlrxrFrJrTr€r�rMrLr5r]r-Úziprt) r¼r’rkrvZtitemÚtshaper*ÚfcÚocr9rzr¬r¬r­r!² sF   '        %&     zRawTurtle._drawturtlec Csÿ|j}|j|jj}|j}|j}|dkrØ|jƒ}|jdkr^d}n$|jdkry|j}n |j }|j |j |ƒƒ}|j |j }}|j||d|d|d|dd ƒný|d kr |jd ƒ}|j||j|ƒnÉ|d krÕg}x'|D]} |jƒ} |j| ƒq%Wt|ƒ}x~t||ƒD]m\} \} }}|j |j | d ƒƒ} |j| | d|j|ƒd|j|ƒd|j dd ƒqdW|jj|ƒ|jjd |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) rtr‹r»rUrr,rzr3TrZr¯rurr)r’rÿr�rcr_rxr-rFrJrTr€r�rMrLr5r[r]r-r.r¶r‰rtror,r�) r¼r’rkrvrŠÚstitemr*r‹rŒÚelementr9rzr¬r¬r­rrÚ s>             %#zRawTurtle.stampcCsú||jkrbt|tƒrBx1|D]}|jj|ƒq%Wn|jj|ƒ|jj|ƒd|f}|j}||jkrŠdS|jj|ƒ}|jj|ƒ||j krÒ|j d|j |_ |jj |j d|j dgƒdS)z9does the work for clearstamp() and clearstamps() rrNr») ror¿r¶r’r:r$r,r~Úindexrr}Úinsert)r¼ÚstampidZsubitemr9Úbufr�r¬r¬r­Ú _clearstamp s   zRawTurtle._clearstampcCs|j|ƒ|jƒ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)r“r;)r¼r‘r¬r¬r­r6 s zRawTurtle.clearstampcCsƒ|dkr"|jdd…}n5|dkrD|jd|…}n|j|d…}x|D]}|j|ƒq^W|jƒ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)ror“r;)r¼rZtoDeleter9r¬r¬r­r7, s   zRawTurtle.clearstampsc CsZ|j|j|jt|jtƒf}|j}d|j|||j|j dd…|j |jƒ|j dd…ff}|j r–|j j |ƒ|j}|jrÐ|jdkrÐ||}|d|jd|d|jd}dt|ddd|j|jƒ}|d |} x�td|ƒD]p} | dkrLd } nd } || | |_|jr—|j|j||jf|j|j| ƒ|jƒq1W|jrÐ|j|jdd d d|jƒ|jré|j j|ƒt|jtƒr |jj|ƒ||_|jr-|jj|ƒt|j ƒdkrL|jƒ|jƒ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à?rŽgš™™™™™ñ?gð?TFrr¯rzé*©rr©rr)r–r—)rNrLrJr¿rkrÔr’r-rmrnrfrÙr,r�rOr r(r)r¥rcr7rgr;r.rirhrdr\) r¼r7Úgo_modesr’Z undo_entryÚstartÚdiffÚdiffsqÚnhopsÚdeltarr3r¬r¬r­r4H sR    (*          zRawTurtle._gotocsÐ|\}}}}|\}}}} |\} } } ‰|j‰t|j|ƒdkrbtdƒ| |_| |_| ddgkr�d} n|} ˆj| | d| d|ƒ‡‡fdd†|jDƒ}x+|D]#}ˆj|ƒ|jj |ƒq×W|}|j r&ˆj d kr&||}|dˆj d |d ˆj d }d t|dd d |j |j ƒ}|d |}xxtd |ƒD]g}|d kr±d}nd}||||_|róˆj|j||jf|||ƒ|jƒq–W|r&ˆj|jdddd|ƒ||_|jr{t|jƒdkrZ|jjƒ|jgkr{d|_d|_| rÂ|jgkr¦d|_tdƒn|jdk rÂ|jjƒ|jƒdS)z)Reverse a _goto. Used for undo() gà?z$undogoto: HALLO-DA-STIMMT-WAS-NICHT!rr¯rrzcs7g|]-}|ˆkrˆj|ƒdkr|‘qS)r©)r_)r`ra)rÙr’r¬r­rb� s z'RawTurtle._undogoto..r»rÄrŽgš™™™™™ñ?gð?TFNzUnwahrscheinlich in _undogoto!)rr)rr©rr©rr)ržrŸ)r’r8r-r¢rmrnr7rÙr:r$rOr r(r)r¥rcrgr;rirdrhr‚rk)r¼ÚentryÚoldÚnewr˜ZcoodataZdrawingZpcZpsrBZcLIZcLreZusepcZtodeleterar™ršr›rœr�rr3r¬)rÙr’r­Ú _undogoto} sb        (*              zRawTurtle._undogotocCsí|jr%|jjd||jfƒ||j9}|jj|ƒ}|jj}|dkrÖ|jdkrÖd|j}dtt |ƒ|ƒ}d||}x3t |ƒD]%}|jj|ƒ|_|j ƒq­W||_|j ƒdS)z&Turns pen clockwise by angle. Úrotr»rg@gð?N) r,r�r1r/rÍr’r rOr¥r8rcr;)r¼rÊZ neworientr"ZanglevelrAr�ràr¬r¬r­r6¾ s     zRawTurtle._rotateTcCs�t|jƒdkrb|jj|j|j|j|jƒ|jjƒ|_|jj |jƒn|jj|jddƒg|_|r™|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»r3TN) rdrnr’r7rmrLrJr6rÙr.r-)r¼r`r¬r¬r­r\Ð s zRawTurtle._newLinecCst|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¿rkrÔ)r¼r¬r¬r­rBà s zRawTurtle.fillingcCsz|jƒs1|jjƒ|_|jj|jƒ|jg|_|jƒ|j rl|j j d|jfƒ|j ƒ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-rjrÙr.r-rkr\r,r�r;)r¼r¬r¬r­r1î s   zRawTurtle.begin_fillcCsƒ|jƒrt|jƒdkre|jj|j|jd|jƒ|jre|jjd|jfƒd|_|_|j ƒ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) rBrdrkr’r5rjrMr,r�r;)r¼r¬r¬r­r> s   zRawTurtle.end_fillc Gs³|sqt|ttfƒrF|j|ƒ}|jt|jdƒ}q¥|j}|s¥|jt|jdƒ}n4|dkr–|jt|jdƒ}|j|ƒ}t|jdƒr|jj |j ||ƒ}|j j |ƒ|j r¯|j jd|fƒn«|jƒ}|j r8|j jdgƒd|j _zQ|jƒdkrW|jƒ|jƒ|j|ƒ|j|ƒ|jdƒWd|j|ƒX|j r¯d |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<TrUrF)r¿rär¶rrJr‚rLÚhasattrr’r§r-rÙr.r,r�rVr€rarMrXrYrWrC)r¼rrr9r9rVr¬r¬r­r< s:           z RawTurtle.dotcCs]|jj|j||||jƒ\}}|jj|ƒ|jrY|jjd|fƒ|S)z)Performs the writing for write() Úwri)r’rHr-rLrÙr.r,r�)r¼rFrGrEr9r7r¬r¬r­rHG s  zRawTurtle._writerPÚArialr‹rXcCsŠ|jr(|jjdgƒd|j_|jt|ƒ|jƒ|ƒ}|rq|jƒ\}}|j||ƒ|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,r�r€rHrärvr[re)r¼ÚargÚmoverGrEr7r¹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-rhri)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)ri)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)rhr¶)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|jj|ƒS)zDSet delay value which determines speed of turtle animation. )r’r)r¼rr¬r¬r­r=¾ szRawTurtle._delayr»cCs-|jj|jj|||ƒ|jƒ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. num -- 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’rQr�rdr;)r¼rKrrPr¬r¬r­rRà szRawTurtle.onclickcCs-|jj|jj|||ƒ|jƒ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. num -- 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’rRr�rdr;)r¼rKrrPr¬r¬r­rTØ szRawTurtle.onreleasecCs#|jj|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. num -- 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’rSr�rd)r¼rKrrPr¬r¬r­rSñ szRawTurtle.ondragcCs’|jdkrdS|dkrV|\}}|j| ||jƒ|jjƒ}n8|dkr||d}|j|ƒn|dkr˜|j|ƒnö|dkrÑ|d}|jj|ƒ|jj |ƒn½|dkr |d}|jj |dd d d d ƒn…|d kra|d}d|_ |_ ||jkrŽ|jj|ƒ|jj |ƒn-|d krŽt j||dƒ|jjƒdS)z2Does the main part of the work for undo() Nr¤rrrr”r©r<r¦rr¯r,r¥rV)r©r<©rr©rr©rr)r­r®r¯)r,r6r1r‚r6r£r’r:rÙr$r5rjrkrErV)r¼ÚactionryrÊZdegPAUÚdummyr�r9r¬r¬r­Ú_undos8            zRawTurtle._undocCs–|jdkrdS|jjƒ}|d}|dd…}|dkr‚xG|r~|jƒ}|j|d|dd…ƒqKWn|j||ƒ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‚r²)r¼r9r°ryr¬r¬r­rw&s    %zRawTurtle.undo)rªr‹rX)9rÐrÑrÒrÓrfr²rør`rhrxrqr5r r;r?rrrtr8rkrlrnrgrtrsrmr€rGr�r!rrr“r6r7r4r£r6r\rBr1r>r<rHr{r2r?rDrFrHrEr=rRrTrSr²rwrvr¬r¬r¬r­r Ð sp %          ((  (  ( -   5 A    0     cCs"tjdkrtƒ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 Ú_screenrer¬r¬r¬r­r Is c@sŠeZdZdZdZedZdd„Zededededd d „Zd d „Z d d„Z dd„Z dd„Z dS)reNr)cCsëtjdkrHtƒt_|_|jjtjƒ|jj|jƒtjdkrçtd}td}td}td}td}td}|jj ||||ƒ|jj ƒt_t j |tjƒ|j ||||ƒdS)Nrzr�r‚rƒr„r…)reÚ_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|jjƒ}|jjƒ}t|tƒrid|koZdknri||}|dkrƒ||d}t|tƒr¸d|ko©dknr¸||}|dkrÒ||d}|jj||||ƒ|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¨r´rr r¿r¤rr,)r¼rzr�rrrAÚshr¬r¬r­r&ms+  +  z _Screen.setupcCs,tjdk rtjj|ƒ|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)rer´r)rµ)r¼Z titlestringr¬r¬r­r)•s z _Screen.titlecCsS|j}|tjkr<dt_dt_dt_dt_dt_|jƒdS)NF) r´rer rr³rûrrr)r¼Úrootr¬r¬r­r¶¦s      z_Screen._destroycCs|jƒdS)z~Shut the turtlegraphics window. Example (for a TurtleScreen instance named screen): >>> screen.bye() N)r¶)r¼r¬r¬r­r°sz _Screen.byec s[‡fdd†}ˆj|ƒtdr-dSy tƒWntk rVtdƒ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ˆjƒ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Òr´rûr²rµrør&r)r¶rrr¬r¬r¬r­reQs   '  rec@sCeZdZdZdZdZedededdd„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. NrkrˆrŒc CsDtjdkrtƒt_tj|tjd|d|d|ƒdS)NrkrˆrŒ)r r³r r rø)r¼rkrˆrŒr¬r¬r­røßs  zTurtle.__init__)rÐrÑrÒrÓrr³r²rør¬r¬r¬r­r Ös Zturtle_docstringdictc CsCi}x+tD]#}d|}t|ƒj||.py It is intended to serve as a template for translation of the docstrings into different languages. z_Screen.zTurtle.z%s.pyr*cSs/g|]%}|jdƒdtkr|‘qS)rœr»)rÚ _alias_list)r`r¹r¬r¬r­rbs z'write_docstringdict..zdocsdict = { Nr»z%s : z """%s """, z """%s """ z} rãrã) Ú_tg_screen_functionsr£rÓÚ_tg_turtle_functionsr�r#rÞr{ÚreprÚclose)r¦ÚdocsdictÚ methodnamerªr§rÞr¬r¬r­r~ìs$        c Cszdd|jƒi}t|ƒ}|j}xH|D]@}y||t|ƒ_Wq2tk rqtd|ƒYq2Xq2WdS)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)rvÚ __import__rÁr£rÓr±r¢)ÚlangÚmodnameÚmodulerÁrªr¬r¬r­Úread_docstringss    rÇzCannot find docsdict forz;Unknown Error when trying to import %s-docstring-dictionaryc Cs<d}}tj|jƒ\}}}|dd…}|dd…}|jpQg}dd„|Dƒ}dgt|ƒt|ƒ|}dd„t||ƒDƒ} |dk rÒ| jd|ƒ|jd|ƒ|dk r| jd|ƒ|jd|ƒd j| ƒ}d |}d j|ƒ}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­rb;s z"getmethparlist..cSs g|]\}}||‘qSr¬r¬)r`r«Zdfltr¬r¬r­rb=s Ú*z**z, z(%s))ÚinspectZgetargsÚ__code__Ú __defaults__rdr‰r.r) ÚobZdefTextZcallTextrZvarargsZvarkwZitems2ZrealArgsÚdefaultsZitems1r¬r¬r­Úgetmethparlist+s& !    rÎcCseddl}|dkrdStd}|jd|dƒ}|jd|ƒ}|jd|ƒ}|S)z>>>>>ÚobjÚinitrZ paramslistZargslist)ÚgetattrrÎr¢Ú __func_bodyÚformatræÚglobalsrÓ) Z functionsr¸rÙrÚZ docreviserÂráZpl1Zpl2Zdefstrr¬r¬r­Ú_make_global_funcsvs  rßzTurtle._screenzScreen()z Turtle._penzTurtle()Ú__main__cCstƒrtƒntƒdS)N)rNr]rUr¬r¬r¬r­Ú switchpen‹s  rácCsÙtƒtdƒtƒtdƒtƒtdƒx‡tdƒD]y}|dkrYtƒx(tdƒD]}tdƒt dƒqfW|dkr¡t dƒt ƒtƒtd ƒtƒq@Wtd ƒt d ƒtd ƒtƒt dƒtdƒt dƒtdƒt d ƒtƒt dd ƒt dd ƒt dƒx<tdƒD].}tdƒt dƒtdƒt dƒqLWtdƒtƒx<tdƒD].}tdƒt dƒtdƒt dƒqœWt ƒdS)zDemo of old turtle.py - moduleTédrŽrÄrˆréZZmaroonrr»rŠFé´Z startstartr™Úredr�N)r`r*ryr0r=rzrcr1rCrPr9r>r_r{)raràr¬r¬r­Údemo1‘sX                           ræcCsFtdƒtƒtdƒttddƒƒtddƒd}tdƒx(tdƒD]}tƒt |dƒqXWt dƒxt ƒr–t ƒqƒWt ƒtdƒtd ƒd}td ƒtdƒtd ƒx¡td-d ƒD]�}|dkrtƒtd d|dd|ƒx(tdƒD]}t|ƒtdƒq(Wtƒ|d7}tdƒttƒddƒqæWtdƒtƒtdƒtdƒtƒtddƒtdƒtƒx?tdƒD]1}t ddƒtdƒtdƒtdƒqÑWtƒtdƒtƒtdƒtƒtdƒtƒ}|jdƒtƒ}|jdƒ|jdƒ|j ƒ|jdƒ|jdƒ|jƒ|jddƒ|jdƒ|jƒ|jdƒ|jddƒ|jd ƒ|jdƒtt|ƒƒd}x‹|j|ƒdkr¡|jdƒ|jdƒ|j|j|ƒƒ|jdƒ|d dkr”|j ƒ|j ƒtƒ|d7}qW|j d!d"d.d%d&ƒ|jd'ƒ|jdƒd(d)„}t!j"d ƒx!t ƒr|j ƒ|j ƒqñW|jdƒ|j d*d"d/ƒ|j#|dƒd,S)0zDemo of some new features.r»rŽrg@rãér‡zwait a moment...rZgreenrärÄr†ééxé éFrråZyellowrˆé2r�rUié(rŒZblueZorangeg @g333333ã?rzCAUGHT! rErªÚboldrGr_rŠcSstƒtƒdS)N)rr)r%r&r¬r¬r­Úbabaszdemo2..babaz Click me!ÚCourierNr�)rªr†rî)rðrêrî)$rprqrYrdrur;rbrcrár4r{rxrwr`rQrrWr1rAr@r>r]rUr9rkrHrar rPryrIr=rrÚtimeÚsleeprR)r@ràZlaengeraZtrir�rƒrïr¬r¬r­Údemo2Æs°                                                    ró)FrÓZ_verÚtkinterrörÛrÆrñrÉrZos.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€rsrr|rr'rErar r r rer r r~rÇZ _LANGUAGEÚ ImportErrorrÎr×rØrÜrßrrrÐrárærórr¬r¬r¬r­Úesü               4 c ÿ� /&ÿÿ,ÿÿÿÍÿÿÿÿy …"               5 c