%! PS % POSTSCRIPT FERN-TO-IMAGE CONVERTER % =================================== % by Don Lancaster % Copyright c 2002 by Don Lancaster and Synergetics, 3860 west First Street % Box 809 Thatcher, AZ, 85552 (728) 428-4073. Further support at % http://www.tinaja.com or email don@tinaja.com All commercial and media rights % are ~fully~ reserved. % ========= % This file requires the previous download of gonzo.ps % available from http://www.tinaja.com/post01.asp % Make sure the following line agrees with your gonzo.ps location % Use DOUBLE SLASHES anytime you want a single slash in a PS string. (C:\\windows\\desktop\\gonzo\\gonzo.ps) run % use internal gonzo % ========== % converts a fractal fern or any other B/W source data into a 256 x 384 bit image % for faster presentation and printing. gonzo begin gutility begin printerror nuisance begin % [yourarray] makestring converts an array to a string... /makestring {dup length string dup % new string of right size /NullEncode filter % make a file out of string 3 -1 roll {1 index exch write} forall pop } def %%% Create three image arrays. For RGB 512x512 of one bit per color /hpixels 256 store /vpixels 384 store %% 64 colors are presently "hard wired". Presently light green on full green. /none 2#00000000 def /dark 2#01010101 def /light 2#10101010 def /full 2#11111111 def /addmask [ 2#11000000 2#00110000 2#00001100 2#00000011 ] def /dropmask [ 2#00111111 2#11001111 2#11110011 2#11111100 ] def /makeimagearrays { % make a full green background mark 32768 { light cvi} repeat] makestring /redimagestring exch store mark 32768 { full cvi} repeat] makestring /greenimagestring exch store mark 32768 { light cvi} repeat] makestring /blueimagestring exch store } def makeimagearrays % makes the actual arrays %% insertbit scales and positions a fern dot from the centered unit square. /insertbit { currentpoint 8.333 div 256 mul floor 32 add % fern specific adjustment /yyy exch store 8.333 div 256 mul 128 add floor cvi 10 sub % fern specific adjustment /xxx exch store xxx 4 mod /xxbitposn exch store % calculate bit and byte positions xxx 4 idiv /xxbyte exch store yyy 64 mul cvi xxbyte add /byteposn exch store redimagestring dup byteposn get % modify red bit pair dropmask xxbitposn get and % zero old value none addmask xxbitposn get and or % replace with new value byteposn exch put greenimagestring dup byteposn get % modify green dropmask xxbitposn get and [ dark light ] 2 random get % try some dither for effect addmask xxbitposn get and or byteposn exch put blueimagestring dup byteposn get % modify blue dropmask xxbitposn get and none addmask xxbitposn get and or byteposn exch put } store %%%%%% This is the modified fern code... /wantrealfern false store % optionally plots fern at bottom save /fernsnap exch store /problistcreate {mark /counter 0 def probabilities {128 mul round cvi {transforms counter get} repeat /counter counter 1 add def} forall counttomark 128 sub neg dup 0 gt { [1 0 0 1 0 0] repeat} {pop} ifelse] /problist exch def} bind def /doit {problistcreate 1 1 20 {problist rand -24 bitshift get transform 2 copy moveto % don't insert originals? 0.001 10 rlineto } repeat newpath numdots {problist rand -24 bitshift get transform 2 copy moveto insertbit 0.001 0 rlineto wantrealfern {stroke}{newpath} ifelse } repeat } bind def /numdots 50000 def % increase for denser image; decrease to print faster /transforms [ [0 0 0 .16 0 0] [.2 .23 -.26 .22 0 1.6] [-.15 .26 .28 .24 0 .44] [.85 -.04 .04 .85 0 1.6] ] def /probabilities [ .01 .07 .07 .85 ] def 1 setlinecap 0.02 setlinewidth % 200 300 translate % 30 dup scale % 10 10 translate 0 0.3 0 setrgbcolor doit wantrealfern { % does a temporary grid for scale evaluation -15 -10 translate 0 0 10 setgrid 5 5 showgrid} if fernsnap restore %%%%%%%%%%%%%%%%%%%%% % code to show the image /showimage {gsave translate hpixels vpixels scale % magnify unit square hpixels vpixels 2 [hpixels 0 0 vpixels 0 0 ] % define color image redimagestring greenimagestring blueimagestring true 3 colorimage grestore } store 50 50 showimage showpage % EOF