from random import *
from openalea.plantgl.all import *

gravity =  -Vector3.OZ * 9.80665
mass = 0.05
step = 0.2
g = gravity*mass*step
maxparticule = 2000
maxtime = 500
maxcol = 35
maxrad = 8

Axiom: [;(0)[_(0.5)F(1)][_(maxrad)F(1)]]A(0)

derivation length: maxtime
production:

A(x) :
  if x < maxparticule:
    nbprod = int(randint(0,4))
    for i in range(nbprod):
      nproduce P(Vector3(0,0,0),Vector3((random()/2)-.25,(random()/2)-.25,3+2*random()),0) 
    produce A(x+nbprod)
  else:
    produce

P(pos,speed,t):
  speed += g
  pos += speed * step
  if pos.z < 0:
     #if norm(pos) > maxrad:
     #    produce
     pos.z *= -1
     speed.z *= -1
     speed *= 0.8
     if norm(speed) < 1e-4:
        produce
  produce P(pos,speed,t+1)

homomorphism:


P(pos,speed,t) --> [;(int(min(35,1+maxcol*t/200)))@M(pos.x,pos.y,pos.z)@O(max(0.1,0.3-0.001*t))]

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

__lpy_code_version__ = 1.1

def __initialiseContext__(context):
	import openalea.plantgl.all as pgl
	Color_0 = pgl.Material("Color_0" , ambient = (26,0,0) , diffuse = 6.15385 , )
	Color_0.name = "Color_0"
	context.turtle.setMaterial(0,Color_0)
	Color_1 = pgl.Material("Color_1" , ambient = (2,0,22) , diffuse = 10.7727 , )
	Color_1.name = "Color_1"
	context.turtle.setMaterial(1,Color_1)
	Color_2 = pgl.Material("Color_2" , ambient = (2,0,22) , diffuse = 10.6878 , )
	Color_2.name = "Color_2"
	context.turtle.setMaterial(2,Color_2)
	Color_3 = pgl.Material("Color_3" , ambient = (3,1,22) , diffuse = 10.6028 , )
	Color_3.name = "Color_3"
	context.turtle.setMaterial(3,Color_3)
	Color_4 = pgl.Material("Color_4" , ambient = (3,1,22) , diffuse = 10.5179 , )
	Color_4.name = "Color_4"
	context.turtle.setMaterial(4,Color_4)
	Color_5 = pgl.Material("Color_5" , ambient = (4,2,22) , diffuse = 10.4329 , )
	Color_5.name = "Color_5"
	context.turtle.setMaterial(5,Color_5)
	Color_6 = pgl.Material("Color_6" , ambient = (4,2,22) , diffuse = 10.348 , specular = (41,41,41) , )
	Color_6.name = "Color_6"
	context.turtle.setMaterial(6,Color_6)
	Color_7 = pgl.Material("Color_7" , ambient = (5,3,22) , diffuse = 10.2631 , specular = (41,41,41) , )
	Color_7.name = "Color_7"
	context.turtle.setMaterial(7,Color_7)
	Color_8 = pgl.Material("Color_8" , ambient = (5,4,22) , diffuse = 10.1781 , specular = (41,41,41) , )
	Color_8.name = "Color_8"
	context.turtle.setMaterial(8,Color_8)
	Color_9 = pgl.Material("Color_9" , ambient = (6,4,22) , diffuse = 10.0932 , specular = (41,41,41) , )
	Color_9.name = "Color_9"
	context.turtle.setMaterial(9,Color_9)
	Color_10 = pgl.Material("Color_10" , ambient = (6,5,23) , diffuse = 10.0082 , specular = (42,42,42) , )
	Color_10.name = "Color_10"
	context.turtle.setMaterial(10,Color_10)
	Color_11 = pgl.Material("Color_11" , ambient = (7,5,23) , diffuse = 9.92328 , specular = (42,42,42) , )
	Color_11.name = "Color_11"
	context.turtle.setMaterial(11,Color_11)
	Color_12 = pgl.Material("Color_12" , ambient = (7,6,23) , diffuse = 9.83834 , specular = (42,42,42) , )
	Color_12.name = "Color_12"
	context.turtle.setMaterial(12,Color_12)
	Color_13 = pgl.Material("Color_13" , ambient = (8,7,23) , diffuse = 9.75339 , specular = (42,42,42) , )
	Color_13.name = "Color_13"
	context.turtle.setMaterial(13,Color_13)
	Color_14 = pgl.Material("Color_14" , ambient = (8,7,23) , diffuse = 9.66845 , specular = (43,43,43) , )
	Color_14.name = "Color_14"
	context.turtle.setMaterial(14,Color_14)
	Color_15 = pgl.Material("Color_15" , ambient = (9,8,23) , diffuse = 9.5835 , specular = (43,43,43) , )
	Color_15.name = "Color_15"
	context.turtle.setMaterial(15,Color_15)
	Color_16 = pgl.Material("Color_16" , ambient = (9,8,23) , diffuse = 9.49856 , specular = (43,43,43) , )
	Color_16.name = "Color_16"
	context.turtle.setMaterial(16,Color_16)
	Color_17 = pgl.Material("Color_17" , ambient = (10,9,23) , diffuse = 9.41362 , specular = (43,43,43) , )
	Color_17.name = "Color_17"
	context.turtle.setMaterial(17,Color_17)
	Color_18 = pgl.Material("Color_18" , ambient = (11,10,24) , diffuse = 9.32867 , specular = (44,44,44) , )
	Color_18.name = "Color_18"
	context.turtle.setMaterial(18,Color_18)
	Color_19 = pgl.Material("Color_19" , ambient = (11,10,24) , diffuse = 9.24373 , specular = (44,44,44) , )
	Color_19.name = "Color_19"
	context.turtle.setMaterial(19,Color_19)
	Color_20 = pgl.Material("Color_20" , ambient = (12,11,24) , diffuse = 9.15878 , specular = (44,44,44) , )
	Color_20.name = "Color_20"
	context.turtle.setMaterial(20,Color_20)
	Color_21 = pgl.Material("Color_21" , ambient = (12,11,24) , diffuse = 9.07384 , specular = (44,44,44) , )
	Color_21.name = "Color_21"
	context.turtle.setMaterial(21,Color_21)
	Color_22 = pgl.Material("Color_22" , ambient = (13,12,24) , diffuse = 8.98889 , specular = (44,44,44) , )
	Color_22.name = "Color_22"
	context.turtle.setMaterial(22,Color_22)
	Color_23 = pgl.Material("Color_23" , ambient = (13,12,24) , diffuse = 8.90395 , specular = (45,45,45) , )
	Color_23.name = "Color_23"
	context.turtle.setMaterial(23,Color_23)
	Color_24 = pgl.Material("Color_24" , ambient = (14,13,24) , diffuse = 8.819 , specular = (45,45,45) , )
	Color_24.name = "Color_24"
	context.turtle.setMaterial(24,Color_24)
	Color_25 = pgl.Material("Color_25" , ambient = (14,14,24) , diffuse = 8.73406 , specular = (45,45,45) , )
	Color_25.name = "Color_25"
	context.turtle.setMaterial(25,Color_25)
	Color_26 = pgl.Material("Color_26" , ambient = (15,14,24) , diffuse = 8.64912 , specular = (45,45,45) , )
	Color_26.name = "Color_26"
	context.turtle.setMaterial(26,Color_26)
	Color_27 = pgl.Material("Color_27" , ambient = (15,15,25) , diffuse = 8.56417 , specular = (46,46,46) , )
	Color_27.name = "Color_27"
	context.turtle.setMaterial(27,Color_27)
	Color_28 = pgl.Material("Color_28" , ambient = (16,15,25) , diffuse = 8.47923 , specular = (46,46,46) , )
	Color_28.name = "Color_28"
	context.turtle.setMaterial(28,Color_28)
	Color_29 = pgl.Material("Color_29" , ambient = (16,16,25) , diffuse = 8.39428 , specular = (46,46,46) , )
	Color_29.name = "Color_29"
	context.turtle.setMaterial(29,Color_29)
	Color_30 = pgl.Material("Color_30" , ambient = (17,17,25) , diffuse = 8.30934 , specular = (46,46,46) , )
	Color_30.name = "Color_30"
	context.turtle.setMaterial(30,Color_30)
	Color_31 = pgl.Material("Color_31" , ambient = (17,17,25) , diffuse = 8.22439 , specular = (47,47,47) , )
	Color_31.name = "Color_31"
	context.turtle.setMaterial(31,Color_31)
	Color_32 = pgl.Material("Color_32" , ambient = (18,18,25) , diffuse = 8.13945 , specular = (47,47,47) , )
	Color_32.name = "Color_32"
	context.turtle.setMaterial(32,Color_32)
	Color_33 = pgl.Material("Color_33" , ambient = (18,18,25) , diffuse = 8.0545 , specular = (47,47,47) , )
	Color_33.name = "Color_33"
	context.turtle.setMaterial(33,Color_33)
	Color_34 = pgl.Material("Color_34" , ambient = (19,19,25) , diffuse = 7.96956 , specular = (47,47,47) , )
	Color_34.name = "Color_34"
	context.turtle.setMaterial(34,Color_34)
	Color_35 = pgl.Material("Color_35" , ambient = (20,20,26) , diffuse = 7.88462 , specular = (48,48,48) , )
	Color_35.name = "Color_35"
	context.turtle.setMaterial(35,Color_35)
	context.animation_timestep = 0.001
