summaryrefslogtreecommitdiff
path: root/ipl/mprocs/viewpack.icn
blob: 1797fd1007f37467be83f25a880fa70661946cb1 (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
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
############################################################################
#
#	File:     viewpack.icn
#
#	Subject:  Procedures to visualize color streams
#
#	Author:   Ralph E. Griswold
#
#	Date:     May 2, 2001
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  These procedures provide various ways of visualizing a stream of colors.
#
############################################################################
#
#  Requires:  Version 9 graphics
#
############################################################################

$define Hold	300

#  blinking light

procedure beacon(win, color, value)	#: 1C visualization as blinking light

   Fg(win, color)
   FillCircle(win, width / 2, height / 2, width / 2)
   WDelay(win, Hold)

end

#  random curves

procedure curves(win, color, value)	#: 1C visualization as random curves
   local x0, y0

   Fg(win, color)
   DrawCurve ! [
      win,
      x0 :=  ?width, y0 := ?height,
      ?width, ?height,
      ?width, ?height,
      ?width, ?height,
      ?width, ?height,
      ?width, ?height,
      ?width, ?height,
      .x0, .y0
      ]

   WDelay(win, Hold)

   return

end

# "haystack"

procedure haystack(win, color, value)	#: 2CS visualization as "haystack"
   static angle, xcenter, ycenter, xorg, yorg, fullcircle

   initial {
      fullcircle := 2 * &pi
      ycenter := height / 2
      xcenter := width / 2
      }

   Fg(win, color)
   angle := ?0 * fullcircle	# angle for locating starting point
   xorg := xcenter + ?xcenter * cos(angle)
   yorg := ycenter + ?ycenter * sin(angle)
   angle := ?0 * fullcircle	# angle for locating end point
   DrawLine(win, xorg, yorg, value * cos(angle) +
      xorg, value * sin(angle) + yorg)

   return

end

#  "nova"

$define Scale	1.5
$define Rays	360

procedure nova(win, color, value)	#: 1C visualization as exploding star
   local clear, xorg, yorg, radius, arc, oldlength, length
   static fullcircle, radians, advance, erase

   initial {
      fullcircle := 2 * &pi
      radians := 0
      advance := fullcircle / Rays		# amount to advance
      erase := list(Rays)
      }

   Fg(win, color)
   xorg := width / 2
   yorg := height / 2
   radius := ((height < width) | height) / 2.0

   length := value * Scale
   put(erase, length)
   oldlength := get(erase)

#  The following are to erase old ray at that angle

#  DrawLine(Background, xorg, yorg, \oldlength * cos(radians) + xorg,
#     oldlength * sin(radians) + yorg)

   DrawLine(win, xorg, yorg, length * cos(radians) +
      xorg, length * sin(radians) + yorg)
   
   radians +:= advance
   radians %:= fullcircle

   return

end

#  "pinwheel"

$define Sectors	240

procedure pinwheel(win, color, value)	#: 1C visualization as radar sweep
   static clear, xorg, yorg, radius, offset
   static arc, advance, blank, max, xratio, yratio
   static fullcircle, background

   initial {
      fullcircle := 2 * &pi
      max := real((width < height) | width)
      xratio := width / max
      yratio := height / max
      offset := 0
      advance := fullcircle / Sectors
      blank := 2 * advance
      xorg := width / 2
      yorg := height / 2
      radius := max / 2

      # This belongs elsewhere

      background := Clone(win, "bg=" || default_color)

      }

   Fg(win, color)
   FillArc(background, 0, 0, width, height, offset + advance, blank)
   FillArc(win, 0, 0, width, height, offset, advance)
   DrawLine(background, xorg, yorg, xratio * radius * cos(offset) +
      xorg, yratio * radius * sin(offset) + yorg)

   offset +:= advance
   offset %:= fullcircle

   return

end

#  random polygons

procedure polygons(win, color, value)	#: 1C visualization as random polygons
   local x0, y0

   Fg(win, color)
   FillPolygon ! [
      win,
      x0 :=  ?width, y0 := ?height,
      ?width, ?height,
      ?width, ?height,
      ?width, ?height,
      ?width, ?height,
      ?width, ?height,
      ?width, ?height,
      .x0, .y0
      ]

   WDelay(win, Hold)

   return

end

#  random dots

procedure splatter(win, color, value)	#: 2CS visualization as random dots
   local radius, xplace, yplace

   Fg(win, color)
   radius := sqrt(value)
   xplace := ?width - 1 - (radius / 2)
   yplace := ?height - 1 - (radius / 2)
   FillCircle(win, xplace, yplace, radius)

   return

end

# scrolling strip

procedure strip(win, color, value)	#: 2CS visualization as scrolling lines
   local count

   Fg(win, color) | "black"
   if /value | (value = 0) then return
   count := log(value, 10) + 1
   every 1 to count do {
      CopyArea(win, 1, 0, width - 1, height, 0, 0)
      EraseArea(win, width - 1, 0, width - 1, height)
      FillRectangle(win, width - 1, 0, 1, height)
      }

   return

end

procedure symdraw(W, mid, x, y, r)

   FillCircle(W, mid + x, mid + y, r)
   FillCircle(W, mid + x, mid - y, r)
   FillCircle(W, mid - x, mid + y, r)
   FillCircle(W, mid - x, mid - y, r)

   FillCircle(W, mid + y, mid + x, r)
   FillCircle(W, mid + y, mid - x, r)
   FillCircle(W, mid - y, mid + x, r)
   FillCircle(W, mid - y, mid - x, r)

   return

end

#  symmetric random dots

procedure symsplat(win, color, value)	#: 2CS visualization as symmetric random dots
   local radius
   static xplace, yplace, oscale

   Fg(win, color)
   radius := sqrt(value)
   xplace := ?width - 1
   yplace := ?height - 1
   symdraw(win, width / 2, xplace, yplace, radius)

   return
   
end

#  evolving vortex

procedure vortex(win, color, value)	#: 1C visualization as an aspirating vortex
   local count
   static x1, x2, y1, y2

   initial {
      x1 := y1 := 0
      x2 := width
      y2 := height
      }

   Fg(win, color)
   if value = 0 then return
   count := log(value, 10) + 1
   every 1 to count do {
      if (x2 | y2) < 0 then {
         x1 := y1 := 0
         x2 := width
         y2 := height
         }
      DrawRectangle(win, x1, y1, x2 - x1, y2 - y1)
      x1 +:= 1
      x2 -:= 1
      y1 +:= 1
      y2 -:= 1
      }
   
   return

end

#  random walk
#
#  This procedure is suspect -- it seems to wander off the display area.

$define Delta	30

procedure web(win, color, value)	#: 2CS visualization as a random walk
   static xorg, yorg, x, y, angle, degrees, radians, resid

   initial {
      resid := 0
      xorg := ?(width - 1)	# starting point
      yorg := ?(height - 1)
      }

   Fg(win, color)
   if resid <= 1 then {
      angle := ?0 * 2 * &pi	# initial direction for new walk
      resid := value
      }

   x := xorg + resid * cos(angle)
   y := yorg + resid * sin(angle)

   if x > width then {
      x := width
      }
   if y > height then {
      y := height
      }
   if x < 0 then {
      x := 0
      }
   if y < 0 then {
      y := 0
      }
   DrawLine(win, xorg, yorg, x, y)
   resid -:= sqrt((x - xorg) ^ 2 + (y - yorg) ^ 2)
   xorg := x			# move to new point
   yorg := y
   angle := -angle		# reflect

   return

end