File: 06.array.pd

package info (click to toggle)
puredata 0.55.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 20,508 kB
  • sloc: ansic: 118,824; tcl: 10,221; cpp: 9,327; makefile: 1,632; sh: 1,476; python: 152; xml: 98; awk: 13
file content (143 lines) | stat: -rw-r--r-- 8,675 bytes parent folder | download | duplicates (2)
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
#N struct template6 float x float y array bazoo template6-element1 array boom template6-element2 array blargh float;
#N struct template6-element1 float y;
#N struct template6-element2 float x float y float w float i;
#N struct float float y;
#N canvas 83 38 717 660 12;
#X obj 284 488 pointer;
#X floatatom 56 465 4 0 0 0 - - - 0;
#X obj 435 381 pointer;
#N canvas 823 38 386 321 data6 1;
#X scalar template6 30 50 \; 0 \; 0 \; 0 \; 0 \; 50 \; 0 \; 0 \; 0 \; 0 \; 0 \; 0 \; -9 \; 0 \; 0 \; 0 \; 3 \; 0 \; 0 \; 0 \; 30 \; 0 \; 0 \; 0 \; -43 \; 0 \; \; 0 80 10 0 \; 10 50 2 1 \; 200 75 15 2 \; 225 25 1 3 \; 40 100 5 4 \; \; 0 \; \;;
#X coords 0 321 1 320 0 0 0;
#X restore 506 512 pd data6;
#N canvas 131 53 529 558 template6 0;
#X obj 24 213 plot bazoo 700 3 30 10 10;
#X text 28 122 This [struct] now also declares arrays named "bazoo" and "boom" whose elements are described by spearate template named \, named respectively "template6-element1" and "template6-element2". Array declarations need this extra element's template name which is declared on a separate subpatch., f 65;
#X text 212 214 draw instruction for the 'bazoo' array;
#X text 31 247 The first argument of [plot] is the array name (bazoo) \, other arguments are: color (700) \, line width (3) \, position coordinate (30 \, 40) and horizontal spacing for the elements (5)., f 64;
#X text 220 324 draw instruction for the 'boom' array;
#X obj 126 30 struct template6 float x float y array bazoo template6-element1 array boom template6-element2 array blargh float, f 32;
#X text 226 416 draw instruction for the 'blargh' array;
#X text 41 358 Since the 'boom' array defines x and w fields \, the arguments for line width and horizontal spacing are ignored in [plot].;
#X text 58 451 This one has a built in float template so we don't need a subpatch to define its element. This is a simple template also used for regular arrays in Pd. Here we plot it with a purple line with a thickness of 2 pixels. It is initialized with a size of 1 \, but you can change it with [setsize].;
#X obj 53 323 plot boom 90 1 30 50 1;
#X obj 43 416 plot blargh 909 2 30 200;
#X restore 506 535 pd template6;
#X msg 435 353 traverse pd-data6 \, next;
#X floatatom 94 400 4 0 256 0 - - - 0;
#X floatatom 284 403 4 0 4 0 - - - 0;
#X floatatom 284 542 7 0 0 1 y-value - - 0;
#X text 53 583 When you press the control (or "command" in mac) before passing the mouse over a point \, the cursor becomes an "X" so you can click and remove that point or it becomes "+" so you can click and add a new point to the array., f 56;
#X text 566 395 see also:;
#X obj 644 395 array;
#N canvas 196 208 538 281 template6-element1 0;
#X text 34 124 We don't really need any drawing instructions for the elements in the array. Note that the top-level template has drawing instructions for the array with the [plot] object. Nonetheless \, we have a small polygon drawn here for each element in the array., f 69;
#X obj 100 21 struct template6-element1 float y;
#X text 27 54 This says that array elements will have a single floating-point number named "y". The variable name "y" is automatically assumed to control the vertical position and it's needed to plot 'y-values'. It also allows you to click and drag to change the y-value of each element., f 70;
#X obj 119 211 drawpolygon 0 2 -2 -2 2 -2 2 2 -2 2 -2 -2;
#X restore 506 558 pd template6-element1;
#N canvas 230 117 497 280 template6-element2 0;
#X obj 78 187 filledpolygon 900 0 2 -2 -2 2 -2 2 2 -2 2;
#X text 81 158 draw a filled polygon on each element.;
#X obj 66 21 struct template6-element2 float x float y float w float i;
#X obj 81 226 drawnumber i 10 5;
#X text 213 226 draw the value of 'i';
#X text 54 55 This says that array elements have special fields x \, y and w \, which set coordinates (x \, y) and line width (w). We can also include other data types and here we add an extra float data type named "i" (used for the array's index). Alternatively \, you can also add symbol fields \, text fields and even nested arrays indefinitely., f 55;
#X restore 506 580 pd template6-element2;
#X text 30 242 The [elemment] object takes an index number and outputs a pointer to the corresponding array element. The [setsize] object sets the array size and [getsize] gets it \, but note you can also use [array] for this and other operations on arrays instead., f 93;
#X text 30 193 Like explained with other scalars \, the x/y/w values depend on the 'Units per pixel' parameter for the x/y dimensions (1 for both in this case). This means that the display will only increment in integer vaues \, even though you can set values with decimal points., f 93;
#X obj 94 437 setsize template6 blargh;
#X floatatom 459 424 5 0 0 0 - - - 0;
#X obj 435 319 bng 25 250 50 0 empty empty <--\ click\ here\ first 32 13 0 14 #dfdfdf #000000 #000000;
#X text 30 10 Scalars may also contain arrays \, whose elements are also scalars with their own template and can include any data type (float \, symbols \, text and even sub-arrays recursively.) In this case \, "template6" contains the definition of the top-level scalar and we have two templates: "template6-element1" for the elements of the 'bazoo' array and "template6-element2" for the elements of the 'boom' array. A third array ('blargh') has a builtin float template. See the template subpatches for more information., f 93;
#X text 30 102 The elements of the array usually have at least a float field 'y' for the vertical values of the array \, but you can also have an 'x' field to set the horizontal value and there's also a special 'w' field that controls the line width. When these three fields are given (as in the green array in this example) you can click on an array point and move it bidimensionally \, and when the cursor becomes a double vertical arrow you can click and drag vertically to change the width. This template also has an 'i' field for the array index \, which is plotted., f 93;
#X text 71 520 [set] and [get] work as before \, but on array elements..., f 20;
#X text 601 535 <-- top-level;
#N canvas 260 134 601 508 initialize 0;
#X obj 112 170 pointer;
#X text 64 43 click here to re-initialize;
#X msg 270 124 \; pd-data6 clear;
#X msg 112 125 traverse pd-data6 \, bang, f 18;
#X obj 497 324 element template6 bazoo, f 10;
#X obj 38 85 trigger bang bang bang, f 31;
#X obj 336 179 trigger bang bang pointer, f 33;
#X msg 450 223 25;
#X msg 336 207 50 4 \, 3 15 \, -9 11 \, 30 19 \, -43 23, f 6;
#X text 494 301 index;
#X obj 450 248 array size -s template6 bazoo, f 15;
#X obj 336 338 set template6-element1 y, f 20;
#X obj 38 244 trigger pointer pointer, f 24;
#X obj 336 296 unpack;
#X obj 37 277 trigger bang bang pointer, f 27;
#X obj 244 415 element template6 boom, f 17;
#X msg 130 313 5;
#X obj 130 343 setsize template6 boom, f 14;
#X obj 37 394 t l b;
#X obj 268 391 + 1;
#X msg 252 362 0;
#X msg 38 145 30 50;
#X obj 38 208 append template6 x y;
#X obj 38 44 bng 19 250 50 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000;
#X obj 38 14 loadbang;
#X obj 37 466 set template6-element2 x y w i;
#X obj 192 430 t f f;
#X obj 220 387 float;
#X msg 37 308 0 80 10 \, 10 50 2 \, 200 75 15 \, 225 25 1 \, 40 100 5, f 10;
#X connect 0 0 22 2;
#X connect 3 0 0 0;
#X connect 4 0 11 1;
#X connect 5 0 21 0;
#X connect 5 1 3 0;
#X connect 5 2 20 0;
#X connect 5 2 2 0;
#X connect 6 0 8 0;
#X connect 6 1 7 0;
#X connect 6 2 4 1;
#X connect 6 2 10 1;
#X connect 7 0 10 0;
#X connect 8 0 13 0;
#X connect 12 0 14 0;
#X connect 12 1 6 0;
#X connect 13 0 11 0;
#X connect 13 1 4 0;
#X connect 14 0 28 0;
#X connect 14 1 16 0;
#X connect 14 2 15 1;
#X connect 14 2 17 1;
#X connect 15 0 25 4;
#X connect 16 0 17 0;
#X connect 18 0 25 0;
#X connect 18 1 27 0;
#X connect 19 0 27 1;
#X connect 20 0 27 1;
#X connect 21 0 22 0;
#X connect 22 0 12 0;
#X connect 23 0 5 0;
#X connect 24 0 23 0;
#X connect 26 0 25 3;
#X connect 26 1 15 0;
#X connect 27 0 19 0;
#X connect 27 0 26 0;
#X connect 28 0 18 0;
#X restore 506 603 pd initialize;
#X obj 459 456 array set -s template6 bazoo;
#X obj 284 437 element template6 boom;
#X obj 284 516 get template6-element2 y;
#X obj 56 492 set template6-element2 y;
#X obj 284 301 vradio 19 1 0 5 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000 0;
#X text 313 309 <---- select element from index, f 8;
#X text 82 326 set 'blargh' size (purple array initialized with a size of 1), f 17;
#X connect 0 0 26 0;
#X connect 1 0 27 0;
#X connect 2 0 16 1;
#X connect 2 0 24 2;
#X connect 2 0 25 1;
#X connect 5 0 2 0;
#X connect 6 0 16 0;
#X connect 7 0 25 0;
#X connect 17 0 24 0;
#X connect 18 0 5 0;
#X connect 25 0 0 0;
#X connect 25 0 27 1;
#X connect 26 0 8 0;
#X connect 28 0 7 0;