Metropoli BBS
VIEWER: demo.c MODE: TEXT (CP437)
               /*┌───────────────────────────────────────────────────────┐
                 │                                                       │
                 │ demo() = PROGRAM TO DEMONSTRATE THE USE OF THE        │
                 │          TURBO C GRAPHICS FUNCTIONS                   │
                 │                                                       │
                 └───────────────────────────────────────────────────────┘*/

               /*┌───────────────────────────────────────────────────────┐
                 │                                                       │
                 │                      INCLUDES                         │
                 │                                                       │
                 └───────────────────────────────────────────────────────┘*/

#include <stdio.h>
#include <math.h>
#include <dos.h>
#include <conio.h>

               /*┌───────────────────────────────────────────────────────┐
                 │                                                       │
                 │                USER WRITTEN INCLUDES                  │
                 │                                                       │
                 └───────────────────────────────────────────────────────┘*/

#include "gtools.h"
#include "gdraws.h"
#include "colors.h"

               /*┌───────────────────────────────────────────────────────┐
                 │                                                       │
                 │     GLOBAL VARIABLES USED BY GRAPHICS FUNCTIONS       │
                 │                                                       │
                 └───────────────────────────────────────────────────────┘*/



char adapt;
int color = 2;
int LINEWIDTH=1, OPERATOR=0, ANGLE, XCENTER, YCENTER;
int pt[12][2]={{-20,0},{0,0},{0,-120},{-200,-120},
	{-200,200},{90,150},{60,0},{200,0},{0,0}},x,y,z;
unsigned long int PATTERN=0xFFFFFFFF;

unsigned long int style[8] = { 0xFFFFFFFF,0xC0C0C0C0,0xFF00FF00,0xFFF0FFF0,
                                0xF000F000,
                                0xFFFF0000,0xFFFFF0F0,0xFFF0F0F0};

int usa[600] = {-151,111,-146,
		107,-144, 96,-140, 96,-138,103,-139,111,-135,112,-111,
		103,-91, 96,-65, 92,-39, 89,-13, 85, 13, 85, 44, 82, 32,
		71, 30, 68, 35, 68, 41, 72, 41, 68, 44, 68, 54, 81, 57,
		81, 53, 74, 61, 72, 62, 70, 73, 75, 73, 72, 79, 71, 79,
		70, 75, 67, 69, 66, 63, 61, 61, 48, 61, 34, 63, 27, 65,
		27, 69, 38, 66, 48, 67, 55, 71, 60, 78, 66, 82, 66, 84,
		61, 84, 59, 87, 56, 86, 49, 89, 55, 93, 45, 87, 34, 93,
		31,114, 48,113, 53,127, 59,130, 68,152, 82,156,107,158,
		110,162,107,162,105,165,105,174, 89,160, 68,160, 61,165,
		55,167, 56,147, 59,158, 59,158, 55,160, 50,149, 34,149,
		20,147, 17,143, 24,140, 24,147, 15,144,  1,147, -2,149,
		-8,149,-13,145,-15,145,-19,149,-19,130,-39,119,-55,119,
		-61,123,-75,123,-75,130,-85,132,-89,134,-96,135,-103,134,
		-114,130,-115,123,-110,115,-96,110,-79,106,-72,104,-71,
		96, -77, 87,-85, 75,-71, 74,-74, 65,-74, 61,-78, 65,-85,
		52,-86, 45,-82, 28,-83, 19, -85, 13,-92,  5,-103,  5,
		-116,  2,-119, -1,-119, -7,-116, -9,-114,-11,-111,-12,
		-104,-13,-100,-21,-90,-26,-83,-33,-82,-42,-90,-57,-70,
		-65,-64,-77,-61,-78,-66,-98,-64,-124,-48,-137,-48,-139,
		-45,-139,-37,-146,-27,-159,-20,-161, -6,-165,  0,-165,
		4,-170, 20,-172, 27,-172, 41,-165, 55,-160, 78,-152, 96,
		-150,103,-151,111,-999};


               /*┌───────────────────────────────────────────────────────┐
                 │                                                       │
                 │                 FUNCTION DEFINITIONS                  │
                 │                                                       │
                 └───────────────────────────────────────────────────────┘*/

