Skip to content

Instantly share code, notes, and snippets.

@nick-paul
Created November 23, 2016 03:30
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 nick-paul/a23b75de577dc3d9bd1676c6598ce876 to your computer and use it in GitHub Desktop.
Save nick-paul/a23b75de577dc3d9bd1676c6598ce876 to your computer and use it in GitHub Desktop.
A J script for drawing fractals from the julia set
NB. A J script for drawing fractals from the julia set.
NB. Algorithm from:
NB. http://mathemartician.blogspot.com/2012/07/julia-set-in-julia.html
require 'viewmat'
S =: 100 NB. Detail level of image
NB. The iteration verb
julia =: 3 : 0 "0
NB. Starting location
c =. _0.8j0.156
maxiter =. 256 NB. Max iteration level
for_n. >:i.maxiter do.
if. (|y) > 2 do.
(n-1)
return.
end.
y =. (y^2) + c
end.
maxiter
return.
)
NB. Normalize
NB. Translate a set or two numbers into (_1 to 1)j(_1 to 1)
s =: S%2
cplx =: dyad : '((x-s)%s) j. ((y-s)%s)' "0
NB. The data matrix to be plotted
dat =: (>:i.S) cplx/ >:i.S
NB. Plot the matrix
viewmat |: julia (dat*1.55)
NB. Save the image as a PNG
NB. savemat_jviewmat_ 'full500.png'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment