lisp or draw error



>> complex numbers. The Lisp code runs 60 times faster. If you are 
>> interested I can look for it tomorrow...

> Yes please do.
> 

Please, note that this code was written for fun and that it could be 
improved in several ways,



/*
c: complex parameter
p1, p2: complex vertices of the rectangular window
    on the complex plane, bottom left and top right,
    respectively
nr, ni: number of discrete points on the real and
    imaginary direction, respectively
*/
conjulia(c,p1,p2,nr,ni):=
    block([rmin   : float(realpart(p1)),
           rmax   : float(realpart(p2)),
           imin   : float(imagpart(p1)),
           imax   : float(imagpart(p2)),
           maxiter: 50,
           maxabs : 100,
           dr,di,jcz, absjcz],
       dr: (rmax-rmin)/nr,
       di: (imax-imin)/ni,
       apply(matrix,
             makelist(
                makelist(
                   (absjcz: abs(jcz: (rmin+i*dr) + %i*(imax-j*di)),
                    for n:1 while n < maxiter and absjcz < maxabs do
                       absjcz: abs(jcz: expand(jcz^2 + c)),
                    absjcz),
                   i,0,nr-1),
                j,0,ni-1)) )$




;; Parameters are the same as above
;;
(defun $conjulia2 (c p1 p2 nr ni)
   (let* ((rmin ($float ($realpart p1)))
          (rmax ($float ($realpart p2)))
          (imin ($float ($imagpart p1)))
          (imax ($float ($imagpart p2)))
          (dr (/ (- rmax rmin) nr))
          (di (/ (- imax imin) ni))
          (maxiter 50)
          (maxabs 100)
          (c (complex ($float ($realpart c))
                      ($float ($imagpart c))))
          jcz absjcz)
     (cons '($matrix)
           (loop for j below ni
             collect (cons '(mlist)
                           (loop for i below nr
                             do (setf jcz (complex (+ rmin (* i dr))
                                                   (- imax (* j di))))
                                (setf absjcz (abs jcz))
                                (loop for n from 1 to maxiter
                                  do (setf jcz (+ (* jcz jcz) c))
                                     (setf absjcz (abs jcz))
                                     (when (>= absjcz maxabs) (return)))
                             collect absjcz))))))


Example of use:


m2: conjulia2(-0.4+%i*0.6, -1.5-1.5*%i, 1.5+1.5*%i, 200, 200) $
m2: matrixmap(log,m2) $
draw2d(image(m2, -1.5,-1.5,3,3),
        palette=[12,-34,21]) $


-- 
Mario Rodriguez Riotorto
http://www.telefonica.net/web2/biomates