summaryrefslogtreecommitdiff
path: root/system/std.graphik/1.8.7/src/GRAPHIK.vektor plot
blob: 8bef1e4103640ae624948b8195c1ec39575ca2b8 (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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
PACKET clipping DEFINES set range,            (*Autor: Heiko Indenbirken *)
                        get range,            (*Stand:    27.06.85/12:39 *)
                        clip:                 (*Änderung: 11.08.86/15:02 *)

INT VAR x min :: 0, x max :: 1024, y min :: 0, y max :: 1024;

PROC set range (INT CONST h min, v min, h max, v max):
  IF h min >= h max OR v min >= v max
  THEN errorstop ("Incorrect Range") FI;
  x min := h min;  x max := h max;
  y min := v min;  y max := v max
END PROC set range;

PROC get range (INT VAR h min, v min, h max, v max):
  h min := x min;  h max := x max;
  v min := y min;  v max := y max
END PROC get range;

PROC clip (INT CONST from x, from y, to x, to y,
           PROC (INT CONST, INT CONST) move,
           PROC (INT CONST, INT CONST) draw):
  INT VAR x, y;
  calculate parts of line;
  IF both points inside
  THEN draw (to x, to y)
  ELIF both points outside
  THEN 
  ELIF first point outside
  THEN intersection (to x, to y, from x, from y, from part, x, y);
       move (x, y);
       draw (x, y);                                    (* Macke im SHARD *)
       draw (to x, to y)
  ELIF second point outside
  THEN intersection (from x, from y, to x, to y, to part, x, y);
       draw (x, y)
  ELSE intersection (to x, to y, from x, from y, from part, x, y);
       move (x, y);
       draw (x, y);                                    (* Macke im SHARD *)
       clip (x, y, to x, to y,  PROC (INT CONST, INT CONST) move,
                                PROC (INT CONST, INT CONST) draw)
  FI  .

calculate parts of line:
  INT CONST from part :: part (from x, from y),
            to part   :: part (to x, to y)  .

both points inside:
  from part = 0 AND to part = 0  .

both points outside:
  (from part AND to part) <> 0  .

first point outside:
  from part <> 0 AND to part = 0  .

second point outside:
  to part <> 0 AND from part = 0  .

END PROC clip;

INT PROC part (INT CONST x, y):
  INT VAR index :: 0;
  IF x > x max
  THEN set bit (index, 0)
  ELIF x < x min
  THEN set bit (index, 1) FI;

  IF y > y max
  THEN set bit (index, 2)
  ELIF y < y min
  THEN set bit (index, 3) FI;

  index

END PROC part;

PROC intersection (INT CONST from x, from y, to x, to y, to part, INT VAR x, y):
  SELECT to part OF
  CASE  1: right side
  CASE  2: left side 
  CASE  4: up side 
  CASE  5: upright side 
  CASE  6: upleft side 
  CASE  8: down side 
  CASE  9: downright side 
  CASE 10: downleft side
  OTHERWISE errorstop ("wrong partno.:" + text (to part)) ENDSELECT  .

right side:
  y := from y + int (real (x max-from x)*(dy/dx));
  x := x max  .

left side:
  y := from y + int (real (x min-from x)*(dy/dx));
  x := x min  .

up side:
  x := from x + int (real (y max-from y)*(dx/dy));
  y := y max  .

down side:
  x := from x + int (real (y min-from y)*(dx/dy));
  y := y min  .

upright side:
  right side;
  IF y > y max
  THEN up side FI  .

downright side:
  right side;
  IF y < y min
  THEN down side FI  . 

upleft side:
  left side;
  IF y > y max
  THEN up side FI  .

downleft side:
  left side;
  IF y < y min
  THEN down side FI  .

dx: real (to x-from x)  .
dy: real (to y-from y)  .

END PROC intersection;

END PACKET clipping;

PACKET thick line DEFINES thick:              (*Autor: Heiko Indenbirken *)
                                              (*Stand:    02.07.85/15:07 *)
                                              (*Änderung: 05.08.86/15:52 *)
PROC thick (INT CONST x0, y0, x1, y1, thick,
            PROC (INT CONST, INT CONST, INT CONST, INT CONST) line):
  IF is point
  THEN draw point
  ELIF is horizontal line 
  THEN horizontal line (PROC (INT CONST, INT CONST, INT CONST, INT CONST) line,
                        x0, y0, x1, y1, thick)
  ELSE vertical line (PROC (INT CONST, INT CONST, INT CONST, INT CONST) line,
                      x0, y0, x1, y1, thick)
  FI  .

is point:
  x0 = x1 AND y0 = y1  .

is horizontal line:
  abs (x0-x1) >= abs (y0-y1)  .

draw point:
  INT VAR i;
  FOR i FROM -thick UPTO thick
  REP line (x0-thick, y0+i, x0+thick, y0+i) PER  .

END PROC thick;

PROC horizontal line (PROC (INT CONST, INT CONST, INT CONST, INT CONST) line,
                      INT CONST from x, from y, to x, to y, thick):
  IF from x > to x
  THEN horizontal line (PROC (INT CONST, INT CONST, INT CONST, INT CONST) line, 
                        to x, to y, from x, from y, thick)
  ELSE draw line FI  .

draw line:
  INT VAR i;
  calculate increase;
  calculate limit points;
  FOR i FROM -thick UPTO thick
  REP calculate delta x;
      line (x start+delta x, y start+i, x end+delta x, y end+i)
  PER  .

calculate increase:
  REAL VAR increase :: -dy / dx  .

calculate limit points:
  INT CONST x start :: from x - thick,
            x end   :: to x   + thick,
            y start :: from y + int (increase * real (thick)), 
            y end   :: to y   - int (increase * real (thick))  .

calculate delta x:
  INT CONST delta x :: int (increase*real (i))  .

dx: real (to x-from x)  .
dy: real (to y-from y)  .

END PROC horizontal line;

PROC vertical line (PROC (INT CONST, INT CONST, INT CONST, INT CONST) line,
                    INT CONST from x, from y, to x, to y, thick):
  IF from y > to y
  THEN vertical line (PROC (INT CONST, INT CONST, INT CONST, INT CONST) line,
                      to x, to y, from x, from y, thick)
  ELSE draw line FI  .

draw line:
  INT VAR i;
  calculate increase;
  calculate limit points;
  FOR i FROM -thick UPTO thick
  REP calculate delta y;
      line (x start+i, y start+delta y, x end+i, y end+delta y)
  PER  .

calculate increase:
  REAL VAR increase :: -dx / dy  .

calculate limit points:
  INT CONST x start :: from x + int (increase * real (thick)), 
            x end   :: to x   - int (increase * real (thick)),
            y start :: from y - thick,
            y end   :: to y   + thick  .

calculate delta y:
  INT CONST delta y :: int (increase*real (i))  .

dx: real (to x-from x)  .
dy: real (to y-from y)  .

END PROC vertical line;

END PACKET thick line;

PACKET graphik text DEFINES draw char,        (*Autor: Heiko Indenbirken *)
                            zeichensatz:      (*Stand:    27.06.85/16:03 *)
                                              (*Änderung: 28.06.85/19:06 *)
                                              (*Änderung: 05.08.86/16:00 *)
LET ZEICHENSATZ = ROW 255 TEXT;
ZEICHENSATZ VAR zeichen;
INT CONST char x :: 6, char y :: 10;

zeichensatz ("ZEICHENSATZ");

PROC zeichensatz (TEXT CONST name):
  IF exists (name)
  THEN BOUND ZEICHENSATZ VAR new zeichen :: old (name);
       zeichen := new zeichen;
  ELSE errorstop ("Der Zeichensatz """ + name + """ existiert nicht") FI
END PROC zeichensatz;

PROC draw char (INT CONST char no, INT CONST x, y, x size, y size, direction,
                PROC (INT CONST, INT CONST, INT CONST, INT CONST) line):
  TEXT CONST character :: zeichen [char no];
  INT VAR n :: 1, x0, y0, x1, y1;
  INT CONST len :: length (character);
  WHILE n < len
  REP value (character, n, x0, y0, x1, y1);
      transform (x0, y0, x, y, x size, y size, direction);
      transform (x1, y1, x, y, x size, y size, direction); 
      line (x0, y0, x1, y1);
      n INCR 4
  PER  .

END PROC draw char;

PROC value (TEXT CONST char, INT CONST n, INT VAR x0, y0, x1, y1):
  x0 := val (code (char SUB n));    y0 := val (code (char SUB n+1));
  x1 := val (code (char SUB n+2));  y1 := val (code (char SUB n+3));
END PROC value;

INT PROC val (INT CONST n):
  IF n > 127
  THEN -256 OR n
  ELSE n FI
END PROC val;

PROC transform (INT VAR x, y, INT CONST x0, y0, x size, y size, direction):
  INT CONST old x :: x, old y :: y;
  SELECT direction OF
  CASE 0: x := x0 + x vektor;  y := y0 + y vektor
  CASE 1: x := x0 - y vektor;  y := y0 + x vektor
  CASE 2: x := x0 - x vektor;  y := y0 - y vektor
  CASE 3: x := x0 + y vektor;  y := y0 - x vektor
  ENDSELECT  .

x vektor:
  IF x size = 0
  THEN old x
  ELSE (old x*x size) DIV char x FI  .

y vektor:
  IF y size = 0
  THEN old y
  ELSE (old y*y size) DIV char y FI  .

END PROC transform;

END PACKET graphik text;

PACKET graphik text DEFINES draw text:        (*Autor: Heiko Indenbirken *)
                                              (*Stand:    03.07.85/11:55 *)
                                              (*Änderung: 05.08.86/16:04 *)
PROC draw text (INT CONST x pos, y pos,
                TEXT CONST msg, REAL CONST angle, INT CONST height, width,
                PROC (INT CONST, INT CONST,
                INT CONST, INT CONST, INT CONST, INT CONST) draw char):
  INT CONST dir :: int (((angle MOD 360.0)+45.0) / 90.0);
  INT VAR i;
  REAL VAR x :: real (x pos), y :: real (y pos),
           x step :: cosd (angle)*real (width),
           y step :: sind (angle)*real (width);
  FOR i FROM 1 UPTO length (msg)
  REP IF control char
      THEN execute control char
      ELSE execute normal char FI
  PER  .

control char:
  akt char < ""32""  .

execute control char:
  SELECT code (akt char) OF
  CASE  1: home
  CASE  2: right
  CASE  3: up
  CASE  7: out (""7"")
  CASE  8: left
  CASE 10: down
  CASE 13: return
  ENDSELECT  .

home:
  x := real (x pos);
  y := real (y pos)  .

right:
  x INCR x step;  y INCR y step  . 

up:
  x INCR y step;  y INCR x step  . 

left:
  x DECR x step;  y DECR y step  .

down:
  x DECR y step;  y DECR x step  . 

return:
  x := real (x pos)  .

execute normal char:
  draw char (code (akt char), dir, int (x+0.5), int (y+0.5), height, width);
  x INCR x step;
  y INCR y step  .

akt char:
  msg SUB i  .

END PROC draw text;

END PACKET graphik text;

PACKET comercial plot DEFINES bar,            (*Autor: Heiko Indenbirken *)
                              circle:         (*Stand:    03.04.1985     *)
                                              (*Änderung: 03.07.85/15:37 *)
PROC bar (INT CONST from x, from y, to x, to y, pattern,
          PROC (INT CONST, INT CONST, INT CONST, INT CONST) line):
  IF from x > to x
  THEN bar (to x, from y, from x, to y, pattern, PROC (INT CONST, INT CONST, INT CONST, INT CONST) line)
  ELIF from y > to y
  THEN bar (from x, to y, to x, from y, pattern, PROC (INT CONST, INT CONST, INT CONST, INT CONST) line)
  ELSE draw frame;
       fill frame with pattern
  FI  .

draw frame:
  line (from x, from y, from x, to y);
  line (from x, to y, to x, to y);
  line (to x, to y, to x, from y);
  line (to x, from y, from x, from y)  .

fill frame with pattern:
  SELECT pattern OF
  CASE 1: fill right (from x, to x, from y, to y, 2, PROC (INT CONST, INT CONST, INT CONST, INT CONST) line)
  CASE 2: fill hor   (from x, to x, from y, to y, 1, PROC (INT CONST, INT CONST, INT CONST, INT CONST) line)
  CASE 3: fill hor   (from x, to x, from y, to y, 5, PROC (INT CONST, INT CONST, INT CONST, INT CONST) line)
  CASE 4: fill vert  (from x, to x, from y, to y, 5, PROC (INT CONST, INT CONST, INT CONST, INT CONST) line)
  CASE 5: fill hor   (from x, to x, from y, to y, 5, PROC (INT CONST, INT CONST, INT CONST, INT CONST) line);
          fill vert  (from x, to x, from y, to y, 5, PROC (INT CONST, INT CONST, INT CONST, INT CONST) line)
  CASE 6: fill right (from x, to x, from y, to y, 5, PROC (INT CONST, INT CONST, INT CONST, INT CONST) line)
  CASE 7: fill left  (from x, to x, from y, to y, 5, PROC (INT CONST, INT CONST, INT CONST, INT CONST) line)
  CASE 8: fill right (from x, to x, from y, to y, 5, PROC (INT CONST, INT CONST, INT CONST, INT CONST) line);
          fill left  (from x, to x, from y, to y, 5, PROC (INT CONST, INT CONST, INT CONST, INT CONST) line)
  ENDSELECT  .

END PROC bar;

PROC fill hor (INT CONST from x, to x, from y, to y, step,
               PROC (INT CONST, INT CONST, INT CONST, INT CONST) line):
  INT VAR y :: from y;
  REP line (from x, y, to x, y);
      y INCR step
  UNTIL y > to y PER  .

END PROC fill hor;

PROC fill vert (INT CONST from x, to x, from y, to y, step,
                PROC (INT CONST, INT CONST, INT CONST, INT CONST) line):
  INT VAR x :: from x;
  REP line (x, from y, x, to y);
      x INCR step
  UNTIL x > to x PER  .

END PROC fill vert;

PROC fill right (INT CONST from x, to x, from y, to y, step,
                 PROC (INT CONST, INT CONST, INT CONST, INT CONST) line):
  INT CONST width  :: to x - from x,
            height :: to y - from y,
            length :: width + height,
            height step :: height + step,
            width step  :: width + step;

  INT VAR t :: step, left  :: from x, right :: from x,
                     lower :: from y, upper :: from y;
(*               Ausfüllen von links unten nach rechts oben              *)
  WHILE t < length
  REP calc start point;
      calc end point;
      line (left, upper, right, lower);
      t INCR step
  PER  .

calc start point:
  IF t < height
  THEN upper INCR step
  ELIF t < height step
  THEN left  := from x + t - height;
       upper := to y
  ELSE left INCR step FI  .

calc end point:
  IF t < width
  THEN right INCR step
  ELIF t < width step
  THEN lower := from y + t - width;
       right := to x
  ELSE lower INCR step FI  .

END PROC fill right;

PROC fill left (INT CONST from x, to x, from y, to y, step,
                PROC (INT CONST, INT CONST, INT CONST, INT CONST) line):
  INT CONST width  :: to x - from x,
            height :: to y - from y,
            length :: width + height,
            height step :: height + step,
            width step  :: width + step;

  INT VAR t :: step, left  :: to x,   right :: to x,
                     lower :: from y, upper :: from y;
(*               Ausfüllen von rechts unten nach links oben              *)
  WHILE t < length
  REP calc start point;
      calc end point;
      line (right, upper, left, lower);
      t INCR step
  PER  .

calc start point:
  IF t < height
  THEN upper INCR step
  ELIF t < height step
  THEN right := to x - t + height;
       upper := to y
  ELSE right DECR step FI  .

calc end point:
  IF t < width
  THEN left DECR step
  ELIF t < width step
  THEN lower := from y + t - width;
       left  := from x
  ELSE lower INCR step FI  .

END PROC fill left;

PROC circle (INT CONST x, y, REAL CONST rad, from, to, INT CONST pattern,
             PROC (INT CONST, INT CONST, INT CONST, INT CONST) line):
  REAL VAR t :: from;
  INT VAR last x :: x, last y :: y;
  WHILE t <= to
  REP calc circle;
      draw step;
      t INCR 1.0
  PER;
  line (x rad, y rad, x, y)  .

draw step:
  IF pattern = 0
  THEN line (last x, last y, x rad, y rad);
       last x := x rad;
       last y := y rad
  ELSE line (x, y, x rad, y rad) FI  .

calc circle:
  INT CONST x rad :: int (cosd (t)*rad+0.5)+x,
            y rad :: int (sind (t)*rad+0.5)+y  .

END PROC circle;

END PACKET comercial plot;