Changeset 391 for python/trunk/Lib/lib-tk/turtle.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/lib-tk/turtle.py
r2 r391 3 3 # Version 1.0.1 - 24. 9. 2009 4 4 # 5 # Copyright (C) 2006 - 20 09Gregor Lingl5 # Copyright (C) 2006 - 2010 Gregor Lingl 6 6 # email: glingl@aon.at 7 7 # … … 28 28 by Wally Feurzig and Seymour Papert in 1966. 29 29 30 Imagine a robotic turtle starting at (0, 0) in the x-y plane. Give it30 Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an ``import turtle``, give it 31 31 the command turtle.forward(15), and it moves (on-screen!) 15 pixels in 32 32 the direction it is facing, drawing a line as it moves. Give it the 33 command turtle. left(25), and it rotates in-place 25 degrees clockwise.33 command turtle.right(25), and it rotates in-place 25 degrees clockwise. 34 34 35 35 By combining together these and similar commands, intricate shapes and … … 97 97 98 98 Behind the scenes there are some features included with possible 99 extensions in inmind. These will be commented and documented elsewhere.99 extensions in mind. These will be commented and documented elsewhere. 100 100 101 101 """ … … 336 336 del _dict[ex] 337 337 for ex in exclude: 338 if _dict.has_key(ex):338 if ex in _dict: 339 339 del _dict[ex] 340 340 for ex in __methods(fromClass): 341 if _dict.has_key(ex):341 if ex in _dict: 342 342 del _dict[ex] 343 343 … … 784 784 if not isinstance(self.cv, ScrolledCanvas): 785 785 return self.canvwidth, self.canvheight 786 if canvwidth is None and canvheight is None andbg is None:786 if canvwidth is canvheight is bg is None: 787 787 return self.cv.canvwidth, self.cv.canvheight 788 788 if canvwidth is not None: … … 812 812 """Will be raised in TurtleScreen.update, if _RUNNING becomes False. 813 813 814 Th us stops execution of turtle graphics script. Main purpose: use in815 in the Demo-Viewer turtle.Demo.py.814 This stops execution of a turtle graphics script. 815 Main purpose: use in the Demo-Viewer turtle.Demo.py. 816 816 """ 817 817 pass … … 860 860 >>> s = Shape("compound") 861 861 >>> s.addcomponent(poly, "red", "blue") 862 ### .. add more components and then use register_shape()862 >>> # .. add more components and then use register_shape() 863 863 """ 864 864 if self._type != "compound": … … 959 959 960 960 Example (for a TurtleScreen instance named screen): 961 screen.clear()961 >>> screen.clear() 962 962 963 963 Note: this method is not available as function. … … 1000 1000 'logo' 1001 1001 """ 1002 if mode ==None:1002 if mode is None: 1003 1003 return self._mode 1004 1004 mode = mode.lower() … … 1031 1031 >>> screen.setworldcoordinates(-10,-0.5,50,1.5) 1032 1032 >>> for _ in range(36): 1033 1034 1033 ... left(10) 1034 ... forward(0.5) 1035 1035 """ 1036 1036 if self.mode() != "world": … … 1137 1137 1.0 1138 1138 >>> screen.colormode(255) 1139 >>> turtle.pencolor(240,160,80)1139 >>> pencolor(240,160,80) 1140 1140 """ 1141 1141 if cmode is None: … … 1205 1205 >>> dist = 2 1206 1206 >>> for i in range(200): 1207 1208 1209 1207 ... fd(dist) 1208 ... rt(90) 1209 ... dist += 2 1210 1210 """ 1211 1211 if n is None: … … 1234 1234 1235 1235 def _incrementudc(self): 1236 " Increment upadate counter."""1236 """Increment update counter.""" 1237 1237 if not TurtleScreen._RUNNING: 1238 1238 TurtleScreen._RUNNNING = True … … 1305 1305 and a Turtle instance named turtle): 1306 1306 1307 >>> screen.onclick(turtle.goto) 1308 1309 ### Subsequently clicking into the TurtleScreen will 1310 ### make the turtle move to the clicked point. 1307 >>> screen.onclick(goto) 1308 >>> # Subsequently clicking into the TurtleScreen will 1309 >>> # make the turtle move to the clicked point. 1311 1310 >>> screen.onclick(None) 1312 1313 ### event-binding will be removed1314 1311 """ 1315 1312 self._onscreenclick(fun, btn, add) … … 1325 1322 must have focus. (See method listen.) 1326 1323 1327 Example (for a TurtleScreen instance named screen 1328 and a Turtle instance named turtle): 1324 Example (for a TurtleScreen instance named screen): 1329 1325 1330 1326 >>> def f(): 1331 fd(50) 1332 lt(60) 1333 1334 1327 ... fd(50) 1328 ... lt(60) 1329 ... 1335 1330 >>> screen.onkey(f, "Up") 1336 1331 >>> screen.listen() 1337 1332 1338 ### Subsequently the turtle can be moved by1339 ### repeatedly pressing the up-arrow key,1340 ### consequently drawing a hexagon 1341 """ 1342 if fun ==None:1333 Subsequently the turtle can be moved by repeatedly pressing 1334 the up-arrow key, consequently drawing a hexagon 1335 1336 """ 1337 if fun is None: 1343 1338 if key in self._keys: 1344 1339 self._keys.remove(key) … … 1370 1365 >>> running = True 1371 1366 >>> def f(): 1372 1373 1374 1375 1376 1377 >>> f() # ##makes the turtle marching around1367 ... if running: 1368 ... fd(50) 1369 ... lt(60) 1370 ... screen.ontimer(f, 250) 1371 ... 1372 >>> f() # makes the turtle marching around 1378 1373 >>> running = False 1379 1374 """ … … 1386 1381 picname -- a string, name of a gif-file or "nopic". 1387 1382 1388 If picname is a filename, set the correspon ing image as background.1383 If picname is a filename, set the corresponding image as background. 1389 1384 If picname is "nopic", delete backgroundimage, if present. 1390 1385 If picname is None, return the filename of the current backgroundimage. … … 1410 1405 canvwidth -- positive integer, new width of canvas in pixels 1411 1406 canvheight -- positive integer, new height of canvas in pixels 1412 bg -- colorstring or color-tup el, new backgroundcolor1407 bg -- colorstring or color-tuple, new backgroundcolor 1413 1408 If no arguments are given, return current (canvaswidth, canvasheight) 1414 1409 … … 1419 1414 Example (for a Turtle instance named turtle): 1420 1415 >>> turtle.screensize(2000,1500) 1421 ### e. g. to search for an erroneously escaped turtle ;-)1416 >>> # e. g. to search for an erroneously escaped turtle ;-) 1422 1417 """ 1423 1418 return self._resize(canvwidth, canvheight, bg) … … 1461 1456 """Set turtle-mode to 'standard', 'world' or 'logo'. 1462 1457 """ 1463 if mode ==None:1458 if mode is None: 1464 1459 return self._mode 1465 1460 if mode not in ["standard", "logo", "world"]: … … 1496 1491 >>> turtle.heading() 1497 1492 90 1498 >>> turtle.degrees(400.0) # angle measurement in gon 1493 1494 Change angle measurement unit to grad (also known as gon, 1495 grade, or gradian and equals 1/100-th of the right angle.) 1496 >>> turtle.degrees(400.0) 1499 1497 >>> turtle.heading() 1500 1498 100 … … 2002 2000 >>> turtle.pensize() 2003 2001 1 2004 turtle.pensize(10) # from here on lines of width 10 are drawn2002 >>> turtle.pensize(10) # from here on lines of width 10 are drawn 2005 2003 """ 2006 2004 if width is None: … … 2442 2440 RawTurtle.screens.append(self.screen) 2443 2441 else: 2444 raise TurtleGraphicsError("bad ca vas argument %s" % canvas)2442 raise TurtleGraphicsError("bad canvas argument %s" % canvas) 2445 2443 2446 2444 screen = self.screen … … 2514 2512 Example (for a Turtle instance named turtle): 2515 2513 >>> while undobufferentries(): 2516 2514 ... undo() 2517 2515 """ 2518 2516 if self.undobuffer is None: … … 2590 2588 >>> dist = 2 2591 2589 >>> for i in range(200): 2592 2593 2594 2590 ... turtle.fd(dist) 2591 ... turtle.rt(90) 2592 ... dist += 2 2595 2593 """ 2596 2594 return self.screen.tracer(flag, delay) … … 2687 2685 """Set/return turtle's stretchfactors/outline. Set resizemode to "user". 2688 2686 2689 Opti nonal arguments:2687 Optional arguments: 2690 2688 stretch_wid : positive number 2691 2689 stretch_len : positive number … … 2705 2703 >>> turtle.shapesize(outline=8) 2706 2704 """ 2707 if stretch_wid is None and stretch_len is None and outline ==None:2705 if stretch_wid is stretch_len is outline is None: 2708 2706 stretch_wid, stretch_len = self._stretchfactor 2709 2707 return stretch_wid, stretch_len, self._outlinewidth … … 2761 2759 >>> turtle.tilt(45) 2762 2760 >>> turtle.tiltangle() 2763 >>>2764 2761 """ 2765 2762 tilt = -self._tilt * (180.0/math.pi) * self._angleOrient … … 2961 2958 Example (for a Turtle instance named turtle): 2962 2959 >>> for i in range(8): 2963 2960 ... turtle.stamp(); turtle.fd(30) 2964 2961 ... 2965 2962 >>> turtle.clearstamps(2) … … 2979 2976 def _goto(self, end): 2980 2977 """Move the pen to the point end, thereby drawing a line 2981 if pen is down. All other method es for turtle movement depend2978 if pen is down. All other methods for turtle movement depend 2982 2979 on this one. 2983 2980 """ … … 3077 3074 # Turtle now at position old, 3078 3075 self._position = old 3079 ## if undo is done during cr ating a polygon, the last vertex3080 ## will be deleted. if the polygon is entirel deleted,3081 ## creati gPoly will be set to False.3076 ## if undo is done during creating a polygon, the last vertex 3077 ## will be deleted. if the polygon is entirely deleted, 3078 ## creatingPoly will be set to False. 3082 3079 ## Polygons created before the last one will not be affected by undo() 3083 3080 if self._creatingPoly: … … 3219 3216 """Draw a dot with diameter size, using color. 3220 3217 3221 Optional argument S:3218 Optional arguments: 3222 3219 size -- an integer >= 1 (if given) 3223 3220 color -- a colorstring or a numeric color tuple … … 3428 3425 3429 3426 >>> def turn(x, y): 3430 3431 3432 >>> onclick(turn) # Now clicking into the turtle will turn it.3427 ... left(360) 3428 ... 3429 >>> onclick(turn) # Now clicking into the turtle will turn it. 3433 3430 >>> onclick(None) # event-binding will be removed 3434 3431 """ … … 3446 3443 Example (for a MyTurtle instance named joe): 3447 3444 >>> class MyTurtle(Turtle): 3448 3449 3450 3451 3452 3445 ... def glow(self,x,y): 3446 ... self.fillcolor("red") 3447 ... def unglow(self,x,y): 3448 ... self.fillcolor("") 3449 ... 3453 3450 >>> joe = MyTurtle() 3454 3451 >>> joe.onclick(joe.glow) 3455 3452 >>> joe.onrelease(joe.unglow) 3456 ### clicking on joe turns fillcolor red, 3457 ### unclicking turns it to transparent. 3453 3454 Clicking on joe turns fillcolor red, unclicking turns it to 3455 transparent. 3458 3456 """ 3459 3457 self.screen._onrelease(self.turtle._item, fun, btn, add) … … 3474 3472 >>> turtle.ondrag(turtle.goto) 3475 3473 3476 ### Subsequently clicking and dragging a Turtle will3477 ### move it across the screen thereby producing handdrawings3478 ### (if pen isdown).3474 Subsequently clicking and dragging a Turtle will move it 3475 across the screen thereby producing handdrawings (if pen is 3476 down). 3479 3477 """ 3480 3478 self.screen._ondrag(self.turtle._item, fun, btn, add) … … 3523 3521 Example (for a Turtle instance named turtle): 3524 3522 >>> for i in range(4): 3525 3526 3523 ... turtle.fd(50); turtle.lt(80) 3524 ... 3527 3525 >>> for i in range(8): 3528 turtle.undo() 3526 ... turtle.undo() 3527 ... 3529 3528 """ 3530 3529 if self.undobuffer is None: … … 3689 3688 3690 3689 class Turtle(RawTurtle): 3691 """RawTurtle auto-cr ating (scrolled) canvas.3690 """RawTurtle auto-creating (scrolled) canvas. 3692 3691 3693 3692 When a Turtle object is created or a function derived from some … … 3729 3728 default value is turtle_docstringdict 3730 3729 3731 Has to be called explicit ely, (not used by the turtle-graphics classes)3730 Has to be called explicitly, (not used by the turtle-graphics classes) 3732 3731 The docstring dictionary will be written to the Python script <filname>.py 3733 3732 It is intended to serve as a template for translation of the docstrings
Note:
See TracChangeset
for help on using the changeset viewer.