-
Notifications
You must be signed in to change notification settings - Fork 33
/
cyan_vision.pl
executable file
·68 lines (52 loc) · 1.75 KB
/
cyan_vision.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
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/perl
# Author: Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 16 November 2016
# Website: https://github.com/trizen
# Redraws each pixel as a cyan colored circle.
# WARNING: this process is *very* slow for large images.
use 5.010;
use strict;
use warnings;
use Imager;
use List::Util qw(max);
my @matrix;
{
my $img = Imager->new(file => shift(@ARGV))
|| die die "usage: $0 [image]\n";
my $height = $img->getheight - 1;
my $width = $img->getwidth - 1;
foreach my $y (0 .. $height) {
push @matrix, [
map {
my ($r, $g, $b) = $img->getpixel(y => $y, x => $_)->rgba;
my $rgb = $r;
$rgb = ($rgb << 8) + $g;
$rgb = ($rgb << 8) + $b;
$rgb
} (0 .. $width)
];
}
}
my $max_color = 2**16 - 1; # normal color is: 2**24 - 1
my $scale_factor = 3; # the scaling factor does not affect the performance
my $radius = $scale_factor / atan2(0, -'inf');
my $space = $radius / 2;
my $img = Imager->new(
xsize => @{$matrix[0]} * $scale_factor,
ysize => @matrix * $scale_factor,
channels => 3,
);
my $max = max(map { @$_ } @matrix);
foreach my $i (0 .. $#matrix) {
my $row = $matrix[$i];
foreach my $j (0 .. $#{$row}) {
$img->circle(
r => $radius,
x => $j * $scale_factor + $radius + $space,
y => $i * $scale_factor + $radius + $space,
color => sprintf("#%06x", $row->[$j] / $max * $max_color),
);
}
}
$img->write(file => 'cyan_image.png');