~uhh-ssd/+junk/humidity_readout

« back to all changes in this revision

Viewing changes to plplot/plplot-5.9.9/examples/perl/x13.pl

  • Committer: Joachim Erfle
  • Date: 2013-07-24 13:53:41 UTC
  • Revision ID: joachim.erfle@desy.de-20130724135341-1qojpp701zsn009p
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env perl
 
2
#
 
3
# Demo x13 for the PLplot PDL binding
 
4
#
 
5
# Does a simple pie chart
 
6
#
 
7
# Copyright (C) 2004  Rafael Laboissiere
 
8
#
 
9
# This file is part of PLplot.
 
10
#
 
11
# PLplot is free software; you can redistribute it and/or modify
 
12
# it under the terms of the GNU Library General Public License as published
 
13
# by the Free Software Foundation; either version 2 of the License, or
 
14
# (at your option) any later version.
 
15
#
 
16
# PLplot is distributed in the hope that it will be useful,
 
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
# GNU Library General Public License for more details.
 
20
#
 
21
# You should have received a copy of the GNU Library General Public License
 
22
# along with PLplot; if not, write to the Free Software
 
23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
24
 
 
25
# SYNC: x13c.c 1.15
 
26
 
 
27
# N.N. Although the visual results of this script is essentially the
 
28
# same as that produced by the equivalent C example x13c, the code
 
29
# below is quite different from that of x13c.c.  I use the vectorized
 
30
# operations of PDL extensively, such that most of the "for" loops
 
31
# disappeared. [R.L.]
 
32
 
 
33
use PDL;
 
34
use PDL::Graphics::PLplot;
 
35
use Math::Trig qw [pi];
 
36
 
 
37
my @text = (
 
38
  "Maurice",
 
39
  "Geoffrey",
 
40
  "Alan",
 
41
  "Rafael",
 
42
  "Vince"
 
43
);
 
44
 
 
45
my $per = pdl [10, 32, 12, 30, 16];
 
46
 
 
47
# Parse and process command line arguments
 
48
 
 
49
plParseOpts (\@ARGV, PL_PARSE_SKIP | PL_PARSE_NOPROGRAM);
 
50
 
 
51
# Initialize plplot
 
52
 
 
53
plinit ();
 
54
 
 
55
pladv(0);
 
56
# Ensure window has aspect ratio of one so circle is
 
57
# plotted as a circle. 
 
58
plvasp(1.0);
 
59
plwind(0., 10., 0., 10.);
 
60
#plenv (0, 10, 0, 10, 1, -2);
 
61
plcol0 (2);
 
62
# n.b. all theta quantities scaled by 2*pi/500 to be integers to avoid
 
63
# floating point logic problems.
 
64
my $theta0 = 0;
 
65
my $dthet = 1;
 
66
for (my $i = 0; $i <= 4; $i++) {
 
67
  # n.b. the theta quantities multiplied by 2*pi/500 afterward so
 
68
  # in fact per is interpreted as a percentage.
 
69
  my $theta1 = 5 * $per->index ($i);
 
70
  my $theta = $theta0 + sequence ($theta1->sclr + 1) * $dthet;
 
71
  my $xx = 5 + 3 * cos ((2 * pi / 500) * $theta);
 
72
  my $n = ($xx->dims)[0];
 
73
  my $x = zeroes ($n + 1);
 
74
  $x->slice("1:$n") .= $xx;
 
75
  $x->index (0) .= 5;
 
76
  my $yy = 5 + 3 * sin ((2 * pi / 500) * $theta);
 
77
  my $y = zeroes ($n + 1);
 
78
  $y->slice("1:$n") .= $yy;
 
79
  $y->index (0) .= 5;
 
80
  plcol0 ($i + 1);
 
81
  plpsty (($i + 3) % 8 + 1);
 
82
  plfill ($x, $y);
 
83
  plcol0 (1);
 
84
  plline ($x, $y);
 
85
  my $just = (2 * pi / 500) * ($theta0 + $theta1 / 2);
 
86
  my $dx = .25 * cos ($just);
 
87
  my $dy = .25 * sin ($just);
 
88
  $just = ((2 * $theta0 + $theta1) < 250
 
89
           || (2 * $theta0 + $theta1) > 750) ? 0 : 1;
 
90
  plptex (($xx->index ($n / 2) + $dx), ($yy->index ($n / 2) + $dy),
 
91
          1.0, 0.0, $just, $text[$i]);
 
92
  $theta0 += $theta1;
 
93
}
 
94
plfont (2);
 
95
plschr (0, 1.3);
 
96
plptex (5.0, 9.0, 1.0, 0.0, 0.5, "Percentage of Sales");
 
97
 
 
98
plend ();