-
Notifications
You must be signed in to change notification settings - Fork 34
/
fact_exp_primorial_growing.pl
executable file
·56 lines (38 loc) · 1.15 KB
/
fact_exp_primorial_growing.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
49
50
51
52
53
54
55
56
#!/usr/bin/perl
# Author: Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 19 August 2015
# Website: https://github.com/trizen
# Plot the growing of exponentiation, factorial and primorial.
# blue is n!
# green is n^n
# red is n-primorial
# The plot is logarithmic in base e.
use 5.010;
use strict;
use warnings;
use Imager qw();
use ntheory qw(nth_prime);
my $xsize = 250;
my $ysize = 600;
my $img = Imager->new(xsize => $xsize, ysize => $ysize);
my $white = Imager::Color->new('#ffffff');
my $red = Imager::Color->new('#ff0000');
my $blue = Imager::Color->new('#0000ff');
my $green = Imager::Color->new('#00ff00');
$img->box(filled => 1, color => $white);
my $x = 0;
{
use Math::AnyNum qw(:overload);
my $f = 1;
my $p = 1;
for (my $i = 1 ; $i <= 100 ; ++$i) {
$f *= $i + 1;
$p *= nth_prime($i);
$img->setpixel(x => $x, y => (abs(log($p) - $ysize))->as_int, color => $red);
$img->setpixel(x => $x, y => (abs(log($f) - $ysize))->as_int, color => $blue);
$img->setpixel(x => $x, y => (abs(log($i**$i) - $ysize))->as_int, color => $green);
$x++;
}
}
$img->write(file => 'grow.png');