Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Sierpinski's Triangle - Wx (dirty)

by PodMaster (Abbot)
on Mar 17, 2004 at 12:32 UTC ( [id://337302]=note: print w/replies, xml ) Need Help??


in reply to Sierpinski's Triangle - Tk

Here it is in Wx, real dirty (currently wxWidgets doesn't have a nice canvas library) . Someone should try an OpenGL approach :)
use strict; use Wx qw( :everything ); use Wx::Event 'EVT_PAINT'; use vars::i qw( $width 4 ); use vars::i qw( $height 4 ); use vars::i '@iterative_set' => ( sub { my @pt = ( 400, 50 ); return( ( $pt[0] + $_[0] ) / 2, ( $pt[1] + $_[1] ) / 2 ); }, sub { my @pt = ( 50, 400 ); return( ( $pt[0] + $_[0] ) / 2, ( $pt[1] + $_[1] ) / 2 ); }, sub { my @pt = ( 750, 400 ); return( ( $pt[0] + $_[0] ) / 2, ( $pt[1] + $_[1] ) / 2 ); }, ); ## cause I don't wanna subclass anything just yet *Wx::App::OnInit = sub { Wx::InitAllImageHandlers(); my $frame = Wx::Frame::->new(undef, -1, 'And Justice For All'); $frame->Show(1); EVT_PAINT( $frame, sub { my($s,$e)=@_; my $dc = Wx::PaintDC->new($s); # must create, to stop crap $dc->SetBackgroundMode( wxTRANSPARENT ); $dc->SetTextForeground( Wx::Colour->newRGB(169,169,69)); # start coordinates my $x = 40; my $y = 400; my $iter = 0; # weed out transients while( $iter++ != 100 ) { ( $x, $y ) = $iterative_set[ int rand 3 ]->( $x, $y ); } $iter = 0; while( $iter++ < 10000 ) { ( $x, $y ) = $iterative_set[ int rand 3 ]->( $x, $y ); $dc->DrawRectangle( int $x, int $y, $width,$height); } return 0; }); return 1; }; Wx::App->new->MainLoop; # we're off'n'runnin'now

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://337302]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2024-05-20 15:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found