AbidingDude
Programmer
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.)
(Press any key toggle the palettes, ESC to exit.)
C:
/*I got the flag dimensions from:
[URL unfurl="true"]http://www.montney.com/flag/proportions.htm[/URL] */
#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]);
}