[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] CDP: Shimmer



#!perl -w

# Shimmer v1.0
# by Kevin Reid <kpreid@ibm.net>
#
# Lots of lines...
# 
# Version History
# 1.0
#   * Initial release

use Mac::Windows;
use Mac::Events;
use Mac::QuickDraw;
use strict;

use constant PI => 3.14159;

my ($CenterX, $CenterY, $Size, $g, @points, $reset);

my $win = MacColorWindow->new(
  Rect->new(50, 50, 450, 450),
  'Shimmer',
  1,
  documentProc,
  1,
);
$win->sethook(layout => sub {
  my $wrect = $win->window->portRect;
  $CenterX = $wrect->right / 2;
  $CenterY = $wrect->bottom / 2;
  $Size = ($CenterX > $CenterY ? $CenterY : $CenterX) - 15;
  
  my $pcnt = int(sqrt($Size) * 2);
  @points = ();
  for (my $pt = 0; $pt < $pcnt; $pt++) {
    my $ang = $pt * (PI * 2 / $pcnt);
    push @points, [$CenterX + $Size * sin($ang), $CenterY + $Size *
cos($ang)];
  }

  EraseRect $wrect;
  $reset = 1;
});
$win->layout;
SetPort $win->window;
  BackColor blackColor;

my @colors = ();
for (qw(R G B)) {
  push @colors, {
    val => rand 65535,
    vel => rand 5000,
  };
}

my $t = 0;
while (1) {
  $reset = 0;
  for my $pt (@points) {
    WaitNextEvent(1) until TickCount() >= $t;
    $t = TickCount() + 2;
    last if $reset;
    $win->window or exit;
    SetPort $win->window;
    foreach my $c (@colors) {
      $c->{val} += $c->{vel};
      if ($c->{val} > 65535 or $c->{val} < 0) {
        $c->{vel} *= -1;
        redo;
      }
    }
    RGBForeColor(new RGBColor( map {$_->{val}} @colors ));
    for my $opt (@points) {
      MoveTo(@$pt);
      LineTo(@$opt);
    }
  }
}

END {$win->dispose if $win}
__END__

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org