4,493
edits
Line 178: | Line 178: | ||
<source lang=apl inline>⊢</source> is the [[identity]] function, which is just used here get the pass-though value from the assignment, as it would otherwise be hidden. (We call assignment ''shy''.) <source lang=apl inline>\</source> is just like <source lang=apl inline>/</source> but gives us the intermediate values. | <source lang=apl inline>⊢</source> is the [[identity]] function, which is just used here get the pass-though value from the assignment, as it would otherwise be hidden. (We call assignment ''shy''.) <source lang=apl inline>\</source> is just like <source lang=apl inline>/</source> but gives us the intermediate values. | ||
=== | === Combining arrays === | ||
<source lang=apl inline> | We need our offsets in two dimensions. So we need to combine the elements of <source lang=apl inline>offset</source> with themselves in all possible combinations. | ||
The [[Rank operator]] (<source lang=apl inline>⍤</source>) allows you to specify what you want paired up with what. In our case, we want individual numbers (which have zero [[axes]]) paired up with other individual numbers. As pairing up the numbers in <source lang=apl inline>3 1 4</source> with those in <source lang=apl inline>2 7 1</source>: | |||
<source lang=apl> | <source lang=apl> | ||
3 1 4(,⍤0)2 7 1 | |||
3 2 | |||
1 7 | |||
4 1 | |||
</source> | </source> | ||
But we want to pair up each of the individual offsets with each of all the offsets. The offsets form a list, so we want to apply this pair-wise pairing function between each number and the entire list, as in: | |||
<source lang=apl> | <source lang=apl> | ||
3 1 4(,⍤0⍤0 1)2 7 1 | |||
3 2 | |||
3 7 | |||
3 1 | |||
1 2 | |||
1 7 | |||
1 1 | |||
4 2 | |||
4 7 | |||
4 1 | |||
</source> | |||
Since we want the offsets paird up with themselves, we can use <source lang=apl inline>⍨</source> again: | |||
<source lang=apl> | |||
,⍤0⍤0 1⍨⍳3 | |||
0 0 | |||
0 1 | |||
0 2 | |||
1 0 | |||
1 1 | |||
1 2 | |||
2 0 | |||
2 1 | |||
2 2 | |||
</source> | |||
The offset pairs form our circle locations: | |||
⍴locs←indices⌷⍤0 1⊢offsets | ⍴locs←indices⌷⍤0 1⊢offsets | ||
5 5 2 | 5 5 2 | ||
</source> | </source> | ||
that is, it is a 3D array with 5 layers, 5 rows in each layer, and 2 columns in each row. The [[Rank operator]] (<source lang=apl inline>⍤</source>) allows me to specify that I want rank 0 sub-arrays on the left paired up with rank-1 sub-arrays on the right. | that is, it is a 3D array with 5 layers, 5 rows in each layer, and 2 columns in each row. The [[Rank operator]] (<source lang=apl inline>⍤</source>) allows me to specify that I want rank 0 sub-arrays on the left paired up with rank-1 sub-arrays on the right. Each row of our result represents an <math>(x,y)</math> value. The first and last layers, which represents the leftmost and rightmost columns of the logo, are: | ||
Each row of our result represents an <math>(x,y)</math> value. The first and last layers, which represents the leftmost and rightmost columns of the logo, are: | |||
<source lang=apl> | <source lang=apl> | ||
(1↑locs) (¯1↑locs) | (1↑locs) (¯1↑locs) |