diff options
author | KatolaZ <katolaz@freaknet.org> | 2018-03-18 10:42:11 +0000 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2018-03-18 10:42:11 +0000 |
commit | 862c242ba9801eb6f69825229c53678e18d886e4 (patch) | |
tree | 0e4340bcd5d9d622821055ea4923b5085e9f1970 /psrw.ps | |
parent | 15326f87b86fcde055abbf57d10703cf3ca5b902 (diff) |
first commit
Diffstat (limited to 'psrw.ps')
-rw-r--r-- | psrw.ps | 105 |
1 files changed, 105 insertions, 0 deletions
@@ -0,0 +1,105 @@ +%% 13331 +%% +%% Visualise a different 2D random walk every time the file is +%% opened +%% +%% (c) 2018 Vincenzo (KatolaZ) Nicosia <katolaz@freaknet.org> +%% +%% Use and distribute under the terms of the GNU General Public Licence +%% Version 3 or, at your option, any later version. +%% + +/myname (./psrw.ps) def +/rwstartx 250 def +/rwstarty 400 def +/rwlength 500 def +/rwstep 8 def + +/myreadlines { + dup + 255 string + readline + { 2 -1 roll myreadlines} {pop exit} ifelse +} def + +/myloadfile { + (r) file + {myreadlines} loop + closefile +} def + +/mywritelines{ + count + 1 ne + { + dup + count -1 roll + writestring + dup + (\n) writestring + mywritelines + } + {exit} ifelse + +} def + +/mywritefile { + (w) file + {mywritelines} loop + closefile +} def + +/replacefirst { + count -1 roll + pop + count 1 roll +} def + + +/get_seed { + myname (r) file + dup + 255 string + readline + pop + (%% ) anchorsearch + {pop cvi} {pop 201} ifelse + exch closefile +} def + +%% This comes from GNU Ghostscript +/concatstrings % (a) (b) -> (ab) + { exch dup length + 2 index length add string + dup dup 4 2 roll copy length + 4 -1 roll putinterval + } bind def + +/rndangle { rand 360 mod 2 -1 roll pop } def + +/newrndpoint { + rndangle + dup + cos rwstep mul + 2 -1 roll + sin rwstep mul +} def + +erasepage + +newpath +rwstartx rwstarty moveto +2 setlinewidth + +get_seed + +srand + +1 1 rwlength { newrndpoint rlineto } for +stroke + +myname myloadfile +(%% ) rand 30 string cvs concatstrings +replacefirst + +myname mywritefile |