Advertisement
Guest User

Untitled

a guest
Nov 7th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 3.23 KB | None | 0 0
  1. ;;-----------------=={ Julia Set Fractal }==------------------;;
  2. ;;                                                            ;;
  3. ;;  The function will create a representation of the Julia    ;;
  4. ;;  set by iteration of the function:                         ;;
  5. ;;                                                            ;;
  6. ;;    f(z) = z^2 + c                                          ;;
  7. ;;                                                            ;;
  8. ;;  Where 'z' & 'c' are complex numbers. The fractal colour   ;;
  9. ;;  is determined by the number of iterations (less than a    ;;
  10. ;;  predetermined maximum iteration number) before the        ;;
  11. ;;  norm of the complex number generated by the above         ;;
  12. ;;  function reaches a limit.                                 ;;
  13. ;;                                                            ;;
  14. ;;  'c' is the constant for each calculation, this            ;;
  15. ;;  distinguishes the Julia set from the Mandelbrot set       ;;
  16. ;;  (in which 'c' is set to the complex values of each point) ;;
  17. ;;  For this reason, there are infinitely many Julia fractals,;;
  18. ;;  but only one Mandelbrot fractal.                          ;;
  19. ;;                                                            ;;
  20. ;;  More interestingly, there exists a Julia fractal for      ;;
  21. ;;  every point of the Mandelbrot fractal.                    ;;
  22. ;;------------------------------------------------------------;;
  23. ;;  Note:                                                     ;;
  24. ;;  --------                                                  ;;
  25. ;;  Fractal calculation is CPU intensive and may take a       ;;
  26. ;;  long time to generate the result. Reduce the iteration    ;;
  27. ;;  limit and image size & resolution to decrease calculation ;;
  28. ;;  time.                                                     ;;
  29. ;;------------------------------------------------------------;;
  30. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  31. ;;------------------------------------------------------------;;
  32.  
  33. (defun c:jfract ( / a b c i im[c] lim re[c] res x xmax xmin y ymax ymin )
  34.     (setvar 'PDMODE 0)
  35.     (setq
  36.         lim 255     ;; Iteration Limit
  37.  
  38.         xmin -0.60  ;; }
  39.         xmax -0.30  ;; | Image
  40.         ymin -0.35  ;; | Size
  41.         ymax -0.05  ;; }
  42.  
  43.         res 0.0025  ;; Image Resolution
  44.  
  45.         Re[c] 0.285 ;; Real Coefficient of Julia Constant
  46.         Im[c] 0.01  ;; Imaginary Coefficient of Julia Constant
  47.     )
  48.     (setq x (- xmin res))
  49.     (while (<= (setq x (+ x res)) xmax)
  50.         (setq y (- ymin res))
  51.         (while (<= (setq y (+ y res)) ymax)
  52.             (setq
  53.                 i 0
  54.                 a x
  55.                 b y
  56.             )
  57.             (while
  58.                 (and
  59.                     (< (+ (* a a) (* b b)) 4.)
  60.                     (<= (setq i (1+ i)) lim)
  61.                 )
  62.                 (setq
  63.                     c (* 2.0 a b)
  64.                     a (+ (- (* a a) (* b b)) Re[c])
  65.                     b (+ c Im[c])
  66.                 )
  67.             )
  68.             (entmake
  69.                 (list
  70.                    '(0 . "POINT")
  71.                     (list 10 x y)
  72.                     (cons 62 (1+ (rem (+ 30 i) 255)))
  73.                 )
  74.             )
  75.         )
  76.     )
  77.     (princ)
  78. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement