-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpiechart.pl
More file actions
32 lines (24 loc) · 816 Bytes
/
piechart.pl
File metadata and controls
32 lines (24 loc) · 816 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
#!/usr/env perl
use lib "../lib";
use CAD::OpenSCAD;
my $EnergyUtilisation={Electricity=>4000,Gas=>5100,Petrol=>1000,Coal=>2300};
pieChart($EnergyUtilisation);
sub pieChart{
my $data=shift;
my $total=0;
my $pecentages={};
my @colours=(qw/red orange yellow green blue indigo violet/);
my $chart=new OpenSCAD;
$chart->square("profile", [20,5],1);
$total+=$data->{$_} foreach(keys %$data);
my @segments=();my $accum=0;my $colIndex=0;
foreach my $segment (keys %$data){
my $angle=360*$data->{$segment}/$total;
$chart->rotate_extrude($segment,"profile",{angle=>$angle})
->rotate($segment,[0,0,$accum])
->color($segment,$colours[$colIndex++]);
push @segments,$segment;
$accum+=$angle;
};
$chart->build(@segments)->save("chart");
}