home *** CD-ROM | disk | FTP | other *** search
/ Rat's Nest 1 / ratsnest1.iso / prgmming / c / jhill_pa.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-19  |  5.7 KB  |  124 lines

  1. Newsgroups: sci.fractals,bit.listserv.frac-l
  2.  
  3. Path: unixg.ubc.ca!nntp.cs.ubc.ca!cyber2.cyberstore.ca!vanbc.wimsey.com!deep.rsoft.bc.ca!sol.ctr.columbia.edu!usc!elroy.jpl.nasa.gov!newncar!noao!CS.Arizona.EDU!zippy.Telcom.Arizona.EDU!mvb.saic.com!ast.saic.com!jupiter!hilljr
  4.  
  5. From: hilljr@jupiter.saic.com (Jay R. Hill)
  6.  
  7. Subject: Re: A warning to DEEPZOOMers
  8.  
  9. Message-ID: <1994Jan11.212307.19702@ast.saic.com>
  10.  
  11. Followup-To: sci.fractals
  12.  
  13. Keywords: Mandelbrot Set color
  14.  
  15. Lines: 109
  16.  
  17. Sender: news@ast.saic.com
  18.  
  19. Organization: SAIC
  20.  
  21. References:  <1994Jan6.003042.5039@ast.saic.com>
  22.  
  23. Date: Tue, 11 Jan 1994 21:23:07 GMT
  24.  
  25. Xref: unixg.ubc.ca sci.fractals:2734 bit.listserv.frac-l:2479
  26.  
  27.  
  28.  
  29. In article <1994Jan6.003042.5039@ast.saic.com>, hilljr@jupiter.saic.com (Jay R. Hill) writes:
  30.  
  31. |> Version 0.13 is now ready ...
  32.  
  33.  
  34.  
  35. There are now 133 potential Mandelmaniacs who have gotten their 
  36.  
  37. lastest fix (at my ftp site or by email). 
  38.  
  39.  
  40.  
  41. |> Several folk have expressed interest in this project.  If the 
  42.  
  43. |> interest is still there, I may post the source to DEEPZOOM in 
  44.  
  45. |> segments (with discussion of technique).  
  46.  
  47.  
  48.  
  49.                        DEEPZOOM - I
  50.  
  51.  
  52.  
  53.               Mandelbrot Set Coloring Method.
  54.  
  55.  
  56.  
  57. One of the most enjoyable things about displaying the Mandelbrot 
  58.  
  59. Set is actually being able to see all the intricate detail after a 
  60.  
  61. lengthy calculation.  This depends on a good choice of palette and
  62.  
  63. color algorithm.  A good palette is one which has no adjacent colors 
  64.  
  65. differing by such a small amount that we can't tell them apart.  
  66.  
  67.  
  68.  
  69. My favorite palettes have no sudden jumps, but instead return 
  70.  
  71. smoothly to the original color.  These provide a continuous sequence 
  72.  
  73. of colors in the display even if the range of banding is great 
  74.  
  75. enough to require more than one pass through the pelette.
  76.  
  77.  
  78.  
  79. Pelettes are defined in the RGB coordinate frame, where intensity
  80.  
  81. of Red, Green and Blue are specified by values between 0 and 63.
  82.  
  83. This is an unnatural system for us, so more useful coordinate
  84.  
  85. systems were invented such as HSV (Hue, Saturation, Value).  Hue 
  86.  
  87. is expressed as an angle in the color wheel.  Saturation specifies 
  88.  
  89. the amount of white or gray in the color.  In DEEPZOOM, I use full 
  90.  
  91. saturation since I want as much color separation as I can get.  
  92.  
  93. Value is a scaling of the intensity ranging from black to full 
  94.  
  95. intensity.
  96.  
  97.  
  98.  
  99. In my early experiments, I used maximum Saturation and let the Hue 
  100.  
  101. range in equal angles around the color wheel.  This resulted in 
  102.  
  103. many adjacent colors being indistinguishable near Blue, Green and 
  104.  
  105. Red.  This color wheel had too few spokes near Cyan, Yellow, and 
  106.  
  107. Magenta.  
  108.  
  109.  
  110.  
  111. Consider the sequence of colors from Green to Yellow.  Colors 
  112.  
  113. formed by ramping Red linearly from 0 to 63 have too little Red 
  114.  
  115. in the steps near Green to be noticable.  Larger steps near Green 
  116.  
  117. are needed with smaller steps near Yellow.  So I tried using a 
  118.  
  119. square root (of component/63) scale.  This made larger steps when 
  120.  
  121. the contribution was small.  This scheme is the one I presently 
  122.  
  123. use in DEEPZOOM.  
  124.  
  125.  
  126.  
  127. Here is my C++ code for the palette specification.  The global 
  128.  
  129. variable 'scales' is the intensity scale factor equivalent to 
  130.  
  131. Saturation. The special_scale function is simply a square root 
  132.  
  133. which can be changed easily.  I use 108 color values to go around 
  134.  
  135. the color wheel, starting with number 20.  I use XOR to paint the 
  136.  
  137. cursor.  The colors XOR with 255 are chosen from the opposite side 
  138.  
  139. of the color wheel so the cursor is clearly visible.
  140.  
  141.  
  142.  
  143. #define COLORSIZE 18
  144.  
  145. #define BRIGHTEST 63.9
  146.  
  147.  
  148.  
  149. float scale,scales;
  150.  
  151. float special_scale(float c){ return(sqrt(c)); }
  152.  
  153. void SetMyColor(int C, int R, int G, int B){
  154.  
  155.   float  red, green, blue, biggest, x;
  156.  
  157.   red=special_scale(R/(float)COLORSIZE);
  158.  
  159.   biggest=red;
  160.  
  161.   green=special_scale(G/(float)COLORSIZE);
  162.  
  163.   if(green>biggest)biggest=green;
  164.  
  165.   blue=special_scale(B/(float)COLORSIZE);
  166.  
  167.   if(blue>biggest)biggest=blue;
  168.  
  169.   // I like my colors bright
  170.  
  171.   x = scale*BRIGHTEST/biggest;
  172.  
  173.   red *= x;
  174.  
  175.   green *= x;
  176.  
  177.   blue *= x;
  178.  
  179.   setrgbpalette(C, (int)red, (int)green, (int)blue);
  180.  
  181. }
  182.  
  183. void MyPalette(void){
  184.  
  185.   int C=20,R,G,B; 
  186.  
  187.   scale=scales;
  188.  
  189.   //  Colors for escapers
  190.  
  191.   for(R=G=0,B=COLORSIZE; G<COLORSIZE; ++G,++C) SetMyColor(C,R,G,B);//B-C
  192.  
  193.   for(R=0,B=G=COLORSIZE; B>0; --B,++C)         SetMyColor(C,R,G,B);//C-G
  194.  
  195.   for(R=B=0,G=COLORSIZE; R<COLORSIZE; ++R,++C) SetMyColor(C,R,G,B);//G-Y
  196.  
  197.   for(B=0,R=G=COLORSIZE; G>0; --G,++C)         SetMyColor(C,R,G,B);//Y-R
  198.  
  199.   for(G=B=0,R=COLORSIZE; B<COLORSIZE; ++B,++C) SetMyColor(C,R,G,B);//R-M
  200.  
  201.   for(G=0,R=B=COLORSIZE; R>0; --R,++C)         SetMyColor(C,R,G,B);//M-B
  202.  
  203.   // and now for the XOR colors (for the cursor and interior)
  204.  
  205.   C=255^20;   scale=1.0;
  206.  
  207.   for(B=0,R=G=COLORSIZE; G>0; --G,--C)         SetMyColor(C,R,G,B);//Y-R
  208.  
  209.   for(G=B=0,R=COLORSIZE; B<COLORSIZE; ++B,--C) SetMyColor(C,R,G,B);//R-M
  210.  
  211.   for(G=0,R=B=COLORSIZE; R>0; --R,--C)         SetMyColor(C,R,G,B);//M-B
  212.  
  213.   for(R=G=0,B=COLORSIZE; G<COLORSIZE; ++G,--C) SetMyColor(C,R,G,B);//B-C
  214.  
  215.   for(R=0,B=G=COLORSIZE; B>0; --B,--C)         SetMyColor(C,R,G,B);//C-G
  216.  
  217.   for(R=B=0,G=COLORSIZE; R<COLORSIZE; ++R,--C) SetMyColor(C,R,G,B);//G-Y
  218.  
  219.   // and make the cursor WHITE over the filements
  220.  
  221.   setrgbpalette(255 ^ LIGHTGRAY, 63, 63, 63);
  222.  
  223.   setrgbpalette(255 ^ DARKGRAY, 63, 63, 63);
  224.  
  225.   setrgbpalette(255 ^ BLACK, 63, 63, 63);
  226.  
  227.   setrgbpalette(255 ^ WHITE, 0, 0, 0);
  228.  
  229. }
  230.  
  231.  
  232.  
  233. Warmly,
  234.  
  235. Jay "It's tonight honey, let's paint the town" Hill
  236.  
  237. -- 
  238.  
  239. { hilljr@jupiter.saic.com } begin writeln(3*ln(640320)/sqrt(163):17:15) end.
  240.  
  241. void main(){double sqrt(), y=1/sqrt(2.), a=.5, m=1,z; int n=0;
  242.  
  243. for(;m*=2,z=sqrt(1-y*y),y=(1-z)/(1+z),a=a*(1+y)*(1+y)-m*y,n<4;n++);
  244.  
  245. printf("%17.15lf\n",1/a);}
  246.  
  247.