// draw function point void set_point ( float_t x_real, float_t y_real ) { if ((x_real> window_left) & (x_real < window_right) & (y_real > window_down) & (y_real <window_up)) { Text_Foreground_Color( COLOR_WHITE ); Draw_Line( scale_x( x_real ), scale_y( y_real ), scale_x( x_real ), scale_y( y_real ) ); RAIO_StartDrawing( LINE ); } }
void Plotter::draw_line(double x1, double y1, double x2, double y2) { //Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface); cr->move_to (scale_x(x1), scale_y(y1)); cr->line_to (scale_x(x2), scale_y(y2)); cr->stroke(); cr->save(); }
void Plotter::draw_point(double x, double y) { //Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface); cr->arc(scale_x(x), scale_y(y), POINT_RES, 0.0, 2.0 * M_PI); cr->stroke(); }
int main() { int Iteration; const int IterationMax=200; /* write header */ printf("P6\n%d\n%d\n%d\n", size_x,size_y,max_color_component_value); /* compute and write image data bytes to the file*/ for(int i_y=0; i_y < size_y ;i_y++) { for(int i_x=0; i_x < size_x ;i_x++){ double x0 = scale_x( i_x ); double y0 = scale_y( i_y ); double x = 0.0; double y = 0.0; // printf("%f,%f\n",x0,y0 ); int iteration = 0; while (( (x*x + y*y) < 4 )&&( iteration < max_iteration )){ /* printf( "\nx= */ double xtemp = x*x - y*y + x0; y = 2*x*y + y0; x = xtemp; ++iteration; } char r,g,b; color_for_iteration( &r, &g, &b, iteration ); printf( "%c%c%c", r, g, b ); } } return 0; }
void example_DrawFunction( int16_t function ) { float_t x_real, y_real; int16_t count; RAIO_clear_screen(); // draw x-axis draw_coords_line ( window_left, 0, window_right, 0 ); for( count = (int16_t)window_left; count < (int16_t)window_right; count++ ) { Draw_Line ( scale_x( count ), scale_y( window_up*0.01 ), scale_x( count ), scale_y( window_down*0.01 ) ); Text_Foreground_Color ( COLOR_WHITE ); RAIO_StartDrawing ( LINE ); } // draw y-axis draw_coords_line ( 0, window_up, 0, window_down ); for( count = (int16_t)window_down; count < (int16_t)window_up; count++ ) { Draw_Line ( scale_x( window_left*0.01 ), scale_y( count ), scale_x( window_right*0.01 ), scale_y( count ) ); Text_Foreground_Color ( COLOR_WHITE ); RAIO_StartDrawing ( LINE ); } // draw function for( x_real = window_left; x_real < window_right; x_real=x_real+0.02 ) { switch (function) // -> see FUNCTIONS { case SIN: y_real = sin( x_real ); break; case COS: y_real = cos( x_real ); break; case TAN: y_real = tan( x_real ); break; case PARABOLA: y_real = x_real * x_real; break; case EXPONENT: y_real = exp( x_real ); break; case LOGN : y_real = log( x_real ); break; default: break; }; set_point( x_real, y_real); } }
// draw coordinate system void draw_coords_line (float_t x1, float_t y1, float_t x2, float_t y2) { Text_Foreground_Color( COLOR_WHITE ); Draw_Line( scale_x( x1 ), scale_y( y1 ), scale_x( x2 ), scale_y( y2 ) ); RAIO_StartDrawing( LINE ); }