art with code

2008-09-02

Almost Burning Ship

Have an almost Burning Ship fractal.




open Prelude

let niter = 32
let limit = 4.0

let burning_ship z x y =
let cr = 2.0 *. float x /. z -. 2.1 in
let ci = 2.0 *. float y /. z -. 1.8 in
let rec aux i zr zi = if i >= niter then 0 else
let nzr = absf (zr *. zr -. zi *. zi +. cr)
and nzi = 2.0 *. absf (zr *. zi +. ci) in
if nzr *. nzr +. nzi *. nzi > limit then niter-i
else aux (i+1) nzr nzi in
aux 0 0.0 0.0

let pbinit2D f w h = pbinit (fun i -> let y,x = quot_rem i w in f x y) (w*h)
let draw_fractal z w h = pbinit2D (burning_ship (float z *. 0.8)) w h
let pgm_fractal w h = sprintf "P5 %i %i %i\n" w h niter ^ draw_fractal (min w h) w h

let () = print_string @@ pgm_fractal (parseInt Sys.argv.(1)) (parseInt Sys.argv.(2))
Post a Comment

Blog Archive

About Me

My photo

Built art installations, web sites, graphics libraries, web browsers, mobile apps, desktop apps, media player themes, many nutty prototypes, much bad code, much bad art.

Have freelanced for Verizon, Google, Mozilla, Warner Bros, Sony Pictures, Yahoo!, Microsoft, Valve Software, TDK Electronics.

Ex-Chrome Developer Relations.