"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Demos/TriD2.pm" between
PDL-2.076.tar.gz and PDL-2.077.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.076):TriD2.pm  (PDL-2.077)
# Copyright (C) 1998 Tuomas J. Lukka. # Copyright (C) 1998 Tuomas J. Lukka.
# All rights reserved, except redistribution # All rights reserved, except redistribution
# with PDL under the PDL License permitted. # with PDL under the PDL License permitted.
package PDL::Demos::TriD2; package PDL::Demos::TriD2;
use PDL;
use PDL::Graphics::TriD; use PDL::Graphics::TriD;
use PDL::Graphics::TriD::Image; use PDL::Graphics::TriD::Image;
PDL::Demos::Routines->import(); sub info {('3d2', '3d demo, part 2. (Somewhat memory-intensive)')}
sub comment($); sub init {'
sub act($); use PDL::Graphics::TriD;
sub actnw($); use PDL::Graphics::TriD::Image;
sub output; '}
sub run {
comment q| my @demo = (
[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; use PDL::Graphics::TriD::Image;
to work. to work.
|; |],
[actnw => q|
# See if we had a 3D window open already
$|.__PACKAGE__.q|::we_opened = !defined $PDL::Graphics::TriD::current_win
dow;
actnw q|
# 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? # 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
# [press 'q' in the graphics window when done] # [press 'q' in the graphics window when done]
|; |],
actnw q| [actnw => q|
# Let's add the real image on top of this... # Let's add the real image on top of this...
hold3d(); hold3d();
imag3d([$r,$g,$b+0.1], [$r,$g,$b]); imag3d([$r,$g,$b+0.1], [$r,$g,$b]);
# For the next demo, please rotate this so that much # For the next demo, please rotate this so that much
# of the image is visible. # of the image is visible.
# Don't make your window too big or you might run out of memory # Don't make your window too big or you might run out of memory
# at the next step. # at the next step.
# [press 'q' in the graphics window when done] # [press 'q' in the graphics window when done]
|; |],
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); $pic = ($pic + $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...
$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 it up
$pic1 = ($pic1 + $l) / (1 + $l); $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(); $o0->data_changed(); $o1->data_changed();
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();
# [press 'q' in the graphics window when done] # close 3D window if we opened it
|; close3d() if $|.__PACKAGE__.q|::we_opened;
|],
);
} sub demo { @demo }
1; 1;
 End of changes. 19 change blocks. 
27 lines changed or deleted 31 lines changed or added

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