L-系统的改写以及简单树形迭代

边改写

看库源码请上GitHub fractal,以下仅显示使用方式。代码本质上,不同迭代字符改写方式不同

代码:

# 皮亚洛曲线
from fractal import Pen
p = Pen([500, 500])
p.setPoint([85, 85])
p.setWidth(1)
p.doD0L(omega="R", P={"L": "L-R--R+L++LL+R-",
                            "R": "+L-RR--R-L++L+R"}, delta=60, times=4, length=139, rate=2)
p.wait()

结果:

代码:

# 龙曲线
from fractal import Pen
from math import sqrt
p = Pen([350, 270])
p.setPoint([140, 60])
p.setWidth(1)
p.doD0L(omega="L", P={"L": "L+R", "R": "L-R"},
              delta=90, times=15, length=200, rate=sqrt(2))
p.wait()

结果:

代码:

from fractal import Pen

p = Pen([500,500])

p.setPoint([10, 490])

p.doD0L(omega = "R", P = {"L":"R+L+R", "R": "L-R-L"}, delta = 60, times = 8, length = 450, rate = 2)

p.wait()

结果:

点改写

用新分形替代点

代码:

# FASS曲线
from fractal import Pen

p = Pen([420,420])

p.setPoint([10,400])

p.doD0L(omega = "L", P = {"L": "LF+RFR+FL-F-LFLFL-FRFR+", "R": "-LFLF+RFRFR+F+RF-LFL-FR"}, delta =  90, times = 4, length = 200 , rate = 3)

p.wait()

结果:

代码:

# FASS曲线
from fractal import Pen

p = Pen([420,420])

p.setPoint([10,10])

p.doD0L(omega = "L", P = {"L": "LFRFL-FF-RFLFR+FF+LFRFL", "R": "RFLFR+FF+LFRFL-FF-RFLFR"}, delta =  90, times = 4, length = 200 , rate = 3, delta0 = 90)

p.wait()

结果:

树形迭代

新增表达式 [ ] 一个中括号代表树在此节点分叉。

代码:

# 树形
from fractal import Pen

p = Pen([260, 500])

p.setPoint([130, 500])

p.setAngle(90)

p.doD0L(omega="f", P={"f": "f[-f]f[+f]f"},
        delta=30, times=5, length=480, rate=3)

p.wait()

结果:

代码:

from fractal import Pen

p = Pen([400, 470])

p.setAngle(90)

p.setPoint([170, 470])

p.doD0L(omega="f", P={"f": "h+[[f]-f]-h[-hf]+f", "h": "hh"},
        delta=22.5, times=6, length=400, rate=2.3)

p.wait()

结果:

代码:

from fractal import Pen

p = Pen([400, 450])

p.setAngle(90)

p.setPoint([200, 450])

p.doD0L(omega="f", P={"f": "h[-f]h[+f]-f", "h": "hh"},
        delta=22.5, times=7, length=400, rate=2.17)

p.wait()

结果:

代码:

from fractal import Pen

p = Pen([400, 470])

p.setAngle(90)

p.setPoint([200,470])

p.doD0L(omega = "f", P = {"f": "h[-f][+f]hf", "h": "hh"}, delta = 25.7, times = 7, length = 400, rate = 2.17)

p.wait()

结果:

代码:

from fractal import Pen

p = Pen([400, 470])

p.setAngle(90)

p.setPoint([170, 470])

p.doD0L(omega="f", P={"f": "h+[[f]-f]-h[-hf]+f", "h": "hh"},
        delta=22.5, times=6, length=400, rate=2.3)

p.wait()

结果:

你可能感兴趣的:(python,算法)