public
Last active

Mandelbrot Set ASCII art for newLISP

  • Download Gist
mandelbrot.lsp
Common Lisp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#!/usr/bin/env newlisp
 
;;; Mandelbrot Set ASCII art (tested newLISP v.10.3.0)
 
;;; Original: (Common Lisp)
;; - http://groups.google.com/group/comp.lang.lisp/msg/d786bbde308e8175
;; - http://bc.tech.coop/blog/040811.html
 
;;; Usage:
;; $ ./mandelbrot.lsp
;;
;; ~~~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}||||||||{{{zyvrwuR{|||||}}}}}}~~~~~~~~~~~~~
;; ~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}|||||||||{{{zyxwoaqwxz{{{|||||}}}}}}~~~~~~~~~~
;; ~~~~~~~~}}}}}}}}}}}}}}}}}}}|||||||||{{zzzyxvn Knwyz{{{{||||}}}}}}~~~~~~~~
;; ~~~~~~}}}}}}}}}}}}}}}}}}||||||||{{zyxuxxxwvuq svwwyzzzyr{||}}}}}}}~~~~~~
;; ~~~~}}}}}}}}}}}}}}}}}|||||{{{{{zzzxt> qf pttfqeqz{|}}}}}}}}~~~~
;; ~~~}}}}}}}}}}}}}}|||{{{{{{{{{zzzywotn atyz{||}}}}}}}}~~~
;; ~~}}}}}}}}}||||{{zwvyyyyyyyyyyyxvsP swvz{||}}}}}}}}~~
;; ~}}}}|||||||{{{{zyxvpN[ur]spvwwvi qxz{|||}}}}}}}}~
;; ~}||||||||{{{{{zyytun qq avz{|||}}}}}}}}~
;; ~||||||{zzzzyyxtroqb a xz{{|||}}}}}}}}~
;; ~>E9. 4" % pvxyz{{||||}}}}}}}~
;; ~||||||{zzzzyyxtroqb a xz{{|||}}}}}}}}~
;; ~}||||||||{{{{{zyytun qq avz{|||}}}}}}}}~
;; ~}}}}|||||||{{{{zyxvpN[ur]spvwwvi qxz{|||}}}}}}}}~
;; ~~}}}}}}}}}||||{{zwvyyyyyyyyyyyxvsP swvz{||}}}}}}}}~~
;; ~~~}}}}}}}}}}}}}}|||{{{{{{{{{zzzywotn atyz{||}}}}}}}}~~~
;; ~~~~}}}}}}}}}}}}}}}}}|||||{{{{{zzzxt> qf pttfqeqz{|}}}}}}}}~~~~
;; ~~~~~~}}}}}}}}}}}}}}}}}}||||||||{{zyxuxxxwvuq svwwyzzzyr{||}}}}}}}~~~~~~
;; ~~~~~~~~}}}}}}}}}}}}}}}}}}}|||||||||{{zzzyxvn Knwyz{{{{||||}}}}}}~~~~~~~~
;; ~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}|||||||||{{{zyxwoaqwxz{{{|||||}}}}}}~~~~~~~~~~
;; ~~~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}||||||||{{{zyvrwuR{|||||}}}}}}~~~~~~~~~~~~~
;; ~~~~~~~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}}|||||{zmt{{{||||}}}}}~~~~~~~~~~~~~~~~~
 
 
;; this is FOOP (Functional Object Oriented Programming) application.
;; http://www.newlisp.org/complex.txt
 
(new Class 'Complex)
 
(define (Complex:rad )
(sqrt (add (pow (self 1)) (pow (self 2)))))
 
(define (Complex:add b)
(Complex (add (self 1) (b 1)) (add (self 2) (b 2))) )
 
(define (Complex:mul b)
(let ((a.re (self 1)) (a.im (self 2))
(b.re (b 1)) (b.im (b 2)))
(Complex (sub (mul a.re b.re) (mul a.im b.im))
(add (mul a.re b.im) (mul a.im b.re)))))
 
 
(context MAIN)
 
(for (y -1 1.1 0.1)
(for (x -2 1 0.04)
(letn ((c 126)
(z (Complex x y))
(a z))
(while (and (begin
(setq z (:add (:mul z z) a))
(< (abs (:rad z)) 2))
(< 32 (dec c))))
(print (char c))))
(println))
 
(exit)
 
;;; EOF

FIXME: FOOPの仕様変更のおかげで現行のnewLISP(v10.2.8)ではComplex周りが動かない

直した (2011-02-03)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.