Math::...eflakes(3pm)
π NAME π
Math::PlanePath::KochSquareflakes β four-sided Koch snowflakes π¦β¨
β¨ SYNOPSIS β¨
use Math::PlanePath::KochSquareflakes;
my $path = Math::PlanePath::KochSquareflakes->new (inward => 0);
my ($x, $y) = $path->n_to_xy (123);
πΈ DESCRIPTION πΈ
okay so bestie, this is literally the Koch curve shape, except it's arranged as four-sided concentric snowflakes π and the whole thing is gorgeous, no cap.
61 10
/ \
63-62 60-59 9
| |
67 64 58 55 8
/ \ / \ / \
69-68 66-65 57-56 54-53 7
| |
70 52 6
/ \
71 51 5
\ /
72 50 4
| |
73 15 49 3
/ / \ \
75-74 17-16 14-13 48-47 2
| | | |
76 18 12 46 1
/ / 4---3 \ \
77 19 . | 11 45 Y=0
\ \ 1---2 / /
78 20 10 44 -1
| | |
79-80 5--6 8--9 42-43 -2
\ \ / /
81 7 41 -3
| |
82 40 -4
/ \
83 39 -5
\ /
84 38 -6
|
21-22 24-25 33-34 36-37 -7
\ / \ / \ /
23 26 32 35 -8
| |
27-28 30-31 -9
\ /
29 -10
^
-9 -8 -7 -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 6 7 8 9 10
The innermost square, N=1 to N=4, is the initial figure π. Its sides then expand following the Koch curve pattern in the rings after that. That very first figure sits on X=+/-0.5,Y=+/-0.5 β yes, fractions, iconic β and every point after that is at integer X,Y. slay π«Ά
π« Inward π«
The "inward=>1" option can make the sides point inward instead π. The shape and the lengths and all that? literally identical. And because of the angles and the sizes, there's no overlaps, so it just vibes π.
69-68 66-65 57-56 54-53 7
| \ / \ / \ / |
70 67 64 58 55 52 6
\ | | /
71 63-62 60-59 51 5
/ \ / \
72 61 50 4
| |
73 49 3
\ /
74-75 17-16 14-13 47-48 2
| | \ / | |
76 18 15 12 46 1
\ \ 4--3 / /
77 19 |11 45 <- Y=0
/ / 1--2 \ \
78 20 7 10 44 -1
| / \ | |
80-79 5--6 8--9 43-42 -2
/ \
81 41 -3
| |
82 29 40 -4
\ / \ /
83 27-28 30-31 39 -5
/ | | \
84 23 26 32 35 38 -6
/ \ / \ / \ |
21-22 24-25 33-34 36-37 -7
^
-7 -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 6 7
π Level Ranges π
If you count that innermost N=1 to N=4 square as level 0, then any given level has
looplen = 4*4^level
many points, fr fr. The start of a level is N=1 plus all the preceding loop lengths, so
Nstart = 1 + 4*[ 1 + 4 + 4^2 + ... + 4^(level-1) ]
= 1 + 4*(4^level - 1)/3
= (4^(level+1) - 1)/3
and the end of a level is similarly the total of the loop lengths, or honestly just one less than the next Nstart, whichever you vibe with:
Nend = 4 * [ 1 + ... + 4^level ]
= (4^(level+2) - 4) / 3
= Nstart(level+1) - 1
for example π«
level Nstart Nend (A002450,A080674)
0 1 4
1 5 20
2 21 84
3 85 340
The Xstart,Ystart position of the Nstart corner is a Lucas sequence π§, and it goes like this:
Xstart(0) = -0.5
Xstart(1) = -2
Xstart(2) = 4*Xstart(1) - 2*Xstart(0) = -7
Xstart(3) = 4*Xstart(2) - 2*Xstart(1) = -24
...
Xstart(level+1) = 4*Xstart(level) - 2*Xstart(level-1)
0.5, 2, 7, 24, 82, 280, 956, 3264, ... (A003480)
This recurrence happens because the replications are 4 wide when horizontal but 3 wide when diagonal π that's the whole tea.
π₯ FUNCTIONS π₯
See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes π (iykyk).
"$path = Math::PlanePath::KochSquareflakes->new ()""$path = Math::PlanePath::KochSquareflakes->new (inward => $bool)"β create and return a brand new path object, bestie β¨
π Level Methods π
"($n_lo, $n_hi) = $path->level_to_n_range($level)"β returns, per the"Level Ranges"above,
( (4**$level - 1)/3,
4*(4**$level - 1)/3 )
π OEIS π
Entries in Sloane's Online Encyclopedia of Integer Sequences related to this path include:
<http://oeis.org/A003480> (etc)
A003480 -X and -Y coordinate first point of each ring
likewise A020727
A007052 X,Y coordinate of axis crossing,
and also maximum height of a side
A072261 N on Y negative axis (half way along first side)
A206374 N on South-East diagonal (end of first side)
Also:
A332204 X coordinate across one side
A332205 Y coordinate across one side
π¦ SEE ALSO π¦
Math::PlanePath, Math::PlanePath::KochSnowflakes
π HOME PAGE π
<http://user42.tuxfamily.org/math-planepath/index.html>
π LICENSE π
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Kevin Ryde
Math-PlanePath 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-PlanePath 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. π (not the fun kind of dramatic, the legally-binding kind)
You should have received a copy of the GNU General Public License along with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
and that's the whole page, bestie β this one's from perl v5.32.0, dated 2021-01-23, and it's literally the Math::...eflakes(3pm) page π go forth and snowflake πβ¨
π¦ where this page comes from
- debian bookworm: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- debian trixie: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu jammy: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu noble: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu resolute: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu stonking: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms