home *** CD-ROM | disk | FTP | other *** search
/ CD Action 56 / cdaction-56.iso / Bonus / C.exe / cz9 / naCD / Julia3 / JuliaAnim.c next >
C/C++ Source or Header  |  2000-11-12  |  989b  |  56 lines

  1. # include <stdio.h>
  2. # include <math.h>
  3. # include <allegro.h>
  4.  
  5.  
  6. void julia(int cx, int cy, BITMAP* bufor)
  7. {
  8.   int i,j,px,py;
  9.   int xn,yn,x2,y2,x,y;
  10.   unsigned char c;
  11.   for (i=-1920,px=0;i<1920;i+=6,px++)
  12.     for (j=-1920,py=0;j<1920;j+=8,py++)
  13.     {
  14.       c=0;
  15.       x=i;y=j;
  16.       x2=x*x;
  17.       y2=y*y;
  18.       while (((x2+y2)<4000000) && (c<31))
  19.       {
  20.         c++;
  21.         y=((x*y)>>9)+cy;
  22.         x=((x2-y2)>>10)+cx;
  23.         x2=x*x;
  24.         y2=y*y;
  25.       }
  26.       ((short int *)bufor->line[py])[px]=makecol16(8*c,8*c,255-c);
  27.     }
  28. }
  29.  
  30. BITMAP* bufor;
  31.  
  32. int main()
  33. {
  34.   float kat1=0,kat2=1;
  35.  
  36.   int cx,cy;
  37.  
  38.   allegro_init();
  39.  
  40.   set_color_depth(16);
  41.   set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
  42.   bufor=create_bitmap(640, 480);
  43.   clear(bufor);
  44.  
  45.   while (!kbhit())
  46.   {
  47.     kat1+=0.01;
  48.     kat2+=0.015;
  49.     cx=900*sin(kat1);
  50.     cy=900*cos(kat2);
  51.     julia(cx, cy, bufor);
  52.     blit(bufor, screen, 0, 0, 0, 0, 640, 480);
  53.   }
  54.   return 0;
  55. }
  56.