mò
ÊFc           @   s³  d  Z  d Z d Z y e Wn d7 \ Z Z n XyŒ d k Z d k Z d k Z d k Z d k	 Z	 e i
 i e i
 i e	 i e i ƒ  ƒ d d d ƒ ƒ e e e i
 ƒ Z 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 d „  Z d k  Z  d k! Ty d k" Z" Wn e d ƒ n Xh  d e d ƒ <d e d ƒ <d e d ƒ <d e d ƒ <Z# d Z$ d Z% d a& d a' e( e# ƒ Z) d Z* d g e$ e% Z+ d d >d Z, e d ƒ Z- e. e+ ƒ e. e+ ƒ a/ a0 e. e+ ƒ Z1 d „  Z2 d  e  i3 f d! „  ƒ  YZ4 d" „  Z5 d# „  Z6 d$ „  Z7 d% „  Z8 d& „  Z9 d' „  Z: d( „  Z; d) „  Z< d* „  Z= d+ „  Z> d, „  Z? d- „  Z@ d. „  ZA d/ „  ZB d0 „  ZC d1 „  ZD eE d2 j ož e ZF e i d ZG e e j oR yD eH eG ƒ o3 eI d3 eG d ƒ o e i d ZF e i d4 ZG n WqƒqƒXn eI d5 eF e eJ eG ƒ ƒ f ƒ p d6 GHn d S(8   sd   simple program to display Mandelbrot set

   this variation uses integers instead of complex numberss3  
    mandelbrot_int32 -- display 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    Ni   t   libt   python(   s   gpls	   jclicenses   %s
s   [0-9A-Za-z]+c          G   s   t  S(   N(   t   False(   t   whatever(    (    t   mandelbrot_int32.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   argst   stringt   arrayt   typet   typest
   StringTypet   evalt   hasattrt   strR   t   joinedt   ranget   lent   index(   R   R   R	   R   R
   (    (    R   R   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   R	   t   string_to_splitR   t   NoneR   R   t   ret   compilet   escape(   R   R	   R   (    (    R   R   C   s      
c         C   sx   t  } |  d j  o |  t }  } n t |  ƒ d >t |  t |  ƒ d d >ƒ B} | o d | } n t d | ƒ | S(   sb   convert floating point to A(3,28) fixed point

    see http://home.earthlink.net/~yatescr/fp.pdf
 i    i   i   l        s	   fixed: %xN(   R   t   negativet   it   Truet   intt   jR   (   R   R   R   (    (    R   t   fixedM   s     ,(   t   *s4   could not import mandelbrot.py for comparison checkst   leftf-2.1000000000000001t   rightf1.1000000000000001t   topf1.2t   bottomf-1.2i@  ið   s   #%02x%02x%02xi   i   c          G   sG   t  d t t t ƒ t ƒ  t i ƒ  } t ƒ  } | i
 ƒ  | i ƒ  d S(   sm   main routine

    draws outline of Mandelbrot set, eventually to allow zoom
    each pixel is z -> z^2 + z0
 s   myself, command, originalselfN(   R   t   myselft   commandt   originalselft   initconstantst   Tkintert   Tkt   tkt
   Mandelbrott   framet   packt   mainloop(   R   R.   R,   (    (    R   t   mandelbrot_int32r   s     	
R-   c           B   s2   t  Z d „  Z e Z d „  Z d „  Z d „  Z RS(   Nc         C   s´   t  i i |  ƒ t  i |  d t d t ƒ|  _ |  i i ƒ  t  i |  ƒ |  _	 t  i
 |  i	 d d d |  i ƒi d t ƒ t  i
 |  i	 d d d |  i ƒi d t ƒ |  i	 i ƒ  d  S(   Nt   widtht   heightt   textt   GoR'   t   sidet   Quit(   R*   t   Framet   __init__t   selft   CanvasR2   R3   t   canvasR/   t	   buttonbart   Buttont   generatet   LEFTt   stop(   R:   (    (    R   R9   €   s    c         G   s  |  i i d d ƒ x• t t ƒ D]‡ } |  i o d  Sn xl t t ƒ D]^ } | t | } t
 t | } |  i i | | | d | h  d t | | | f <ƒ t | <qE Wq  WxK t t
 ƒ D]= } |  i o d  Sn t d | d ƒ |  i ƒ  |  i ƒ  q¸ Wt d t ƒ |  i i d d ƒ d  S(   Nt   cursort   waiti   t   fills   starting iterationt
   iterationsR   (   R:   R<   t   configR   R3   t   yt   stop_requestedR2   t   xR   t   maxiterationsRE   R   t   create_linet   colort   pixelst   nR   t   iteratet   update(   R:   R   R   R   RG   RI   RN   (    (    R   R?      s(     
  + 
 
c      
   G   sí  xæt  t t ƒ ƒ D]Ò} t | t ƒ | t t | } } } y t	 | ƒ t | <Wn t
 d | t | ƒ n Xt | } | d d @| d j p | d d @| d j o= t d | | t | ƒ f ƒ t d ƒ t d ƒ g t | <n y¸ t t | d ƒ t ƒ o‘ t t | d ƒ t ƒ ow t t | d ƒ t | d ƒ t ƒ oO t | c d 7<t t | } |  i i t | h  d t | | | f <ƒ n
 t d ‚ Wq t d	 | | t | ƒ f ƒ t d ƒ t d ƒ g t | <q Xq Wd  S(
   Nt   faili    l   ÿÿ i   s   overflow at x=%d, y=%d, z=%si   RD   s   max reached at this pixels   max at x=%d, y=%d, z=%s(   R   R   t   valuesR   R   R2   RI   RG   t   zt   update_pixelRQ   t	   constantsR   t   show_complexR    t   lesst	   fixed_abst   maxvaluet   squareRE   RJ   R   R:   R<   t   itemconfigureRM   RL   t	   Exception(   R:   R   R   RS   R   RG   RI   (    (    R   RO   ž   s(     &
2 \1c         C   s   t  |  _ |  i ƒ  d  S(   N(   R   R:   RH   t   quit(   R:   (    (    R   RA   ¸   s    	(   t   __name__t
   __module__R9   R   RH   R?   RO   RA   (    (    (    R   R-      s
   			c         C   s$   t  |  } t t | | ƒ t |  ƒ S(   N(   RR   R   RS   t   complex_addt   complex_multiplyRU   (   R   RS   (    (    R   RT   ¼   s    
c         C   s_   |  | \ } } \ } } t t | | ƒ t t | | ƒ ƒ ƒ t t | | ƒ t | | ƒ ƒ g S(   N(	   R   R   t   at   bt   ct   dt	   fixed_addt   fixed_multiplyt   neg(   R   R   Rb   Rd   Rc   Re   (    (    R   Ra   À   s    c         C   sD   |  \ } } t t | | ƒ t t | | ƒ ƒ ƒ d t | | ƒ g S(   Ni   (   R   Rb   Rc   Rf   Rg   Rh   (   R   Rb   Rc   (    (    R   t   complex_squareÅ   s    c         C   s5   |  | \ } } \ } } t | | ƒ t | | ƒ g S(   N(   R   R   Rb   Rc   Rd   Re   Rf   (   R   R   Rb   Rd   Rc   Re   (    (    R   R`   Ê   s    c         C   s%   |  } |  d j o d |  } n | S(   s   negate fixed-point numberi    l        N(   R   R   (   R   R   (    (    R   Rh   Î   s
     c         C   s%   |  } |  d @o t |  ƒ } n | S(   s+   return absolute value of fixed-point numberl        N(   R   R   Rh   (   R   R   (    (    R   RX   Õ   s
     c         C   s   t  |  |  ƒ } | S(   s   square fixed-point numberN(   Rg   R   R   (   R   R   (    (    R   RZ   Ü   s     c      	   C   s]   t  i i |  d t | d ƒ t | d ƒ t | d ƒ t | d ƒ f ƒ t  i d ƒ d S(   s)   report error with current pixel, then dies&    z=z**2+c with z=(%f,%f) and c=(%f,%f)i    i   N(   t   syst   stderrt   writet   messaget
   show_fixedRS   Rd   t   exit(   Rm   RS   Rd   (    (    R   RQ   â   s     Lc         C   sá   t  o* t d |  t |  ƒ | t | ƒ f ƒ n t  } t |  ƒ t |  ƒ j p t | ƒ t | ƒ j o t |  ƒ t | ƒ }  } n |  d @o |  d 8}  n | d @o | d 8} n |  | } | d j  o | d 7} n | S(   s'   simulate 32-bit microprocessor additions6   adding fixed-point numbers 0x%08x (%f) and 0x%08x (%f)l        l        i    N(
   R   R   R   Rn   R   R   t   floatR   R    t   k(   R   R   Rq   R   (    (    R   Rf   è   s     *2
c         C   se   |  d @o | d @o d SnC |  d @o | d @o d Sn$ |  d @o |  | j Sn |  | j  Sd  S(   Nl        i   i    (   Rb   Rc   (   Rb   Rc   (    (    R   RW   ù   s    c      	   C   sÿ   t  } t |  ƒ t |  ƒ j p t | ƒ t | ƒ j o t |  ƒ t | ƒ }  } n |  d @o | } t |  ƒ }  n | d @o | } t | ƒ } n |  | d ?} | o t | ƒ } n t	 o6 t
 d |  t |  ƒ | t | ƒ | t | ƒ f ƒ n | S(   s{   see PDF file referenced by fixed()

    A(a1,b1) * A(a2,b2) = A(a1+a2+1,b1+b2)
    using A(3,28) fixed-point representationl        i   s!   0x%x (%f) * 0x%x (%f) = 0x%x (%f)N(   R   R   Rp   R   R   R   R    Rh   Rq   R   R   Rn   (   R   R   Rq   R   (    (    R   Rg     s      26c         C   s'   |  d @o |  d 8}  n t |  ƒ d S(   Nl        l        i   (   R   Rp   (   R   (    (    R   Rn     s    c         C   s"   |  \ } } t | ƒ t | ƒ f S(   N(   Rb   R   R   Rn   (   Rb   R   R   (    (    R   RV     s    c          G   s›   |  d } t t d t t t t t | ƒ t	 ƒ ƒ ƒ ƒ } t ƒ  oQ t i | ƒ } t | t | ƒ ƒ d j o! t d | t | ƒ | f ƒ q— n | S(   Ni    R$   f0.01s   height: %08x (%f) != %f(   R   t   pixelheightRf   t   currentRh   Rg   t
   heightspanR    Rp   R3   t   valueR   t
   mandelbrott   heightvaluet   comparet   absRn   (   R   Rx   Ru   Rr   (    (    R   Rw   "  s    

(
%c          G   s•   |  d } t t d t t t t | ƒ t ƒ ƒ ƒ } t
 ƒ  oQ t i | ƒ } t | t | ƒ ƒ d j o! t
 d | t | ƒ | f ƒ q‘ n | S(   Ni    R"   f0.01s   width: %08x (%f) != %f(   R   t
   pixelwidthRf   Rs   Rg   t	   widthspanR    Rp   R2   Ru   R   Rv   t
   widthvalueRx   Ry   Rn   (   R   Rx   Ru   Rz   (    (    R   R|   ,  s    

"
%c          G   s  t  t d t t d ƒ ƒ a t d t t t ƒ f ƒ t  t d t t d ƒ ƒ a t d t t t ƒ f ƒ xQ t t t	 ƒ ƒ D]= } | t t | t ƒ } } t | ƒ t | ƒ g t	 | <q Wt t	 ƒ a t d t t t	 d d	 !ƒ d
 t t t	 d ƒ ƒ d  S(   NR$   R%   s   heightspan: 0x%08x (%f)R#   R"   s   widthspan: 0x%08x (%f)s   constants initializedi    i
   s   ...iöÿÿÿ(   Rf   Rs   Rh   Rt   R   Rn   R{   R   R   RU   RN   R2   R   RI   RG   R|   Rw   t   listRR   t   mapRV   (   R   RN   RG   RI   (    (    R   R)   6  s       t   __main__s   type(%s) == types.FunctionTypei   s   %s%sR   (   i   i    (K   t   __doc__t	   Copyrightt   errormessageR   R   Rj   t   osR   R   t   pwdt   patht   appendR   t   getpwuidt   geteuidt   reprt   com.jcomeaut   gplt	   jclicenseRk   Rl   R   t   argvR&   t   splitextR'   R   t   searcht   groupR(   R   R    R*   t   TkconstantsRv   t   startR2   R3   Rt   R{   t   dictRs   RL   RE   RJ   RY   R}   RU   RR   RM   R1   R8   R-   RT   Ra   Ri   R`   Rh   RX   RZ   RQ   Rf   RW   Rg   Rn   RV   Rw   R|   R)   R^   t   functionR   R   R   t   tuple(1   Ri   RZ   R   RW   RL   R-   Rv   R3   R   RQ   RV   RE   R|   R‹   Rw   R)   R’   Rh   Rf   Ra   Rs   R   R1   R   R   R”   R*   R(   R   Rj   R„   R`   R   RM   R   R&   RJ   R   Rg   R‚   RY   Rn   RŒ   R'   RX   RT   R    Rƒ   R2   (    (    R   t   ?   sŠ   -5				
		B	=										
				
	
	"" 