-
Notifications
You must be signed in to change notification settings - Fork 33
/
factor_circles.pl
executable file
·48 lines (39 loc) · 1.16 KB
/
factor_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
46
47
48
#!/usr/bin/perl
# Author: Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 14 September 2016
# Website: https://github.com/trizen
# For each factor `f` of a composite number `n`, draw a circle
# in such a way that the line of the circle passes through both `n` and `f`.
use 5.014;
use strict;
use warnings;
use Imager;
use List::Util qw(uniq);
use ntheory qw(is_prime factor);
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) {
if (not is_prime($n)) {
foreach my $f (uniq(factor($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 => 'factor_circles.png');