void building();
void wait(char title[]);
void print_scr();

               /*┌───────────────────────────────────────────────────────┐
                 │                                                       │
                 │                     MAIN PROGRAM                      │
                 │                                                       │
                 └───────────────────────────────────────────────────────┘*/

main()
{
	int i, j, k, x, y, oldx, oldy, midpoint;
        double xd,yd,ampl,aspect;
        char ch;

        cls (1);
        adapt = getAdapter();
        if ((adapt != 'E') && (adapt != 'C') && (adapt != 'V'))
                printf("Cannot Run Demo -- No CGA, EGA or VGA Installed!");
        else
	{
		if (adapt == 'V')
		{
                	setMode(0x12);
	                cls(1);
        	        write_big_str(-119,131,"GRAPHICS",226);
                	write_vid_str(-200,-6,"DEMONSTRATION",91);
		}
                if (adapt == 'E')
		{
                	setMode(16);
	                cls(1);
        	        write_big_str(-119,131,"GRAPHICS",226);
                	write_vid_str(-200,-6,"DEMONSTRATION",91);
		}
                if (adapt == 'C')
		{
                	setMode(4);
			setCGAPalette(0);
	                cls(1);
        	        write_big_str(-319,131,"GRAPHICS",0x23);
                	write_vid_str(-319,-6,"DEMONSTRATION",91);
		}
                wait("");

                LINEWIDTH = 3;
                cls(4);
                drawRect(-309,210,310,-200,11);
                drawLine(-309,210,310,-200,11);
                drawLine(-309,-200,310,210,11);

		wait("Rectangle with Diagonals");

                LINEWIDTH = 5;
                ampl = 220;
                oldx = -315;
                oldy = 0;
		cls(1);
                for (i=0; i<=32; i++)
                {
                        y = ampl * sin(6.283 * ((double)i)/32);
                        x = 620 * (double)i/32 - 310;
                        drawLine (oldx, oldy, x, y, 12);
                        oldx = x;
                        oldy = y;
                }
                wait("Sine Wave");

	       	cls(0);
        	PATTERN = style[0];
	        drawRect(-310,230,-280,200,1);
        	PATTERN = style[1];
	        drawRect(-300,160,-240,75,2);
        	PATTERN = style[2];
	        drawRect(-280,35,-220,-100,3);
        	PATTERN = style[3];
	        LINEWIDTH = 1;
        	drawRect(-200,230,20,100,5);
	        PATTERN = style[4];
        	drawRect(-180,90,-70,-200,6);
	        PATTERN = style[5];
        	drawRect(40,75,60,200,7);
	        PATTERN = style[6];
        	drawRect(100,230,230,-175,9);
	        PATTERN = style[7];
        	drawRect(250,180,300,-90,10);
	        PATTERN = style[0];
		wait("Examples of Dashed Lines");

		LINEWIDTH = 1;
                fillRect(-304,210,30,-30,1);
                drawRect(-304,210,30,-30,11);
                fillRect(-220,80,-20,-180,10);
                drawRect(-220,80,-20,-180,11);
                fillRect(-240,140,-70,30,15);
                drawRect(-240,140,-70,30,11);
                fillRect(-260,130,-150,-50,13);
                drawRect(-260,130,-150,-50,11);
                wait("Filled Rectangles");

                LINEWIDTH = 1;
                drawOval(-175,0,90,13,0.7);
                LINEWIDTH = 3;
                drawOval(65,0,90,WHITE,1.0);
                LINEWIDTH = 5;
                drawOval(240,0,90,LIGHTGREEN,1.3);
                wait("Ovals and Circle");

                LINEWIDTH = 3;
                drawOval(-150,70,120,LIGHTBLUE,1.);
                drawOval(0,-70,120,LIGHTBLUE,1.);
                drawOval(150,70,120,LIGHTBLUE,1.);
                wait("Overlapping Circles");

                fillOval(-120,0,110,LIGHTBLUE,0.8);
                fillOval(180,0,110,YELLOW,1.);
                fillOval(220,50,20,BLACK,1.);
                fillOval(140,50,20,BLACK,1.);
                LINEWIDTH= 5;
                drawLine(150,-60,210,-60,BLACK);
                drawLine(130,-53,150,-60,BLACK);
                drawLine(230,-53,210,-60,BLACK);
                drawLine(120,-40,130,-53,BLACK);
                drawLine(240,-40,230,-53,BLACK);
                wait("Filled Ovals");

                aspect = .50;
                for (i=0; i<3; i++)
                {
                LINEWIDTH = 3;
                        drawArc(0,0,120,0,450,5,aspect);
                        drawArc(0,0,120,450,900,15,aspect);
                        drawArc(0,0,120,900,1350,2,aspect);
                        drawArc(0,0,120,1350,1800,15,aspect);
                        drawArc(0,0,120,1800,2250,9,aspect);
                        drawArc(0,0,120,2250,2700,15,aspect);
                        drawArc(0,0,120,2700,3150,10,aspect);
                        drawArc(0,0,120,3150,3590,15,aspect);
                        wait("Oval Drawn By Combining Arcs");
                        aspect +=.5;
                }

                fillArc(0,0,140,480,1380,1,1.);
                fillArc(0,0,140,1380,1800,2,1.);
                fillArc(0,0,140,1800,2600,3,1.);
                fillArc(0,0,140,2600,3150,9,1.);
                fillArc(0,0,140,3150,3600,14,1.);
                fillArc(0,0,140,0,480,15,1.);
                wait("Pie Chart from Filled Arcs");

		LINEWIDTH = 1;
		PATTERN = style[1];
		for (i=0; i<7; i++)
			drawLine(pt[i][0],pt[i][1],pt[i+1][0],pt[i+1][1],3);
		PATTERN = style[0];
		drawBezier(160,14,-20,0,0,0,0,-120,-200,-120,-200,200,90,150,60,
			0,200,0,-999);
		wait("Bezier Curve");

		PATTERN = style[1];
		drawLine(-250,-25,-300,240,3);
		drawLine(-300,240,-80,210,3);
		drawLine(-80,210,-40,-25,3);
		drawLine(-40,-25,160,-25,3);
		drawLine(160,-25,300,-25,5);
		drawLine(300,-25,300,220,5);
		drawLine(300,220,40,240,5);
		drawLine(40,240,-80,-239,5);
		PATTERN = style[0];
		drawBezier(160,13,-250,-25,-300,240,-80,210,-40,-25,
			160,-25,-999);
		drawBezier(160,14,160,-25,300,-25,300,220,40,240,-80,-239,
			-999);
		wait("Two Bezier Curves");

		PATTERN = style[1];
                drawLine(-250,0,-220,200,3);
                drawLine(-220,200,-180,-200,3);
                drawLine(-180,-200,-140,60,3);
                drawLine(-140,60,-100,-30,3);
                drawLine(-100,-30,-70,-10,3);
		drawLine(-70,-10,-20,208,3);
		drawLine(-20,208,+60,-130,3);
		drawLine(+60,-130,100,125,3);
		drawLine(100,125,125,185,3);
		drawLine(125,185,140,160,3);
        	drawLine(140,160,170,-200,3);
        	drawLine(170,-200,190,-60,3);
        	drawLine(190,-60,220,20,3);
		PATTERN = style[0];
		drawBspline(160,14,-250,0,-220,200,-180,-200,-140,60,-100,-30,
			-70,-10,-20,208,60,-130,100,125,125,185,140,160,
			170,-200,190,-60,220,20,-999);
		wait("B-Spline Curve");

                x= -275;
                y= 200;
                for (k=0; k<37; k++)
                {
                        write_horz_char(x, y, k+33, 31);
                        x += 16;
                }
		x = -275;
		y = 180;
                for (k=37; k<74; k++)
                {
                        write_horz_char(x, y, k+33, 31);
                        x += 16;
                }
		x = -275;
   		y = 160;
                for (k=74; k<93; k++)
                {
                        write_horz_char(x, y, k+33, 31);
                        x += 16;
                }
		x= -310;
                y= -210;
                for (k=0; k<17; k++)
                {
                        write_vert_char(x, y, k+33, 47);
                        y += 20;
                }
		x = -294;
                y = -210;
                for (k=17; k<34; k++)
                {
                        write_vert_char(x, y, k+33, 47);
                        y += 20;
                }
		x = -278;
                y = -210;
                for (k=34; k<51; k++)
                {
                        write_vert_char(x, y, k+33, 47);
                        y += 20;
                }
		x = -262;
                y = -210;
                for (k=51; k<68; k++)
                {
                        write_vert_char(x, y, k+33, 47);
                        y += 20;
                }
		x = -246;
                y = -210;
                for (k=68; k<85; k++)
                {
                        write_vert_char(x, y, k+33, 47);
                        y += 20;
                }
		x = -230;
                y = -210;
                for (k=85; k<93; k++)
                {
                        write_vert_char(x, y, k+33, 47);
                        y += 20;
                }
                write_horz_str(-150,35, "HELLO WORLD!",62);
                write_vert_str(80,-200, "HOW ARE YOU TODAY?",109);
                wait("Alphanumerics");

                LINEWIDTH = 3;
                drawRoundRect(-300,210,300,-210,60,11);
                wait("Rounded Rectangle");

                fillRoundRect(-300,210,300,-210,60,13);
                wait("Filled Rounded Rectangle");

                building();
                wait("City Skyline at Night");

		drawPoly(11,-259, 90,-59, 90,-159,-90,-999);
		drawPoly(11,-259,-20,-159,160,-59,-20,-999);
		fillOval(161,34,107,9,1.0);
		fillPoly(14,60,66,262,66,104,-55,161,140,218,-55,-999);
		wait("Stars");

		fillPoly(13,-129,103,-69,172,-59,158,-64,144,-39,130,-34,151,
			-24,158,-19,116,1, 75,-9, 48, -49, 61,-19, -6,
			 -59,-34,-79,-6,-109,-48,-149,-6,-129,48,-149,61,
			-159,20,-179,61,-209,-34,-229,-6,-299,89,-249,103,
			-299,103,-299,130,-249,130,-269,172,-259,185,-999);

		PATTERN = style[1];
		LINEWIDTH = 1;
		drawPoly(11,-129,103,-69,172,-59,158,-64,144,-39,130,-34,151,
			-24,158,-19,116,1, 75,-9, 48, -49, 61,-19, -6,
			 -59,-34,-79,-6,-109,-48,-149,-6,-129,48,-149,61,
			-159,20,-179,61,-209,-34,-229,-6,-299,89,-249,103,
			-299,103,-299,130,-249,130,-269,172,-259,185,-999);

		fillPoly(14,120,0,168,-96,232,-96,232,-144,168,-144,72,-192,
			24,-160,24,-128,56,-128,40,-144,88,-128,88,-96,24,
			-64,120,32,-999);
		drawPoly(15,120,0,168,-96,232,-96,232,-144,168,-144,72,-192,
			24,-160,24,-128,56,-128,40,-144,88,-128,88,-96,24,
			-64,120,32,-999);
		wait ("Irregular Polygons");

		PATTERN = style[0];
		fill2Poly(10,usa);
		wait("United States of America");

        	LINEWIDTH = 1;
	        cls(0);
        	color=3;
	        XCENTER = -70;
        	YCENTER = 35;
	        for (ANGLE=0; ANGLE<180; ANGLE+=15)
        	{
	        	rotateRect(-220,100,80,-35,color);
	                color++;
			if ((color % 4 == 0) && (adapt == 'C'))
				color++;
        	}
	        wait("Rotated Rectangles");

        	cls(0);
	        color=3;
        	XCENTER = 0;
	        YCENTER = 0;
        	for (ANGLE=0; ANGLE<360; ANGLE+=15)
	        {
        		rotatePoly(color,-120,-70,0,100,120,-70,-999);
               		color++;
			if ((color % 4 == 0) && (adapt == 'C'))
				color++;
			if (color == 0) color++;
       		}

	        wait("Rotated Triangles");
        	cls(0);
	       	color=3;
        	for (ANGLE=0; ANGLE<180; ANGLE+=15)
	       	{
        		rotateOval(0,0,160,color,1.5);
               		color++;
			if ((color % 4 == 0) && (adapt == 'C'))
				color++;
	       	}
        	wait("Rotated Ovals");

	}
}

