from math import degrees, atan2
from openalea.plantgl.all import cross, dot
length = 4 
dl = 0.1 
Axiom : FFF [ \(90) &(90) M(0)] FF 
production: 
derivation length: length/dl

M(l): 
  if l < length: 
    u, nextu = l/length, (l+dl)/length 
    if l == 0: 
      tgt = (1,0)
      nexttgt = curve.getTangentAt(0) 
    else:
      tgt = curve.getTangentAt(u) 
      nexttgt = curve.getTangentAt(nextu) 
    rotangle = degrees(atan2(cross(tgt,nexttgt),dot(tgt,nexttgt))) 
    produce ^(rotangle)  F(dl) M(l+dl) 

endlsystem
###### INITIALISATION ######

__lpy_code_version__ = 1.1

def __initialiseContext__(context):
	import openalea.plantgl.all as pgl
	Color_1 = pgl.Material("Color_1" , ambient = (65,45,15) , diffuse = 1.04615 , )
	Color_1.name = "Color_1"
	context.turtle.setMaterial(1,Color_1)
	import openalea.plantgl.all as pgl
	curve = pgl.NurbsCurve2D(	
	    ctrlPointList = pgl.Point3Array([(-0.5, 0, 1),(-0.0454546, 0.298701, 1),(-0.0108225, -0.281385, 1),(0.534632, -0.008658, 1)]) , 
	    )
	curve.name = "curve"
	panel_0 = ({'active': True, 'visible': True, 'name': 'Panel 1'},[('Curve2D',curve)])
	parameterset = [panel_0,]
	context["__functions__"] = []
	context["__curves__"] = [('curve',curve),]
	context["__parameterset__"] = parameterset
	context["curve"] = curve
