-
Notifications
You must be signed in to change notification settings - Fork 34
/
julia_set.pl
executable file
·49 lines (36 loc) · 1.02 KB
/
julia_set.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
#!/usr/bin/perl
# Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 07 March 2016
# Edit: 25 January 2018
# Website: https://github.com/trizen
# See also:
# https://en.wikipedia.org/wiki/Julia_set
# https://trizenx.blogspot.com/2016/05/julia-set.html
use 5.010;
use strict;
use warnings;
use Imager;
use Math::GComplex qw(cplx);
my($w, $h, $zoom) = (1000, 1000, 0.7);
my $img = Imager->new(xsize => $w, ysize => $h, channels => 3);
my $color = Imager::Color->new('#000000');
my $I = 255;
my $L = 2;
my $c = cplx(-0.7, 0.27015);
my ($moveX, $moveY) = (0, 0);
foreach my $x (0 .. $w - 1) {
foreach my $y (0 .. $h - 1) {
my $z = cplx(
(2 * $x - $w) / ($w * $zoom) + $moveX,
(2 * $y - $h) / ($h * $zoom) + $moveY,
);
my $i = $I;
while (abs($z) < $L and --$i) {
$z = $z*$z + $c;
}
$color->set(hsv => [$i / $I * 360 - 120, 1, $i / $I]);
$img->setpixel(x => $x, y => $y, color => $color);
}
}
$img->write(file => 'julia_set.png');