!---------------------------------------------------------------
!
! TUTORIAL25 - RayDance tutorial script #25.
!
! This script demonstrates basic animation.  It creates 5
! spheres of various colors orbiting one larger, reflective,
! sphere.
!
! In order to view the animated frames you will need
! a way of converting the 24 bit frames to HAM (or DCTV or
! whatever format) and animation playback software.
!
! Art Department Proffesional tm works well for making HAM
! pictures from IFF24 pictures.  Possibilities for making anim
! files are BuildAnim, AStation, or DPAINT4.  DPAINTIII will
! work for playing back DCTV pictures.
!
! Concepts include :
!
!  o Frameloops
!
!  o Calculating motion paths
!
!  o PROGRESS variable
!
!---------------------------------------------------------------

? "TUTORIAL25 - This script contains a frameloop.  If first\n",
  "and last frames are set to 1 and 30, then when this\n",
  "script is executed it will create 30 pictures.  The\n",
  "frames show a large, mirrored sphere with other spheres\n",
  "in orbit around it.\n\n";

! The camera looks up the positive y axis
CAMERA'POS = [0,-2400,400];
CAMERA'TARGET = [0,0,0];

! Variables
real  ORBIT_ANGLE,
      X,Y,Z,
      RADIUS = 500,  ! Radius of large sphere
      RADIUS1 = 60,  ! Radius of small spheres
      ALTITUDE = RADIUS + RADIUS1 * 2;  ! Orbit height

! Create color values
vector RED    = [.8, 0, 0],
       YELLOW = [.6,.6, 0],
       GREEN  = [ 0,.8, 0],
       CYAN   = [ 0,.6,.6],
       BLUE   = [ 0, 0,.8];

OFFWHITE : color( RGB, [.8,.8,.6] );

! Create surfaces for our stuff.
MATTE  : surface(PHONG, 0.4,0.8, 0.0,  0,  0,0,0, 0, 0 );
SHINY  : surface(PHONG, 0.1,0.1, 0.1,100, .9,0,0, 0, 0 );


! We're going to call this procedure when we want to create a
! sphere.  We will calculate the position of the sphere using
! sine and cosine functions.
proc MAKESPHERE( real ANGLE, vector RGB_VALUE )
  X = cos(ANGLE) * ALTITUDE;
  Y = sin(ANGLE) * ALTITUDE;
  SCOLOR : color( RGB, RGB_VALUE );

  sphere( [X,Y,0], RADIUS1, SCOLOR, MATTE );
endproc

! Start the frame loop
frameloop

  clearscene;  ! all spheres must be created after this

! Create the central sphere
  sphere( [0,0,0], RADIUS, OFFWHITE, SHINY );

! Create the orbiting spheres.  We will assume that they are in
! a circular orbit in the xy plane (z = 0).  Each sphere will
! be seperated from its neighbors by 20 degrees of arc.  We will
! use sine and cosine functions to change angle and orbital
! height to x and y coordinates.  z will always be zero here.

  ORBIT_ANGLE = PROGRESS * 360; ! Position of leading sphere

  boundary
    MAKESPHERE( ORBIT_ANGLE, RED );
    MAKESPHERE( ORBIT_ANGLE-20, YELLOW );
    MAKESPHERE( ORBIT_ANGLE-40, GREEN );
    MAKESPHERE( ORBIT_ANGLE-60, CYAN );
    MAKESPHERE( ORBIT_ANGLE-80, BLUE );
  endboundary

! Specify the lighting.  Make sure the star is large enough for
! its reflection to be visible in the large sphere.
  ambient( [0,0,0], [0.6,0.6,0.6], [0,0,1], 0, 0 );
  star( [40000,-50000,60000], [1,.9,1], 3000 );

! A plain black background
  background( PLAIN, [0,0,0] );

  render;

nextframe  ! end of the frame loop

END
