���ѧۧݧ�ӧ�� �ާ֧ߧ֧էا֧� - ���֧էѧܧ�ڧ��ӧѧ�� - /home/ukubnwwtacc0unt/chapelbellstudios.com/uploads/cover/turtledemo.tar
���ѧ٧ѧ�
__init__.py 0000644 00000000472 15204140311 0006647 0 ustar 00 """ -------------------------------------- About this viewer -------------------------------------- Tiny demo viewer to view turtle graphics example scripts. Quickly and dirtyly assembled by Gregor Lingl. June, 2006 For more information see: turtledemo - Help Have fun! """ bytedesign.py 0000755 00000010227 15204140311 0007247 0 ustar 00 #! /usr/bin/python3.8 """ turtle-example-suite: tdemo_bytedesign.py An example adapted from the example-suite of PythonCard's turtle graphics. It's based on an article in BYTE magazine Problem Solving with Logo: Using Turtle Graphics to Redraw a Design November 1982, p. 118 - 134 ------------------------------------------- Due to the statement t.delay(0) in line 152, which sets the animation delay to 0, this animation runs in "line per line" mode as fast as possible. """ from turtle import Turtle, mainloop from time import perf_counter as clock # wrapper for any additional drawing routines # that need to know about each other class Designer(Turtle): def design(self, homePos, scale): self.up() for i in range(5): self.forward(64.65 * scale) self.down() self.wheel(self.position(), scale) self.up() self.backward(64.65 * scale) self.right(72) self.up() self.goto(homePos) self.right(36) self.forward(24.5 * scale) self.right(198) self.down() self.centerpiece(46 * scale, 143.4, scale) self.getscreen().tracer(True) def wheel(self, initpos, scale): self.right(54) for i in range(4): self.pentpiece(initpos, scale) self.down() self.left(36) for i in range(5): self.tripiece(initpos, scale) self.left(36) for i in range(5): self.down() self.right(72) self.forward(28 * scale) self.up() self.backward(28 * scale) self.left(54) self.getscreen().update() def tripiece(self, initpos, scale): oldh = self.heading() self.down() self.backward(2.5 * scale) self.tripolyr(31.5 * scale, scale) self.up() self.goto(initpos) self.setheading(oldh) self.down() self.backward(2.5 * scale) self.tripolyl(31.5 * scale, scale) self.up() self.goto(initpos) self.setheading(oldh) self.left(72) self.getscreen().update() def pentpiece(self, initpos, scale): oldh = self.heading() self.up() self.forward(29 * scale) self.down() for i in range(5): self.forward(18 * scale) self.right(72) self.pentr(18 * scale, 75, scale) self.up() self.goto(initpos) self.setheading(oldh) self.forward(29 * scale) self.down() for i in range(5): self.forward(18 * scale) self.right(72) self.pentl(18 * scale, 75, scale) self.up() self.goto(initpos) self.setheading(oldh) self.left(72) self.getscreen().update() def pentl(self, side, ang, scale): if side < (2 * scale): return self.forward(side) self.left(ang) self.pentl(side - (.38 * scale), ang, scale) def pentr(self, side, ang, scale): if side < (2 * scale): return self.forward(side) self.right(ang) self.pentr(side - (.38 * scale), ang, scale) def tripolyr(self, side, scale): if side < (4 * scale): return self.forward(side) self.right(111) self.forward(side / 1.78) self.right(111) self.forward(side / 1.3) self.right(146) self.tripolyr(side * .75, scale) def tripolyl(self, side, scale): if side < (4 * scale): return self.forward(side) self.left(111) self.forward(side / 1.78) self.left(111) self.forward(side / 1.3) self.left(146) self.tripolyl(side * .75, scale) def centerpiece(self, s, a, scale): self.forward(s); self.left(a) if s < (7.5 * scale): return self.centerpiece(s - (1.2 * scale), a, scale) def main(): t = Designer() t.speed(0) t.hideturtle() t.getscreen().delay(0) t.getscreen().tracer(0) at = clock() t.design(t.position(), 2) et = clock() return "runtime: %.2f sec." % (et-at) if __name__ == '__main__': msg = main() print(msg) mainloop() peace.py 0000755 00000002051 15204140311 0006163 0 ustar 00 #! /usr/bin/python3.8 """ turtle-example-suite: tdemo_peace.py A simple drawing suitable as a beginner's programming example. Aside from the peacecolors assignment and the for loop, it only uses turtle commands. """ from turtle import * def main(): peacecolors = ("red3", "orange", "yellow", "seagreen4", "orchid4", "royalblue1", "dodgerblue4") reset() Screen() up() goto(-320,-195) width(70) for pcolor in peacecolors: color(pcolor) down() forward(640) up() backward(640) left(90) forward(66) right(90) width(25) color("white") goto(0,-170) down() circle(170) left(90) forward(340) up() left(180) forward(170) right(45) down() forward(170) up() backward(170) left(90) down() forward(170) up() goto(0,300) # vanish if hideturtle() is not available ;-) return "Done!" if __name__ == "__main__": main() mainloop() minimal_hanoi.py 0000755 00000004002 15204140311 0007710 0 ustar 00 #! /usr/bin/python3.8 """ turtle-example-suite: tdemo_minimal_hanoi.py A minimal 'Towers of Hanoi' animation: A tower of 6 discs is transferred from the left to the right peg. An imho quite elegant and concise implementation using a tower class, which is derived from the built-in type list. Discs are turtles with shape "square", but stretched to rectangles by shapesize() --------------------------------------- To exit press STOP button --------------------------------------- """ from turtle import * class Disc(Turtle): def __init__(self, n): Turtle.__init__(self, shape="square", visible=False) self.pu() self.shapesize(1.5, n*1.5, 2) # square-->rectangle self.fillcolor(n/6., 0, 1-n/6.) self.st() class Tower(list): "Hanoi tower, a subclass of built-in type list" def __init__(self, x): "create an empty tower. x is x-position of peg" self.x = x def push(self, d): d.setx(self.x) d.sety(-150+34*len(self)) self.append(d) def pop(self): d = list.pop(self) d.sety(150) return d def hanoi(n, from_, with_, to_): if n > 0: hanoi(n-1, from_, to_, with_) to_.push(from_.pop()) hanoi(n-1, with_, from_, to_) def play(): onkey(None,"space") clear() try: hanoi(6, t1, t2, t3) write("press STOP button to exit", align="center", font=("Courier", 16, "bold")) except Terminator: pass # turtledemo user pressed STOP def main(): global t1, t2, t3 ht(); penup(); goto(0, -225) # writer turtle t1 = Tower(-250) t2 = Tower(0) t3 = Tower(250) # make tower of 6 discs for i in range(6,0,-1): t1.push(Disc(i)) # prepare spartanic user interface ;-) write("press spacebar to start game", align="center", font=("Courier", 16, "bold")) onkey(play, "space") listen() return "EVENTLOOP" if __name__=="__main__": msg = main() print(msg) mainloop() rosette.py 0000644 00000002521 15204140311 0006572 0 ustar 00 """ turtle-example-suite: tdemo_wikipedia3.py This example is inspired by the Wikipedia article on turtle graphics. (See example wikipedia1 for URLs) First we create (ne-1) (i.e. 35 in this example) copies of our first turtle p. Then we let them perform their steps in parallel. Followed by a complete undo(). """ from turtle import Screen, Turtle, mainloop from time import perf_counter as clock, sleep def mn_eck(p, ne,sz): turtlelist = [p] #create ne-1 additional turtles for i in range(1,ne): q = p.clone() q.rt(360.0/ne) turtlelist.append(q) p = q for i in range(ne): c = abs(ne/2.0-i)/(ne*.7) # let those ne turtles make a step # in parallel: for t in turtlelist: t.rt(360./ne) t.pencolor(1-c,0,c) t.fd(sz) def main(): s = Screen() s.bgcolor("black") p=Turtle() p.speed(0) p.hideturtle() p.pencolor("red") p.pensize(3) s.tracer(36,0) at = clock() mn_eck(p, 36, 19) et = clock() z1 = et-at sleep(1) at = clock() while any(t.undobufferentries() for t in s.turtles()): for t in s.turtles(): t.undo() et = clock() return "runtime: %.3f sec" % (z1+et-at) if __name__ == '__main__': msg = main() print(msg) mainloop() __main__.py 0000644 00000033641 15204140311 0006634 0 ustar 00 """ ---------------------------------------------- turtleDemo - Help ---------------------------------------------- This document has two sections: (1) How to use the demo viewer (2) How to add your own demos to the demo repository (1) How to use the demo viewer. Select a demoscript from the example menu. The (syntax colored) source code appears in the left source code window. IT CANNOT BE EDITED, but ONLY VIEWED! The demo viewer windows can be resized. The divider between text and canvas can be moved by grabbing it with the mouse. The text font size can be changed from the menu and with Control/Command '-'/'+'. It can also be changed on most systems with Control-mousewheel when the mouse is over the text. Press START button to start the demo. Stop execution by pressing the STOP button. Clear screen by pressing the CLEAR button. Restart by pressing the START button again. SPECIAL demos, such as clock.py are those which run EVENTDRIVEN. Press START button to start the demo. - Until the EVENTLOOP is entered everything works as in an ordinary demo script. - When the EVENTLOOP is entered, you control the application by using the mouse and/or keys (or it's controlled by some timer events) To stop it you can and must press the STOP button. While the EVENTLOOP is running, the examples menu is disabled. - Only after having pressed the STOP button, you may restart it or choose another example script. * * * * * * * * In some rare situations there may occur interferences/conflicts between events concerning the demo script and those concerning the demo-viewer. (They run in the same process.) Strange behaviour may be the consequence and in the worst case you must close and restart the viewer. * * * * * * * * (2) How to add your own demos to the demo repository - Place the file in the same directory as turtledemo/__main__.py IMPORTANT! When imported, the demo should not modify the system by calling functions in other modules, such as sys, tkinter, or turtle. Global variables should be initialized in main(). - The code must contain a main() function which will be executed by the viewer (see provided example scripts). It may return a string which will be displayed in the Label below the source code window (when execution has finished.) - In order to run mydemo.py by itself, such as during development, add the following at the end of the file: if __name__ == '__main__': main() mainloop() # keep window open python -m turtledemo.mydemo # will then run it - If the demo is EVENT DRIVEN, main must return the string "EVENTLOOP". This informs the demo viewer that the script is still running and must be stopped by the user! If an "EVENTLOOP" demo runs by itself, as with clock, which uses ontimer, or minimal_hanoi, which loops by recursion, then the code should catch the turtle.Terminator exception that will be raised when the user presses the STOP button. (Paint is not such a demo; it only acts in response to mouse clicks and movements.) """ import sys import os from tkinter import * from idlelib.colorizer import ColorDelegator, color_config from idlelib.percolator import Percolator from idlelib.textview import view_text from turtledemo import __doc__ as about_turtledemo import turtle demo_dir = os.path.dirname(os.path.abspath(__file__)) darwin = sys.platform == 'darwin' STARTUP = 1 READY = 2 RUNNING = 3 DONE = 4 EVENTDRIVEN = 5 menufont = ("Arial", 12, NORMAL) btnfont = ("Arial", 12, 'bold') txtfont = ['Lucida Console', 10, 'normal'] MINIMUM_FONT_SIZE = 6 MAXIMUM_FONT_SIZE = 100 font_sizes = [8, 9, 10, 11, 12, 14, 18, 20, 22, 24, 30] def getExampleEntries(): return [entry[:-3] for entry in os.listdir(demo_dir) if entry.endswith(".py") and entry[0] != '_'] help_entries = ( # (help_label, help_doc) ('Turtledemo help', __doc__), ('About turtledemo', about_turtledemo), ('About turtle module', turtle.__doc__), ) class DemoWindow(object): def __init__(self, filename=None): self.root = root = turtle._root = Tk() root.title('Python turtle-graphics examples') root.wm_protocol("WM_DELETE_WINDOW", self._destroy) if darwin: import subprocess # Make sure we are the currently activated OS X application # so that our menu bar appears. subprocess.run( [ 'osascript', '-e', 'tell application "System Events"', '-e', 'set frontmost of the first process whose ' 'unix id is {} to true'.format(os.getpid()), '-e', 'end tell', ], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL,) root.grid_rowconfigure(0, weight=1) root.grid_columnconfigure(0, weight=1) root.grid_columnconfigure(1, minsize=90, weight=1) root.grid_columnconfigure(2, minsize=90, weight=1) root.grid_columnconfigure(3, minsize=90, weight=1) self.mBar = Menu(root, relief=RAISED, borderwidth=2) self.mBar.add_cascade(menu=self.makeLoadDemoMenu(self.mBar), label='Examples', underline=0) self.mBar.add_cascade(menu=self.makeFontMenu(self.mBar), label='Fontsize', underline=0) self.mBar.add_cascade(menu=self.makeHelpMenu(self.mBar), label='Help', underline=0) root['menu'] = self.mBar pane = PanedWindow(orient=HORIZONTAL, sashwidth=5, sashrelief=SOLID, bg='#ddd') pane.add(self.makeTextFrame(pane)) pane.add(self.makeGraphFrame(pane)) pane.grid(row=0, columnspan=4, sticky='news') self.output_lbl = Label(root, height= 1, text=" --- ", bg="#ddf", font=("Arial", 16, 'normal'), borderwidth=2, relief=RIDGE) self.start_btn = Button(root, text=" START ", font=btnfont, fg="white", disabledforeground = "#fed", command=self.startDemo) self.stop_btn = Button(root, text=" STOP ", font=btnfont, fg="white", disabledforeground = "#fed", command=self.stopIt) self.clear_btn = Button(root, text=" CLEAR ", font=btnfont, fg="white", disabledforeground="#fed", command = self.clearCanvas) self.output_lbl.grid(row=1, column=0, sticky='news', padx=(0,5)) self.start_btn.grid(row=1, column=1, sticky='ew') self.stop_btn.grid(row=1, column=2, sticky='ew') self.clear_btn.grid(row=1, column=3, sticky='ew') Percolator(self.text).insertfilter(ColorDelegator()) self.dirty = False self.exitflag = False if filename: self.loadfile(filename) self.configGUI(DISABLED, DISABLED, DISABLED, "Choose example from menu", "black") self.state = STARTUP def onResize(self, event): cwidth = self._canvas.winfo_width() cheight = self._canvas.winfo_height() self._canvas.xview_moveto(0.5*(self.canvwidth-cwidth)/self.canvwidth) self._canvas.yview_moveto(0.5*(self.canvheight-cheight)/self.canvheight) def makeTextFrame(self, root): self.text_frame = text_frame = Frame(root) self.text = text = Text(text_frame, name='text', padx=5, wrap='none', width=45) color_config(text) self.vbar = vbar = Scrollbar(text_frame, name='vbar') vbar['command'] = text.yview vbar.pack(side=LEFT, fill=Y) self.hbar = hbar = Scrollbar(text_frame, name='hbar', orient=HORIZONTAL) hbar['command'] = text.xview hbar.pack(side=BOTTOM, fill=X) text['yscrollcommand'] = vbar.set text['xscrollcommand'] = hbar.set text['font'] = tuple(txtfont) shortcut = 'Command' if darwin else 'Control' text.bind_all('<%s-minus>' % shortcut, self.decrease_size) text.bind_all('<%s-underscore>' % shortcut, self.decrease_size) text.bind_all('<%s-equal>' % shortcut, self.increase_size) text.bind_all('<%s-plus>' % shortcut, self.increase_size) text.bind('<Control-MouseWheel>', self.update_mousewheel) text.bind('<Control-Button-4>', self.increase_size) text.bind('<Control-Button-5>', self.decrease_size) text.pack(side=LEFT, fill=BOTH, expand=1) return text_frame def makeGraphFrame(self, root): turtle._Screen._root = root self.canvwidth = 1000 self.canvheight = 800 turtle._Screen._canvas = self._canvas = canvas = turtle.ScrolledCanvas( root, 800, 600, self.canvwidth, self.canvheight) canvas.adjustScrolls() canvas._rootwindow.bind('<Configure>', self.onResize) canvas._canvas['borderwidth'] = 0 self.screen = _s_ = turtle.Screen() turtle.TurtleScreen.__init__(_s_, _s_._canvas) self.scanvas = _s_._canvas turtle.RawTurtle.screens = [_s_] return canvas def set_txtsize(self, size): txtfont[1] = size self.text['font'] = tuple(txtfont) self.output_lbl['text'] = 'Font size %d' % size def decrease_size(self, dummy=None): self.set_txtsize(max(txtfont[1] - 1, MINIMUM_FONT_SIZE)) return 'break' def increase_size(self, dummy=None): self.set_txtsize(min(txtfont[1] + 1, MAXIMUM_FONT_SIZE)) return 'break' def update_mousewheel(self, event): # For wheel up, event.delta = 120 on Windows, -1 on darwin. # X-11 sends Control-Button-4 event instead. if (event.delta < 0) == (not darwin): return self.decrease_size() else: return self.increase_size() def configGUI(self, start, stop, clear, txt="", color="blue"): self.start_btn.config(state=start, bg="#d00" if start == NORMAL else "#fca") self.stop_btn.config(state=stop, bg="#d00" if stop == NORMAL else "#fca") self.clear_btn.config(state=clear, bg="#d00" if clear == NORMAL else "#fca") self.output_lbl.config(text=txt, fg=color) def makeLoadDemoMenu(self, master): menu = Menu(master) for entry in getExampleEntries(): def load(entry=entry): self.loadfile(entry) menu.add_command(label=entry, underline=0, font=menufont, command=load) return menu def makeFontMenu(self, master): menu = Menu(master) menu.add_command(label="Decrease (C-'-')", command=self.decrease_size, font=menufont) menu.add_command(label="Increase (C-'+')", command=self.increase_size, font=menufont) menu.add_separator() for size in font_sizes: def resize(size=size): self.set_txtsize(size) menu.add_command(label=str(size), underline=0, font=menufont, command=resize) return menu def makeHelpMenu(self, master): menu = Menu(master) for help_label, help_file in help_entries: def show(help_label=help_label, help_file=help_file): view_text(self.root, help_label, help_file) menu.add_command(label=help_label, font=menufont, command=show) return menu def refreshCanvas(self): if self.dirty: self.screen.clear() self.dirty=False def loadfile(self, filename): self.clearCanvas() turtle.TurtleScreen._RUNNING = False modname = 'turtledemo.' + filename __import__(modname) self.module = sys.modules[modname] with open(self.module.__file__, 'r') as f: chars = f.read() self.text.delete("1.0", "end") self.text.insert("1.0", chars) self.root.title(filename + " - a Python turtle graphics example") self.configGUI(NORMAL, DISABLED, DISABLED, "Press start button", "red") self.state = READY def startDemo(self): self.refreshCanvas() self.dirty = True turtle.TurtleScreen._RUNNING = True self.configGUI(DISABLED, NORMAL, DISABLED, "demo running...", "black") self.screen.clear() self.screen.mode("standard") self.state = RUNNING try: result = self.module.main() if result == "EVENTLOOP": self.state = EVENTDRIVEN else: self.state = DONE except turtle.Terminator: if self.root is None: return self.state = DONE result = "stopped!" if self.state == DONE: self.configGUI(NORMAL, DISABLED, NORMAL, result) elif self.state == EVENTDRIVEN: self.exitflag = True self.configGUI(DISABLED, NORMAL, DISABLED, "use mouse/keys or STOP", "red") def clearCanvas(self): self.refreshCanvas() self.screen._delete("all") self.scanvas.config(cursor="") self.configGUI(NORMAL, DISABLED, DISABLED) def stopIt(self): if self.exitflag: self.clearCanvas() self.exitflag = False self.configGUI(NORMAL, DISABLED, DISABLED, "STOPPED!", "red") turtle.TurtleScreen._RUNNING = False def _destroy(self): turtle.TurtleScreen._RUNNING = False self.root.destroy() self.root = None def main(): demo = DemoWindow() demo.root.mainloop() if __name__ == '__main__': main() lindenmayer.py 0000755 00000004601 15204140311 0007420 0 ustar 00 #! /usr/bin/python3.8 """ turtle-example-suite: xtx_lindenmayer_indian.py Each morning women in Tamil Nadu, in southern India, place designs, created by using rice flour and known as kolam on the thresholds of their homes. These can be described by Lindenmayer systems, which can easily be implemented with turtle graphics and Python. Two examples are shown here: (1) the snake kolam (2) anklets of Krishna Taken from Marcia Ascher: Mathematics Elsewhere, An Exploration of Ideas Across Cultures """ ################################ # Mini Lindenmayer tool ############################### from turtle import * def replace( seq, replacementRules, n ): for i in range(n): newseq = "" for element in seq: newseq = newseq + replacementRules.get(element,element) seq = newseq return seq def draw( commands, rules ): for b in commands: try: rules[b]() except TypeError: try: draw(rules[b], rules) except: pass def main(): ################################ # Example 1: Snake kolam ################################ def r(): right(45) def l(): left(45) def f(): forward(7.5) snake_rules = {"-":r, "+":l, "f":f, "b":"f+f+f--f--f+f+f"} snake_replacementRules = {"b": "b+f+b--f--b+f+b"} snake_start = "b--f--b--f" drawing = replace(snake_start, snake_replacementRules, 3) reset() speed(3) tracer(1,0) ht() up() backward(195) down() draw(drawing, snake_rules) from time import sleep sleep(3) ################################ # Example 2: Anklets of Krishna ################################ def A(): color("red") circle(10,90) def B(): from math import sqrt color("black") l = 5/sqrt(2) forward(l) circle(l, 270) forward(l) def F(): color("green") forward(10) krishna_rules = {"a":A, "b":B, "f":F} krishna_replacementRules = {"a" : "afbfa", "b" : "afbfbfbfa" } krishna_start = "fbfbfbfb" reset() speed(0) tracer(3,0) ht() left(45) drawing = replace(krishna_start, krishna_replacementRules, 3) draw(drawing, krishna_rules) tracer(1) return "Done!" if __name__=='__main__': msg = main() print(msg) mainloop() paint.py 0000755 00000002412 15204140311 0006222 0 ustar 00 #! /usr/bin/python3.8 """ turtle-example-suite: tdemo_paint.py A simple event-driven paint program - left mouse button moves turtle - middle mouse button changes color - right mouse button toggles between pen up (no line drawn when the turtle moves) and pen down (line is drawn). If pen up follows at least two pen-down moves, the polygon that includes the starting point is filled. ------------------------------------------- Play around by clicking into the canvas using all three mouse buttons. ------------------------------------------- To exit press STOP button ------------------------------------------- """ from turtle import * def switchupdown(x=0, y=0): if pen()["pendown"]: end_fill() up() else: down() begin_fill() def changecolor(x=0, y=0): global colors colors = colors[1:]+colors[:1] color(colors[0]) def main(): global colors shape("circle") resizemode("user") shapesize(.5) width(3) colors=["red", "green", "blue", "yellow"] color(colors[0]) switchupdown() onscreenclick(goto,1) onscreenclick(changecolor,2) onscreenclick(switchupdown,3) return "EVENTLOOP" if __name__ == "__main__": msg = main() print(msg) mainloop() forest.py 0000755 00000005625 15204140311 0006422 0 ustar 00 #! /usr/bin/python3.8 """ turtlegraphics-example-suite: tdemo_forest.py Displays a 'forest' of 3 breadth-first-trees similar to the one in tree. For further remarks see tree.py This example is a 'breadth-first'-rewrite of a Logo program written by Erich Neuwirth. See http://homepage.univie.ac.at/erich.neuwirth/ """ from turtle import Turtle, colormode, tracer, mainloop from random import randrange from time import perf_counter as clock def symRandom(n): return randrange(-n,n+1) def randomize( branchlist, angledist, sizedist ): return [ (angle+symRandom(angledist), sizefactor*1.01**symRandom(sizedist)) for angle, sizefactor in branchlist ] def randomfd( t, distance, parts, angledist ): for i in range(parts): t.left(symRandom(angledist)) t.forward( (1.0 * distance)/parts ) def tree(tlist, size, level, widthfactor, branchlists, angledist=10, sizedist=5): # benutzt Liste von turtles und Liste von Zweiglisten, # fuer jede turtle eine! if level > 0: lst = [] brs = [] for t, branchlist in list(zip(tlist,branchlists)): t.pensize( size * widthfactor ) t.pencolor( 255 - (180 - 11 * level + symRandom(15)), 180 - 11 * level + symRandom(15), 0 ) t.pendown() randomfd(t, size, level, angledist ) yield 1 for angle, sizefactor in branchlist: t.left(angle) lst.append(t.clone()) brs.append(randomize(branchlist, angledist, sizedist)) t.right(angle) for x in tree(lst, size*sizefactor, level-1, widthfactor, brs, angledist, sizedist): yield None def start(t,x,y): colormode(255) t.reset() t.speed(0) t.hideturtle() t.left(90) t.penup() t.setpos(x,y) t.pendown() def doit1(level, pen): pen.hideturtle() start(pen, 20, -208) t = tree( [pen], 80, level, 0.1, [[ (45,0.69), (0,0.65), (-45,0.71) ]] ) return t def doit2(level, pen): pen.hideturtle() start(pen, -135, -130) t = tree( [pen], 120, level, 0.1, [[ (45,0.69), (-45,0.71) ]] ) return t def doit3(level, pen): pen.hideturtle() start(pen, 190, -90) t = tree( [pen], 100, level, 0.1, [[ (45,0.7), (0,0.72), (-45,0.65) ]] ) return t # Hier 3 Baumgeneratoren: def main(): p = Turtle() p.ht() tracer(75,0) u = doit1(6, Turtle(undobuffersize=1)) s = doit2(7, Turtle(undobuffersize=1)) t = doit3(5, Turtle(undobuffersize=1)) a = clock() while True: done = 0 for b in u,s,t: try: b.__next__() except: done += 1 if done == 3: break tracer(1,10) b = clock() return "runtime: %.2f sec." % (b-a) if __name__ == '__main__': main() mainloop() tree.py 0000755 00000002570 15204140311 0006053 0 ustar 00 #! /usr/bin/python3.8 """ turtle-example-suite: tdemo_tree.py Displays a 'breadth-first-tree' - in contrast to the classical Logo tree drawing programs, which use a depth-first-algorithm. Uses: (1) a tree-generator, where the drawing is quasi the side-effect, whereas the generator always yields None. (2) Turtle-cloning: At each branching point the current pen is cloned. So in the end there are 1024 turtles. """ from turtle import Turtle, mainloop from time import perf_counter as clock def tree(plist, l, a, f): """ plist is list of pens l is length of branch a is half of the angle between 2 branches f is factor by which branch is shortened from level to level.""" if l > 3: lst = [] for p in plist: p.forward(l) q = p.clone() p.left(a) q.right(a) lst.append(p) lst.append(q) for x in tree(lst, l*f, a, f): yield None def maketree(): p = Turtle() p.setundobuffer(None) p.hideturtle() p.speed(0) p.getscreen().tracer(30,0) p.left(90) p.penup() p.forward(-210) p.pendown() t = tree([p], 200, 65, 0.6375) for x in t: pass def main(): a=clock() maketree() b=clock() return "done: %.2f sec." % (b-a) if __name__ == "__main__": msg = main() print(msg) mainloop() turtle.cfg 0000644 00000000240 15204140312 0006530 0 ustar 00 width = 800 height = 600 canvwidth = 1200 canvheight = 900 shape = arrow mode = standard resizemode = auto fillcolor = "" title = Python turtle graphics demo. __pycache__/peace.cpython-38.pyc 0000644 00000002140 15204140312 0012446 0 ustar 00 U e5d) � @ s, d Z ddlT dd� Zedkr(e� e� dS )z� turtle-example-suite: tdemo_peace.py A simple drawing suitable as a beginner's programming example. Aside from the peacecolors assignment and the for loop, it only uses turtle commands. � )�*c C s d} t � t� t� tdd� td� | D ]@}t|� t� td� t� td� t d� td� t d� q,td� td � td d� t� td� t d� td � t� t d� td� t d� t� td� t� td� t d� t� td� t� td d� dS )N)Zred3ZorangeZyellowZ seagreen4Zorchid4Z royalblue1Zdodgerblue4i����i=����F i� �Z �B � Zwhiter iV���� iT � �- i, zDone!)�resetZScreenZupZgoto�widthZcolorZdownZforwardZbackward�left�rightZcircle)ZpeacecolorsZpcolor� r �(/usr/lib64/python3.8/turtledemo/peace.py�main sH r �__main__N)�__doc__Zturtler �__name__Zmainloopr r r r �<module> s - __pycache__/bytedesign.cpython-38.pyc 0000644 00000010263 15204140312 0013533 0 ustar 00 U e5d� � @ sX d Z ddlmZmZ ddlmZ G dd� de�Zdd� Ze dkrTe� Z ee � e� d S ) a� turtle-example-suite: tdemo_bytedesign.py An example adapted from the example-suite of PythonCard's turtle graphics. It's based on an article in BYTE magazine Problem Solving with Logo: Using Turtle Graphics to Redraw a Design November 1982, p. 118 - 134 ------------------------------------------- Due to the statement t.delay(0) in line 152, which sets the animation delay to 0, this animation runs in "line per line" mode as fast as possible. � )�Turtle�mainloop)�perf_counterc @ sT e Zd Zdd� Zdd� Zdd� Zdd� Zd d � Zdd� Zd d� Z dd� Z dd� ZdS )�Designerc C s� | � � td�D ]J}| �d| � | �� | �| �� |� | � � | �d| � | �d� q| � � | �|� | �d� | �d| � | �d� | �� | � d| d|� | � � �d � d S ) N� g�����)P@�H �$ g �8@�� �. g������a@T)�up�range�forward�down�wheel�position�backward�right�goto�centerpiece� getscreen�tracer)�selfZhomePos�scale�i� r �-/usr/lib64/python3.8/turtledemo/bytedesign.py�design s zDesigner.designc C s� | � d� td�D ]}| �||� q| �� | �d� td�D ]}| �||� q>| �d� td�D ]:}| �� | � d� | �d| � | �� | �d| � qb| �d� | � � � � d S )N�6 � r r r � )r r � pentpiecer �left�tripiecer r r r �update)r �initposr r r r r r 2 s zDesigner.wheelc C s� | � � }| �� | �d| � | �d| |� | �� | �|� | �|� | �� | �d| � | �d| |� | �� | �|� | �|� | �d� | � � � � d S )Ng @g �?@r )�headingr r �tripolyrr r � setheading�tripolylr! r r# )r r$ r �oldhr r r r"