Category : Files from Magazines
Archive   : CGAZV4N1.ZIP
Filename : PIE.C

 
Output of file : PIE.C contained in archive : CGAZV4N1.ZIP
/************************* PIE.C *************************
* A demonstration of drawing scaling
*
* Author: John M. Dlugosz (port to Turbo C by John Rex)
********************************************************/

#include
#include
#include
#include

#define POINTMAX 12

typedef double real;

typedef struct {
real x, y;
} realpoint;


real adjustment; /* stretch the horizontal to proper aspect ratio */

/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */

/* set the adjustment variable */
void set_adjustment()
{
int xasp,yasp;

getaspectratio (&xasp,&yasp);
adjustment = ((real) yasp) / ((real) xasp);
}

/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */

void drawline(realpoint *source, realpoint *dest)
{
line ((int) source->x, (int) source->y, (int) dest->x, (int) dest->y);
}

/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
/* compute a point on the circle given the angle, and adjust its
horizontal coordinate for the current aspect ratio
*/

void angle (
realpoint *point, /* the answer */
realpoint *center, /* center of circle */
real radius, /* vertical size of circle */
real theta /* angle of point to find */
)
{
point->y = radius * sin(theta) + center->y;
point->x = radius * cos(theta) * adjustment + center->x;
}

/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */

void WaitForKeypressWithoutTrashingGraphicsScreen()
{
(void) getch();
}

/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */

void draw_piechart (realpoint *center, real size, int n)
{
realpoint p[POINTMAX];
int loop, a;
real interval;

/* put up an ellipse */
ellipse ((int) center->x,(int) center->y, 0, 360,
(int) (adjustment*size), (int) size);

/* Pick n regularly spaced points on the ellipse. */
interval = (2*M_PI)/(n);
for (loop=0; loop < n; loop++) {
angle (&p[loop],center,size,loop*interval);
}


for (a = 0; a < n; a++)
drawline (center, &p[a]);
}

/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */

int startupgraphics()
{
char path[100];
int graphdriver,graphmode;
void bgiparse(char *, char *, int *, int *);

bgiparse(getenv("BGI"), path, &graphdriver, &graphmode);
initgraph (&graphdriver, &graphmode, path);
return (graphresult() == 0);
}

/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */

void show()
{
int loop;
real radius;
realpoint center;

/* sense size of screen, and adjust to it */
center.x = (getmaxx()-1)/2;
center.y = (getmaxy()-1)/2;
radius = center.y;

for (loop = 5; loop <= POINTMAX; loop++) {
clearviewport();
draw_piechart(¢er, radius, loop);
WaitForKeypressWithoutTrashingGraphicsScreen();
}
}

/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */

void main()
{
if (startupgraphics()) {
set_adjustment();
show();
closegraph();
}
else printf("Error going into graphics mode.\n");
}

  3 Responses to “Category : Files from Magazines
Archive   : CGAZV4N1.ZIP
Filename : PIE.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/