-
Notifications
You must be signed in to change notification settings - Fork 34
/
divisor_circles.pl
executable file
·45 lines (36 loc) · 1.05 KB
/
divisor_circles.pl
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
#!/usr/bin/perl
# Author: Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 14 September 2016
# Website: https://github.com/trizen
# For each divisor `d` of a number `n`, draw a circle in such a
# way that the line of the circle passes through both `n` and `d`.
use 5.014;
use strict;
use warnings;
use Imager;
use ntheory qw(divisors);
my $limit = 1000;
my $scale = 10;
my $red = Imager::Color->new('#ff0000');
my $img = Imager->new(xsize => $limit * $scale,
ysize => $limit * $scale,);
sub get_circle {
my ($n, $f) = @_;
my $r = ($n * $scale - $f * $scale) / 2;
($r, $r + $f * $scale, $limit * $scale / 2);
}
foreach my $n (1 .. $limit) {
foreach my $f (divisors($n)) {
my ($r, $x, $y) = get_circle($n, $f);
$img->circle(
x => $x,
y => $y,
r => $r,
color => $red,
filled => 0
);
}
}
$img = $img->rotate(degrees => 90);
$img->write(file => 'divisor_circles.png');