!---------------------------------------------------------------
!
! TUTORIAL14 - RayDance tutorial script #14.
!
! This script demonstrates tree creation.
!
! Concepts include :
!
!  o Trees with leaves.
!
!  o Importing a texture map to use as tree leaves.
!
!  o TRANSLUCENT flag in phong surface.
!
!---------------------------------------------------------------

! Use a print statement to display descriptive text on the
! message window.


? "TUTORIAL14 - NOTE:  This script creates trees\n",
  "that total about 27,000 polygons.  This requires some\n",
  "where around 5 megs of ram to render.  If you have less\n",
  "ram then set the TAPER variable below to a slightly\n",
  "smaller value (good values are 0.95 and higher).\n\n",
  "This script can take a while to execute.  If you are in\n",
  "a hurry use small pixel sizes or wireframe mode.\n\n",
  "Three trees are created in this script, a large one and\n",
  "two shrubs.  The large tree has polygonal leaves with\n",
  "there coloration applied as a texture map.  The shrubs\n",
  "have their BONSAI flags set giving the illusion of\n",
  "flowers.\n";


real TAPER = 0.98;


! Create colors for our objects

GRAY   : color(RGB, [.6,.5,.4] );
GREEN  : color(RGB, [.1,.4,0] );
BLUE   : color(RGB, [0,.1,.3] );
WHITE  : color(RGB, [1,1,1] );
PINK   : color(RGB, [1,.8,.8] );
DKGREEN: color(RGB, [.1,.3,.1] );

! Create surfaces.  Note the use of the TRANSLUCENT flag in 
! LEAF_SURF.  This allows leaves to illuminated by a light
! source behind them.

!                ka kd ks  n km kr ir kb flgs
MATTE     :
  surface(PHONG, .5,.8, 0, 0, 0, 0, 0, 0, 0 );
LEAF_SURF :
  surface(PHONG, .5,.8, 0, 0, 0, 0, 0, 0, TRANSLUCENT );


! Declare a treespec

treespec OUR_TREESPEC;


! Setup the treespec fields for a bush with spherical leaves.
! Color the leaves white and pink to simulate flowers.

OUR_TREESPEC'FLAGS       = PHONG BONSAI;
OUR_TREESPEC'DROOP       = -0.05; ! Grow somewhat upward
OUR_TREESPEC'TWIST       = -0.9;
OUR_TREESPEC'BEND        = 0.10;  ! Straight branches
OUR_TREESPEC'TAPER       = TAPER;
OUR_TREESPEC'GROWLEN     = 2.0;   ! Shorter growth segments
OUR_TREESPEC'BRANCHODDS  = 0.60;  ! Fork sometimes
OUR_TREESPEC'BRANCHANGLE = 0.5;
OUR_TREESPEC'FORKDELAY   = 1;
OUR_TREESPEC'MINFORK     = 0.1;
OUR_TREESPEC'TWIGSIZE    = 0.07;
OUR_TREESPEC'TRUNKSURF   = MATTE;
OUR_TREESPEC'TRUNKCOLOR  = DKGREEN;
OUR_TREESPEC'LEAFRADIUS  = 0.6;
OUR_TREESPEC'LEAFSURF    = MATTE;
OUR_TREESPEC'LEAFCOLOR   = WHITE;

!     seed  position  base radius  treespec

tree(  15,  [-20,-10,0],    1.0,     OUR_TREESPEC );

OUR_TREESPEC'LEAFCOLOR   = PINK;

tree(  11,  [ 20,-10,0],    1.0,     OUR_TREESPEC );


! Import a texture map to use as our leaf color.  This map was
! created using DPAINT.  All of the black areas in it (color 0)
! will become invisible.

LEAF_MAP : texturemap( "leaf2.ilbm" );


! Setup the treespec fields for a tree with leaves.

OUR_TREESPEC'FLAGS       = PHONG LEAVES;
OUR_TREESPEC'DROOP       = -0.2;  ! Grow upward
OUR_TREESPEC'TWIST       = -0.9;
OUR_TREESPEC'BEND        = 0.20;
OUR_TREESPEC'TAPER       = TAPER;
OUR_TREESPEC'GROWLEN     = 3.0;
OUR_TREESPEC'BRANCHODDS  = 0.80;
OUR_TREESPEC'BRANCHANGLE = 0.5;
OUR_TREESPEC'FORKDELAY   = 1;
OUR_TREESPEC'MINFORK     = 0.2;
OUR_TREESPEC'TWIGSIZE    = 0.16;
OUR_TREESPEC'TRUNKSURF   = MATTE;
OUR_TREESPEC'TRUNKCOLOR  = GRAY;
OUR_TREESPEC'LEAFSIZE    = 0.40;
OUR_TREESPEC'LEAFRADIUS  = 3.0;
OUR_TREESPEC'LEAFSURF    = LEAF_SURF;
OUR_TREESPEC'LEAFCOLOR   = LEAF_MAP;


!     seed  position  base radius  treespec

tree(  100,  [0,0,0],    3.5,     OUR_TREESPEC );


! Specify the ambient light.

!       always 0's  lamp color   dir.    k1  k2

ambient( [0,0,0], [0.6,0.6,0.6], [0,0,1], 0, 0 );


! Specify the STAR light.

!         position        lamp color rad  flags

star( [3000,-50000,30000], [1,.9,1], 300, NOSHADOWS );


! A checkerboard ground

!            type   height tile  color  surf   color surf
!                          size  

ground( CHECKERBOARD,  0,   30, GREEN, MATTE, BLUE, MATTE );


! Set the background color to a dark purple

BACKGROUND( PLAIN, [0,0.05,0.15] );


! The camera will be positioned along the negative y axis aiming
! toward the central objects

CAMERA'POS = [0,-170,30];
CAMERA'TARGET = [0,0,25];


! The scene has now been constructed, render it!

RENDER;


! All scripts must terminate with an END

END
