2 USING: arrays io kernel math math.order namespaces sequences
3 byte-arrays byte-vectors math.functions math.parser io.files
4 colors.hsv io.encodings.binary ;
6 : max-color 360 ; inline
7 : zoom-fact 0.8 ; inline
11 : center -0.65 ; inline
13 : scale 255 * >fixnum ; inline
15 : scale-rgb ( r g b -- n )
16 rot scale rot scale rot scale 3array ;
21 : <color-map> ( nb-cols -- map )
23 360 * swap 1+ / sat val
24 3array hsv>rgb first3 scale-rgb
27 : iter ( c z nb-iter -- x )
28 over absq 4.0 >= over zero? or
29 [ 2nip ] [ 1- >r sq dupd + r> iter ] if ; inline
33 : x-inc width 200000 zoom-fact * / ; inline
34 : y-inc height 150000 zoom-fact * / ; inline
38 x-inc * center real-part x-inc width 2 / * - + >float
40 y-inc * center imaginary-part y-inc height 2 / * - + >float
46 c 0 nb-iter iter dup zero? [
49 cols get [ length mod ] keep nth
54 : ppm-header ( w h -- )
55 "P6\n" % swap # " " % # "\n255\n" % ;
57 : buf-size ( -- n ) width height * 3 * 100 + ;
61 buf-size <byte-vector> building set
62 width height ppm-header
63 nb-iter max-color min <color-map> cols set
65 building get >byte-array
69 mandel "mandel.ppm" temp-file binary set-file-contents ;