
#include "colors.inc"
#include "transforms.inc"
#include "math.inc"
#include"langue_palme_obj3.inc"

#ifndef (Main)

background { color <0.5,0.5,1.000>*1.5 }
// perspective (default) camera


camera {  //  Camera Camera01
location  <0,-18,1> 
//location <0,0,10>

  sky       <0,0,1>
  up       <0,0,1> 
 right     x*image_width/image_height
  angle         40
  //translate <0,-5,7>
  //rotate x*90
  look_at z*3
}

//
// *******  L I G H T S *******
//

light_source {   // Light001
  <0.0, 0.0, 0.0>
  color rgb <1.000, 1.000, 1.000>*3
  translate  <10.0, -20.0, 20.0>
  scale 1000.0
}

light_source {   // Light001
  <0.0, 0.0, 0.0>
  color rgb <0.90 0.9, 1.000>*0.8
  translate  <-50.0, -20.0, 20.0> 
  scale 1000.0
  shadowless
}

#end
#declare T_coco=texture{
                pigment{
                color rgb<.4,.4,.35>*1.2
                }
                // texture component
  normal {
    bumps 0.5      scale <0.02,0.02,.2>
    }
  finish{ambient 0 }
  

        }
#declare Coco=sphere{0,1 
        texture{T_coco}
        scale <1,1,1.4>*0.08 translate z*-0.5
        }
#declare N_coco=8;
#declare Cnt_coco=0;
#declare S_h_coco=seed(12);
#declare Grappe_coco= union{
        #while (Cnt_coco<N_coco)
        object{Coco  rotate <0,20,360*Cnt_coco/N_coco>translate z*rand(S_h_coco)*0.5}
        #declare Cnt_coco=Cnt_coco+1;
        #end
}
#declare Coco_sol=sphere{0,1 
        texture{T_coco}
        scale <1,1,1.4>*0.08 rotate x*90
        }

#declare Palm_tex=texture{pigment{color rgbt<0.1,1,0.2,0.1>*0.3}finish{ambient 0}}
#declare Dia=0.01;
#declare Point=<0,0,0.8>;
#declare S1=seed(0);
#declare S_npalm=seed(20);
#declare S_R_Langue=seed(2);
#declare S0=seed(255); 
#declare S2=seed(256); 
#declare S3=seed(0);  
#declare S4=seed(500);
#declare S_Coco_sol=seed(20);


#declare Taille_spl=spline{natural_spline
-0.01,0,
0.5,0.5,
1,0.5
}
#declare S_rot_palm=seed(16);
#declare Langue_Palme_obj2= object{Langue_Palme_obj }
#macro Palm_tree(Pos,Ech,Rot)// debut macro
#declare N_Palm=15+5*rand(S_npalm);//15;
#declare Palm_Cnt=0;
#declare S_Lance=seed(0);


#declare Panache=union{
#while (Palm_Cnt<N_Palm)
     #local Rot_palm=260*Palm_Cnt;
        #declare Ang1=10+120*pow(Palm_Cnt/N_Palm,0.8)+30*(0.5-rand(S_rot_palm));
        
        #declare Ang2=180*sind(Ang1/2);

        #declare Point1=vrotate (Point,- Ang1*x);
        #declare Point2=vrotate (Point,-Ang2*x)+Point1;
        #declare Hampe_spl=spline{natural_spline 
        0,0,
        0.5,Point1,
        1,Point2
        }
        #declare Spl_cnt=0;
        #declare Spl_step=0.012;//0.01;
        #declare Palme=union{
        #while (Spl_cnt<1)
               #declare Segment=cone {Hampe_spl(Spl_cnt) , Dia*(1-Spl_cnt), Hampe_spl(Spl_cnt+Spl_step), Dia*(1-(Spl_cnt+Spl_step)) texture{Palm_tex}} 
                object{Segment }
                object{Langue_Palme_obj2 rotate x*5*(.5-rand(S_R_Langue)) rotate z*(96+16*rand(S_R_Langue)) rotate y*(-90*pow(Spl_cnt,4)+rand(S_R_Langue)*5)  Spline_Trans (Hampe_spl, Spl_cnt, z, Spl_step*10, 1)scale <(1-rand(S_Lance)*0.12),1,1>}
                object{Langue_Palme_obj2 rotate x*5*(.5-rand(S_R_Langue)) rotate z*(96+16*rand(S_R_Langue)) rotate y*(-90*pow(Spl_cnt,4)+rand(S_R_Langue)*5)  Spline_Trans (Hampe_spl, Spl_cnt, z, Spl_step*10, 1)scale <-(1-rand(S_Lance)*0.12),1,1>}
               #declare Spl_cnt=Spl_cnt+Spl_step;
        #end
        double_illuminate}
     // #while (Palm_Cnt<N_Palm)
     // #local Rot=155*Palm_Cnt/N_Palm;
        object{Palme 
    rotate <rand(S_rot_palm)*5,0,(Rot_palm+rand(S_rot_palm))*10>
        }
       // object{Palme rotate z*90}
        #declare Palm_Cnt=Palm_Cnt+1;
