Attachment 'gd10.c'

Download

   1 // gd10.c
   2 //  orbiting  circle
   3 
   4 #include "gd.h"
   5 #include "math.h"
   6 #include <stdio.h>
   7 
   8 #define  SEMIMAJOR   430
   9 #define  ECCENTRIC   0.7000
  10 #define  CENTERX     200
  11 #define  CENTERY     384
  12 
  13 int main() {
  14    gdImagePtr im;                          /* Declare the image */
  15    FILE *gifout;                           /* Declare output file */
  16    int black, white, red, green, blue;     /* Declare color indexes */
  17    int  gray ;
  18    double  pi2   = 8.0 * atan( 1.0 );
  19    double  delta = pi2 / 200 ;
  20    double  angle ;
  21    double  r     ;
  22    double  r00 = SEMIMAJOR * ( 1.0 - ECCENTRIC*ECCENTRIC ) ; 
  23    gdPoint points[1000] ;
  24    int     point ;
  25 
  26    double  object=0.0 ;
  27    int     ox, oy ;  
  28 
  29    im = gdImageCreate(1024, 768 );
  30 
  31    /* Allocate the colors black, white, red, green, blue */
  32    black = gdImageColorAllocate(im,   0,   0,   0);
  33    white = gdImageColorAllocate(im, 255, 255, 255);
  34    red   = gdImageColorAllocate(im, 255,   0,   0);
  35    green = gdImageColorAllocate(im,   0, 255,   0);
  36    blue  = gdImageColorAllocate(im,   0,   0, 255);
  37    gray  = gdImageColorAllocate(im, 128, 128, 128);
  38 
  39    /* line thickness of 1 */
  40    gdImageSetThickness( im, 1 );
  41 
  42    point = 0 ;
  43    /* draw ellipse with line segments */
  44    for( angle=0.0 ; angle <= pi2 ; ) {
  45       r  = r00/( 1.0 + ECCENTRIC * cos( angle ));
  46       points[point].x = CENTERX - (int) ( r * cos( angle ) );
  47       points[point].y = CENTERY + (int) ( r * sin( angle ) );
  48       angle += delta * SEMIMAJOR / r ;
  49       point++ ;
  50    }
  51    gdImagePolygon( im, points, point, blue );
  52 
  53    ox = CENTERX ;
  54    oy = CENTERY ;
  55    gdImageFilledArc( im, ox, oy, 130, 130, 0, 360, green, gdArc );
  56 
  57    r  = r00/( 1.0 + ECCENTRIC * cos( object ));
  58    ox = CENTERX - (int) ( r * cos( object ) );
  59    oy = CENTERY + (int) ( r * sin( object ) );
  60    gdImageFilledArc(im, ox    , oy,    60, 60, 0, 360, gray,  gdArc);
  61    gdImageFilledArc(im, ox    , oy+40, 20, 20, 0, 360, white, gdArc);
  62    gdImageFilledArc(im, ox-35 , oy-20, 20, 20, 0, 360, white, gdArc);
  63    gdImageFilledArc(im, ox+35 , oy-20, 20, 20, 0, 360, white, gdArc);
  64 
  65    /* JPEG-format file. */
  66    gifout = fopen("test10.gif", "wb");
  67 
  68    /* Output the image to the disk file in GIF format. */
  69    gdImageGif(im, gifout);
  70 
  71    /* Close the files. */
  72    fclose(gifout);
  73 
  74    /* Destroy the image in memory. */
  75    gdImageDestroy(im);
  76 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-04-07 07:49:28, 2.3 KB) [[attachment:gd10.c]]
  • [get | view] (2009-04-07 07:55:24, 3.3 KB) [[attachment:gd12.c]]
  • [get | view] (2009-04-07 07:51:23, 4.4 KB) [[attachment:test10.gif]]
  • [get | view] (2009-04-07 07:55:07, 124.4 KB) [[attachment:test12.gif]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.