INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Happy Belated 4th!

Happy Belated 4th!

(OP)
Here's a dopey, old-school BGI program that will draw the American flag in the retro CGA video mode. This was compiled with Borland C++ 4.52. Because it's BGI related, a couple addition files it needs is: CGA.BGI to reference at runtime and graphics.lib to compile with.
(Press any key toggle the palettes, ESC to exit.)

CODE --> C

/*I got the flag dimensions from:
	http://www.montney.com/flag/proportions.htm */
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <conio.h>
#include <dos.h>

#define ESC 0x1B

int main(void)
{
   int D=CGA, M=CGAC1;
   int stripe,x,y,j;
   int pal;
   int errorcode;
   void star5pt(int x,int y,int r);
   void CGAswitchpal(int p);

   initgraph(&D,&M,"C:\\BC45\\BGI");
   errorcode = graphresult();
   if (errorcode != grOk) {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }

   setbkcolor(BLUE);

   /*Red Stripes*/
   setfillstyle(SOLID_FILL,CGA_LIGHTMAGENTA);
   for(stripe=1;stripe<=13;stripe+=2){
      bar(0,(getmaxy()/13)*(stripe-1),getmaxx(),(getmaxy()/13)*stripe);
   }

   /*White stripes*/
   setfillstyle(SOLID_FILL,CGA_WHITE);
   for(stripe=2;stripe<=13;stripe+=2){
      bar(0,(getmaxy()/13)*(stripe-1)+1,getmaxx(),(getmaxy()/13)*stripe);
   }

   /*Star field*/
   setfillstyle(EMPTY_FILL,CGA_CYAN);
   bar(0,0,(getmaxx()*2)/5,(getmaxy()/13)*7);

   setfillstyle(SOLID_FILL,CGA_WHITE);

   x=(getmaxx()*33)/1000;
   y=(getmaxy()*54)/1000;
   for(j=1;j<10;j+=2){
   /*Stripes are already drawn.
      I can re-use it in the for loops*/
      for(stripe=1;stripe<12;stripe+=2)
      star5pt(x*stripe,y*j,(getmaxy()*3)/100);
   }

   for(j=1;j<8;j+=2)
      for(stripe=1;stripe<10;stripe+=2)
         star5pt(x+x*stripe,y+y*j,(getmaxy()*3)/100);

   pal=1;
   while(getch()!=ESC){
      if(pal==0)
         pal=1;
      else
         pal=0;
      CGAswitchpal(pal);
   }
   closegraph();
   return 0;
}

void CGAswitchpal(int p)
{
   union REGS in,out;
   in.h.ah=0x0B;
   in.h.bh=0x01;
   in.h.bl=p;

   int86(0x10,&in,&out);
}

void star5pt(int x,int y,int r2)
{
   int i,r1;
   int v[11][2];
   int n[10][2]={{0,100},{59,81},{95,31},{95,-31},{59,-81},{0,-100},
                  {-59,-81},{-95,-31},{-95,31},{-59,81}};

   /*r1: Radius of hypothetical circle that would connect to
      all inner-vertex points.
      True value would be sin(18 deg)/sin(126 deg), which is ~38/100 */
   r1=38*r2/100;

   for(i=0;i<10;i++){
      if(i%2==0){ /*Outer radius*/
         v[i][0]=x+(r2*n[i][0])/100;
         v[i][1]=y-(r2*n[i][1])/100;
      }
      else{ /*Inner radius*/
         v[i][0]=x+(r1*n[i][0])/100;
         v[i][1]=y-(r1*n[i][1])/100;
      }
   }
   v[10][0]=v[0][0];
   v[10][1]=v[0][1];

   moveto(x,y);
   drawpoly(11,v[0]);
} 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close