Example #1
0
int main()
{
  double xp[1000],yp[1000] ;
  int n,q ;
  double P[2] ;


  swidth = 700 ; sheight = 700 ;
  G_init_graphics(swidth, sheight) ;
  G_rgb(0,0,0) ;
  G_clear() ;

  G_rgb(1,0,0) ;
  n = click_and_save(xp,yp) ;
  G_rgb(0,1,0) ;
  G_fill_polygon(xp,yp,n) ;
while(1==1){
  G_wait_click(P) ;
  if(P[1] < 40){
    break;
  }
  int r = in_out(xp,yp,n,P);
  if(r==1){
    G_rgb(1,0,0);
  }else{
  G_rgb(0,0,1) ;
}
  G_fill_circle(P[0],P[1],2) ;
}

  q = G_wait_key() ;
}
Example #2
0
int main()
{
  double swidth, sheight ;
  double i,x,y ;
  double z[2] ;

  swidth = 600 ; sheight = 600 ;
  G_init_graphics(swidth, sheight);


  i = 0;
  while(i<600){
  G_rgb(0,0,1) ;
  G_line (i, 0, i, 599) ;
  G_line(0,i,599,i) ;
  i=i+10 ;
  }

  i=0;
  while(i<10){
  G_wait_click(z) ;
  x = z[0] ; y = z[1] ;
  x=x-fmod(x,10);
  y=y-fmod(y,10);
  G_fill_rectangle(x, y ,10,10);
  i++;
}

  G_wait_key();
}
Example #3
0
int click_and_save (double *x, double *y)
{
  int n ;
  double P[2] ;

  G_rgb(0,1,0.5) ;
  G_fill_rectangle(0,0,swidth,20) ;

  G_rgb(1,0,0) ;
  G_wait_click(P);

  n = 0 ;
  while (P[1] > 20) {
    x[n] = P[0] ;
    y[n] = P[1] ;
    G_circle(x[n],y[n],2) ;
    if (n > 0) { G_line(x[n-1],y[n-1], x[n],y[n]) ;}
    n++ ;
    G_wait_click(P) ;
  }

  return n ;
}
Example #4
0
  int clickandsave(double x[], double y[]){
    double coords[2];
    int length;
    int i;
    for(i = 0; i< 100; i++){
    G_wait_click(coords);
    if(coords[0] < 44 && coords[1] > 580){
      break;
    }
    else{
      x[i] = coords[0];
      y[i] = coords[1];
G_fill_rectangle(coords[0] -1, coords[1] -1 , 3, 3 );
      length = i;
    }
    }
    return i;
  }
