Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.