hi
im making a program in turbo C dat prints a graph of integers varying from -150 to about 250. the integers are on y axis and on x axis, constant distance of 1 pixel is maintained.
My problem is dat when i run the program then the graph is not proper. as the (0,0) point lies at the top left corner of the screen(by default: try using putpixel(0,0,RED);. and increases on moving down or towards right ( Im using the principle dat my comp. resolution is 680 by 400, n im giving put pixel as putpixel(%26lt;the program generated integer%26gt; , i);
such that it is in the while loop, n i increments by 1 each time.
Wat i wat is dat the x axis should should somewhere in the center of the screen.
value of ordinate can be +ve or -ve, but my absisa (i) is always +ve.
Thnx 4 ur help in advance.
"TURBO C" help in changing axis while printing graph using putpixel(), line()?
Hello,
What you want to do is transform your data into screen coordinates. It sounds like the abscissa (i) is correct: as i increases, the screen x-coordinate moves to the right.
For the ordinate, you need to do two things. First, since the screen coordinates increase downward rather than up, you will need to negate your generated value. You also need to shift that value so it is in the range 0-400.
The most readable way to do this would be to write a function:
/*
* This function assumes an input range of -150 to 250, and
* will always place the graph at the top of the screen.
*/
int TranslateYToScreen(int value)
{
return (250 - value);
}
Then instead of using
putpixel(%26lt;integer%26gt; , i);
you would use
putpixel(TranslateYToScreen( %26lt;integer%26gt;) , i);
If you ever need to change the way the screen coordinates are calculated (if your data range changes, or the screen size changes), you can change the code in one place.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment