-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathspiral_tree.pl
More file actions
executable file
·47 lines (34 loc) · 861 Bytes
/
spiral_tree.pl
File metadata and controls
executable file
·47 lines (34 loc) · 861 Bytes
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
#!/usr/bin/perl
# Author: Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 13 August 2015
# https://github.com/trizen
# Generate a spiral tree with branches
# Inspired from: https://www.youtube.com/watch?v=RWAcbV4X7C8
use GD::Simple;
my $img = GD::Simple->new(1000, 700);
$img->moveTo(500, 650);
$img->turn(-90);
sub branch {
my ($len) = @_;
$img->line($len);
$len *= 0.64;
if ($len > 2) {
my @pos1 = $img->curPos;
my $angle1 = $img->angle;
$img->turn(45);
branch($len);
$img->moveTo(@pos1);
$img->angle($angle1);
my @pos2 = $img->curPos;
my $angle2 = $img->angle;
$img->turn(-90);
branch($len);
$img->moveTo(@pos2);
$img->angle($angle2);
}
}
branch(250);
open my $fh, '>:raw', 'spiral_tree.png';
print $fh $img->png;
close $fh;