-
Notifications
You must be signed in to change notification settings - Fork 34
/
square_of_circles.pl
executable file
·69 lines (53 loc) · 1.31 KB
/
square_of_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl
# Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 19 December 2016
# https://github.com/trizen
# Draws a square with diagonals made out of circles.
use 5.010;
use strict;
use warnings;
use GD::Simple;
my $img = 'GD::Simple'->new(1000, 1000);
$img->fgcolor('blue');
$img->bgcolor(undef);
$img->moveTo(200, 150);
my $n = 15;
my $size = 45;
my $dsize = $size / (1 + sqrt(2));
my $dmove = $size / 4;
for (1 .. $n) {
my ($x, $y) = $img->curPos;
$img->moveTo($x, $y + $size);
$img->ellipse($size, $size);
}
for (1 .. $n - 1) {
my ($x, $y) = $img->curPos;
$img->moveTo($x + $size, $y);
$img->ellipse($size, $size);
}
for (1 .. $n - 1) {
my ($x, $y) = $img->curPos;
$img->moveTo($x, $y - $size);
$img->ellipse($size, $size);
}
my ($x, $y) = $img->curPos;
for (1 .. $n - 1) {
my ($x, $y) = $img->curPos;
$img->moveTo($x - $size, $y);
$img->ellipse($size, $size);
}
for (1 .. 4 * ($n - 1) - 2) {
my ($x, $y) = $img->curPos;
$img->moveTo($x + $dmove, $y + $dmove);
$img->ellipse($dsize, $dsize) if $_ > 1;
}
$img->moveTo($x, $y);
for (1 .. 4 * ($n - 1) - 2) {
my ($x, $y) = $img->curPos;
$img->moveTo($x - $dmove, $y + $dmove);
$img->ellipse($dsize, $dsize) if $_ > 1;
}
open my $fh, '>:raw', 'square_of_circles.png';
print $fh $img->png;
close $fh;