unicode precipitation

wthr 638B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use 5.10.0;
  5. use Time::HiRes qw(sleep);
  6. use Term::ReadKey qw(GetTerminalSize);
  7. use File::Slurp;
  8. my @snowflakes = qw(❄ ❅ ❆);
  9. my ($width, $height) = GetTerminalSize();
  10. my $cpu_count = grep { /^processor\s+: [0-9]/ } read_file('/proc/cpuinfo');
  11. while (1) {
  12. my ($load) = (read_file('/proc/loadavg') =~ m/^([\d.]+)/);
  13. my $heaviness = int($load / $cpu_count);
  14. for (0 .. $heaviness) {
  15. my $flake = $snowflakes[ rand @snowflakes ];
  16. say ' ' x int(rand($width)) . $flake;
  17. }
  18. if ($heaviness > 0) {
  19. sleep (1 / $heaviness)
  20. } else {
  21. sleep .75;
  22. }
  23. }