home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / Life Simulator / InitFromMain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-04  |  1.8 KB  |  97 lines  |  [TEXT/MMCC]

  1. /* Cell Proj 1.0 */
  2.  
  3. #include "Cell_Proto.h"
  4. #include "Cell_Definitions.h"
  5. #include "Cell_Variables.h"
  6.  
  7. ToolBoxInit()
  8. {
  9.     unsigned long mySeed;
  10.  
  11.     InitGraf( &qd.thePort );
  12.     GetDateTime(&mySeed);
  13.     LMSetRndSeed(mySeed);
  14.     InitFonts();
  15.     FlushEvents( everyEvent, REMOVE_ALL_EVENTS );
  16.     InitWindows();
  17.     InitMenus();
  18.     TEInit();
  19.     InitDialogs( NIL_POINTER );
  20.     InitCursor();
  21. }
  22.  
  23. WindowInit()
  24. {    
  25.     gCellWindow = GetNewWindow( BASE_RES_ID, NIL_POINTER, MOVE_TO_BACK );
  26.     
  27.     gSizeRect.top = MIN_WINDOW_HEIGHT;
  28.     gSizeRect.left = MIN_WINDOW_WIDTH;
  29.     gSizeRect.bottom = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top;
  30.     gSizeRect.right = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
  31.     SetPort( gCellWindow );
  32.     SetOrigin( -5, -5 );
  33. }
  34.  
  35. DialogInit()
  36. {
  37.     gCellInfoDialog = GetNewDialog( BASE_RES_ID, NIL_POINTER,
  38.                                 ( WindowPtr ) MOVE_TO_FRONT );
  39.     ShowWindow( gCellInfoDialog );
  40. }
  41.  
  42. MenuBarInit()
  43. {
  44.     Handle        myMenuBar;
  45.     
  46.     myMenuBar = GetNewMBar( BASE_RES_ID );
  47.     SetMenuBar( myMenuBar );
  48.     gAppleMenu = GetMHandle( APPLE_MENU_ID );
  49.     gFileMenu = GetMHandle( FILE_MENU_ID );
  50.     
  51.     AddResMenu( gAppleMenu, 'DRVR' );
  52.     DrawMenuBar();
  53. }
  54.  
  55. SetUpDragRect()
  56. {
  57.     gDragRect = qd.screenBits.bounds;
  58.     gDragRect.left += DRAG_THRESHOLD;
  59.     gDragRect.right -= DRAG_THRESHOLD;
  60.     gDragRect.bottom -= DRAG_THRESHOLD;
  61. }
  62.  
  63. DisplayCellWindow()
  64. {
  65.     ShowWindow( gCellWindow );
  66.     DrawControls( gCellWindow );
  67. }
  68.  
  69. PlaceRandomCells()
  70. {
  71.     int        randomLiveCell;
  72.     int        count;
  73.     
  74.     for ( count = 0; count < NUMBER_OF_CELLS; count++ )
  75.     {
  76.         gCellStatus[count] = 0;
  77.     }
  78.     
  79.     for ( count = 0; count < 800; count++ )
  80.     {
  81.         randomLiveCell = Randomize( 9999 );
  82.         gCellStatus[randomLiveCell] = 1;
  83.         GraphAlive( randomLiveCell );
  84.     }
  85.     
  86. }    
  87.     
  88. Randomize( range )
  89. int        range;
  90. {
  91.     long    rawResult;
  92.     
  93.     rawResult = Random();
  94.     if ( rawResult < 0 )
  95.         rawResult *= -1;
  96.     return((( rawResult * ( range )) / 32768 ) + 1 );
  97. }