|
| 1 | +from openalea.plantgl.all import * |
| 2 | + |
| 3 | +NbSteps = 20 |
| 4 | +dt = 1./NbSteps |
| 5 | +print dt |
| 6 | +totlength = [] |
| 7 | + |
| 8 | +def Start(): |
| 9 | + global totlength |
| 10 | + totlength = [(0,length(0))] |
| 11 | + |
| 12 | +def plotCurve(data, xextend = None, yextend = None, pos = (0.1,-0.8), dim = (0.8,0.8), xtick = None, ytick = None ): |
| 13 | + from math import ceil, floor |
| 14 | + if len(data) > 1: |
| 15 | + print data |
| 16 | + if xextend: |
| 17 | + minx, maxx = xextend |
| 18 | + else : |
| 19 | + minx = floor(min([x for x,y in data])) |
| 20 | + maxx = ceil(max([x for x,y in data])) |
| 21 | + if yextend: |
| 22 | + miny, maxy = yextend |
| 23 | + else : |
| 24 | + miny = floor(min([y for x,y in data])) |
| 25 | + maxy = ceil(max([y for x,y in data])) |
| 26 | + xext = maxx - minx |
| 27 | + yext = maxy - miny |
| 28 | + x2Dlength, y2Dlength = dim |
| 29 | + projx = lambda x: (x2Dlength*(x-minx)/xext) |
| 30 | + projy = lambda y: (y2Dlength*(y-miny)/yext) |
| 31 | + if xtick is None: |
| 32 | + xtick = yext*0.1 |
| 33 | + if ytick is None: |
| 34 | + ytick = xext*0.1 |
| 35 | + |
| 36 | + data = [(projx(x),projy(y)) for x,y in data] |
| 37 | + ticklength = 0.02 |
| 38 | + |
| 39 | + nproduce [ @2D ,(3) @M(pos[0],pos[1]) @g(Polyline2D(data,width=2)) |
| 40 | + if miny <= 0 <= maxy: |
| 41 | + nproduce ,(5) @g(Polyline2D([(projx(minx),projy(0)),(projx(maxx),projy(0))])) |
| 42 | + cxtick = minx + xtick |
| 43 | + while cxtick < maxx: |
| 44 | + nproduce ,(5) @g(Polyline2D([(projx(cxtick),projy(-ticklength)),(projx(cxtick),projy(ticklength))])) |
| 45 | + cxtick += xtick |
| 46 | + if minx <= 0 <= maxx: |
| 47 | + nproduce ,(2) @g(Polyline2D([(projx(0),projy(miny)),(projx(0),projy(maxy))])) |
| 48 | + cytick = miny + ytick |
| 49 | + while cytick < maxy: |
| 50 | + nproduce ,(2) @g(Polyline2D([(projx(-ticklength),projy(cytick)),(projx(ticklength),projy(cytick))])) |
| 51 | + cytick += ytick |
| 52 | + nproduce ] |
| 53 | + |
| 54 | +#import matplotlib.pyplot as plt |
| 55 | +import pylab as plt |
| 56 | + |
| 57 | +def StartEach(): |
| 58 | + plt.close() |
| 59 | + |
| 60 | +def plotCurve2(data): |
| 61 | + if len(data) > 1: |
| 62 | + plt.plot([x for x in data], [y for y in data], '-', linewidth=2) |
| 63 | + plt.show() |
| 64 | + plt.draw() |
| 65 | + |
| 66 | +Axiom: I(0,length(0)) |
| 67 | + |
| 68 | +derivation length: NbSteps |
| 69 | +production: |
| 70 | + |
| 71 | +I(t,l) : |
| 72 | + nt = t+dt |
| 73 | + if nt >= 1.0: nt = 1.0 |
| 74 | + l = length(nt) |
| 75 | + totlength.append((nt,l)) |
| 76 | + produce I(nt,l) |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +interpretation: |
| 81 | + |
| 82 | +I(t,l) : |
| 83 | + plotCurve2(totlength) |
| 84 | + plotCurve(totlength) |
| 85 | + nproduce F(l) |
| 86 | + |
| 87 | + |
| 88 | +endlsystem |
| 89 | +###### INITIALISATION ###### |
| 90 | + |
| 91 | +__lpy_code_version__ = 1.1 |
| 92 | + |
| 93 | +def __initialiseContext__(context): |
| 94 | + import openalea.plantgl.all as pgl |
| 95 | + length = pgl.NurbsCurve2D( |
| 96 | + ctrlPointList = pgl.Point3Array([(0, 0, 1),(0.175114, 0.0522138, 1),(0.369245, 0.047519, 1),(0.369245, 0.619904, 1),(0.558015, 0.67878, 1),(1, 0.69864, 1)]) , |
| 97 | + ) |
| 98 | + length.name = "length" |
| 99 | + panel_0 = ({'active': True, 'visible': True, 'name': 'Panel 1'},[('Function',length)]) |
| 100 | + parameterset = [panel_0,] |
| 101 | + context["__functions__"] = [('length',length),] |
| 102 | + context["__curves__"] = [] |
| 103 | + context["__parameterset__"] = parameterset |
| 104 | + context["length"] = pgl.QuantisedFunction(length) |
0 commit comments