2 USING: arrays io kernel math namespaces sequences strings sbufs
3 math.functions math.parser io.files colors.hsv ;
5 : max-color 360 ; inline
6 : zoom-fact 0.8 ; inline
10 : center -0.65 ; inline
12 : scale 255 * >fixnum ; inline
14 : scale-rgb ( r g b -- n )
15 rot scale rot scale rot scale 3array ;
20 : <color-map> ( nb-cols -- map )
22 360 * swap 1+ / 360 / sat val
26 : iter ( c z nb-iter -- x )
27 over absq 4.0 >= over zero? or
28 [ 2nip ] [ 1- >r sq dupd + r> iter ] if ; inline
32 : x-inc width 200000 zoom-fact * / ; inline
33 : y-inc height 150000 zoom-fact * / ; inline
37 x-inc * center real x-inc width 2 / * - + >float
39 y-inc * center imaginary y-inc height 2 / * - + >float
45 c 0 nb-iter iter dup zero? [
48 cols get [ length mod ] keep nth
53 : ppm-header ( w h -- )
54 "P6\n" % swap # " " % # "\n255\n" % ;
56 : sbuf-size width height * 3 * 100 + ;
58 : mandel ( -- string )
60 sbuf-size <sbuf> building set
61 width height ppm-header
62 nb-iter max-color min <color-map> cols set
67 : mandel-main ( file -- )
68 "mandel.ppm" resource-path <file-writer>
69 [ mandel write ] with-stream ;