void wait(char title[])
{
        int tab,width,line,mode;

        mode = getMode(&width);
    	if ((mode == 0x11) || (mode == 0x12))
		line = 29;
	else
		line = 24;
	tab = (width - strlen(title))/2;
        gotoxy(tab,0);
        writString(title,WHITE,0);
        tab = (width - 33)/2;
        gotoxy(tab,line);
        writString("Press any key to continue demo...", WHITE,0);
        getch();
        cls(0);
}


void building()
{
        int i,j,hue;

        cls(0);

        fillRect(-280,130,-220,-200,9);

        for(i=-275; i<=-235; i+=20)
        {
                for(j=125; j>=-170; j-=40)
                {
                        hue = ((rand()%2)*14);
                        fillRect(i,j,i+10,j-25,hue);
                }
        }


        fillRect(-140,160,-60,-230,10);

        for(i=-130; i<=-80; i+=20)
        {
                for(j=155; j>=-190; j-=42)
                {
                        hue = ((rand()%2)*14);
                        fillRect(i,j,i+10,j-25,hue);
                }
        }


        fillRect(-80,-7,60,-200,11);
        fillRect(-40,50,30,-7,11);

        for(i=-75; i<=45; i+=20)
        {
                for(j=-12; j>=-185; j-=30)
                {
                        hue = ((rand()%2)*14);
                        fillRect(i,j,i+10,j-10,hue);
                }
        }

        fillRect(40,80,100,-230,5);

        for(i=45; i<=85; i+=20)
        {
                for(j=75; j>=-215; j-=30)
                {
                        hue = ((rand()%2)*14);
                        fillRect(i,j,i+10,j-10,hue);
                }
        }
	fillRect(-220,50,-120,-175,3);

        for(i=-215; i<=-135; i+=20)
        {
                for(j=45; j>=-160; j-=30)
                {
                        hue = ((rand()%2)*14);
                        fillRect(i,j,i+10,j-10,hue);
                }
        }
        fillRect(200,100,280,-175,3);

        for(i=205; i<=265; i+=20)
        {
                for(j=95; j>=-160; j-=35)
                {
                        hue = ((rand()%2)*14);
                        fillRect(i,j,i+10,j-15,hue);
                }
        }

        fillRect(180,190,240,-200,13);
        fillRect(200,75,220,190,13);

        for(i=185; i<=225; i+=20)
        {
                for(j=185; j>=-185; j-=30)
                {
                        hue = ((rand()%2)*14);
                        fillRect(i,j,i+10,j-10,hue);
                }
        }
        fillRect(90,75,190,-230,9);
        fillRect(110,105,170,75,9);
        fillRect(130,130,150,105,9);


        for(i=95; i<=175; i+=20)
        {
                for(j=67; j>=-215; j-=30)
                {
                        hue = ((rand()%2)*14);
                        fillRect(i,j,i+10,j-10,hue);
                }
        }
        for(i=115; i<=155; i+=20)
        {
                for(j=100; j>=90; j-=30)
                {
                        hue = ((rand()%2)*14);
                        fillRect(i,j,i+10,j-10,hue);
                }
        }

        fillRect(-220,105,-180,50,13);

        fillRect(-215,70,-205,55,0);
        fillRect(-195,70,-185,55,0);
        fillRect(-215,90,-205,75,14);
        fillRect(-195,90,-185,75,0);

	fillOval(-20,195,20,14,1.);
	fillOval(-30,195,20,0,1.);
}

[ RETURN TO DIRECTORY ]