blib/lib/PDL/Demos/TriD1.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 40 CC 1 SCAR 6.9
CC
1
Cov
0%
run
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 # Copyright (C) 1998 Tuomas J. Lukka.
2 # All rights reserved, except redistribution
3 # with PDL under the PDL License permitted.
4  
5 package PDL::Demos::TriD1;
6  
7 use PDL;
8 use PDL::Graphics::TriD;
9 use PDL::Graphics::TriD::Image;
10  
11 PDL::Demos::Routines->import();
12 sub comment($);
13 sub act($);
14 sub actnw($);
15 sub output;
16  
17 sub run {
18  
19  
20 comment q|
21 Welcome to a short tour of the capabilities of
22 PDL::Graphics::TriD.
23  
24 Press 'q' in the graphics window for the next screen.
25 Rotate the image by pressing mouse button one and
26 dragging in the graphics window.
27 Zoom in/out by pressing MB3 and drag up/down.
28 Note that a standalone TriD script must start with
29  
30 use PDL;
31 use PDL::Graphics::TriD;
32 use PDL::Graphics::TriD::Image;
33  
34 to work properly.
35 |;
36  
37 actnw q|
38 # Number of subdivisions for lines / surfaces.
39 $size = 25;
40  
41 $cz = (xvals zeroes $size+1) / $size; # interval 0..1
42 $cx = sin($cz*12.6); # Corkscrew
43 $cy = cos($cz*12.6);
44 line3d [$cx,$cy,$cz]; # Draw a line
45 # [press 'q' in the graphics window when done]
46 |;
47  
48 actnw q|
49 $r = sin($cz*6.3)/2 + 0.5;
50 $g = cos($cz*6.3)/2 + 0.5;
51 $b = $cz;
52 line3d [$cx,$cy,$cz], [$r,$g,$b]; # Draw a colored line
53 # [press 'q' in the graphics window when done]
54 |;
55  
56 actnw q|
57 $x = (xvals zeroes $size+1,$size+1) / $size;
58 $y = (yvals zeroes $size+1,$size+1) / $size;
59 $z = 0.5 + 0.5 * (sin($x*6.3) * sin($y*6.3)) ** 3; # Bumps
60 line3d [$x,$y,$z]; # Draw several lines
61 # [press 'q' in the graphics window when done]
62 |;
63  
64 actnw q|
65 $r = $x;
66 $g = $y;
67 $b = $z;
68 line3d [$x,$y,$z], [$r,$g,$b]; # Draw several colored lines
69 # [press 'q' in the graphics window when done]
70 |;
71  
72 actnw q|
73 lattice3d [$x,$y,$z], [$r,$g,$b]; # Draw a colored lattice
74 # [press 'q' in the graphics window when done]
75 |;
76  
77 actnw q|
78 points3d [$x,$y,$z], [$r,$g,$b], {PointSize=>4}; # Draw colored points
79 # [press 'q' in the graphics window when done]
80 |;
81  
82 actnw q|
83 imag3d_ns [$x,$y,$z], [$r,$g,$b]; # Draw a colored surface
84 # [press 'q' in the graphics window when done]
85 |;
86  
87 actnw q|
88 imag3d [$x,$y,$z]; # Draw a shaded surface
89 # [press 'q' in the graphics window when done]
90 |;
91  
92 actnw q|
93 hold3d(); # Leave the previous object in..
94 imag3d_ns [$x,$y,$z+1], [$r,$g,$b];
95 # ...and draw a colored surface on top of it...
96 # [press 'q' in the graphics window when done]
97 |;
98  
99 actnw q|
100 lattice3d [$x,$y,$z-1], [$r,$g,$b];
101 # ...and draw a colored lattice under it...
102 # [press 'q' in the graphics window when done]
103 |;
104  
105 actnw q|
106 nokeeptwiddling3d(); # Don't wait for user while drawing
107 for(-2,-1,0,1,2) {
108 line3d [$cx,$cy,$cz+$_]; # ... and corkscrews...
109 }
110 keeptwiddling3d(); # Do wait for user while drawing...
111 twiddle3d(); # and actually, wait right now.
112 release3d();
113 # [press 'q' in the graphics window when done]
114 |;
115  
116 actnw q|
117 # The reason for the [] around $x,$y,$z:
118 # 1. You can give all the coordinates and colors in one piddle.
119 $c = (zeroes 3,$size+1) / $size;
120 $coords =
121 sin((3+3*xvals $c)*yvals $c);
122 $colors = $coords;
123 line3d $coords, $colors; # Draw a curved line, colored
124 # (this works also for lattices, etc.)
125 # [press 'q' in the graphics window when done]
126 |;
127  
128 actnw q|
129 # 2. You can use defaults inside the brackets:
130 lattice3d [$z], [$r]; # Note: no $x, $y, and $r is greyscale
131 # [press 'q' in the graphics window when done]
132 |;
133  
134 actnw q|
135 # 3. You can plot in certain other systems as defaults
136 imag3d_ns [POLAR2D, $z], [$r, $g, $b]; # Draw the familiar
137 # bumpy surface in polar
138 # coordinates
139 # [press 'q' in the graphics window when done]
140 |;
141  
142 actnw q|
143 # One last thing: you can plot a color image like this
144 imagrgb([$r,$g,$b]);
145 # [press 'q' in the graphics window when done]
146 |;
147  
148 comment q|
149 '3d2' contains some of the more special constructions available
150 in the PDL::Graphics::TriD modules.
151 |;
152  
153 }
154  
155 1;