-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathmoebius_walking_line.pl
More file actions
executable file
·46 lines (35 loc) · 937 Bytes
/
moebius_walking_line.pl
File metadata and controls
executable file
·46 lines (35 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/perl
# Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 13 November 2016
# Website: https://github.com/trizen
# Draw a line using the values of the Möbius function: μ(n)
# The rules are the following:
# when μ(n) = -1, the angle is changed to -45 degrees
# when μ(n) = +1, the angle is changed to +45 degrees
# when μ(n) = 0, the angle is changed to 0 degrees
# In all three cases, a pixel is recorded for each value of μ(n).
use 5.010;
use strict;
use warnings;
use GD::Simple;
use ntheory qw(moebius);
my $width = 1000;
my $height = 100;
my $img = GD::Simple->new($width, $height);
$img->moveTo(0, $height / 2);
foreach my $u (moebius(1, $width)) {
if ($u == 1) {
$img->angle(45);
}
elsif ($u == -1) {
$img->angle(-45);
}
else {
$img->angle(0);
}
$img->line(1);
}
open my $fh, '>:raw', 'moebius_walking_like.png';
print $fh $img->png;
close $fh;