start printing my graph starting from the left down corner
--------------------------------------------------------------------------------
How i can start printing my graph starting from the left down corner
and not from the top left corner?
( (0,0) is oriented in the left down corner)
Code:
#include <stdio.h>
#include <math.h>
void plot_point (double, int);
/* Plots a '*' part way across a screen of a given width */
double plotting_function (double);
/* A function mapping [0,1]->[0,1] to plot*/
int main(int argc, char* argv[])
{
int i;
int width_l= 80; /* Width of the screen */
int height_c= 24; /* Height of the screen */
double x_pos, y_pos; /* x value and y value on our graph */
/* First print the "y-axis" of our graph */
for (i= 0; i < width_l-1; i++) {
printf ("*");
}
printf ("\n");
/* Now loop round for all our possible x positions */
for (i= 1; i < height_c; i++) {
x_pos= (double)i/(double)height_c; /* Calculate our x posn */
y_pos= plotting_function(x_pos);
plot_point(y_pos, width_l);
}
return 0;
}
void plot_point (double y_pos, int screen_width)
/* Plot the point at "y_pos" */
{
int i;
int y_int; /* The y_position as an integer position on the screen */
printf ("*"); /* Print the "x-axis"*/
y_int= (int) (y_pos * screen_width);
/* If we cannot print this point then just return */
if (y_int <= 0 || y_int >= screen_width -1) {
printf ("\n");
return;
}
/* Print a * in the correct place */
for (i= 1; i < y_int; i++) {
printf (" ");
}
printf ("*\n");
}
double plotting_function (double x)
/* Replace this with any function - but remember that only x and y
values in the range [0,1] will be plotted */
{
double y;
y=x*x;
return y;
}