Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun mandelbrot-value (w h d x y)
- "Find the Mandelbrot value from a scaled set"
- (let* ((cx (* 1.5 (/ (- x (/ w 1.45)) w 0.45)))
- (cy (* 1.5 (/ (- y (/ h 2.0)) h 0.5)))
- (zr 0)
- (zi 0))
- (dotimes (i d d)
- (if (> (+ (* zr zr) (* zi zi)) 4)
- (return i)
- (psetq zr (+ (* zr zr) (- (* zi zi)) cx)
- zi (+ (* zr zi 2) cy))))))
- (defun mandelbrot-image (w h d)
- "Sometimes I get bored and render the Mandelbrot set in Emacs Lisp"
- (interactive "nWidth: \nnHeight: \nnDepth: ")
- (pop-to-buffer (get-buffer-create "*mandelbrot*"))
- (fundamental-mode)
- (erase-buffer)
- (set-buffer-multibyte nil)
- (insert (format "P6\n%d %d\n255\n" w h))
- (dotimes (y h)
- (dotimes (x w)
- (insert-char (floor (* 256 (/ (mandelbrot-value w h d x y) 1.0 d))) 3)))
- (image-mode))
- (defun mandelbrot-text (w h d)
- "Sometimes it needs to be textual"
- (interactive "nWidth: \nnHeight: \nnDepth: ")
- (pop-to-buffer (get-buffer-create "*mandelbrot*"))
- (fundamental-mode)
- (erase-buffer)
- (set-buffer-multibyte nil)
- (dotimes (y h)
- (dotimes (x w)
- (let* ((v (mandelbrot-value w h d x y))
- (c (cond ((= v d) ? )
- ((evenp v) ?*)
- (t ?#))))
- (insert-char c 1)))
- (insert-char ?\n 1)))
- (provide 'mandelbrot-image)
- (provide 'mandelbrot-text)
Add Comment
Please, Sign In to add comment