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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
############################################################################
#
# File: profile.icn
#
# Subject: Program to display scrolling histogram
#
# Author: Ralph E. Griswold
#
# Date: January 21, 1999
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# This program displays successive numbers by lines of corresponding
# height. When the display area is full, it scrolls from right to
# left.
#
# If a line has a number followed by a blank and a string, the string
# is interpreted as a color.
#
############################################################################
#
# Requires: Version 9 graphics
#
############################################################################
#
# Links: interact, navitrix, vsetup
#
############################################################################
link interact
link vsetup
global animate # animation toggle
global count # frame count
global height # height of scrolling area
global input # input file
global name # input file name
global offset # base-line offset
global pause # pause vidget
global prefix # image file name prefix
global rate # sample rate
global reset # reset switch
global scale # vertical scale
global state # pause/run state
global strip # graphics context for display
global width # width of scrolling area
global vidgets
global root
procedure main()
local value, n, color
init()
color := "black" # default color
while value := read() do {
if (*Pending() > 0) | \state then
ProcessEvent(root, , shortcuts)
value ? {
n := tab(upto(' \t') | 0)
if tab(many(' \t')) then color := tab(0)
}
n := (scale * numeric(n)) | {
Fg("black")
Notice("Nonnumeric data; terminating.")
exit()
}
n >:= height # clip to avoid window-manager bugs
CopyArea(strip, 1, 0, width - 1, height, 0, 0)
EraseArea(strip, width - 1, 0, width, height)
Fg(strip, color) | stop("bad color: ", image(color))
DrawLine(strip, width - 1, height - n - offset, width - 1,
height - offset)
if \animate then
WriteImage(strip, prefix || right(count +:= 1, 4, "0") || ".gif",
0, 0, width, height)
}
Fg("black")
case TextDialog("End of stream.", , , , ["Quit", "Snapshot", "Hold"]) of {
"Quit" : exit()
"Snapshot" : snapshot(strip, 0, 0, width, height)
"Hold" : WDone()
}
end
procedure init()
vidgets := ui()
root := vidgets["root"]
pause := vidgets["pause"]
VSetState(pause, 1) # initially paused
name := ""
rate := 1
scale := 1
offset := 0
count := 0
prefix := "image"
width := vidgets["strip"].uw
height := vidgets["strip"].uh
strip := Clone("dx=" || vidgets["strip"].ux, "dy=" || vidgets["strip"].uy)
Clip(strip, 0, 0, width, height)
return
end
procedure animation_cb(vidget, value)
case value[1] of {
"prefix" : set_prefix()
"rate" : set_frame_rate()
}
end
procedure set_prefix()
return
end
procedure set_frame_rate()
return
end
procedure animate_cb(vidget, value)
animate := value
return
end
procedure parameters_cb(vidget, value)
case value[1] of {
"scale @V" : set_scale()
"offset @F" : set_offset()
"rate @R" : set_rate()
}
fail
end
procedure file_cb(vidget, value)
case value[1] of {
"snapshot @S" : return snapshot(strip, 0, 0, width, height)
"quit @Q" : exit()
}
end
procedure pause_cb(vidget, value)
state := value
return
end
procedure clear_cb()
EraseArea(strip)
return
end
procedure set_rate()
repeat {
if TextDialog(, "sample rate", rate, 10) == "Okay" then {
rate := (0 < numeric(dialog_value[1])) | {
Notice("Invalid sample rate.")
next
}
clear_cb()
return
}
else fail # user canceled
}
end
procedure set_offset()
repeat {
if TextDialog(, "vertical offset", offset, 10) == "Okay" then {
offset := numeric(dialog_value[1]) | {
Notice("Invalid offset.")
next
}
clear_cb()
return
}
else fail # user canceled
}
end
procedure set_scale()
repeat {
if TextDialog(, "vertical scale", scale, 10) == "Okay" then {
scale := (0 < numeric(dialog_value[1])) | {
Notice("Invalid scale value.")
next
}
clear_cb()
return
}
else fail # user canceled
}
end
procedure shortcuts(e)
if &meta then
case map(e) of {
"c" : clear_cb()
"f" : set_offset()
"p" : if \state then VSetState(pause) else VSetState(pause, 1)
"q" : exit()
"r" : set_rate()
"s" : snapshot(strip, 0, 0, width, height)
"v" : set_scale()
}
return
end
#===<<vib:begin>>=== modify using vib; do not remove this marker line
procedure ui_atts()
return ["size=651,305", "bg=pale gray", "label=Scrolling Histogram"]
end
procedure ui(win, cbk)
return vsetup(win, cbk,
[":Sizer:::0,0,651,305:Scrolling Histogram",],
["animate:Button:regular:1:21,189,56,20:movie",animate_cb],
["animation:Menu:pull::113,1,71,21:Animation",animation_cb,
["prefix","rate","clear"]],
["clear:Button:regular::21,88,56,20:clear",clear_cb],
["file:Menu:pull::0,1,36,21:File",file_cb,
["snapshot @S","quit @q"]],
["label1:Label:::619,144,21,13:100",],
["label10:Label:::90,269,21,13:500",],
["label11:Label:::584,269,21,13: 0",],
["label2:Label:::619,195,21,13: 50",],
["label3:Label:::619,94,21,13:150",],
["label4:Label:::619,45,21,13:200",],
["label5:Label:::619,247,21,13: 0",],
["label6:Label:::489,269,21,13:100",],
["label7:Label:::388,269,21,13:200",],
["label8:Label:::287,269,21,13:300",],
["label9:Label:::188,269,21,13:400",],
["line10:Line:::501,253,501,262:",],
["line11:Line:::200,255,200,264:",],
["line12:Line:::500,40,500,49:",],
["line13:Line:::200,40,200,49:",],
["line14:Line:::615,51,604,51:",],
["line15:Line:::615,253,604,253:",],
["line16:Line:::603,256,603,265:",],
["line17:Line:::101,255,101,264:",],
["line18:Line:::101,253,90,253:",],
["line19:Line:::100,51,89,51:",],
["line2:Line:::90,151,99,151:",],
["line20:Line:::603,40,603,49:",],
["line21:Line:::101,40,101,49:",],
["line22:Line:::400,255,400,264:",],
["line23:Line:::400,40,400,49:",],
["line3:Line:::90,200,99,200:",],
["line4:Line:::90,100,99,100:",],
["line5:Line:::615,100,604,100:",],
["line6:Line:::615,151,604,151:",],
["line7:Line:::615,201,604,201:",],
["line8:Line:::300,255,300,264:",],
["line9:Line:::300,40,300,49:",],
["menu line:Line:::0,23,655,23:",],
["parameters:Menu:pull::35,1,78,21:Parameters",parameters_cb,
["scale @V","offset @F","rate @R"]],
["pause:Button:regular:1:21,41,56,20:pause",pause_cb],
["strip:Rect:grooved::100,50,504,204:",],
)
end
#===<<vib:end>>=== end of section maintained by vib
|