home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1997 #3 / amigamamagazinepolishissue03-1 / ma_1995 / 09 / ami936a.txt < prev    next >
Text File  |  1997-04-07  |  3KB  |  215 lines

  1. <l>
  2. /***********************************************************/
  3.  
  4. /* Program rysuje zbiory Mandelbrota dla wielomianu z=z^2+c */
  5.  
  6. /*      Napisane dla Magazynu Amiga    (c) 1995 by BsZ     */
  7.  
  8. /***********************************************************/
  9.  
  10. #include <ctype.h>
  11.  
  12. #include <fctype.h>
  13.  
  14. #include <functions.h>
  15.  
  16. #include <math.h>
  17.  
  18. #include <stdio.h>
  19.  
  20. #include <stdlib.h>
  21.  
  22. #include <exec/types.h>
  23.  
  24. #include <intuition/intuition.h>
  25.  
  26. #define DEPTH 4
  27.  
  28. #define COLORS 16
  29.  
  30. #define WIDTH 640
  31.  
  32. #define HEIGHT 512
  33.  
  34. #define da (a_max-a_min)/WIDTH
  35.  
  36. #define db (b_max-b_min)/HEIGHT
  37.  
  38. struct Screen *scr;
  39.  
  40. struct IntuitionBase *IntuitionBase;
  41.  
  42. struct GfxBase *GfxBase;
  43.  
  44. struct NewScreen scr_data={
  45.  
  46.     0,0,WIDTH,HEIGHT,DEPTH,1,1,HIRES|LACE,CUSTOMSCREEN,0,
  47.     
  48.     (UBYTE *)"Fraktal1",0,0};
  49.     
  50. void niedobrze(void)
  51.  
  52. {
  53.  
  54.     if (scr) CloseScreen(scr);
  55.     
  56.     if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  57.     
  58.     if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  59.     
  60.     exit(0);
  61.     
  62. }
  63.  
  64. void OpenAllLibraries(void)
  65.  
  66. {
  67.  
  68.     IntuitionBase=(struct IntuitionBase *)OldOpenLibrary("intuition.library");
  69.     
  70.     if (!IntuitionBase) exit(100);
  71.     
  72.     GfxBase=(struct GfxBase *)OldOpenLibrary("graphics.library");
  73.     
  74.     if (!GfxBase) exit(100);
  75.     
  76. }
  77.  
  78. void paleta(void)
  79.  
  80. {
  81.  
  82.     ULONG i;
  83.     
  84.     for(i=0;i<COLORS;i++)
  85.     
  86.         SetRGB4(&scr->ViewPort, i, i, i, i);
  87.         
  88. }
  89.  
  90. void main(int argc,char *argv[])
  91.  
  92. {
  93.  
  94.     int kolor;
  95.     
  96.     long int i,j; /* wsp. graficzne */
  97.     
  98.     double x,y; /* wspóîrzëdne punktu z */
  99.     
  100.     double tempx;
  101.     
  102.     double a,b; /* wspóîrzëdne punktu c */
  103.     
  104.     double a_min,a_max,b_min,b_max; /* zakresy zmian parametru c*/
  105.     
  106.     long int N; /* iloôê iteracji */
  107.     
  108.     long int L; /* licznik punktów zawartych w kole o promieniu 2 */
  109.     
  110.     if(argc!=6)
  111.     
  112.     {
  113.     
  114.         printf("Argumenty:a_min a_max b_min b_max N\n");
  115.         
  116.         exit(0);
  117.         
  118.     }
  119.     
  120.     a_min = atof(argv[1]);
  121.     
  122.     a_max = atof(argv[2]);
  123.     
  124.     b_min = atof(argv[3]);
  125.     
  126.     b_max = atof(argv[4]);
  127.     
  128.     N     = atol(argv[5]);
  129.     
  130.     OpenAllLibraries();
  131.     
  132.     if(!(scr=OpenScreen(&scr_data))) niedobrze();
  133.     
  134.     paleta();
  135.     
  136.     SetRast(&scr->RastPort,15);
  137.     
  138.     b=b_max;
  139.     
  140.     for(j=0;j<HEIGHT;j++)
  141.     
  142.     {
  143.     
  144.         if(scr->MouseX<2 && scr->MouseY<2)
  145.         
  146.         {
  147.         
  148.             niedobrze();
  149.             
  150.             break;
  151.             
  152.         }
  153.         
  154.         a=a_min;
  155.         
  156.         for(i=0;i<WIDTH;i++)
  157.         
  158.         {
  159.         
  160.             x=0;
  161.             
  162.             y=0;
  163.             
  164.             for(L=1;L<=N;L++)
  165.             
  166.             {
  167.             
  168.                 tempx = x * x - y * y + a;
  169.                 
  170.                 y = 2 * x * y + b;
  171.                 
  172.                 x=tempx;
  173.                 
  174.             if( (x * x + y * y) < 2) L++;
  175.             
  176.                 else break;
  177.                 
  178.             }
  179.             
  180.             kolor = (int)( 15.0*(1.0 - L/(double)N) );
  181.             
  182.             SetAPen(&scr->RastPort,kolor);
  183.             
  184.             WritePixel(&scr->RastPort,i,j);
  185.             
  186.             a+=da;
  187.             
  188.         }
  189.         
  190.         b-=db;
  191.         
  192.     }
  193.     
  194.     for(;;)
  195.     
  196.     {
  197.     
  198.         if(scr->MouseX<2 && scr->MouseY<2)
  199.         
  200.         {
  201.         
  202.             niedobrze();
  203.             
  204.             break;
  205.             
  206.         }
  207.         
  208.         Delay(50);
  209.         
  210.         printf("Najedú myszkâ na lewy górny róg ekranu...\n");
  211.         
  212.     }
  213.     
  214. }
  215.