BANNER.C
Path: unixg.ubc.ca!vanbc.wimsey.com!scipio.cyberstore.ca!math.ohio-state.edu!howland.reston.ans.net!torn!hermes.acs.ryerson.ca!jupiter!aaab
From: aaab@jupiter.scs.Ryerson.CA (Al Aab - CNED/W94)
Newsgroups: bit.listserv.frac-l
Subject: A fractal banner listing in Borland C
Date: 7 Dec 1994 12:20:37 GMT
Organization: School of Computer Science, Ryerson Polytechnic University
Lines: 395
Message-ID: <3c49al$1eae@hermes.acs.ryerson.ca>
NNTP-Posting-Host: jupiter.scs.ryerson.ca
Summary: a frctal banner in C
Keywords: listing, C
X-Newsreader: TIN [version 1.2 PL2]
 
/* barnsley  15 june 94 4p20 ========= (c)copyright 1994 al aab  =============
   Program    : A banner gnerator.  
		A peano curve as modified by, probabley, professor Barnsley.
 				  A surface filler.
				  One contiuous nonselftouching curve per line.
 		Wrote this version after its predecessor, which is based on
				  Hilbert curve.  
 
N.B.
   Compile w Borland C.  
				  
  ========================================================================== */
     #include 
     #include 
     #include 
     #include 
     #include 
     #include 
// ---------------------------------------------------------------------------
     #define  maxNAMElen 11     //   characters PER line if basic VGA resolution of 640 pixels across.
     #define  char_bios  0xffa6
     #define  MAX_NUM_OF_LYNES 7
     #define  INTERLINE_GAP 19
     #define  Y out_ltr_Y_position-INTERLINE_GAP
 
     #define UP ( linerel( 0,-VV ) )
     #define DN ( linerel( 0,+VV ) )
     #define RT ( linerel( +HH,0 ) )
     #define LT ( linerel( -HH,0 ) )
// ---------------------------------------------------------------------------
 int xmax,
      ymax,
      NAMElen,
      l=2, HH=l,VV=l,
      o=3,
 
      x1=0,
      x2=l*2,
      x3=100,
 
      y1=0,
      y2=x2,
      y3=100,
      yy,
 
      YY,
      mini_width=3*l,
      letter_times_8,
      letter_times_8_times_y,
      width=26*l,
      biggestNAMElen=0,
      out_ltr_X_position=mini_width,
      out_ltr_Y_position=width  +  INTERLINE_GAP ,
      parity_index
 
	    ;
 
  unsigned size;
  unsigned char *U,*D,*two_units,*U_unit,*D_unit,
		bios_buf[128*8],
		letter
	     ;
 
  char NAME[MAX_NUM_OF_LYNES][1  +  maxNAMElen];     // maxNAMElen being 10 characters for a basic VGA screen of 640 picels across.
// ------------------------  declare sub prototypes  -----------------------------------------
void select_parity();
void stamp( unsigned char letter);
void	stamp_prepare();
void    draw_bx(int);
void barn_RU();
void barn_LD();
void barn_LU();
void barn_RD();
int  even(int n);
void stamp_upper_row();
void stamp_leftthand_cols();
void stamp_prepare();
void prepare_two_units();
void tile_screen_w_background();
void tile_screen_w_foreground();
 
