Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

That thing for the dragon curve? Yeah, again, but for the moore curve.

View moore.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#!/usr/bin/python
from itertools import chain
import sdxf
from math import sin,cos,pi
 
axiom = list("LFL+F+LFL")
 
rules = { 'L' : list("-RF+LFL+FR-"),
'R' : list("+LF-RFR-FL+") }
 
def L_repl(c):
global rules
if rules.has_key(c):
return rules[c]
return [c]
 
def L_iter(system):
a = map(L_repl,system)
return list(chain.from_iterable(a))
 
def L_sys(system,depth):
l = axiom
for i in range(depth):
l = L_iter(l)
return l
 
seq=L_sys(axiom,6)
 
direction = 0.0
theta = (pi/2)*0.95
distance = 1.5
location = (0.0,0.0)
 
def move(pos,angle,distance):
nx = pos[0] + sin(angle)*distance
ny = pos[1] + cos(angle)*distance
return (nx,ny)
 
d=sdxf.Drawing()
d.layers.append(sdxf.Layer(name='MOORE'))
for e in seq:
if e == 'F':
nl = move(location, direction, distance)
d.append(sdxf.Line(points=[location,nl],layer='MOORE'))
location = nl
elif e == '+':
direction = direction + theta
elif e == '-':
direction = direction - theta
 
d.saveas("moore.dxf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.