File: tree.pl

package info (click to toggle)
libsvg-graph-perl 0.02-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 616 kB
  • sloc: perl: 2,793; makefile: 2
file content (45 lines) | stat: -rwxr-xr-x 896 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

use strict;
use Data::Dumper;
use SVG::Graph;
use SVG::Graph::Data;
use SVG::Graph::Data::Tree;

my %fill = (
	   1=>'red',
	   2=>'orange',
	   3=>'yellow',
	   4=>'green',
	   5=>'blue',
	   6=>'indigo',
	   7=>'violet',
	   );

my $graph = SVG::Graph->new(width=>600,height=>600,margin=>30);

my $group0 = $graph->add_frame;

my $tree = SVG::Graph::Data::Tree->new;

$group0->add_data($tree);

my $root = $tree->root;
$root->branch_length(int(rand(10)+1));

my @nodes = ();
for my $c (0..20){
  my $node = $tree->new_node(branch_length=>int(rand(10)+2),stroke=>$fill{int(rand(7)+1)},'stroke-width'=>int(rand(5)+1));

  if($c < 2){
    $root->add_daughter($node);
  } else {
    my $rand_parent = $nodes[int(rand($#nodes))];
    $rand_parent->add_daughter($node);
  }

  push @nodes, $node;
}

$group0->add_glyph('tree', stroke=>'black','stroke-width'=>2);
print $graph->draw;