// ======================================================== sub defs =========
int bit_value( unsigned char byte, int bit_pos )
{
     switch( bit_pos )
	       {
		       case 0: return 128 & byte;
		       case 1: return  64 & byte;
		       case 2: return  32 & byte;
		       case 3: return  16 & byte;
		       case 4: return   8 & byte;
		       case 5: return   4 & byte;
		       case 6: return   2 & byte;
		       case 7: return   1 & byte;
		     default : puts( " xxxx bit_value function: "\
				     " bit_pos not 0 to 7. ABORTING. XXXXXXX" );
				       exit ( 1 );
	       }
     return 5555;
}
// ----------------------------- stamp() ---------------------------------------
void stamp( unsigned char letter,int ltr_num)
{
 
 
    if ( letter>127 )
       {
       puts( "HIL banner xxxxxxxxxxx BUG xxxxxxxxxxxxxxxxxxx "\
	     "letter ASCII value is greater than 127.\n A B O R T I N G." ) ;
       exit (1);
       }
       letter_times_8=letter*8;
 
 
 
 
 
//printf("\n\t\t\t\t\t\tline 104in stamp x=%i",getx());
 
YY=gety();
     int pixel_byte; for (pixel_byte=0;pixel_byte<8;pixel_byte++)
	   {
		   yy = YY +  pixel_byte*mini_width+mini_width;  // YY added 10 july 94 ???????????
		   int letter_times_8_plus_pixel_byte;
		   letter_times_8_plus_pixel_byte=letter_times_8+pixel_byte;
 
		   int bit; for ( bit=0; bit<8; bit++)
		     {
			 if ( ! bit_value( bios_buf[letter_times_8_plus_pixel_byte], bit ) )
			 {
			 moveto(out_ltr_X_position  +  mini_width*bit,yy);
if (even(ltr_num))
	if(even(pixel_byte)!=even(bit))
		putimage(getx(),gety(),U,COPY_PUT);
	else
		putimage(getx(),gety(),D,COPY_PUT);
else
	if(even(pixel_byte)!=even(bit))
		putimage(getx(),gety(),D,COPY_PUT);
	else
		putimage(getx(),gety(),U,COPY_PUT);
 
			 }
		     }
	   }
	   out_ltr_X_position+=width  +  l;
 
}
// ---------------------------------------------------------------------------
void barn_RU()
{
		if ( o<1) return;
		o--;
 
barn_RU();
		RT;
barn_RD();
		RT;
barn_RU();
		UP;
barn_LU();
		LT;
barn_LD();
		LT;
barn_LU();
		UP;
barn_RU();
		RT;
barn_RD();
		RT;
barn_RU();
		o++;
}
// ---------------------------------------------------------------------------
void barn_LU()
{
	HH=-HH;
	barn_RU();
	HH=-HH;
}
// ---------------------------------------------------------------------------
void barn_RD()
{
	VV=-VV;
	barn_RU();
	VV=-VV;
}
// ---------------------------------------------------------------------------
void barn_LD()
{
	VV=-VV;HH=-HH;
	barn_RU();
	VV=-VV;HH=-HH;
}
// ------------------------------- setgrafics() ------------------------------
void setgrafics()
{
     clrscr();    //XXXXXX  tish te ghelsh XXXXXXXXXXXXXXXXXXXXXXXXXXX
 
   int gmode,
       errorcode,
       gdriver = DETECT;                   /* request auto detection */
   initgraph( &gdriver, &gmode, "");       /* initialize graphics and
					       local variables */
   errorcode = graphresult();               /* read result of initialization */
   if ( errorcode != grOk )                 /* an error occurred */
   {
      printf( "\nGraphics error: %s\n", grapherrormsg( errorcode ) );
      printf( "Press any key to halt:" );
      getch();
      exit( 1 );
   }
   setcolor( getmaxcolor() );
   xmax = getmaxx();
   ymax = getmaxy();
}
// ---------------------------------------------------------------------------
void get_input_string()
{
    clrscr();
    printf( "\n(c) Copyright Al Aab 1994.\n\n"\
	    "This program asks you for 7 lines, each is a string of( 7-bit ) ASCII\n"
	    "characters.  The output is a banner.  The original contribution\n"\
	    "is that each line of the banner is one continous non selftouching "\
	    "curve, based on the Peano/Barnsley curve.\n\n\n");
 
    printf( "Please type %i lines of strings (A carriage return by itself"
	    " is an empty line.\nEvery line longer than %i characters will be truncated to %i characters.):\n", MAX_NUM_OF_LYNES, maxNAMElen, maxNAMElen);
    printf( "\n\n\n	12345678901\n");
     int lyn; for (lyn=1;lyn<= MAX_NUM_OF_LYNES;lyn++)
    {
	printf("%i\t",lyn);
	gets( NAME[lyn] );
	NAMElen = strlen( NAME[lyn] );
	if ( NAMElen > maxNAMElen )   NAMElen=maxNAMElen;
	if(biggestNAMElen < NAMElen) biggestNAMElen=NAMElen;
}
}
// ---------------------------------------------------------------------------
void save_char_bios ( char near *buffer )
{
    movedata( char_bios , 14, _DS, (unsigned)buffer, 128*8 );
}
// ........................   start   main  ........................
void main()
{
 
	save_char_bios( bios_buf );
	get_input_string();
	setgrafics();
	stamp_prepare();
	prepare_two_units();
	tile_screen_w_background();
	tile_screen_w_foreground();
 
	getch(); closegraph();
 
}
//--------------------------------------------------------------- sub
void stamp_prepare()
{
   size=imagesize( x1, y1, x2, y2 );
 
 
D   = (char *) malloc(size);
   cleardevice();
   line( x1, y1, x2, y2 );
   getimage( x1, y1, x2, y2, D );
 
U    = (char *) malloc(size);
   cleardevice();
   line(x1,y2,x2,y1);
   getimage( x1, y1, x2, y2, U );
 
   cleardevice();
 
}
//---------------------------------
int even(int n)
{
	int r=n/2;
	return (r+r==n);
 
}
//---------------------------------
void stamp_upper_row()
{
moveto(0,0);
int sub_unit;	for ( sub_unit=0; sub_unit<9; sub_unit++ )
		{
 
 
		putimage(getx(),gety(),D,COPY_PUT);	moverel(mini_width,0);
		putimage(getx(),gety(),U,COPY_PUT);	moverel(mini_width,0);
	      }
 
}
 
 
//------------------------
void stamp_leftthand_cols()
{
moveto(0,mini_width);
int sub_unit; for ( sub_unit=0; sub_unit<4; sub_unit++ )
 
	{
 
		putimage(getx(),gety(),U,COPY_PUT);	moverel(0,mini_width);
		putimage(getx(),gety(),D,COPY_PUT);	moverel(0,mini_width);
 
	}
//------
moveto(l+width,mini_width);
	      for ( sub_unit=0; sub_unit<4; sub_unit++ )
 
	{
 
		putimage(getx(),gety(),D,COPY_PUT);	moverel(0,mini_width);
		putimage(getx(),gety(),U,COPY_PUT);	moverel(0,mini_width);
 
	}
 }
