Re: Superformula with Perl?



Hello,
thank you for the hint to gnuplot; I need the 2D version of the
superformula.
So I took a look at the Perl API at
http://search.cpan.org/%7Eilyaz/Term-Gnuplot-0.5704/Gnuplot.pm
I hope there is somewhere a tutorial about this because with my
knowledge about Perl based on PerlMagick this API is difficult to
understand. But perhaps there are other options like turtle graphics
where the turtle is controlled by a formula.

Thank you
Günter



zentara schrieb:

On 28 Dec 2006 03:47:05 -0800, "guba@xxxxxxxxxx" <guba@xxxxxxxxxx>
wrote:

Hello,

I am wondering how parametric formulas like the Superformula
http://en.wikipedia.org/wiki/Superformula
can be drawn with Perl. GD or ImageMagick has only some graphic
primitives and I can not see how this could be done which such
programs. Or can Perl API to a mathe library be used to
draw such graphs? Thank you for hints!

Günter

These are cool, thanks for pointing them out.

If you just want the 2d , gnuplot will do polar coordinates.

But the general solution for 3d, would be to use PDL.
The TriD graphics will do parametric equations.
See http://www.johnlapeyre.com/pdl/pdldoc/newbook/index.html!
for a guide.

Here is a chopped down version from the PDL demo, which is close,
and you could probably modify it for your SuperFormula parametric
equations.

#!/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' );

# a trick needed to display
# set the graphic when the window is first opened
$e_button->bind( "<Configure>", [
sub {
my $but = shift;
Torusdemos();
$e_button->bind( "<Configure>", '' );
} ]
);

$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();
}
__END__


--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

.


Quantcast