From 862c242ba9801eb6f69825229c53678e18d886e4 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Sun, 18 Mar 2018 10:42:11 +0000 Subject: first commit --- psrw.ps | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 psrw.ps (limited to 'psrw.ps') diff --git a/psrw.ps b/psrw.ps new file mode 100644 index 0000000..41a430a --- /dev/null +++ b/psrw.ps @@ -0,0 +1,105 @@ +%% 13331 +%% +%% Visualise a different 2D random walk every time the file is +%% opened +%% +%% (c) 2018 Vincenzo (KatolaZ) Nicosia +%% +%% 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 -- cgit v1.2.3