module Bud(int rank, int order, float tempsum) extends Sphere(0.1) {
	{ setShader(GREEN); }
}

module Nodium extends Sphere(0.05) {
	{ setShader(GREEN); }
}

module Leaf (int rank, int order, float tempsum)  ==> 
{ 	
	float scale = 1;
	if(rank>5 && rank<10) scale = 0.5;
	if(rank>=10) scale = 0.2; 
} Scale(scale) Parallelogram(2,1).(setColor(0x82B417));

module Internode (int rank, int order, float tempsum) extends F(1,0.1,7);

module Flower (int rank, int order, float tempsum) ==> 
	Scale(0.66)
	RU(180) 
	Cone(0.3,0.3).(setColor(1,1,0)) 
	M(-0.25) RL(90) 
[ 
	for (int i=1; i<=5; i++) ([RU(i*360/5) RL(20) Parallelogram(2,1).(setColor(1,1,0))])]
	RU(45) 
	[ 
		for (int j=1; j<=5; j++) ([RU(j*360/5) RL(40) F(0.3,0.1,14) RV(-0.3) F(0.3,0.1,14) RV(-0.3) F(0.3,0.1,14)]) 
	]
	RU(-45) 
	[ for (int k=1; k<=5; k++) ([RU(k*360/5) RL(70) Frustum(0.7,0.2,0.05).(setColor(1,1,0))]) 
];
	
const float[] degreedays = {4.56,9.7,15.61,21.49,27.65,33.23,37.74,41.66,45.84,
	50.73,55.86,60.14,64.39,69,74.36,79.66,84.22,88.77,93.61,98.74,104.33,110.34,
	115.98,121.35,127.69,135.61,144.23,152.22,160.11,168.57,177.59,186.89,196.13,
	206.22,216.4,226.47,237.71,248.75,258.74,269.1,280.63,292.45,302.65,312.05,
	320.67,328.96,337.2,345.83,354.09,362.19,370.67,379.11,388.04,397.8,408.23,
	419.79,431.72,443.7,455.2,467.05,479.12,491.8,505.11,518.29,531.32,544.17,
	556.72,569.5,582.53,595.7,609.37,623.22,636.82,650.36,663.92,677.62,691.09,
	704.8,718.69,733.09,748.78,765.12,780.9,795.72,811.49,828.22,844.79,861.99,
	879.78,898.71,918.39,937.57,955.33,974.36,993.91,1012.65,1030.28,1046.7,
	1063.09,1079.73,1095.6,1111.91,1128.86,1145.62,1162.48,1179.89,1197.98,
	1216.44,1235.65,1254.55,1273.14,1291.83,1310.28,1327.67,1344.44,1361.11,
	1377.93,1395.21,1413.49,1432.2,1450.38,1469.32};

int time = 0;
	
protected void init () [ 
	{ time = 0; }
	Axiom ==> Bud(1,1,0);
]

public void run () [
	{
		float deltaT = degreedays[time+1]-degreedays[time];
	}
	
	Bud(r,o,ts), (r<10 && o<=2) ==> 
		RV(-0.1) 
		Internode(r,o,0)
		Nodium 
			[RL(70) Leaf(r,o,0)] 
			[RL(50) Bud(r+1,o+1,ts+deltaT)] 
		RH(137.5) 
		Bud(r+1,o,ts+deltaT);

	Bud(r,o,ts), (r>=10 && r<=15) ==> 
		Internode(r,o,0) 
			[RL(70) Leaf(r,o,0)] 
			[ Scale(0.5) RL(80) F(2) Flower(r,o,0) ] 
		RH(137.5) 
		Bud(r+1,o,ts+deltaT);

	Flower(r,o,ts) ==> 
		if(probability(0.9)) (
			Cylinder(2,0.2).(setShader(GREEN))
		) else ();
	
	{
		time++;
	}
]






















