from openalea.plantgl.all import *
from random import uniform,seed
from math import pi

seed(5)

def amplitude(x): return 1

def gen_noise_branch(radius,nbp=10):
    return  NurbsCurve2D([(uniform(0,radius*amplitude(pt/float(nbp-1))),pt/float(nbp-1),1) for pt in range(nbp)],degree=min(nbp-1,3),stride=nbp*10)

length = 10
dis = 1./unitstep
print (dis)

path = gen_noise_branch(radius/100.,freq)
l = path.getLength()
Axiom:  _(0.01) -(90)@g(Scaled(length/l,AxisRotated(Vector3.OZ,pi,AxisRotated(Vector3.OX,pi/2,Translated(Vector3(-path.ctrlPointList[0].x,0,0),path)))))[Frame()SetGuide(path,length,True)A(length/dis)][,(2)B(freq,length/l)]

derivation length: 1
production:
A(x):
    for i in range(int(x)):
        nproduce F(dis)[,(3)SetGuide()+(90)F(dis)]

B(freq,length):
  if with_ticks:
    ul = length/freq
    nproduce @O(ul/5)
    for i in range(int(freq)):
        nproduce F(ul)@O(ul/5)

interpretation:


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

__lpy_code_version__ = 1.1

def __initialiseContext__(context):
	scalars = [('radius', 'Integer', 14, 1, 100), ('freq', 'Integer', 33, 3, 100), ('unitstep', 'Integer', 1, 1, 1000), ('with_ticks', 'Bool', False)]
	context["__scalars__"] = scalars
	for s in scalars:
		if not s[1] == "Category" : context[s[0]] = s[2]
	import openalea.plantgl.all as pgl
	amplitude = pgl.NurbsCurve2D(	
	    ctrlPointList = pgl.Point3Array([(0, 0.00398406, 1),(0.135147, 1.09012, 1),(0.255548, 1.10149, 1),(0.462358, -0.133011, 1),(0.575864, 0.0540148, 1),(0.666072, 0.994762, 1),(0.857973, 1.00619, 1),(1, 0, 1)]) , 
	    )
	amplitude.name = "amplitude"
	panel_0 = ({'name': 'Panel 1', 'active': True, 'visible': False},[('Function',amplitude)])
	parameterset = [panel_0,]
	context["__functions__"] = [('amplitude',amplitude),]
	context["__curves__"] = []
	context["__parameterset__"] = parameterset
	context["amplitude"] = pgl.QuantisedFunction(amplitude)
