Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi, I didn't author this, but it will give you a good idea of how easy it would be in perl/tk.

UPDATE Got rid of huge ugly array.

#!/usr/bin/perl use Tk; my $STEP = 20; my $BOXSIZE = 70; my $WINDOWX = 700; my $WINDOWY = 500; my $mw = new MainWindow( -title => "This is a test", -width => $WINDOWX, -height => $WINDOWY, ); my $canvas = $mw->Canvas( -bg => "black", -width => $WINDOWX, -height => $WINDOWY )->pack(); $canvas->repeat( $STEP, sub { rect($canvas); } ); $canvas->repeat( $STEP, sub { oval($canvas); } ); MainLoop(); sub oval { my $c = shift; my $x = rand $WINDOWX; my $y = rand $WINDOWY; my $sizex = rand $BOXSIZE; my $sizey = rand $BOXSIZE; my $o = $c->createOval( $x, $y, $x + $sizex, $y + $sizey, -fill => getcolor(), ); push ( @ovals, $o ); while ( @ovals > 1000 ) { $c->delete( shift (@ovals) ); } } sub rect { my $c = shift; my $x = rand $WINDOWX; my $y = rand $WINDOWY; my $size = rand $BOXSIZE; my $r = $c->createRectangle( $x, $y, $x + $size, $y + $size, -fill => getcolor(), ); push ( @rects, $r ); while ( @rects > 1000 ) { $c->delete( shift (@rects) ); } } sub getcolor{ my($string) = '#'; my($length) = 7; my(@chars) = ('a' .. 'f', 0 .. 9); while (length($string) != $length) { $string .= $chars[ rand($#chars) ]; } return $string; }

In reply to Re: Perl & C/C++ by zentara
in thread Perl & C/C++ by hemaexp26

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-03-29 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found