Dragon curves

92 days ago by Sandor_Czirbusz

Dragon Curves

From Gerald. A. Edgar: Measure, Topology and Fractal Geometry

A programok nem futnak ezen a szervereren; le kell tölteni.

A kód tiszta Python, kell hozzá Tkinter

Barnsley levél

# -*- coding: iso-8859-2 -*- from turtle import * import time stwo = sqrt(2) def Leaf(depth, size): if depth < 1: forward(2 * size) back(2 * size) else: forward(size) Leaf(depth - 2, size / 2) back(size) left(45) Leaf(depth - 1 , size / stwo) right(90) Leaf(depth - 1, size / stwo) left(45) return def LeafCall(d, s): speed(0) Leaf(d, s) time.sleep(15) 
       
LeafCall(3,100) 
       
Traceback (click to the left of this block for traceback)
...
_tkinter.TclError: no display name and no $DISPLAY environment variable
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_4.py", line 10, in <module>
    exec compile(u"print _support_.syseval(python, u'LeafCall(3,100)', __SAGE_TMP_DIR__)" + '\n', '', 'single')
  File "", line 1, in <module>
    
  File "/sagenb/sage_install/sage-4.8-sage.math.washington.edu-x86_64-Linux/devel/sagenb-git/sagenb/misc/support.py", line 481, in syseval
    return system.eval(cmd, sage_globals, locals = sage_globals)
  File "/sagenb/sage_install/sage-4.8-sage.math.washington.edu-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/python.py", line 56, in eval
    eval(z, globals)
  File "", line 1, in <module>
    
  File "", line 22, in LeafCall
    
  File "<string>", line 1, in speed
  File "/sagenb/sage_install/sage-4.8-sage.math.washington.edu-x86_64-Linux/local/lib/python2.6/lib-tk/turtle.py", line 3715, in _getpen
    Turtle._pen = Turtle()
  File "/sagenb/sage_install/sage-4.8-sage.math.washington.edu-x86_64-Linux/local/lib/python2.6/lib-tk/turtle.py", line 3704, in __init__
    Turtle._screen = Screen()
  File "/sagenb/sage_install/sage-4.8-sage.math.washington.edu-x86_64-Linux/local/lib/python2.6/lib-tk/turtle.py", line 3553, in Screen
    Turtle._screen = _Screen()
  File "/sagenb/sage_install/sage-4.8-sage.math.washington.edu-x86_64-Linux/local/lib/python2.6/lib-tk/turtle.py", line 3569, in __init__
    _Screen._root = self._root = _Root()
  File "/sagenb/sage_install/sage-4.8-sage.math.washington.edu-x86_64-Linux/local/lib/python2.6/lib-tk/turtle.py", line 458, in __init__
    TK.Tk.__init__(self)
  File "/sagenb/sage_install/sage-4.8-sage.math.washington.edu-x86_64-Linux/local/lib/python2.6/lib-tk/Tkinter.py", line 1643, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

Dragon

# -*- coding: iso-8859-2 -*- from turtle import * import time def Dragon(d, s, p): fct = 1/sqrt(2) if d == 0: forward(s) return left(p * 45) Dragon(d - 1, s * fct, 1) right(p * 90) Dragon(d - 1, s * fct, -1) left(p * 45) return def DragonCall(d, s, p): Dragon(d, s, p) time.sleep(3) 
       
speed(0) DragonCall(7, 200, 1) 
       

Fudgeflake

# -*- coding: iso-8859-2 -*- from turtle import * import time def Fudge(d, s, p): fct = 1/sqrt(2) if d == 0: forward(s) return right(p * 120) Fudge(d - 1, s * fct, 1) left(p * 60) Fudge(d - 1, s * fct, -1) right(p * 120) return def FudgeCall(d, s, p): Fudge(d, s, p) time.sleep(10) #FudgeCall(8, 50, 1) def FudgeFlake(d, s, p): Fudge(d, s, p) right(60) Fudge(d,s, p) right(60) Fudge(d,s, p) time.sleep(3) 
       
speed(0) FudgeFlake(8, 50, 1) 
       

Heighway's Dragon

# Heighway's Dragon # -*- coding: iso-8859-2 -*- from turtle import * import time factor = 1 / sqrt(2) def Heighway(depth, size, parity): if depth == 0: forward(size) return else: left(parity * 45) Heighway(depth - 1, size * factor, 1) right(parity * 90) Heighway(depth - 1, size * factor, -1) left(parity * 45) return def HeighwayCall(d, s,p): speed(0) Heighway(d, s, p) time.sleep(2) 
       
HeighwayCall(10, 200,1) 
       

Koch curve

# -*- coding: iso-8859-2 -*- from turtle import * import time def Koch (d, s): """Koch görbe d -- az iteráció mélysége s -- induló hossz """ if d == 0: forward(s) return Koch(d - 1, s / 3) left(60) Koch(d - 1, s / 3) right(120) Koch(d - 1, s / 3) left(60) Koch(d - 1, s / 3) return def KochCall(d,s): Koch(d,s) time.sleep(2) #KochCall(4, 200) def SnowFlake(d, s): speed(0) Koch(d, s) right(120) Koch(d,s) right(120) Koch(d,s) time.sleep(3) 
       
SnowFlake(4,200) 
       

McWorter pentigree

# -*- coding: iso-8859-2 -*- from turtle import * import time shrink = (3 + sqrt(5))/2 def Pentigree(d, s): """McWorter pentigree """ if d == 0: forward(s) return left(36) Pentigree(d - 1, s / shrink) left(72) Pentigree(d - 1, s / shrink) right(144) Pentigree(d - 1, s / shrink) right(72) Pentigree(d - 1, s / shrink) left(72) Pentigree(d - 1, s / shrink) left(72) Pentigree(d - 1, s / shrink) right(36) def PentigreeCall(d, s): speed(0) Pentigree(d, s) time.sleep(2) 
       
PentigreeCall(4, 200) 
       

Peano curve

# -*- coding: iso-8859-2 -*- from turtle import * import time def Pean(n, a, h): if n == 0: return right(a) Pean(n - 1, -a, h) forward(h) Pean(n - 1, a, h) forward(h) Pean(n - 1, -a, h) left(a) return def Peano(): pu() # setpos(-500, -500) pd() speed(0) Pean(6, 90, 12) time.sleep(12) return 
       
Peano() 
       

Sierpinski sárkány

# -*- coding: iso-8859-2 -*- from turtle import * import time def SDragon(d, s, p): """ Sierpinski sárkány """ if d == 0: forward(s) return left(60 * p) SDragon(d - 1, s / 2, -p) right(60 * p) SDragon(d - 1, s / 2, p) right(60 * p) SDragon(d - 1, s / 2, -p) left(60 * p) def SDragonCall(d, s, p): SDragon(d, s, p) time.sleep(2) 
       
SDragonCall(5, 200, 1)