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;
}
-
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.