home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / video / 13 / 13_1b.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  817 b   |  36 lines

  1. /* Listing 13-1b */
  2.  
  3. /* draws an n-leaved rose of the form  rho = a * cos(n*theta) */
  4.  
  5. #define Leaves        (double)11    /* n must be an odd number */
  6.  
  7. #define    Xmax        640
  8. #define    Ymax        350
  9. #define PixelValue    14
  10. #define    ScaleFactor    (double) 1.37
  11.  
  12. main()
  13. {
  14.     int    x,y;            /* pixel coordinates */
  15.     double    a;            /* length of the semi-axis */
  16.     double    rho,theta;        /* polar coordinates */
  17.  
  18.     double    pi = 3.14159265358979;
  19.     double    sin(),cos();
  20.  
  21.     void SetPixel();
  22.  
  23.  
  24.     a = (Ymax / 2) - 1;        /* a reasonable choice for a */
  25.  
  26.     for (theta=0.0; theta < pi; theta+=0.001)
  27.     {
  28.       rho = a * cos( Leaves*theta );    /* apply the formula */
  29.  
  30.       x = rho * cos( theta );    /* convert to rectangular coords */
  31.       y = rho * sin( theta ) / ScaleFactor;
  32.  
  33.       SetPixel( x+Xmax/2, y+Ymax/2, PixelValue );    /* plot the point */
  34.     }
  35. }
  36.