Skip to content

Instantly share code, notes, and snippets.

@adrian17
Last active August 29, 2015 14:17
Show Gist options
  • Save adrian17/048b2fa76d1b1c2bb0f7 to your computer and use it in GitHub Desktop.
Save adrian17/048b2fa76d1b1c2bb0f7 to your computer and use it in GitHub Desktop.
collatz fractal in J
load 'viewmat'
gen_table =: 4 : '(0j1*(i: x)) +/ i: y'
fractal =: 1 : 0
:
x u"0 (y +~ 30000 %~ 150 gen_table 150) NB. resolution and scale, not sure how to decouple them
)
collatz =: 4 %~ 2 + (7*]) - (2+5*])* 2 o. o.
is_bounded_c =: 4 : '((0: collatz^:x) :: 1:) y' NB. collatz
is_bounded_cc =: 4 : '+/ 10 < | (collatz :: _:)^:(<x) y' NB. collatz color
mandelbrot =: [ + [: *: ]
is_bounded_m =: 4 : '2 < | y (mandelbrot^:x :: _:) 0' NB. mandelbrot
is_bounded_mc =: 4 : '+/ 2 < | y (mandelbrot :: _:)^:(<x) 0' NB. mandelbrot color
NB. x is number of iterations, y is position of centerpoint
viewmat 50 (is_bounded_mc fractal) _0.7911j0.1563
NB. issues:
NB. slow.
NB. I'm assuming :: in is_bounded isn't the fastest thing ever as it relies on error handling
NB. J's number errors are confusing
NB. with collatz sequence I'm getting limit errors (which I'm using with ::)
NB. with mandelbrot I'm getting _ (which is okay) or NaN errors (which I'm also catching with ::)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment