/*    Program vykreslující Juliovy množiny
 * --------------------------------------------------
 * Copyright (c) 1999 Martin Hinner, <mhi@penguin.cz>
 */
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <complex.h>

#include "gr.c"

#define ITER  255
#define N     2      /* Exponent juliovy množiny */

//#define C complex(-1.286,-0.434)     /* C */
#define C complex(-1,-0.434)
//#define C complex(-1,-0.3)

void main()
{
 int x,y,i,j;
 complex c,z;

 initg();           /* inicializace grafiky */

 for (x=0;x<0x8;x++)      /* Nastavení palety */
  setpal(x,x*8,0,x*8);
 for (x=0x8;x<0x10;x++)
  setpal(x,(x-8)*8,(x-8)*8,0);
 for (x=0x10;x<0x40;x++)
  setpal(x,0,63-x,63-x);
 for (x=0;x<0x40;x++)
  setpal(x+64,0,x,63);
 for (x=0;x<0x40;x++)
  setpal(x+128,x,63,63);
 for (x=0;x<0x40;x++)
  setpal(x+192,63-x,63-x,0);

 for (x=0;x<320;x++)
  {
   if (kbhit())
    {
     getch();
     break;
    }
   for (y=0;y<200;y++)
    {
     z = complex((x-160)/70.0,(y-100)/70.0);    /* vlastní výpočet */
     c = C;
     for (i=0;i<ITER;i++)
      {
       z = pow(z,N)+c;
       if (abs(z)>2)
	break;
      }
     putpix(x,y,i);
    }
   putpix(x,199,62);
  }

 getch();
 doneg();
}
