APL Wiki logo: Difference between revisions
Jump to navigation
Jump to search
→Towards an SVG
Miraheze>Adám Brudzewsky No edit summary |
Miraheze>Adám Brudzewsky |
||
Line 143: | Line 143: | ||
</source> | </source> | ||
== | == Placing the circles == | ||
=== | === Pairwise summation === | ||
Now that we have our radii, we need to figure out where to put our circles. The horizontal pair-wise sum shows how much adjacent circles "reach out" towards each other. [[N-wise Reduce]] solves that. Here, <source lang=apl inline>/</source> is an operator which takes the plus function and applies it in-between the elements of each horizontal run of length ''N'' (the left argument) in the right argument: | Now that we have our radii, we need to figure out where to put our circles. The horizontal pair-wise sum shows how much adjacent circles "reach out" towards each other. [[N-wise Reduce]] solves that. Here, <source lang=apl inline>/</source> is an operator which takes the plus function and applies it in-between the elements of each horizontal run of length ''N'' (the left argument) in the right argument: | ||
<source lang=apl> | <source lang=apl> | ||
Line 154: | Line 154: | ||
3 5 5 3 | 3 5 5 3 | ||
</source> | </source> | ||
=== Finding maxima === | |||
Since the circles line up on a grid, we need the maximum for each horizontal space, that is for each column. APL uses [[dyad]]ic <source lang=apl inline>a⌈b</source> as the [[maximum]] of ''a'' and ''b''. <source lang=apl inline>⌈⌿</source> is the columnar maximum-[[reduce|reduction]]: | Since the circles line up on a grid, we need the maximum for each horizontal space, that is for each column. APL uses [[dyad]]ic <source lang=apl inline>a⌈b</source> as the [[maximum]] of ''a'' and ''b''. <source lang=apl inline>⌈⌿</source> is the columnar maximum-[[reduce|reduction]]: | ||
<source lang=apl> | <source lang=apl> | ||
Line 165: | Line 166: | ||
</source> | </source> | ||
<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 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''.) | ||
=== Generating indices in 2D === | |||
<source lang=apl inline> | <source lang=apl inline>⍴r</source> is the [[shape]] of our array of radii. Now, you remember <source lang=apl inline>⍳</source>, [[#Generating_indices|right]]? As it turns out, it can actually generate of an array of any number of dimensions; two in our case: | ||
<source lang=apl> | <source lang=apl> | ||
⊢indices←⍳⍴r | ⊢indices←⍳⍴r | ||
┌───┬───┬───┬───┬───┐ | ┌───┬───┬───┬───┬───┐ |