The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Math::PlanePath::MathImageGrayCurve -- 2x2 self-similar Z shape digits

SYNOPSIS

 use Math::PlanePath::MathImageGrayCurve;

 my $path = Math::PlanePath::MathImageGrayCurve->new;
 my ($x, $y) = $path->n_to_xy (123);

DESCRIPTION

In progress... Mostly works.

This is a split of N into X,Y by alternate bits, but with N values in Gray code order.

      7  |  63--62  57--56  39--38  33--32
         |       |   |           |   |
      6  |  60--61  58--59  36--37  34--35
         |
      5  |  51--50  53--52  43--42  45--44
         |       |   |           |   |
      4  |  48--49  54--55  40--41  46--47
         |
      3  |  15--14   9-- 8  23--22  17--16
         |       |   |           |   |
      2  |  12--13  10--11  20--21  18--19
         |
      1  |   3-- 2   5-- 4  27--26  29--28
         |       |   |           |   |
     Y=0 |   0-- 1   6-- 7  24--25  30--31
         +----------------------------------
            X=0  1   2   3   4   5   6   7

Within an power of 2 square 2x2, 4x4, 8x8, 16x16 etc (2^k)x(2^k), all the N values 0 to 2^(2*k)-1 are within the square. The top left corner 3, 15, 63, 255 etc of each is the 2^(2*k)-1 maximum. The bottom left corner 1, 7, 31, 127 etc is half-way, ie. one bit less.

FUNCTIONS

See "FUNCTIONS" in Math::PlanePath for the behaviour common to all path classes.

$path = Math::PlanePath::MathImageGrayCurve->new ()

Create and return a new path object. The optional radix parameter gives the base for digit splitting (the default is binary, radix 2).

($x,$y) = $path->n_to_xy ($n)

Return the X,Y coordinates of point number $n on the path. Points begin at 0 and if $n < 0 then the return is an empty list.

SEE ALSO

Math::PlanePath, Math::PlanePath::ZOrderCurve