#end
}



#declare Ech_tronc=3;
#declare Point_tronc=<0,0,-.1>;
#declare Seg_tronc =  <0,0,0.5>;

//#macro Palm_tree(Pos,Ech,Rot)
/*
#declare Point_tronc1 =  <0.3*rand(S2),0,0.3>;
#declare Point_tronc2 =  Point_tronc1+<0.2*rand(S2),0,(1+rand(S2))*0.5>;
#declare Point_tronc3=Point_tronc2+<0.0,0,(1+rand(S2))*0.5>;
*/
#declare Dev=pow(rand(S2),3);//deviation
#declare Point_tronc1 = vrotate(Seg_tronc,<0,Dev*90,0>);
#declare Point_tronc2 =  Point_tronc1+vrotate(Seg_tronc,<0,Dev*20,0>);
#declare Point_tronc3 =Point_tronc2+vrotate(Seg_tronc,<0,Dev*5,0>);



#declare Trunc_spl=spline {natural_spline
0,Point_tronc
0.3,Point_tronc1*Ech_tronc,
0.7,Point_tronc2*Ech_tronc,
1,Point_tronc3*Ech_tronc,
}
#declare Trunc_scl_spl=spline {natural_spline
0,  1.5,
0.1,1.1,
0.4,0.7,
1,0.6
}
#declare Trunc_cnt=0;
#declare Trunc_step=0.002;//0.002
#declare Trunc=union{
#while (Trunc_cnt<1)
sphere{Trunc_spl(Trunc_cnt)+<(0.5-rand(S0))*0.01,(0.5-rand(S0))*0.01,0>,Ech_tronc*0.032*Trunc_scl_spl(Trunc_cnt).x*1+rand(S0)*0.015 texture{pigment{color rgb <1,1,1>*(1-rand(S0)*0.2)*1}// texture component
  normal {
   bumps 0.5
scale 0.01
  }
finish{ambient 0}}}
#declare Trunc_cnt=Trunc_cnt+Trunc_step;
#end
}
//#declare Palmier =
union{
object{Trunc}
object{Panache scale 0.8+rand(S4)*0.4 rotate z*rand(S4)*360 translate Trunc_spl(1)}
object{Grappe_coco translate Trunc_spl(1)}
object {Coco_sol translate <Trunc_spl(1).x+(.5-rand(S_Coco_sol)),Trunc_spl(1).y+(.5-rand(S_Coco_sol)),00.05>}
rotate Rot scale Ech translate Pos}



#end

#ifndef (Main)
//#else
#declare N_palmier=3;
#declare Cnt_palmier=0;
#declare S_palm= seed (21);
#while (Cnt_palmier<N_palmier)

Palm_tree(<Cnt_palmier-4,0,0>,1,0)

#declare Cnt_palmier=Cnt_palmier+1;
#end
plane{z,0 pigment{color rgbt <1,0,0,.5>}}
//object{Palme rotate <-120,-45,90> translate <0,0,.3>}
#end


