[comp.lang.c] graphics challenge.....

steves@longs.LANCE.ColoState.EDU (Steve Smith) (04/18/91)

	I'm trying to build a mini program that reads in an ascii data file and plots
the data on the screen.  I have the program reading in the data just
fine and in the 
correct order.  The problem is getting the data points to plot out correctly...

here is what the code looks like:

#include <stdio.h>
#include <graphics.h>

main()
{
	int graphdriver = DETECT, graphmode, pen, x,y;
	int maxx, maxy, maxvalue, scale;
/* more stuff */


	getmaxx();
	getmaxy();

	/* get the name of the file etc.... */

{
	initgraph(&graphdriver, &graphmode, "c:\\tc");
	setcolor(WHITE);
}

	do {
		fgets(buffer, 6000, infile);
		sscanf(buffer, " %d %d %d ", &pen, &x, &y);

	/* HERE'S THE PROBLEM */

	scale = (getmaxx()/maxvalue);  /* maxvalue is the maximum value of any
data point in the data.fil*/
					/* scale should set a scale for the specific screen size */

	xp = abs((x - getmaxx())) * 1/scale; /* xp, yp are the new points to
fit within the screen area */
	yp = abs((y - getmaxy())) * 1/scale; /* Should scale the values for any
specific graphics type */

	if (pen == 0)
	moveto(xp,yp);
else {
	lineto(xp,yp);
     }
} while (fgets(buffer, 6000, infile) != NULL);

	/* more ending code */

	The code needs to take into account any data value and then use the
scale to fit it within
	a specific graphics screen.  So far I get the graphic, but a data file
to plot a box doesn't
	even look close to a box in shape.?

Is there an easy and slick way to handle all this?


Thanks in advance

Steve Smith
Colorado State University
Engineering