NAME
haferman-carpet-x11.pl -- display the Haferman carpet
SYNOPSIS
haferman-carpet-x11.pl [--options]
DESCRIPTION
haferman-carpet-x11.pl displays the Haferman carpet in a scrollable X11 window. A relatively simple drawing rule produces an repeating pattern of interlocking rings.
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
OPTIONS
--fullscreen-
Start with the window full screen.
--geometry WIDTHxHEIGHT-
Initial size of the window. For example
--geometry=300x200. --initial 1-
Set the initial cell value, which is the cell at the very centre of the pattern. It can be 0 or 1. The default is 0.
--scale N-
Number of pixels per cell.
KEYS
The key and button controls are
- c
-
Centre the carpet in the window (its initial position).
- f
-
Toggle fullscreen (requires a Net-WM window manager).
- i
-
Invert black/white colours.
- q
-
Quit.
- arrow keys, page up, page down
-
Scroll the carpet in the window.
- space
-
Toggle initial cell value 0 <-> 1.
- +, -
-
Increase or decrease the scale (zoom in or out).
-
Drag the carpet in the window.
IMPLEMENTATION
Carpet Cells
The value of the carpet at a given X,Y is given by the position of the lowest odd digit pair of X,Y when X and Y are written in negaternary,
lowest "odd" carpet
X,Y digit pair value
-------------- ------
even position 0
odd position 1
no such pair initial cell
An "odd" pair of digits means a pair which has xdigit+ydigit == 1 mod 2. Since each digit is -1,0,1 this is abs(xdigit)!=abs(ydigit).
"even" digit pairs "odd" digit pairs
0,0 1,1 -1,1 1,-1, -1,-1 0,1 1,0 0,-1 -1,0
For example X=-4, Y=1 written in negaternary is X=[-1][-1], Y=[0][1]. The two lowest digits are xdigit=-1, ydigit=1 which is an "even" pair. The next two digits are xdigit=-1, ydigit=0 which is an "odd" pair. That "odd" pair is at an odd position (the low end is position 0 and the next is position 1, etc). So in the table look under "odd position" for carpet value 1.
If there are no "odd" digit pairs at all in X,Y then the carpet cell is the initial cell value which is the cell at the very centre of the carpet. Per the --initial option, the default is 0.
Drawing
The X drawing is done by constructing two bitmaps which are a block of "0" or "1" expanded down according to the Haferman carpet rule.
+---+---+---+ +---+---+---+
| | | 0 | 1 | 0 |
+ + +---+---+---+
| 1 | => | 1 | 0 | 1 |
+ + +---+---+---+
| | | 0 | 1 | 0 |
+---+---+---+ +---+---+---+
The bitmap size is scale*3^exp with exp chosen so this size is less than the window size (the bigger of width and height). With such a size, at most three blocks across and down suffice to cover the window,
block block block
+--------+--------+--------+
block | | | |
| window| | | Y=+1
| +-------------------+ |
| | | | | |
+--|-----+--------+----|---+
block | | | | | |
| | | | | | Y=0
| | | | | |
| | | | | |
+--|-----+--------+----|---+
block | | | | | |
| +-------------------+ | Y=-1
| | | |
| | | |
+--------+--------+--------+
X=-1 X=0 X=+1
The desired pixel region X,Y becomes X,Y coordinates of the "block" and an offset. The block X,Y gives a cell value as described above, and that cell value selects the "0" or "1" bitmap. If exp in the bitmap size is odd then the "initial" value used for the cell calculation must be inverted. This is since an odd exp is an odd number of expansions and that flips the centre cell 0<->1.
Scrolling is smoothed by drawing with the server DOUBLE-BUFFER extension if available. But even without that it's only at most 9 block copies and so should look reasonable.
ENVIRONMENT VARIABLES
DISPLAY-
The X display to use.
SEE ALSO
X11::Protocol, X11::Protocol::Other, Math::NumSeq::HafermanCarpet
http://mathworld.wolfram.com/HafermanCarpet.html
HOME PAGE
http://user42.tuxfamily.org/math-numseq/index.html
LICENSE
Math-NumSeq is Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2019, 2020 Kevin Ryde
Math-NumSeq is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-NumSeq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.