use strict; use Win32; use Win32::Console::ANSI; use Term::ANSIColor; my @colours = ( 'bold blue', 'bold blink yellow', 'red', 'white', 'green', 'cyan', 'magenta', 'bold red' ); my $list = make_list(12, @colours); #print join("\t", @{$list}); print "\n"; foreach my $colour (@{$list}) { print colored ("*", $colours[$colour]); print "\r"; sleep(1); } sub make_list { my ($size, @cols) = @_; unless(defined($size) || $size <= 0) { $size = $#cols; } # We need to grab all the possible numbers from # our colours, shuffle those and then pick the # first 'size' list. To avoid having a repeated # pattern, we reshuffle the list after we reach # a potential period point. my @copy = qw(0 1 2 3 4 5 6 7); shuffle(\@copy); my @array; my $j = 0; for(my $i = 0; $i < $size; $i++) { push @array, $copy[$j]; $j++; if(($j % $#cols) == 0) { # Reshuffle $j = 0; @copy = qw(0 1 2 3 4 5 6 7); shuffle(\@copy); } } return \@array; } # The Fisher-Yates Shuffle - taken from node 30243 sub shuffle { my $arrayref = shift; my $i = @$arrayref; while ( $i-- ) { my $newloc = int rand (1+$i); # next if $index == $newloc; # Not needed in Perl. @$arrayref[$i, $newloc] = @$arrayref[$newloc, $i]; } }