
M"Gc           @   sj  d  Z  d Z d Z y e Wn d@ \ Z Z n Xy d d k Z d d k Z d d k Z d d k Z d d k	 Z	 e i
 i e i
 i e	 i e i    d d d	   e e e i
  Z d d
 k l Z l Z Wn1 y e i i d e  Wn e GHn X  n Xe i
 i e i d  d Z e i
 i e  d Z e i d  i e  i   Z d   Z d   Z d   Z h  d d <d d <d d <d d <d d <d d <e i d <d d <d d <d d <d  d! <Z! d"   Z" d#   Z# d$   Z$ d%   Z% d&   Z& d'   Z' d(   Z( d)   Z) d*   Z* d+   Z+ d,   Z, d-   Z- d.   Z. d/   Z/ d0   Z0 d1   Z1 d2   Z2 d3   Z3 d4   Z4 d5   Z5 d6   Z6 d7   Z7 d8   Z8 d9   Z9 d:   Z: e; d; j o e Z< e i d Z= e e j oR yD e> e=  o3 e? d< e= d  o e i d Z< e i d= Z= n Wq:q:Xn e? d> e< e e@ e=   f  p d? GHn d S(A   sb   simple program to create Mandelbrot set

   this takes command-line arguments to create a PPM files-  
    mandelgen -- generate image of Mandelbrot set
    Copyright (C) 2005  John Comeau <jc.jcomeau.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    s7   Not all needed libraries found, upgrade or check path: i   i    iNi   t   libt   python(   t   gplt	   jclicenses   %s
s   [0-9A-Za-z]+c          G   s   t  S(   N(   t   False(   t   whatever(    (    s   ./mandelgen.pyt
   DebugPrint2   s    c          G   s   |  \ } } t  |  t i j o t |  } n t t d  o | i |  Sn^ d } xP t d t |   D]9 } | | | } | t |  d j o | | } qo qo W| Sd S(   s   for pythons without str.joint   joint    i    i   N(	   t   typet   typest
   StringTypet   evalt   hasattrt   strR   t   ranget   len(   t   argst   stringt   arrayt   joinedt   index(    (    s   ./mandelgen.pyR   5   s    & c          G   sg   |  \ } } t  |  p
 d } n t d d  o | i |  Sn  t i t i |   i |  Sd S(   s   for pythons without str.splitR   t   splitN(   R   t   NoneR   R   t   ret   compilet   escape(   R   R   t   string_to_split(    (    s   ./mandelgen.pyR   C   s
    g      t   xg        t   yi@  t   widthi   t   heightt   ratiog      ?t   zoomt   outputt   colorst   maxiterationsi   t   maxvaluei   t
   ppm_maxvalc       	   G   s]   t  d |   t |   t   t  d t d t d t d t d t d t d  t   d	 S(
   s   main routine

    creates PPM image of Mandelbrot set at a particular location and zoom level
    each pixel is z -> z^2 + z0
 R   t   currentR   R   R   R   R    R!   N(   R   t   initt	   ppmheaderR'   t   gen_by_pixel(   R   (    (    s   ./mandelgen.pyt	   mandelgen]   s    
c          G   s  t  d } } t i i d  t d  o d t d <n x'| t d t d j  o| t d t | t d  } } t t |  t	 |   t d d  d } } } xm | t d j  o[ | | | } y> | i
 d | i d t d	 j  o | d
 7} n
 t d  Wq Pq Xq Wt |  | o) | t d d j o t i i d  n | d
 7} q; W| o t i i d  n d  S(   Ni    s#   Showing one dot per line processed
s   gen_by_pixel() startingi   R$   R   R   i   R%   i   t   escapedt   .s   
(   t   Truet   syst   stderrt   writeR   R'   t   intt   complext
   widthvaluet   heightvaluet   realt   imagt	   Exceptiont   ppmpixel(   R   t   showprogressR   R   R   t   ct   zt
   iterations(    (    s   ./mandelgen.pyR*   j   s*    #2#

c         C   s;   |  | \ } } \ } } | | | | | | | | g S(   N(    (   t   it   jt   at   bR;   t   d(    (    s   ./mandelgen.pyt   complex_multiply   s    c         C   s+   |  | \ } } \ } } | | | | g S(   N(    (   R>   R?   R@   RA   R;   RB   (    (    s   ./mandelgen.pyt   complex_add   s    c          G   s4   t  d t  d } |  d } t  d | | t  d S(   Nt   topt   bottomi    R   (   R'   (   R   t
   heightspant   pixelheight(    (    s   ./mandelgen.pyR5      s    
c          G   s4   t  d t  d } |  d } t  d | | t  d S(   Nt   rightt   lefti    R   (   R'   (   R   t	   widthspant
   pixelwidth(    (    s   ./mandelgen.pyR4      s    
c          C   s7   t    t t t d  }  t |   } t d |  | S(   NR#   t   maxval(   R(   t   mapt   maxR'   R   (   t   maxrgbRM   (    (    s   ./mandelgen.pyt   find_maxval   s
    c          G   s  t  d d  j oot |   d j o |  d }  n t d |   t |   d j o- t |  d  t |  d  t  d <t  d <n d t  d d	 t  d
 <t |   d j o- t |  d  t |  d  t  d <t  d <n t |   d j o t |  d  t  d <n t } t |   d j o t |  d  } n t |   d j oP y. d d  k } | i	   t
 i i d d  Wqt
 i i d d  qXn |   t  d <t   t  d <t t  d  d t  d <t d t  d  t t  d
  t  d t  d
 <t  d t  d t  d
 d t  d <t  d t  d t  d
 t  d <t  d t  d t  d
 d t  d <t  d t  d t  d
 t  d <t   t  d <n d  S(   NR#   i   i    s   init() argsi   R   R   g      @id   R    i   i   R   R   i   R!   i   i   is   %s
s!   Psyco loaded for faster executions*   Psyco could not be loaded; expect slowdownR&   R$   RF   RE   RJ   RI   t   pixels(   R'   R   R   R   R2   t   floatt	   rgbvaluesR   t   psycot   fullR/   R0   R1   RQ   t   colormap(   R   t   colorgeneratorRU   (    (    s   ./mandelgen.pyR(      s>    !--
"c         C   s5   d } x( |  D]  } | d K} | | d j O} q W| S(   Ni    i   t   1(    (   t   binary_stringt   numbert	   character(    (    s   ./mandelgen.pyt   binary   s     
c          G   s   d d d g S(   s6   simple 3-pass coloring scheme to match WikiHow articlei   i    (   i   i    i    (   i    i   i    (   i    i    i   (    (   R   (    (    s   ./mandelgen.pyt   rgb   s    c          G   sv   g  } g  } t  d d d  D]1 } | | d d f d | d f d d | f g q ~ } x | D] } | | 7} q^ W| S(   s.   alternate r, g, b darker and darker to 0, 0, 0i   ii    (   R   (   R   t   valuest   _[1]t   colorR#   t   triplet(    (    s   ./mandelgen.pyt	   rgb2black   s    J c          G   sb   t  d  } t  d  } g  } t | d d  D]& } | d | | d >| | d >f q/ ~ } | S(   sp  define start color as cyan: r=0 g>=b

    decrement for each iteration such that 0 is black
    to match the colorForth program, g must be 6 bits and b 5, with the low
    bits of each cleared, and two subtracted each time
    also, found out that the g and b values must be shifted into the
    high-order bits of their respective bytes, to match colorForth results
 t   11111011110t   100000ii    i   i   (   R]   R   (   R   t   cyant   divisorR`   Ra   R_   (    (    s   ./mandelgen.pyRT      s
    	?c          G   s:   g  } t  d d d  D] } | d d | f q ~ } | S(   s   use blue values from 1023 to 0i  ii    (   R   (   R   R`   Ra   R_   (    (    s   ./mandelgen.pyt
   bluevalues   s    6c          G   s   g  } t  d d d  D] } | | d d f q ~ g  } t  d d d  D] } | d | d f qJ ~ g  } t  d d d  D] } | d d | f q~ ~ } | S(   s,   progress from white to cyan to blue to blacki   ii   i    (   R   (   R   R`   t   redt   _[2]t   greent   _[3]t   blueR_   (    (    s   ./mandelgen.pyt   shadesofblue   s    g7c       	   G   sn   g  } t  d d d  D] } | d | d f q ~ g  } t  d d d  D] } | d d | f qJ ~ } | S(   s#   progress from cyan to blue to blacki  i    ii  (   R   (   R   R`   Rk   Rj   Rm   R_   (    (    s   ./mandelgen.pyt   shadesofblue2   s    37c          G   s>   g  } t  d d  D] } | d | | f q ~ d g } | S(   s<   go from dark to light until the black of the Mandelbrot lakei   i   i  i    (   i    i    i    (   R   (   R   R`   Ra   R_   (    (    s   ./mandelgen.pyt   inverse_red   s    :c          G   s>   g  } t  d d  D] } | | | d f q ~ d g } | S(   s<   go from dark to light until the black of the Mandelbrot lakei    i   i  (   i    i    i    (   R   (   R   R`   Ra   R_   (    (    s   ./mandelgen.pyt   inverse_blue   s    :c          G   s^   g  } xQ t  d d d  D]= } x4 t  | d d  D]  } | | | | | f g 7} q2 Wq W| S(   sJ   Fn's alternating color scheme

    e.g. yellow rg0 fading into magenta r0bi   ii(   R   (   R   R_   t   stepRa   (    (    s   ./mandelgen.pyt   fnbrot  s      "c       	   G   sn   g  } t  d d d  D] } | d | | f q ~ g  } t  d d d  D] } | d d | f qJ ~ } | S(   s   cyan to black, blue to blacki  ii    (   R   (   R   R`   Ra   Rj   Rm   R_   (    (    s   ./mandelgen.pyt   twotoneblue  s    37c          G   s   g  } t  d d d  D]a } | | | | f | | d f | d | f d | | f d d | f | d d f d | d f g q ~ } g  } x | D] } | i |  q W| d g 7} | d S(   sg   switch between different color patterns from white to black

    it looks Peter Max-ish, hence the namei   i    ii(   i    i    i    (   R   t   extend(   R   R`   Ra   R_   R#   Rb   (    (    s   ./mandelgen.pyt	   maxelbrot  s    z c             s  t    t d  o d t d <n t d d t t d  j  o t t d  t d d   t t d  t d d o   d 7  n t d    t   f d   t d  } xC t |  t d d j  o | i t d d  q Wn t d } t d	 t |   | S(
   Ns   testing colormapi   R$   i   R#   Rg   c            s   t  d  i |     d j S(   R#   i    (   R'   R   (   t   s(   Rg   (    s   ./mandelgen.pyt   <lambda>0  s    is   len(colormap)(   R(   R   R'   R   t   filtert   append(   R   RW   (    (   Rg   s   ./mandelgen.pyRW   &  s     

c           C   s1   t  d i d d t  d t  d t  d f  d  S(   NR"   s   %s %d %d %d
t   P6R   R   R&   (   R'   R1   (    (    (    s   ./mandelgen.pyR)   9  s    c      	   C   s   t  d |  \ } } } t  d d j  o" t  d i d | | | f  n@ t  d i d | d ?| d | d ?| d | d ?| d f  d  S(   NRR   R&   i   R"   s   %c%c%cs   %c%c%c%c%c%ci   (   R'   R1   (   R=   t   rt   gRA   (    (    s   ./mandelgen.pyR9   =  s
    "c          G   s0   t  d d  t d <t |    t t d  GHd  S(   Ns	   /dev/nullt   wR"   R#   (   t   openR'   t	   colortestR   (   R   (    (    s   ./mandelgen.pyt   colorlengthE  s    
c          G   s   d \ } } t |   o t |  d    } n t i i d  t d  t t |  | d d d |  d  t   t	 t
 d  x; t |  D]- } x$ t t |   D] } t |  q Wq Wd  S(   Ni
   i    s.   colortest must be called with a function name
i   RR   (   Ni
   (   R   R   R   R/   R0   R1   t   exitR(   R)   R   R'   R   R9   (   R   RX   R   R#   t   rowt   column(    (    s   ./mandelgen.pyR   J  s    
#  t   __main__s   type(%s) == types.FunctionTypei   s   %s%sR   (   i   i    (A   t   __doc__t	   Copyrightt   errormessageR.   R   R/   t   osR
   R   t   pwdt   pathRz   R   t   getpwuidt   geteuidt   reprt   com.jcomeauR   R   R0   R1   R   t   argvt   myselft   splitextt   commandR   t   searcht   groupt   originalselfR   t   stdoutR   R'   R+   R*   RC   RD   R5   R4   RQ   R(   R]   R^   Rc   RT   Rh   Rn   Ro   Rp   Rq   Rs   Rt   Rv   RW   R)   R9   R   R   t   __name__t   functionR   R   R   t   tuple(    (    (    s   ./mandelgen.pys   <module>   s   <5				
																	#											
							"",