APL Wiki logo: Difference between revisions

Jump to navigation Jump to search
3,080 bytes added ,  14:43, 5 November 2019
no edit summary
Miraheze>Adám Brudzewsky
No edit summary
Miraheze>Adám Brudzewsky
No edit summary
Line 11: Line 11:
1 2 3 2 1
1 2 3 2 1
</source>
</source>
This page explains, step-by-step, how we generate our SVG logo, using the above expression<ref>[https://codegolf.stackexchange.com/users/78410/bubbler "Bubbler"], message [https://chat.stackexchange.com/transcript/message/52389201#52389201 "52389201"] in ''The Nineteenth Byte'' chat room. Stack Exchange network, 2019-10-31 23:57</ref> — an expression which happens to demonstrates quite a few APL features.
This page explains, step-by-step, how we generate our SVG logo, using the above expression<ref>[https://codegolf.stackexchange.com/users/78410/bubbler "Bubbler"], message [https://chat.stackexchange.com/transcript/message/52389201#52389201 "52389201"] in ''The Nineteenth Byte'' chat room. Stack Exchange network, 2019-10-31 23:57</ref>. This demonstrates quite a few APL features.


We will follow APL's evaluation from [[Evaluation order|right to left]].
We will follow APL's evaluation from [[Evaluation order|right to left]].
Line 138: Line 138:
1 2 3 2 1
1 2 3 2 1
</source>
</source>
And there it is!
Those are our radii! Let's save them:
<source lang=apl>
      r←⌊∘.+⍨.5×4!⍨⍳5
</source>
 
== Towards an SVG ==
=== Placing the circles ===
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>
      2+/sizes
3  5  5 3
6  9  9 6
8 11 11 8
6  9  9 6
3  5  5 3
</source>
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>
      ⌈⌿2+/sizes
8 11 11 8
</source>
But obviously, we can't let the circles touch, so we add 1. Finally, we prepend a 0 which is the offset of the first circle:
<source lang=apl>
      ⊢offsets←0,+\1+⌈⌿2+/sizes
0 9 21 33 42
</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 [[shape]] and <source lang=apl inline>⍳</source> generates the [[index of|indices]] of an array of that size.
<source lang=apl>
      ⍴r
5 5
      ⊢indices←⍳⍴r
┌───┬───┬───┬───┬───┐
│0 0│0 1│0 2│0 3│0 4│
├───┼───┼───┼───┼───┤
│1 0│1 1│1 2│1 3│1 4│
├───┼───┼───┼───┼───┤
│2 0│2 1│2 2│2 3│2 4│
├───┼───┼───┼───┼───┤
│3 0│3 1│3 2│3 3│3 4│
├───┼───┼───┼───┼───┤
│4 0│4 1│4 2│4 3│4 4│
└───┴───┴───┴───┴───┘
</source>
Now we take each coordinate (i.e. each [[rank]] 0 cell) from that and use it to [[Squad index|index]] into the list (a [[rank]] 1 array) of offsets. The result is has shape…
<source lang=apl>
      ⍴xy←indices⌷⍤0 1⊢offsets
5 5 2
</source>
that is, it is a 3D array with 5 layers, 5 rows in each layer, and 2 columns in each row. Each row 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>
      (1↑xy) (¯1↑xy)
┌────┬─────┐
│0  0│42  0│
│0  9│42  9│
│0 21│42 21│
│0 33│42 33│
│0 42│42 42│
└────┴─────┘
</source>
E.g. the second row in the first layer is <math>(x,y)=(0,9)</math>
 
<source lang=apl>
</source>
=== Making <code><circle/></code> tags ===
<source lang=apl>
</source>
 
<source lang=apl>
</source>
 
<source lang=apl>
</source>


== References ==
== References ==
<references />
<references />

Navigation menu