home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / winsrc.zip / JB.C < prev    next >
Text File  |  1990-10-16  |  9KB  |  254 lines

  1. #include "fractint.h"
  2. #include "mpmath.h"
  3.  
  4. struct fullscreenvalues
  5. {
  6.    int type;   /* 'd' for decimal, 's' for string, '*' for comment */
  7.    union
  8.    {
  9.       double dval;
  10.       char   sval[16];
  11.    } uval;
  12. };
  13.  
  14. extern void (*plot)(int, int, int);
  15. extern  int fullscreen_prompt(char *hdg,int numprompts,char * far *prompts,
  16.                struct fullscreenvalues values[],int options,int fkeymask);
  17. void stackscreen(void);
  18. void unstackscreen(void);
  19.  
  20. extern int row, col, xdots, ydots, bitshift, fractype;
  21. extern int ixstart, ixstop, iystart, iystop, colors;
  22. extern double param[], xxmin, xxmax, yymin, yymax;
  23. extern long delx, dely, ltempsqrx, ltempsqry, far *lx0, far *ly0;
  24. extern struct lcomplex lold, lnew, *longparm;
  25. extern llimit2;
  26. static int bbase;
  27. static long xpixel, ypixel;
  28. static long initjx, initjy, initmx, initmy, initz, djx, djy, dmx, dmy;
  29. static long jx, jy, mx, my, dx, dy, dz, initzx, initzy, xoffset, yoffset;
  30. static long jxmin, jxmax, jymin, jymax, mxmin, mxmax, mymin, mymax;
  31. static long x_per_inch, y_per_inch, inch_per_xdot, inch_per_ydot;
  32. struct Perspective {
  33.    long x, y, zx, zy;
  34. };
  35.  
  36. struct Perspective LeftEye, RightEye, *Per;
  37. struct lcomplex jbc;
  38.  
  39. #define NUM_VAR 17
  40.  
  41. static double fg, fg16;
  42. static long
  43.         zdots = 128L,
  44.         shell = 30L,
  45.         origin = (long)(8.0 * (1L << 16)),
  46.    height = (long)(7.0 * (1L << 16)),
  47.         width = (long)(10.0 * (1L << 16)),
  48.    dist = (long)(24.0 * (1L << 16)),
  49.    eyes = (long)(0.0 * (1L << 16)),
  50.    depth = (long)(8.0 * (1L << 16)),
  51.    brratio = (long)(0.0 * (1L << 16));
  52.  
  53. int JulibrotSetup(void) {
  54.         int r;
  55.    struct fullscreenvalues d[NUM_VAR];
  56.    static char StereoFile[] = "glasses1.map";
  57.    static char GreyFile[] = "altern.map";
  58.    char *mapname;
  59.    static char *v[NUM_VAR] = {
  60.       "Julia from x",                              /* d[0] */
  61.       "Julia to x",                                /* d[1] */
  62.       "Julia from y",                              /* d[2] */
  63.       "Julia to y",                                /* d[3] */
  64.       "Mandelbrot from x",                         /* d[4] */
  65.       "Mandelbrot to x",                           /* d[5] */
  66.       "Mandelbrot from y",                         /* d[6] */
  67.       "Mandelbrot to y",                           /* d[7] */
  68.       "Number of z pixels",                        /* d[8] */
  69.       "Penetration level",                         /* d[9] */
  70.       "Location of z origin",                      /* d[10] */
  71.       "Depth of z",                                /* d[11] */
  72.       "Screen height",                             /* d[12] */
  73.       "Screen width",                              /* d[13] */
  74.       "Distance to Screen",                        /* d[14] */
  75.       "Distance between eyes (0 for Greyscale)",   /* d[15] */
  76.       "Blue:Red Ratio (0 for Greyscale)",          /* d[16] */
  77.    };
  78.  
  79.    if(colors < 255) {
  80.       stopmsg(0,"Sorry, but Julibrots require a 256-color video mode");
  81.       return(0);
  82.    }
  83.  
  84.    fg = (double)(1L << bitshift);
  85.    fg16 = (double)(1L << 16);
  86.  
  87.    for (r = 0; r < NUM_VAR; ++r)
  88.       d[r].type = 'd';
  89.  
  90.         jxmax = (long)((d[0].uval.dval = xxmax) * fg);
  91.         jxmin = (long)((d[1].uval.dval = xxmin) * fg);
  92.         jymax = (long)((d[2].uval.dval = yymax) * fg);
  93.         jymin = (long)((d[3].uval.dval = yymin) * fg);
  94.         mxmax = (long)((d[4].uval.dval = param[0]) * fg);
  95.         mxmin = (long)((d[5].uval.dval = param[1]) * fg);
  96.         mymax = (long)((d[6].uval.dval = param[2]) * fg);
  97.         mymin = (long)((d[7].uval.dval = param[3]) * fg);
  98.    d[8].uval.dval = (double)zdots;
  99.    d[9].uval.dval = (double)shell;
  100.    d[10].uval.dval = (double)origin / fg16;
  101.    d[11].uval.dval = (double)depth / fg16;
  102.    d[12].uval.dval = (double)height / fg16;
  103.    d[13].uval.dval = (double)width / fg16;
  104.    d[14].uval.dval = (double)dist / fg16;
  105.    d[15].uval.dval = (double)eyes / fg16;
  106.    d[16].uval.dval = (double)brratio / fg16;
  107.  
  108.    stackscreen();
  109.    if((r = fullscreen_prompt("Julibrot Parameters",
  110.                               NUM_VAR, v, d, 0, 0)) >= 0) {
  111.       jxmin = (long)((xxmax = d[0].uval.dval) * fg);
  112.       jxmax = (long)((xxmin = d[1].uval.dval) * fg);
  113.       xoffset = (jxmax + jxmin) / 2;       /* Calculate average */
  114.       jymin = (long)((yymax = d[2].uval.dval) * fg);
  115.       jymax = (long)((yymin = d[3].uval.dval) * fg);
  116.       yoffset = (jymax + jymin) / 2;       /* Calculate average */
  117.       mxmin = (long)((param[0] = d[4].uval.dval) * fg);
  118.       mxmax = (long)((param[1] = d[5].uval.dval) * fg);
  119.       mymin = (long)((param[2] = d[6].uval.dval) * fg);
  120.       mymax = (long)((param[3] = d[7].uval.dval) * fg);
  121.       zdots = (long)(d[8].uval.dval);
  122.       shell = (long)(d[9].uval.dval);
  123.       origin = (long)(d[10].uval.dval * fg16);
  124.       depth = (long)(d[11].uval.dval * fg16);
  125.       height = (long)(d[12].uval.dval * fg16);
  126.       width = (long)(d[13].uval.dval * fg16);
  127.       dist = (long)(d[14].uval.dval * fg16);
  128.       eyes = (long)(d[15].uval.dval * fg16);
  129.       brratio = (long)(d[16].uval.dval * fg16);
  130.       dmx = (mxmax - mxmin) / zdots;
  131.       dmy = (mymax - mymin) / zdots;
  132.       longparm = &jbc;
  133.  
  134.       x_per_inch = (long)((d[1].uval.dval - d[0].uval.dval) / d[13].uval.dval * fg);
  135.       y_per_inch = (long)((d[3].uval.dval - d[2].uval.dval) / d[12].uval.dval * fg);
  136.                 inch_per_xdot = (long)(d[13].uval.dval / xdots * fg16);
  137.                 inch_per_ydot = (long)(d[12].uval.dval / ydots * fg16);
  138.       initz = origin - (depth / 2);
  139.       LeftEye.x = -(RightEye.x = eyes / 2);
  140.       LeftEye.y = RightEye.y = 0l;
  141.       LeftEye.zx = RightEye.zx = dist;
  142.       LeftEye.zy = RightEye.zy = dist;
  143.       bbase = (int)(128.0 * d[16].uval.dval);
  144.    }
  145.  
  146.    unstackscreen();
  147.  
  148.    if(d[16].uval.dval == 0.0)
  149.       mapname = GreyFile;
  150.    else
  151.       mapname = StereoFile;
  152.    if (ValidateLuts(mapname) != 0) {
  153.       char msg[200];
  154.       sprintf(msg,"Could not load color map %s",mapname);
  155.       stopmsg(0,msg);
  156.       return(0);
  157.    }
  158.    spindac(0,1);                 /* load it, but don't spin */
  159.  
  160.    return(r >= 0);
  161. }
  162.  
  163. int jb_per_pixel(void) {
  164.         jx = multiply(Per->x - xpixel, initz, 16);
  165.    jx = divide(jx, dist, 16) - xpixel;
  166.    jx = multiply(jx << (bitshift - 16), x_per_inch, bitshift);
  167.    jx += xoffset;
  168.         djx = divide(depth, dist, 16);
  169.         djx = multiply(djx, Per->x - xpixel, 16) << (bitshift - 16);
  170.         djx = multiply(djx, x_per_inch, bitshift) / zdots;
  171.  
  172.         jy = multiply(Per->y - ypixel, initz, 16);
  173.         jy = divide(jy, dist, 16) - ypixel;
  174.         jy = multiply(jy << (bitshift - 16), y_per_inch, bitshift);
  175.    jy += yoffset;
  176.         djy = divide(depth, dist, 16);
  177.         djy = multiply(djy, Per->y - ypixel, 16) << (bitshift - 16);
  178.         djy = multiply(djy, y_per_inch, bitshift) / zdots;
  179.  
  180.    return(1);
  181. }
  182.  
  183. static int n, zpixel, blank, plotted, color;
  184.  
  185. int zline(long x, long y) {
  186.    xpixel = x;
  187.    ypixel = y;
  188.         mx = mxmin;
  189.         my = mymin;
  190.    if((row + col) & 1)
  191.       Per = &LeftEye;
  192.    else
  193.       Per = &RightEye;
  194.    fractalspecific[fractype].per_pixel();
  195.    for(zpixel = 0; zpixel < zdots; zpixel++) {
  196.       lold.x = jx;
  197.       lold.y = jy;
  198.       jbc.x = mx;
  199.       jbc.y = my;
  200.       if(check_key())
  201.          return(-1);
  202.       ltempsqrx = multiply(lold.x, lold.x, bitshift);
  203.       ltempsqry = multiply(lold.y, lold.y, bitshift);
  204.       for(n = 0; n < shell; n++) {
  205.          if(fractalspecific[fractype].orbitcalc())
  206.             break;
  207.       }
  208.       if(n == shell) {
  209.          if(brratio) {
  210.             color = (int)(128l * zpixel / zdots);
  211.             if((row + col) & 1)
  212.                (*plot)(col, row, 127 - color);
  213.             else {
  214.                                 color = (int)(multiply((long)color << 16, brratio, 16) >> 16);
  215.                (*plot)(col, row, 127 + bbase - color);
  216.             }
  217.          }
  218.          else {
  219.             color = (int)(254l * zpixel / zdots);
  220.             (*plot)(col, row, color + 1);
  221.          }
  222.          plotted = 1;
  223.          break;
  224.       }
  225.       mx += dmx;
  226.       my += dmy;
  227.       jx += djx;
  228.       jy += djy;
  229.    }
  230.    return(0);
  231. }
  232.  
  233. int Std4dFractal(void) {
  234.    long x, y;
  235.    int xdot, ydot;
  236.  
  237.    for(y = 0, ydot = (ydots >> 1) - 1; ydot >= 0; ydot--, y -= inch_per_ydot) {
  238.                 plotted = 0;
  239.                 x = -(width >> 1);
  240.                 for(xdot = 0; xdot < xdots; xdot++, x += inch_per_xdot) {
  241.          col = xdot;
  242.          row = ydot;
  243.          if(zline(x, y) < 0)
  244.             return(-1);
  245.          col = xdots - col - 1;
  246.          row = ydots - row - 1;
  247.          if(zline(-x, -y) < 0)
  248.             return(-1);
  249.       }
  250.       if(!plotted) break;
  251.    }
  252.    return(0);
  253. }
  254.