#!perl -w # Volve v1.1 # by Kevin Reid # # Slowly changing colors. # # This program may be freely distributed, and you may # use code from it, as long as my name stays on it. # Revision history # # 1.1 # * Wobbles are now drawn rather than scrolled. # 1.0 # * First release. use Mac::Windows; use Mac::QuickDraw; use Mac::Events; # Try changing these: sub Width () {140} # width of window sub Height () {200} # height of window sub WobbleAmp () {2} # horizontal wobble parameters sub WobbleFreq () {1} sub Scroll () {-1} # scroll speed and direction sub RandFreq {.996} sub CThird () {65535 / 3} sub Extra () {- WobbleAmp} sub DrawPos () {Scroll < 0 ? Height - 1 : 0} # where in window to draw new iterations sub ltwh {new Rect ($_[0], $_[1], $_[0] + $_[2], $_[1] + $_[3])} # for specifying rectangles as left, top, width, height $win = new MacColorWindow (ltwh(200, 150, Width + Extra*2, Height), "Volve", 1, noGrowDocProc, 1); $win->sethook(drawgrowicon => sub {}); # eliminate fake grow box SetPort $win->window; RGBBackColor(new RGBColor(0,0,0)); # set black background # initialization @set = (0) x Width; $wrect = new Rect (0, 0, Width + Extra*2, Height); # rectangle to scroll $junkrgn = NewRgn; # dummy for ScrollRect for ($time = 0; $win->window; $time++, WaitNextEvent(0)) { for ($d = 1; $d < Width - 1; $d++) { my $avg = ($set[$d-1] + $set[$d] + $set[$d+1]) / 3; # average of nearby values my $diff = $avg - $set[$d]; # difference between average and current value my $change = $diff * .4 + (rand > RandFreq() ? (rand() - .5) * 40 : 0); # amount to change value by $set[$d] += $change; } SetPort $win->window; ScrollRect($wrect, 0, Scroll, $junkrgn); # scroll display up for ($d = 0; $d < Width; $d++) { my $ThePix = $d + Extra + (sin($time / WobbleFreq) * WobbleAmp); # anyone know a better-looking color mapping function? my $cv = $set[$d] * 6553; SetCPixel $ThePix, DrawPos, new RGBColor ( ($cv) % 65535, ($cv + CThird) % 65535, ($cv + CThird*2) % 65535, ); } } END {$win->dispose} __END__