home *** CD-ROM | disk | FTP | other *** search
- /*
- * twinkle.c
- */
-
- #include "curses.h"
-
- #define NDISPLAY 10
- #define NCOLS 80
- #define NLINES 25
- #define MAXPATT 4
-
- typedef struct {
- char y, x;
- } LOCS;
-
-
- LOCS Layout[ NCOLS*NLINES ];
-
- int pat;
- int nstar;
-
-
- int ison( y, x )
- int y, x;
- {
- switch( pat ){
- case 0: /* every odd line is solid */
- return( !(y & 0x01) );
- case 1: /* box shape - 3 line/col boarder */
- if( x >= NLINES && y >= NCOLS )
- return( 0 );
- if( y < 3 || y >= NLINES - 3 )
- return( 1 );
- return( x < 3 || x >= NCOLS - 3 );
- case 2: /* fill screen every other dot */
- return( (x + y) & 0x01 );
- case 3: /* solid bar in the middle */
- return( y >= 9 && y <= 15 );
- }
- }
-
-
- void makeboard()
- {
- int y, x;
- LOCS *lp;
-
- pat = rand() % MAXPATT;
- lp = Layout;
- for( y = 0; y < NLINES; y++ )
- for( x = 0; x < NCOLS; x++ )
- if( ison( y, x ) ){
- lp->y = y;
- lp->x = x;
- lp++;
- }
- nstar = lp - Layout;
- }
-
-
- void puton( ch )
- char ch;
- {
- LOCS *lp, *end, temp;
- int r;
-
- end = &Layout[ nstar ];
- for( lp = Layout; lp < end; lp++ ){
- r = rand() % nstar;
- temp = *lp;
- *lp = Layout[ r ];
- Layout[ r ] = temp;
- }
- for( lp = Layout; lp < end; lp++ ){
- mvaddch( lp->y, lp->x, ch );
- refresh();
- }
- }
-
-
- void main()
- {
- int i;
-
- initscr();
- scrollok( stdscr, 0);
- for( i = 0; i < NDISPLAY; i++ ){
- makeboard();
- puton( '*' );
- puton( ' ' );
- }
- endwin();
- }
-