home *** CD-ROM | disk | FTP | other *** search
/ Fractal Creations (Second Edition) / FRACTALS_2E.iso / frasrc.exe / TESTPT.C < prev    next >
C/C++ Source or Header  |  1992-07-10  |  2KB  |  60 lines

  1. /*
  2.  
  3. Write your fractal program here. initreal and initimag are the values in
  4. the complex plane; parm1, and parm2 are paramaters to be entered with the
  5. "params=" option (if needed). The function should return the color associated
  6. with initreal and initimag.  FRACTINT will repeatedly call your function with
  7. the values of initreal and initimag ranging over the rectangle defined by the
  8. "corners=" option. Assuming your formula is iterative, "maxit" is the maximum
  9. iteration. If "maxit" is hit, color "inside" should be returned.
  10.  
  11. Note that this routine could be sped up using external variables/arrays
  12. rather than the current parameter-passing scheme.  The goal, however was
  13. to make it as easy as possible to add fractal types, and this looked like
  14. the easiest way.
  15.  
  16. This module is part of an overlay, with calcfrac.c.  The routines in it
  17. must not be called by any part of Fractint other than calcfrac.
  18.  
  19. The sample code below is a straightforward Mandelbrot routine.
  20.  
  21. */
  22.  
  23. extern int xdots;        /* the screen is this many dots across */
  24. extern int ydots;        /* the screen is this many dots down */
  25. extern int colors;        /* the screen has this many colors */
  26.  
  27. int teststart()     /* this routine is called just before the fractal starts */
  28. {
  29.     return( 0 );
  30. }
  31.  
  32. void testend()         /* this routine is called just after the fractal ends */
  33. {
  34. }
  35.  
  36.         /* this routine is called once for every pixel */
  37.     /* (note: possibly using the dual-pass / solif-guessing options */
  38.  
  39. testpt(initreal,initimag,parm1,parm2,maxit,inside)
  40. double initreal,initimag,parm1,parm2;
  41. int maxit,inside;
  42. {
  43. double oldreal, oldimag, newreal, newimag, magnitude;
  44. int color;
  45.    oldreal=parm1;
  46.    oldimag=parm2;
  47.    magnitude = 0.0;
  48.    color = 0;
  49.    while ((magnitude < 4.0) && (color < maxit)) {
  50.       newreal = oldreal * oldreal - oldimag * oldimag + initreal;
  51.       newimag = 2 * oldreal * oldimag + initimag;
  52.       color++;
  53.       oldreal = newreal;
  54.       oldimag = newimag;
  55.       magnitude = newreal * newreal + newimag * newimag;
  56.       }
  57. if (color >= maxit) color = inside;
  58. return(color);
  59. }
  60.