-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsequence.ps
More file actions
100 lines (89 loc) · 2.8 KB
/
sequence.ps
File metadata and controls
100 lines (89 loc) · 2.8 KB
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
%%BeginResource: procset sequence
%
% See http://www.pjb.com.au/comp/sequence.html
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This Postscript is Copyright (c) 2016, Peter J Billam %
% Permission is granted to any individual or institution to use, copy, %
% modify or redistribute this software, so long as it is not resold for %
% profit, and provided this notice is retained. It is provided "as is", %
% without any express or implied warranty. http://www.pjb.com.au %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% see: ~/lua/lib/Sequence.lua but returning an array not a closure
/aaba { % usage: [ something somethingelse ] n aaba
15 dict begin
/new_n exch def /seed_arr exch def
/seed_n seed_arr length def
/new_arr new_n array def
new_arr % return
end
} bind def
/cycle { % usage: [ array of things ] n cycle
15 dict begin
/new_n exch def /seed_arr exch def
/seed_n seed_arr length def
/new_arr new_n array def
new_arr % return
end
} bind def
/leibnitz { % usage : [ array of things ] n leibnitz
15 dict begin
/new_n exch def /seed_arr exch def
/seed_n seed_arr length def
/new_arr new_n array def
new_arr % return
end
} bind def
/morse_thue { % usage : [ array of things ] n morse_thue
15 dict begin
/new_n exch def /seed_arr exch def
/seed_n seed_arr length def
/new_arr new_n array def
new_arr 0 seed_arr putinterval % bootstrap
/new_i seed_n def % and adjust pointer
/indexes_arr new_n array def
/indexes_i 0 def {
indexes_i seed_n ge { exit } if
indexes_arr indexes_i indexes_i put
/indexes_i indexes_i 1 add def
} loop
{
new_i new_n ge { exit } if
indexes_arr new_i
indexes_arr new_i seed_n idiv get new_i add seed_n mod
put
new_arr new_i
seed_arr indexes_arr new_i get get
put
/new_i new_i 1 add def
} loop
new_arr % return
end
} bind def
/rabbit { % usage : [ something somethingelse ] n rabbit
15 dict begin
/new_n exch def /seed_arr exch def
/new_arr new_n array def
/pattern [ [ 0 1 0 0 1 ] [ 0 1 0 ] ] def
/pattern_choice 0 def % 0..1
/pattern_choice_i 0 def % 0..4 or 0..2
/new_i 0 def {
/choice pattern pattern_choice get def % time-saver
new_i new_n ge { exit } if
new_arr new_i seed_arr choice pattern_choice_i get get put
/pattern_choice_i pattern_choice_i 1 add def
pattern_choice_i choice length ge {
/pattern_choice pattern_choice 1 add 2 mod def % 0 or 1
/pattern_choice_i 0 def
} if
/new_i new_i 1 add def
} loop
new_arr % return
end
} bind def
/randomget { % usage: [ an array ] randomget from random.ps
dup length rand exch mod get
} bind def
/random { % usage : [ array of things ] n random
} bind def
%%EndResource