Skip to content

Instantly share code, notes, and snippets.

@florence
Created July 26, 2015 02:01
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 florence/d91a3e590e80ab75a574 to your computer and use it in GitHub Desktop.
Save florence/d91a3e590e80ab75a574 to your computer and use it in GitHub Desktop.
#lang typed/racket
(require pict3d)
(: aprox-mandel : (Natural -> (Dir -> Dir)))
(define ((aprox-mandel n) c)
(define Z (mandel c))
(let loop : Dir ([n : Natural n] [z_n : Dir zero-dir])
(if (zero? n)
(Z z_n)
(loop (sub1 n) (Z z_n)))))
(: mandel (Dir -> (Dir -> Dir)))
(define ((mandel c) z)
(dir+ (dir^2 z) c))
(: dir^2 : Dir -> Dir)
(define (dir^2 p)
(match-define (dir i j k) p)
(dir (- (sqr i) (sqr j) (sqr k))
(- (* i j) (* j k))
(- (* i k) (* j k))))
(: render-at-passes : (Natural
Integer Integer
Integer
-> Pict3D))
(define (render-at-passes n
start end
steps)
(parameterize ([current-material
(material #:ambient 0.01
#:diffuse 0.6
#:specular 0.39
#:roughness 0.2)])
(define step-size (/ (- end start) steps))
(define point
(freeze
(with-color (rgba "peru")
(with-emitted (emitted "peru" .1)
(sphere origin step-size)))))
(define seq (in-range start end step-size))
(define f (aprox-mandel n))
(for*/fold ([res : Pict3D empty-pict3d])
([x : Exact-Rational seq]
[y : Exact-Rational seq]
[z : Exact-Rational seq])
(with-handlers ([exn:fail? (lambda _ res)])
(define loc (f (dir x y z)))
(combine (move point loc)
res)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment