| 1 | sub Animation { | ||
| 2 | |||
| 3 | # lines | ||
| 4 | # | ||
| 5 | # Reflect two points about the confines of the canvas. The cool effect comes from drawing a line between the | ||
| 6 | # points and assigning each line a color from the (visible) spectrum. Each line is tagged with (effectively) | ||
| 7 | # an integer, so after N lines are drawn we begin to delete them, oldest first, maintaining N lines playing | ||
| 8 | # follow the leader. | ||
| 9 | # | ||
| 10 | # Stephen.O.Lidie@Lehigh.EDU, 98/09/20. | ||
| 11 | |||
| 12 | my($canvas) = @_; | ||
| 13 | |||
| 14 | if ($init) { # if already initialized | ||
| 15 | my $tag = 'l' . ($line_count - $max_lines); | ||
| 16 | $canvas->delete($tag); | ||
| 17 | foreach my $point (@points) { | ||
| 18 | my($x0, $y0) = ($point->[0], $point->[1]); | ||
| 19 | my($vx, $vy) = ($point->[2], $point->[3]); | ||
| 20 | my($nx, $ny) = ($x0+$vx, $y0+$vy); | ||
| 21 | if ($nx >= $w) { | ||
| 22 | $nx = $w; | ||
| 23 | $vx = -$vx; | ||
| 24 | } elsif ($nx <= 1) { | ||
| 25 | $nx = 1; | ||
| 26 | $vx = -$vx; | ||
| 27 | } elsif ($ny >= $h) { | ||
| 28 | $ny = $h; | ||
| 29 | $vy = -$vy; | ||
| 30 | } elsif ($ny <= 1) { | ||
| 31 | $ny = 1; | ||
| 32 | $vy = -$vy; | ||
| 33 | } | ||
| 34 | ($point->[0], $point->[1]) = ($nx, $ny); | ||
| 35 | ($point->[2], $point->[3]) = ($vx, $vy); | ||
| 36 | } | ||
| 37 | $tag = 'l' . $line_count++; | ||
| 38 | $canvas->createLine($points[0][0], $points[0][1], | ||
| 39 | $points[1][0], $points[1][1], | ||
| 40 | -tags => $tag, -fill => '#' . $colors[$line_count % scalar(@colors)]); | ||
| 41 | $canvas->lower($tag); | ||
| 42 | } else { # initialize 'lines' plugin | ||
| 43 | ($w, $h) = ($canvas->screenwidth, $canvas->screenheight); | ||
| 44 | (@points) = ( [20,20, 6, 9], [580,380,-3, -5] ); # initial end points (and X/Y velocities) of the line | ||
| 45 | $max_lines = 80; | ||
| 46 | $line_count = 0; | ||
| 47 | @colors = (qw/ | ||
| 48 | ffff00000000 ffff13f80000 ffff2b020000 ffff420c0000 ffff59160000 ffff70200000 ffff872a0000 ffff9e350000 | ||
| 49 | ffffb53f0000 ffffcc490000 ffffe3530000 fffffa5d0000 ee97ffff0000 d78cffff0000 c082ffff0000 a978ffff0000 | ||
| 50 | 926effff0000 7b64ffff0000 645affff0000 4d50ffff0000 3645ffff0000 1f3bffff0000 0831ffff0000 0000ffff0ed9 | ||
| 51 | 0000ffff25e3 0000ffff3ced 0000ffff53f7 0000ffff6b02 0000ffff820c 0000ffff9916 0000ffffb020 0000ffffc72a | ||
| 52 | 0000ffffde34 0000fffff53f 0000f3b5ffff 0000dcabffff 0000c5a1ffff 0000ae97ffff 0000978dffff 00008083ffff | ||
| 53 | 00006978ffff 0000526effff 00003b64ffff 0000245affff 00000d50ffff 09ba0000ffff 20c40000ffff 37cf0000ffff | ||
| 54 | 4ed90000ffff 65e30000ffff 7ced0000ffff 93f70000ffff ab010000ffff c20c0000ffff d9160000ffff f0200000ffff | ||
| 55 | ffff0000f8d4 ffff0000e1ca ffff0000cac0 ffff0000b3b6 ffff00009cab ffff000085a1 ffff00006e97 ffff0000578d | ||
| 56 | /); # 64 colors from my 1000 data-point "continuous spectra" file | ||
| 57 | $init = 1; # mark initialization complete | ||
| 58 | } | ||
| 59 | |||
| 60 | 1000/5; # 5 cycles/second | ||
| 61 | |||
| 62 | } # end lines animation | ||
| 63 | |||
| 64 | 1; |