#!/usr/bin/perl use warnings; use strict; use Tk; use PDL; use PDL::Graphics::TriD; use PDL::Graphics::TriD::Contours; use PDL::Graphics::TriD::GL; use PDL::Graphics::TriD::Tk; my $TriDW; # declare the graph object in main, defined in initialize my $MW = MainWindow->new(); my $bframe = $MW->Frame()->pack( -side => 'top', -fill => 'x' ); # This is the TriD Tk widget it is a Tk Frame widget and has all of the # attributes of a Frame $TriDW = $MW->Tk()->pack( -expand => 1, -fill => 'both'); # The exit button my $e_button = $bframe->Button( -text => "Exit", -command => sub { exit } )->pack( -side => 'right', -anchor => 'nw', -fill => 'y' ); # Sets a default focus style for viewport #setfocusstyle( 'Pointer' ); # This sets the graphic that will be displayed when the window is first opened $e_button->bind( "", [ sub { my $but = shift; Torusdemos(); $e_button->bind( "", '' ); } ] ); $TriDW->MainLoop; sub Torusdemos { my ( $bh ) = @_; return unless defined $TriDW->{ GLwin }; my $graph; $graph = $TriDW->{ GLwin }->current_viewport->graph(); # define the graph object $graph = new PDL::Graphics::TriD::Graph(); $graph->default_axes(); my $data; my $s = 40; my $a = zeroes 2 * $s, $s / 2; my $t = $a->xlinvals( 0, 6.284 ); my $u = $a->ylinvals( 0, 6.284 ); my $o = 0.5; my $i = 0.1; my $v = $o + $i * sin $u; my $x = $v * sin $t; my $y = $v * cos $t; my $z = $i * cos( $u ) + $o * sin( 3 * $t ); # color $data = new PDL::Graphics::TriD::SLattice( [ $x, $y, $z ], [ 0.5 * ( 1 + sin $t ), 0.5 * ( 1 + cos $t ), 0.25 * ( 2 + cos( $u ) + sin( 3 * $t ) ) ] ); # black and white # $data = new PDL::Graphics::TriD::SLattice_S( [ $x, $y, $z ] ); $graph->add_dataseries( $data, 'Torus-demo' ); $graph->scalethings(); $TriDW->current_viewport()->delete_graph( $graph ); $TriDW->current_viewport()->graph( $graph ); $TriDW->refresh(); }