summaryrefslogtreecommitdiff
path: root/psrw.ps
blob: 41a430acc1c06703b10b0cb60cb019499ae71717 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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