Skip to content

Instantly share code, notes, and snippets.

@soma-arc
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soma-arc/9564293 to your computer and use it in GitHub Desktop.
Save soma-arc/9564293 to your computer and use it in GitHub Desktop.
void setup(){
size(500, 500);
translate(250, 250);
String lines[] = loadStrings("mandelbrot.csv");
for(String line : lines){
String tmp[] = line.split(",");
float x = (float(tmp[0]));
float y = (float(tmp[1]));
int count = 0;
if(!tmp[2].equals("NIL")){
count = int(tmp[2]);
}
stroke(0, count * 255 / 12, count * 255 / 12);
point(round(x * 100), round(y * 100));
}
}
(defparameter *width* 500)
(defparameter *height* 500)
(defparameter *reduction* 100.0)
(defun get-latice-points (width height reduction)
(apply #'append (loop for x from (* -1 (/ width 2)) below (1+ (/ width 2))
collect (loop for y from (* -1 (/ height 2)) below (1+ (/ height 2))
collect (complex (/ x reduction) (/ y reduction))))))
(defun calc-mandelbrot (c)
(labels ((f (z c n)
(cond ((= n 27) `(,c nil))
((< 2 (abs z)) `(,c ,n))
(t (f (+ c (expt z 2)) c (1+ n))))))
(f 0 c 0)))
(defun get-mandelbrot ()
(mapcar #'calc-mandelbrot (get-latice-points *width* *height* *reduction*)))
(defun to-csv (coordinates-count)
(let ((coordinates (car coordinates-count))
(recursion-count (cadr coordinates-count)))
(concatenate 'string
(write-to-string (realpart coordinates) ) "\,"
(write-to-string (imagpart coordinates) ) "\,"
(write-to-string recursion-count))))
(defun to-csv-file (calculated-latice-points)
(with-open-file (*standard-output* "mandelbrot.csv"
:direction :output
:if-exists :supersede)
(mapcan (lambda (s)
(format t (concatenate 'string s "~%")))
(mapcar #'to-csv calculated-latice-points))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment