#!perl -w # Bouncer # by Kevin Reid # # Run this in the highest color depth you can. use Mac::QuickDraw; use Mac::Windows; use Mac::Events; $bbx = GetGrayRgn->rgnBBox; $bw = $bbx->right - $bbx->left; $bh = $bbx->bottom - $bbx->top; $excess = 20; $win = new MacColorWindow ( $bbx, 'Bouncer', 1, plainDBox, 0, ); $win->sethook('drawgrowicon', sub {}); $win->sethook('click', sub {$tick = -1}); $win->sethook('redraw', sub { RGBForeColor(new RGBColor(0,0,0)); PaintRect(new Rect(0,0,$bw,$bh)); }); SetPort $win->window; PenSize(2,2); sub getcolor { my @colors = (); for (qw(R G B)) { push @colors, { val => rand 65535, vel => rand 100, }; } return \@colors; } for (1..1) { my @points = (); for (1..5) { push @points, { xp => rand $bw, yp => rand $bh, xv => rand, yv => rand, }; } push @loops, {pts => \@points, col => getcolor()}; } WaitNextEvent; $tick = 0; while (++$tick) { SetPort $win->window; foreach $l (@loops) { RGBForeColor(new RGBColor(map {$_->{val}} @{$l->{col}})); MoveTo($l->{pts}[-1]{xp}, $l->{pts}[-1]{yp}); foreach $p (@{$l->{pts}}) { $p->{xp} += $p->{xv}; $p->{yp} += $p->{yv}; if ($p->{xp} > $bw + $excess or $p->{xp} < 0 - $excess) { $p->{xv} *= -1; } if ($p->{yp} > $bh + $excess or $p->{yp} < 0 - $excess) { $p->{yv} *= -1; } LineTo($p->{xp}, $p->{yp}); } foreach $c (@{$l->{col}}) { $c->{val} += $c->{vel}; if ($c->{val} > 65535 or $c->{val} < 0) { $c->{vel} *= -1; redo; } } } WaitNextEvent unless $tick % 100; } END {$win->dispose} __END__ -- Kevin Reid. | Macintosh. "I'm me." | Think different. ***** Want to unsubscribe from this list? ***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch