 NAME
 SYNOPSIS
 DESCRIPTION
 OPTIONS
 KEYS
 IMPLEMENTATION
 ENVIRONMENT VARIABLES
 SEE ALSO
 HOME PAGE
 LICENSE
NAME
hafermancarpetx11.pl  display the Haferman carpet
SYNOPSIS
hafermancarpetx11.pl [options]
DESCRIPTION
hafermancarpetx11.pl
displays the Haferman carpet in a scrollable X11 window.
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * *
OPTIONS
fullscreen

Start with the window full screen.
geometry WIDTHxHEIGHT

Starting size of the window. For example
geometry=300x200
. scale N

Number of pixels per cell.
KEYS
The key and button controls are
 C

Centre the carpet in the window (which is its initial position).
 F

Toggle fullscreen (requires a NetWM window manager).
 I

Invert the black/white colours.
 Q

Quit.
 arrow keys, page up/down

Scroll the carpet in the window.
 +, 

Increase or decrease the scale (zoom in or out).
 Button 1

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 when X and Y are expressed in negaternary,
lowest "odd" carpet
X,Y digit pair value
 
even position 0
odd position 1
no such pair initial
An "odd" pair of digits means a pair which has xdigit+ydigit == 1 mod 2. Since each 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 "even". The next two digits are xdigit=1, ydigit=0 which is "odd". 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. The default in the program is initial value 0.
Drawing
The X drawing is done by constructing two bitmaps which is a block of "1" expanded down according to the Haferman carpet rule, and a block of "0".
++++ ++++
   0  1  0 
+ + ++++
 1  =>  1  0  1 
+ + ++++
   0  1  0 
++++ ++++
The bitmap size is scale*3^exp, where exp is chosen so the 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 "block" X,Y coordinates 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 is odd then the "initial" value used for the cell calculation must be inverted, since an odd exp is an odd number of expansions and flips the centre cell 0<>1.
Scrolling is smoothed by drawing with the server DOUBLEBUFFER extension if available. But even if it's not then it's only 9 block copies and should look reasonable.
ENVIRONMENT VARIABLES
DISPLAY

The X display to use.
SEE ALSO
X11::Protocol, Math::NumSeq::HafermanCarpet
http://mathworld.wolfram.com/HafermanCarpet.html
HOME PAGE
http://user42.tuxfamily.org/mathnumseq/index.html
LICENSE
MathNumSeq is Copyright 2010, 2011, 2012, 2013 Kevin Ryde
MathNumSeq 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.
MathNumSeq 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 MathNumSeq. If not, see <http://www.gnu.org/licenses/>.