Skip to content

Instantly share code, notes, and snippets.

@timo

timo/hilbert.p6 Secret

Created August 6, 2019 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timo/47faa5c04b41c88a729aaa64fcc2aca8 to your computer and use it in GitHub Desktop.
Save timo/47faa5c04b41c88a729aaa64fcc2aca8 to your computer and use it in GitHub Desktop.
sub rot($n, int $x is rw, int $y is rw, $rx, $ry) {
if $ry == 0 {
if $rx == 1 {
$x = $n - 1 - $x;
$x = $n - 1 - $y;
}
my int $t = $x;
$x = $y;
$y = $t;
}
}
sub d2xy($n, $d, int $x is rw, int $y is rw) {
my $t = $d;
$x = 0;
$y = 0;
for 1, 2, 4 ... $n -> int $s {
my $rx = 1 +& ($t div 2);
my $ry = 1 & ($t +^ $rx);
rot($s, $x, $y, $rx, $ry);
$x += $s * $rx;
$y += $s * $ry;
$t div= 4;
}
}
sub frame($_, $t, $dt) {
.rgb(1, 0.75, 0.1);
my int $x;
my int $y;
for ^128 {
d2xy(8, $_, $x, $y);
.line_to($x, $y);
}
.stroke();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment