
/* Grid.c -- example script-generating program for Sculpt Animate 4D

by Marcus Brooks

This example program creates a text-file script for SA4D which, in
turn, creates disk-shaped grid of disconnected edges in the Tri-View.
Since the edges do not form triangles, they are not visible in any
SA4D mode except Wire Frame.  The grid thus created, however, may be
enlarged and used to simulate the ground in a wire-frame animation. 

To use this program (assuming it is in eithr the current directory or
in C:), type "grid" in the CLI and hit return.  This prints the script
out to the screen.  To redirect the script to a file, type 
"grid > grid.script" in the CLI.  The script file will be written to
the current directory.

Under Lattice 4.0, this file compiles with the command "lc -L grid"
(case sensitive).

History:
  24-Oct-88 MB -- made old ad-hoc code more readable.

And now, today's program...
*/


/* Constant definitions: */

#define gridsize  10
#define radius    140
#define rsquared  19600


/* The actual program: */

void main()
{
   long int x, y, temp;

   for ( x = gridsize ; x < radius ; x += gridsize )
     { 
       temp = rsquared - (x*x);

       for ( y = 0 ; y < radius ; y++ )         /* This loop finds y, */
          {                                    /* the integer square */
            if ( (y+1)*(y+1) > temp ) break;  /* root of "temp".    */
          }
  
       /* translation: y = sqrt(rsquared - x^2) */

       /* We have calculated a position on a circle in one quadrant. */
       /* Now we use this value to print statements to create four   */
       /* edges spanning the circle across each axis.  (C inserts    */
       /* the variables listed after the "format string" wherever    */
       /* a "%d" is found.)        */

       printf( "(%d,%d,0)-(%d,%d,0)\n",  x , -y ,  x ,  y );
       printf( "(%d,%d,0)-(%d,%d,0)\n", -y ,  x ,  y ,  x );
       printf( "(%d,%d,0)-(%d,%d,0)\n", -x , -y , -x ,  y );
       printf( "(%d,%d,0)-(%d,%d,0)\n", -y , -x ,  y , -x );
     }

   /* Now all the grid edges have been created except for */
   /*  the ones that coincide with the x and y axes.  We  */
   /*   do these next.                                    */
   
   printf("( 0,%d,0)-( 0,%d,0)\n", -radius, radius);
   printf("(%d, 0,0)-(%d, 0,0)\n", -radius, radius);

   /* if you un-comment the next 4 lines, the resulting  */
   /*  script will create a grid that is visible in the  */
   /*   color rendering modes.                           */

/* printf("(0,0,0)\n");
   printf("extrude\n");
   printf("(%d,%d,0)\n",(gridsize/5), (gridsize/5));
   printf("grab off\n");
*/

}
