home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo3.zoo / demo / misc / lock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-29  |  6.7 KB  |  246 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /* ************************************************************ *\
  9. /* star-trek lock screen (sau/sdh) */
  10.  
  11. #include <sgtty.h>
  12. #include <stdio.h>
  13. #include <pwd.h>
  14. #include <sys/time.h>
  15. #include <signal.h>
  16. #include "bitmap.h"
  17.  
  18. #define WIDE    BIT_WIDE(display)
  19. #define HIGH    BIT_HIGH(display)
  20. #define NICE    10
  21.  
  22. struct passwd *pwd, *getpwuid();
  23. struct timeval poll = {0,50000};
  24. struct sgttyb sg,save;
  25. char buff[100];
  26. static int dir = 1;
  27.  
  28. main()
  29.    {
  30.    int read;
  31.     int pid;
  32.     int flop();
  33.    BITMAP *display = bit_open("/dev/bwtwo0");
  34.    BITMAP *stash = bit_alloc(WIDE,HIGH,NULL,1);
  35.  
  36.    if (!(display&&stash)) {
  37.       printf("Can't initialize the display, sorry\n");
  38.         exit(1);
  39.       }
  40.  
  41.    pwd = getpwuid(getuid());
  42.  
  43.    signal(SIGINT,SIG_IGN);
  44.    signal(SIGHUP,SIG_IGN);
  45.    signal(SIGTERM,SIG_IGN);
  46.    signal(SIGQUIT,SIG_IGN);
  47.    signal(SIGTSTP,SIG_IGN);
  48.  
  49.    gtty(0,&sg);
  50.    save = sg;
  51.    sg.sg_flags &= ~(ECHO|RAW);
  52.    sg.sg_flags |= CBREAK;
  53.    stty(0,&sg);
  54.    
  55.    bit_blit(stash,0,0,WIDE,HIGH,BIT_SRC,display,0,0);
  56.    bit_blit(display,0,0,WIDE,HIGH,BIT_SET,NULL,0,0);
  57.    if (NICE > 0)
  58.       nice(NICE);
  59.     if ((pid=fork()) == 0) {/* child */
  60.         signal(SIGALRM,flop);
  61.         fly(display);
  62.         }
  63.    else {
  64.         while(1) {
  65.             read = 1;
  66.             if (select(32,&read,0,0,&poll) && read) {
  67.                 gets(buff);
  68.                 kill(pid,SIGALRM);    /* change directions */
  69.                 if (strcmp(pwd->pw_passwd,crypt(buff,pwd->pw_passwd)) == 0) {
  70.                     stty(0,&save);
  71.                     kill(pid,SIGKILL);
  72.                     while(wait(0)!=pid);
  73.                     bit_blit(display,0,0,WIDE,HIGH,BIT_SRC,stash,0,0);
  74.                     exit(0);
  75.                     }
  76.                 }
  77.             }
  78.         }
  79.     }
  80.  
  81. /* star trek effect */
  82. /*
  83.  * porter.c  Steve Hawley 4/3/87
  84.  * rehacked 5/18/1988 for extra speed.
  85.  * re-re hacked 6/20/88 for MGR (SAU)
  86.  * A demo to get stars inspired by Star Trek without
  87.  * using quickdraw, and by addressing the screen directly.
  88.  * this version is roughly 8 times faster than its quickdraw
  89.  * equivalent.
  90.  * In considering the bit drawing routines, remember that
  91.  * on the macintosh, a bit turned on is black, not white.
  92.  */
  93.  
  94. #define BG_COLOR    4        /* usually blue */
  95. #define SSIZE    2    /* star size */
  96. #define MAXZ 500 /* maximum z depth */
  97. #define NSTARS 256 /* maximum number of stars */
  98. #define SPEED    6        /* star speed */
  99. #define SCALE    (short)7    /* for rotator */
  100. #define COUNT    (short)3    /* for rotator */
  101. #define ON 1  /* plotting states */
  102. #define OFF 0
  103. #define Random() rand()
  104.  
  105. short maxv, maxh; /* display size */
  106. short hmaxv, hmaxh;    /* 1/2 display size */
  107.  
  108. struct st {
  109.    short x, y, z;
  110.     short color;
  111.     short dir;
  112.    } stars[NSTARS]; /* our galaxy */
  113.  
  114. fly (where)
  115. BITMAP *where;
  116. {
  117.         register short i;
  118.         register struct st *stp;
  119.  
  120.         init_all(where);     /* set up global variables */
  121.         for (i=0, stp = stars; i< NSTARS; i++, stp++) {
  122.                 /* initialize galaxy */
  123.                 do {
  124.                         stp->x = Random();
  125.                         stp->y = Random();
  126.                         stp->z = (Random() % MAXZ) + 1;
  127.                         stp->dir = dir ? COUNT : -COUNT;
  128.                         stp->color = Random() % 23;
  129.                                 if (stp->color == BG_COLOR)
  130.                             stp->color++;
  131.             
  132.                 } while(project(where,stp->x, stp->y, stp->z, stp->color, ON)); /* on screen? */
  133.         }
  134.         while (1) { /* loop 'til button */
  135.                 i = NSTARS;
  136.                 stp = stars;
  137.                 do {
  138.                         project(where,stp->x, stp->y, stp->z, stp->color, OFF); /* turn star off*/
  139.                         if ((stp->z -= SPEED) <= 0) { /* star went past us */
  140.                                 stp->x = Random();
  141.                                 stp->y = Random();
  142.                                 stp->z = MAXZ;
  143.                                 stp->dir = dir ? COUNT : -COUNT;
  144.                         }
  145.                                 else {        /* rotate universe */
  146.                                     cordic(&stp->x,&stp->y,SCALE,stp->dir);
  147.                                 }
  148.                         if (project(where,stp->x, stp->y, stp->z, stp->color, ON)) {
  149.                                 /* if projection is off screen, get a new position */
  150.                                 stp->x = Random();
  151.                                 stp->y = Random();
  152.                                 stp->z = MAXZ;
  153.                                 stp->dir = dir ? COUNT : -COUNT;
  154.                         }
  155.                 ++stp;
  156.                 } while(--i);
  157.         }
  158. }
  159.  
  160. project(where,x, y, z, col, state)
  161. register BITMAP *where;
  162. register short x, y, z;
  163. register int col;
  164. register short state;
  165. {
  166.         
  167.         /* one-point perspective projection */
  168.         /* the offsets (maxh/2) and maxv/2) ensure that the
  169.          * projection is screen centered
  170.          */
  171.         x = (x/z) + hmaxh;
  172.         y = (y/z) + hmaxv;
  173.         return(xplot(where,x, y, z, col, state));
  174.  
  175. }
  176.  
  177. init_all(where)
  178. register BITMAP *where;
  179. {
  180.    maxv = BIT_HIGH(where);
  181.    hmaxv = maxv>>1;
  182.    maxh = BIT_WIDE(where);
  183.    hmaxh = maxh>>1;
  184. }       
  185.  
  186. xplot(where,x, y, z, col, state)
  187. register BITMAP *where;
  188. register int x, y;
  189. register int z;    /* actually z position */
  190. register int col;
  191. int state;
  192. {
  193.         register int size = SSIZE;
  194.         /* are we on the screen? If not, let the caller know*/
  195.         if (x < 0 || x >= maxh || y < 0 || y >= maxv )
  196.             return(1);
  197.  
  198.       if (z > (3*MAXZ/4))
  199.          size--;
  200.       else if ( z< (MAXZ/4))
  201.          size++;
  202.       bit_blit(where,x,y,size,size, state ?
  203.         BIT_SRC^BIT_DST | GETCOLOR(col)^GETCOLOR(BG_COLOR) :
  204.         BIT_SRC | GETCOLOR(BG_COLOR),
  205.                  0l,0,0);
  206.         return(0);
  207. }
  208.  
  209. /* CORDIC rotator. Takes as args a point (x,y) and spins it */
  210. /* count steps counter-clockwise.                   1       */
  211. /*                                Rotates atan( --------- ) */
  212. /*                                                  scale   */
  213. /*                                                 2        */
  214. /* Therefore a scale of 5 is 1.79 degrees/step and          */
  215. /* a scale of 4 is 3.57 degrees/step                        */
  216.  
  217. cordic(x, y, scale, count)
  218. short *x, *y;
  219. register short scale, count;
  220.  
  221. {
  222.    register short tempx, tempy;
  223.  
  224.    tempx = *x;
  225.    tempy = *y;
  226.  
  227.    if (count > 0) /* positive count (counter-clockwise) */
  228.       for (; count; count--){
  229.          tempx -= (tempy >> scale);
  230.          tempy += (tempx >> scale); 
  231.       }
  232.    else          /* negative count (clockwise) */
  233.       for (; count; count++){
  234.          tempx += (tempy >> scale);
  235.          tempy -= (tempx >> scale);
  236.       }
  237.  
  238.    *x = tempx;
  239.    *y = tempy;
  240. }
  241.  
  242. int flop()
  243.    {
  244.    dir = 1-dir;
  245.     }
  246.