//--------------------------
void prepare_two_units()
{
cleardevice();
setcolor(getmaxcolor());
moveto(0,00);
barn_RD(); RT;
barn_RU(); RT;
//--------------- get 2 units
int two_widths; two_widths= 2*(width+l);
int size=imagesize(0,0,two_widths,width);
two_units=(char *) malloc(size);
//getimage(0,0,two_widths,width,two_units);
//--------------- clear top & lefthandside
stamp_upper_row();
stamp_leftthand_cols();
//--------------- getimage of two_units in their final glory
getimage(0,0,two_widths ,width,two_units);
//--------------- allocate mem for  U_unit & D_unit
size=imagesize(0,0,width+l,width);
U_unit=(char *) malloc(size);
D_unit=(char *) malloc(size);
//--------------- get  U_unit & D_unit
getimage(0,0,width+l-1,width,U_unit);
getimage(l+width,0,two_widths-1,width,D_unit);
 
putimage(0,10+width,U_unit,COPY_PUT);
putimage(20+width,10+width,D_unit,COPY_PUT);
 
 
 
cleardevice();
}
//-------------------------------------- ---------------------------
 
void	tile_screen_w_background()
{
cleardevice();
int two_widths=2*(width+l);
int width_plus_l=width+l;
int row; for (row=0;row