#!perl -w # CircleDemo v1.0 # # Precursor to Clock. use Mac::Events; use Mac::Windows; use Mac::QuickDraw; $ang = 1; $win = new MacWindow ( new Rect (100, 100, 500, 500), 'Circle Demo', 1, documentProc, 1, ); $win->sethook(layout => sub { my $wRect = $win->window->contRgn->rgnBBox; SetPort($win->window); my $sPt = GlobalToLocal(new Point ($wRect->right, $wRect->bottom)); InvalRect new Rect (0, 0, $wd = $sPt->h, $ht = $sPt->v); $wd2 = $wd / 2; $ht2 = $ht / 2; }); $win->layout; $win->sethook(redraw => sub { FrameOval(new Rect(0, 0, $wd, $ht)); MoveTo($wd2, $ht2); LineTo($xt, $yt); PaintRect new Rect 0, $yt, $wd, $yt+1; PaintRect new Rect $xt, 0, $xt+1, $ht; }); $t = $xb = $yb = $xt = $yt = $xe = $ye = 0; while ($win->window) { unless ($t++ % 2) { SetPort($win->window); InvalRect new Rect ($xb, $yb, $xe+1, $ye+1); InvalRect new Rect 0, $yt, $wd, $yt+1; InvalRect new Rect $xt, 0, $xt+1, $ht; $ang += .1; $xt = cos($ang)*$wd2+$wd2; $yt = sin($ang)*$ht2+$ht2; SetPort($win->window); ($xb, $xe) = ($xt < $wd2) ? ($xt, $wd2) : ($wd2, $xt); ($yb, $ye) = ($yt < $ht2) ? ($yt, $ht2) : ($ht2, $yt); InvalRect new Rect ($xb, $yb, $xe+1, $ye+1); InvalRect new Rect 0, $yt, $wd, $yt+1; InvalRect new Rect $xt, 0, $xt+1, $ht; } WaitNextEvent; } END {$win->dispose} __END__