"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Demos/TriD2.pm" between
PDL-2.077.tar.gz and PDL-2.078.tar.gz

About: PDL (Perl Data Language) aims to turn perl into an efficient numerical language for scientific computing (similar to IDL and MatLab).

TriD2.pm  (PDL-2.077):TriD2.pm  (PDL-2.078)
skipping to change at line 13 skipping to change at line 13
# with PDL under the PDL License permitted. # with PDL under the PDL License permitted.
package PDL::Demos::TriD2; package PDL::Demos::TriD2;
use PDL::Graphics::TriD; use PDL::Graphics::TriD;
use PDL::Graphics::TriD::Image; use PDL::Graphics::TriD::Image;
sub info {('3d2', '3d demo, part 2. (Somewhat memory-intensive)')} sub info {('3d2', '3d demo, part 2. (Somewhat memory-intensive)')}
sub init {' sub init {'
use PDL::Graphics::TriD; use PDL::Graphics::TriD;
use PDL::Graphics::TriD::Image;
'} '}
my @demo = ( my @demo = (
[comment => q| [comment => q|
Welcome to a short tour of the more esoteric capabilities of Welcome to a short tour of the more esoteric capabilities of
PDL::Graphics::TriD. PDL::Graphics::TriD.
As in '3d', press 'q' in the graphics window for the next As in '3d', press 'q' in the graphics window for the next
screen. Rotate the image by pressing mouse button one and screen. Rotate the image by pressing mouse button one and
dragging in the graphics window. dragging in the graphics window.
Note that the script must start with Note that the script must start with
use PDL; use PDL;
use PDL::Graphics::TriD; use PDL::Graphics::TriD;
use PDL::Graphics::TriD::Image;
to work. to work.
|], |],
[actnw => q| [actnw => q|
# See if we had a 3D window open already # See if we had a 3D window open already
$|.__PACKAGE__.q|::we_opened = !defined $PDL::Graphics::TriD::current_win dow; $|.__PACKAGE__.q|::we_opened = !defined $PDL::Graphics::TriD::current_win dow;
# Number of subdivisions for lines / surfaces. # Number of subdivisions for lines / surfaces.
$size = 25; $size = 25;
# You remember this from the first 3d demo, right?
$r = (xvals zeroes $size+1,$size+1) / $size; $r = (xvals zeroes $size+1,$size+1) / $size;
$g = (yvals zeroes $size+1,$size+1) / $size; $g = (yvals zeroes $size+1,$size+1) / $size;
$b = ((sin($r*6.3) * sin($g*6.3)) ** 3)/2 + 0.5; # Bumps $b = ((sin($r*6.3) * sin($g*6.3)) ** 3)/2 + 0.5; # Bumps
imagrgb [$r,$g,$b]; # Draw an image imagrgb [$r,$g,$b]; # Draw an image
# [press 'q' in the graphics window when done] # [press 'q' in the graphics window when done]
|], |],
[actnw => q| [actnw => q|
# How about this? # How about this?
imagrgb3d([$r,$g,$b]); # Draw an image on the lower plane imagrgb3d([$r,$g,$b]); # Draw an image on the lower plane
skipping to change at line 75 skipping to change at line 72
[actnw => q| [actnw => q|
# Warning: your mileage will vary based on which # Warning: your mileage will vary based on which
# OpenGL implementation you are using :( # OpenGL implementation you are using :(
# Let's grab this picture... # Let's grab this picture...
$pic = grabpic3d(); $pic = grabpic3d();
# Lighten it up a bit so you see the background, # Lighten it up a bit so you see the background,
# black on black is confusing # black on black is confusing
$l = 0.3; $l = 0.3;
$pic = ($pic + $l) / (1 + $l); sub lighten { $_[0] = ($_[0] + $l) / (1 + $l) }
lighten($pic);
# And plot it in the picture ;) ;) # And plot it in the picture ;) ;)
hold3d(); # You remember, we leave the previous one in... hold3d(); # You remember, we leave the previous one in...
$o0 = imagrgb3d($pic, {Points => [[0,0,0],[0,1,0],[0,1,1],[0,0,1]]}); $o0 = imagrgb3d($pic, {Points => [[0,0,0],[0,1,0],[0,1,1],[0,0,1]]});
# Because we have the data in $pic, we could just as easily # Because we have the data in $pic, we could just as easily
# save it in a jpeg using the PDL::IO::Pic module - or read # save it in a jpeg using the PDL::IO::Pic module - or read
# it from one. # it from one.
# [press 'q' in the graphics window when done] # [press 'q' in the graphics window when done]
|], |],
[actnw => q| [actnw => q|
# That was fun - let's do that again! # That was fun - let's do that again!
$pic1 = grabpic3d(); $pic1 = grabpic3d();
# Lighten it up lighten($pic1); # Lighten it up
$pic1 = ($pic1 + $l) / (1 + $l);
# And plot it in the picture ;) ;) # And plot it in the picture ;) ;)
hold3d(); # You remember, we leave the previous one in... hold3d(); # You remember, we leave the previous one in...
$o1 = imagrgb3d($pic1, {Points => [[0,0,0],[1,0,0],[1,0,1],[0,0,1]]}); $o1 = imagrgb3d($pic1, {Points => [[0,0,0],[1,0,0],[1,0,1],[0,0,1]]});
# [press 'q' in the graphics window when done] # [press 'q' in the graphics window when done]
|], |],
[actnw => q| [actnw => q|
# Now, let's update them in real time! # Now, let's update them in real time!
nokeeptwiddling3d(); # Don't wait for user while drawing nokeeptwiddling3d(); # Don't wait for user while drawing
while(1) { while(1) {
$p = grabpic3d(); $p = grabpic3d();
$p = ($p + $l) / (1 + $l); $p = ($p + $l) / (1 + $l);
$pic .= $p; $pic1 .= $p; $pic .= $p; $pic1 .= $p;
$o0->data_changed(); $o1->data_changed(); $_->data_changed for $o0, $o1;
last if twiddle3d(); # exit from loop when 'q' pressed last if twiddle3d(); # exit from loop when 'q' pressed
} }
# [press 'q' in the graphics window when done] # [press 'q' in the graphics window when done]
|], |],
[actnw => q| [actnw => q|
# Finally, leave 3d in a sane state # Finally, leave 3d in a sane state
keeptwiddling3d(); # Don't wait for user while drawing keeptwiddling3d(); # Don't wait for user while drawing
release3d(); release3d();
# close 3D window if we opened it # close 3D window if we opened it
 End of changes. 6 change blocks. 
7 lines changed or deleted 4 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)