home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff214.lzh / MandelVroom / src / mandieee.c < prev    next >
C/C++ Source or Header  |  1989-05-30  |  6KB  |  290 lines

  1. /*
  2.  * MandelVroom 2.0
  3.  *
  4.  * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
  5.  *
  6.  * All rights reserved.
  7.  *
  8.  * Permission is hereby granted to distribute this program's source
  9.  * executable, and documentation for non-comercial purposes, so long as the
  10.  * copyright notices are not removed from the sources, executable or
  11.  * documentation.  This program may not be distributed for a profit without
  12.  * the express written consent of the author Kevin L. Clague.
  13.  *
  14.  * This program is not in the public domain.
  15.  *
  16.  * Fred Fish is expressly granted permission to distribute this program's
  17.  * source and executable as part of the "Fred Fish freely redistributable
  18.  * Amiga software library."
  19.  *
  20.  * Permission is expressly granted for this program and it's source to be
  21.  * distributed as part of the Amicus Amiga software disks, and the
  22.  * First Amiga User Group's Hot Mix disks.
  23.  *
  24.  * contents: this file contains the Mandelbrot and Julia picture generators
  25.  * in IEEE floating point format.
  26.  */
  27.  
  28. #include "mandp.h"
  29. #include "parms.h"
  30.  
  31. extern SHORT MaxOrbit;
  32.  
  33. extern char *IEEELib;
  34.  
  35. /*
  36.  * IEEE Floating Point Mandelbrot Generator
  37.  */
  38. int
  39. MandelbrotIEEE( Pict )
  40.   register struct Picture *Pict;
  41. {
  42.   register int i, j, k;
  43.   register SHORT *CountPtr;
  44.   register int  MathMode;
  45.  
  46.   struct PotentialParms Parms;
  47.   struct RastPort *Rp;
  48.  
  49.   struct MathIeeeDoubBasBase *LocalMathBase;
  50.  
  51.   LocalMathBase = (struct MathIeeeDoubBasBase *) OpenLibrary( IEEELib, 0L );
  52.  
  53.   if (LocalMathBase == NULL)
  54.     return;
  55.  
  56.   MathMode = Pict->MathMode;
  57.  
  58.   if (Pict->Flags & NO_RAM_GENERATE)
  59.     CountPtr = Pict->Counts;
  60.   else
  61.     CountPtr = Pict->Counts + (Pict->CurLine*Pict->CountX);
  62.  
  63.   Parms.ScreenReal = Pict->Real;
  64.   Parms.ScreenImag = Pict->Imag;
  65.  
  66.   /* start in the upper left hand corner */
  67.  
  68.   Parms.C_Imag = Pict->ImagLow;
  69.   Parms.C_Imag += Pict->CurLine*Pict->ImagGap;
  70.  
  71.   Parms.MaxIteration = Pict->MaxIteration;
  72.  
  73.   /*
  74.    * for each pixel, calculate mandelbrot
  75.    */
  76.   for (i = Pict->CurLine; i < Pict->CountY; i++) {
  77.  
  78.     Parms.C_Real = Pict->RealLow;
  79.  
  80.     if ( Pict->Flags & NO_RAM_GENERATE )
  81.       CountPtr = Pict->Counts;
  82.  
  83.     for (j = 0; j < Pict->CountX; j++) {
  84.  
  85.       if (*CountPtr == 0) {
  86.         if (MathMode == 4) {
  87.           k = Height_68881( &Parms );
  88.         } else {
  89.           k = IEEE_Height( &Parms );
  90.         }
  91.  
  92.         *CountPtr = k;
  93.       }
  94.       CountPtr++;
  95.  
  96.       Parms.C_Real += Pict->RealGap;
  97.  
  98.       ChildPause( Pict );
  99.     }
  100.     Parms.C_Imag += Pict->ImagGap;
  101.  
  102.     CheckEOL( Pict );
  103.   }
  104.   CloseLibrary( LocalMathBase );
  105. } /* MandelbrotIEEE */
  106.  
  107. /*
  108.  * IEEE Floating Point Juliaelbrot Generator
  109.  */
  110. JuliaIEEE( Pict )
  111.   register struct Picture *Pict;
  112. {
  113.   register int i, j, k;
  114.   register SHORT *CountPtr;
  115.  
  116.   struct PotentialParms Parms;
  117.  
  118.   struct MathIeeeDoubBasBase *LocalMathBase;
  119.  
  120.   LocalMathBase = (struct MathIeeeDoubBasBase *) OpenLibrary( IEEELib, 0L );
  121.  
  122.   if (Pict->Flags & NO_RAM_GENERATE)
  123.     CountPtr = Pict->Counts;
  124.   else
  125.     CountPtr = Pict->Counts + (Pict->CurLine*Pict->CountX);
  126.  
  127.   Parms.C_Real = Pict->Real;
  128.   Parms.C_Imag = Pict->Imag;
  129.   Parms.C_Imag += Pict->CurLine*Pict->ImagGap;
  130.  
  131.   /* start in the upper left hand corner */
  132.   Parms.ScreenImag = Pict->ImagLow;
  133.  
  134.   Parms.MaxIteration = Pict->MaxIteration;
  135.  
  136.   /*
  137.    * for each pixel, calculate mandelbrot
  138.    */
  139.   for (i = Pict->CurLine; i < Pict->CountY; i++) {
  140.  
  141.     Parms.ScreenReal = Pict->RealLow;
  142.  
  143.     if ( Pict->Flags & NO_RAM_GENERATE )
  144.       CountPtr = Pict->Counts;
  145.  
  146.     for (j = 0; j < Pict->CountX; j++) {
  147.  
  148.       if (*CountPtr == 0) {
  149.         if (Pict->MathMode == 2) {
  150.           k = IEEE_Height( &Parms );
  151.         } else {
  152.           k = Height_68881( &Parms );
  153.         }
  154.  
  155.         *CountPtr = k;
  156.       }
  157.       CountPtr++;
  158.  
  159.       Parms.ScreenReal += Pict->RealGap;
  160.  
  161.       ChildPause( Pict );
  162.     }
  163.     Parms.ScreenImag += Pict->ImagGap;
  164.  
  165.     CheckEOL( Pict );
  166.   }
  167.   CloseLibrary( LocalMathBase );
  168. } /* JuliaIEEE */
  169.  
  170. IEEE_Height( Parms )
  171.   register struct PotentialParms *Parms;
  172. {
  173.   register double cura,  curb;
  174.            double cura2, curb2;
  175.  
  176.   int k;
  177.  
  178. #ifdef CHECK_TASK_STACK
  179.  
  180.   CheckStack();
  181.  
  182. #endif
  183.  
  184.   cura = cura2 = Parms->ScreenReal;
  185.   curb = curb2 = Parms->ScreenImag;
  186.  
  187.   cura2 *= cura2;
  188.   curb2 *= curb2;
  189.  
  190.   for (k = 0; k < Parms->MaxIteration; k++ ) {
  191.  
  192.     curb *= cura;
  193.     curb += curb + Parms->C_Imag;
  194.  
  195.     cura = cura2 - curb2 + Parms->C_Real;
  196.  
  197.     cura2 = cura * cura;
  198.     curb2 = curb * curb;
  199.  
  200.     if (cura2+curb2 >= 16.0)
  201.       return( k );
  202.   }
  203.   return( k );
  204. }
  205.  
  206. DrawOrbitIEEE( Pict )
  207.   register struct Picture *Pict;
  208. {
  209.   register struct RastPort *Rp;
  210.   register double cura,  curb;
  211.            double cura2, curb2;
  212.            double realc, imagc;
  213.   register int k;
  214.   double x_scale, y_scale;
  215.   int x_center, y_center;
  216.   int width, height;
  217.   int x, y;
  218.  
  219.   struct Window *Window;
  220.  
  221.   Window = OrbitWind;
  222.  
  223.   Rp = Window->RPort;
  224.  
  225.   width  = (Window->Width-Pict->LeftMarg-Pict->RightMarg);
  226.   height = (Window->Height-Pict->TopMarg-Pict->BotMarg);
  227.  
  228.   x_center = width/2 + Pict->LeftMarg;
  229.   y_center = height/2 + Pict->TopMarg;
  230.  
  231.   y_scale = x_scale = (float) height / 2.0;
  232. /*x_scale *= AspectRatio( Pict );*/
  233.  
  234.   realc = Pict->RealLow + (float) (MouseX-Pict->LeftMarg) * Pict->RealGap;
  235.   imagc = Pict->ImagLow + (float) (MouseY-Pict->TopMarg)  * Pict->ImagGap;
  236.  
  237.   if ( Pict->pNode.ln_Type == MANDPICT ) {
  238.  
  239.     cura = cura2 = Pict->Real;
  240.     curb = curb2 = Pict->Imag;
  241.  
  242.   } else {
  243.  
  244.     cura = cura2 = realc;
  245.     curb = curb2 = imagc;
  246.     realc = Pict->Real;
  247.     imagc = Pict->Imag;
  248.   }
  249.  
  250.   cura2 *= cura2;
  251.   curb2 *= curb2;
  252.  
  253.   SetAPen( Rp, 0 );
  254.   RectFill( Rp, Pict->LeftMarg, Pict->TopMarg, width+Pict->LeftMarg-1, height+Pict->TopMarg-1);
  255.  
  256.   SetAPen( Rp, HIGHLIGHTPEN);
  257.  
  258.   for (k = 0; k < MaxOrbit; k++ ) {
  259.  
  260.     curb *= cura;
  261.     curb += curb + imagc;
  262.  
  263.     cura  = cura2 - curb2 + realc;
  264.  
  265.     cura2 = cura * cura;
  266.     curb2 = curb * curb;
  267.  
  268.     if (cura2+curb2 >= 16.0)
  269.       return( k );
  270.  
  271.     /* map real and imaginary parts into window coordinates */
  272.  
  273.     x = x_center + (int)(x_scale*cura);
  274.     y = y_center + (int)(y_scale*curb);
  275.  
  276.     if ( x >= Pict->LeftMarg && x < Window->Width-Pict->RightMarg &&
  277.          y >= Pict->TopMarg  && y < Window->Height-Pict->BotMarg ) {
  278.  
  279.       /* plot pixel location */
  280.  
  281.       WritePixel( Rp, x, y);
  282.     }
  283.  
  284.   }
  285.   return( k );
  286. }
  287.  
  288.  
  289.  
  290.