-
Notifications
You must be signed in to change notification settings - Fork 33
/
dancing_shapes.pl
executable file
·71 lines (55 loc) · 1.72 KB
/
dancing_shapes.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
69
70
71
#!/usr/bin/perl
# Author: Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 30 April 2014
# Website: https://github.com/trizen
# Generate mathematical shapes
# -- feel free to play with the numbers --
use 5.010;
use strict;
use warnings;
use GD::Simple;
my $img = 'GD::Simple'->new(3000, 3000);
sub t($) {
$img->turn(shift);
}
sub l($) {
$img->line(shift);
}
sub c($) {
$img->fgcolor(shift);
}
my $dirname = "Dancing shapes";
-d $dirname or do {
mkdir($dirname)
or die "Can't mkdir '$dirname': $!";
};
chdir($dirname)
or die "Can't chdir into '$dirname': $!";
foreach my $t (1 .. 179) { # turn from 1 to 179
for my $k (5 .. 9) { # draw this many pictures for each turn
# Info to STDOUT
say "$t:$k";
$img->clear;
$img->moveTo(1500, 1500); # hopefully, at the center of the image
for my $i (1 .. $t) { # another interesting set is from 1..$k
for my $j (1 .. $k) {
$img->fgcolor('green');
l(40 * $j); # the length of a given line (in pixels)
$img->fgcolor('blue');
l(-40 * ($j / 2)); # if you happen to love textiles, comment this line :)
t $t;
}
$img->fgcolor('red');
l 40;
##last; # to generate only the basic shapes, uncomment this line.
}
my $image_name = sprintf('%03d-%02d.png', $t, $k);
open my $fh, '>:raw', $image_name or die $!;
print {$fh} $img->png;
close $fh;
## View the image as soon as it is generated
#system "gliv", $image_name; # edit this line
#$? == 0 or die "Non-zero exit code of the image viewer: $?";
}
}