Example #5
0
void getClippingWindow(){
	double coords[2];
	int i = 0;
	G_rgb(255,0,0);
	G_fill_rectangle(0,0,40,40);
while(1==1){
G_wait_click(coords);
if(coords[0] < 40 && coords[1] < 40){
	break;}
else{
	cx[i] = coords[0];
	cy[i] = coords[1];
	G_rgb(255,255,255);
	G_fill_rectangle(coords[0],coords[1], 5,5);
	center[0] += cx[i];
	center[1] += cy[i];
	i++;
}
}

center[0] /=i;
center[1] /=i;
cSize = i;
}
Example #6
0
int main()
{
   double swidth, sheight ;
   double lowleftx, lowlefty, width, height ;
   double x[10],y[10] ;
   double numpoints,q, x0,y0,x1,y1 ;
   double p[2] ;

   // must do this before you do 'almost' any other
   // graphical tasks 
   swidth = 400 ;  sheight = 400 ;
   G_init_graphics (swidth, sheight) ;


   // draw a point, a line, some rectangles, some triangles 

   G_rgb(1, 0, 0) ;  // red 
   G_point(200, 380) ;

   G_rgb(0, 1, 0) ;  // green
   //   G_line (0, 0, 400, 400) ; // won't show if part is off screen
   G_line (0, 0, 399, 399) ;
  
   G_rgb(0, 0, 1) ;  // blue 
   lowleftx = 200 ; lowlefty = 50 ; width = 10 ; height = 30 ;
   G_rectangle (lowleftx, lowlefty, width, height) ;
   lowleftx = 250 ; 
   G_fill_rectangle (lowleftx, lowlefty, width, height) ;

   G_rgb(1, 1, 0) ;  // yellow
   G_triangle (10, 300,  40,300,  60,250) ;
   G_fill_triangle (10,100,  40,100,  60,150) ;

   G_rgb(1, 0.5, 0) ;  // orange
   G_circle (100, 300, 75) ;
   G_fill_circle (370, 200, 50) ;

   // prints text in your graphics window 
   G_rgb(0, 0, 0) ;  // black
   G_draw_string ("hello",300,100) ;

   // draw a polygon 
   x[0] = 100 ;   y[0] = 100 ;
   x[1] = 100 ;   y[1] = 300 ;
   x[2] = 300 ;   y[2] = 300 ;
   x[3] = 300 ;   y[3] = 100 ;
   x[4] = 200 ;   y[4] = 175 ;
   numpoints = 5 ;
   G_polygon (x,y,numpoints) ;


   q = G_wait_key() ; // pause to look ...any key to continue


   G_rgb (0.4, 0.2, 0.1) ; // brown
   G_fill_polygon (x,y,numpoints) ;

   G_rgb (0.5, 0.8, 0.4) ;// what color is this?

   G_wait_click(p) ;   // wait for a mouse click
   x0 = p[0] ; y0 = p[1] ; // extract coordinates 
   G_fill_rectangle (x0-2, y0-2, 4,4) ;// mark the clicked point


   G_wait_click(p) ;  
   x1 = p[0] ; y1 = p[1] ;
   G_fill_rectangle (x1-2, y1-2, 4,4) ;


   G_rgb (0.5, 0.5, 0.5) ; // a grey
   G_line (x0,y0, x1,y1) ;

   q = G_wait_key() ;    // pause again before exit 

   G_save_image_to_file ("t01c.xwd") ;

   G_close() ; // terminate graphics...probably not fatal if forgotten

}
int main()
{
   int    swidth, sheight ;
   double lowleftx, lowlefty, width, height ;
   double x[10],y[10] ;
   double numpoints,q, x0,y0,x1,y1 ;
   double p[2] ;
   int    i ;


   // must do this before you do 'almost' any other
   // graphical tasks 
   swidth = 400 ;  sheight = 500 ;
   G_init_graphics (swidth, sheight) ;


   // draw a point, a line, some rectangles, some triangles 

   G_rgb(1, 0, 0) ;  // red 
   G_point(200, 380) ;
   G_fill_rectangle (300,400, 50, 20) ;

   G_rgb(0, 1, 0) ;  // green
   //   G_line (0, 0, 400, 400) ; // won't show if part is off screen
   G_line (0, 0, 399, 399) ;
   G_fill_triangle(50, 400,  100,400,  150,475) ;
  
   G_rgb(0, 0, 1) ;  // blue 
   lowleftx = 200 ; lowlefty = 50 ; width = 10 ; height = 30 ;
   G_rectangle (lowleftx, lowlefty, width, height) ;
   lowleftx = 250 ; 
   G_fill_rectangle (lowleftx, lowlefty, width, height) ;


   G_rgb(1, 1, 0) ;  // yellow
   G_triangle (10, 300,  40,300,  60,250) ;
   G_fill_triangle (10,100,  40,100,  60,150) ;

   G_rgb(1, 0.5, 0) ;  // orange
   G_circle (100, 300, 75) ;
   G_fill_circle (370, 200, 50) ;

   // prints text in your graphics window 
   G_rgb(0, 0, 0) ;  // black
   G_draw_string ("hello",300,100) ;



   // draw a polygon 
   x[0] = 100 ;   y[0] = 100 ;
   x[1] = 100 ;   y[1] = 300 ;
   x[2] = 300 ;   y[2] = 300 ;
   x[3] = 300 ;   y[3] = 100 ;
   x[4] = 200 ;   y[4] = 175 ;
   numpoints = 5 ;
   G_polygon (x,y,numpoints) ;


   G_rgb (0.4, 0.2, 0.1) ; // brown
   G_fill_polygon (x,y,numpoints) ;

   G_rgb (0.5, 0.8, 0.4) ;// what color is this?



   int xc,yc ;
   int pixel ;
   int rgbI[3] ;
   double rgb[3] ;

   G_wait_click(p) ;  
   xc = p[0] ; yc = p[1] ;
   while (yc > 20) {

     printf("%d %d\n",xc,yc) ;
     pixel = G_get_pixel(xc,yc) ;
     G_convert_pixel_to_rgbI(pixel, rgbI) ;
     G_convert_rgbI_to_rgb(rgbI, rgb) ;

     printf("pixel = %x\n",pixel) ;
     printf("%3d %3d %3d\n",rgbI[0],rgbI[1],rgbI[2]) ;
     printf("%lf %lf %lf\n",rgb[0],rgb[1],rgb[2]) ;
     printf("\n") ;

     G_wait_click(p) ;  
     xc = p[0] ; yc = p[1] ;
   }





}