home *** CD-ROM | disk | FTP | other *** search
/ CD Action 56 / cdaction-56.iso / Bonus / C.exe / cz9 / naCD / Mandelbrot / Mand.cpp next >
C/C++ Source or Header  |  2000-11-13  |  960b  |  52 lines

  1. # include <complex.h>
  2. # include <stdio.h>
  3. # include <pc.h>
  4. # include <allegro.h>
  5.  
  6. BITMAP* bufor;
  7. complex<double> c;
  8.  
  9. void RysujMand()
  10. {
  11.   int i,j;
  12.   double px,py;
  13.   complex<double> x;
  14.   unsigned char iter;
  15.  
  16.   clear(bufor);
  17.   for (j=0,py=-2.1;j<480;j++,py+=0.00875)
  18.     for (i=0,px=-2.5;i<640;i++,px+=0.00625)
  19.     {
  20.       iter=0;
  21.       c=complex<double>(px, py);
  22.       x=complex<double>(0, 0);
  23.       while ((abs(x)<4.0) && (iter<255))
  24.       {
  25.         iter++;
  26.         x=x*x+c;
  27.       }
  28.       ((short int *)bufor->line[j])[i]=makecol16(iter,iter,255-iter);
  29.       blit(bufor, screen, i, j, i, j, 1, 1);
  30.     }
  31. }
  32.  
  33.  
  34. int main()
  35. {
  36.    int err;
  37.  
  38.    allegro_init();
  39.    set_color_depth(16);
  40.    if ((err=set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0))<0)
  41.    {
  42.      printf("Error: %s\n",allegro_error);
  43.      return(1);
  44.    }
  45.    bufor = create_bitmap(640, 480);
  46.  
  47.    RysujMand();
  48.    while (!kbhit());
  49.  
  50.    destroy_bitmap(bufor);
  51. }
  52.