Skip to content

Instantly share code, notes, and snippets.

@WizardOfArc
Created December 5, 2012 18:03
Show Gist options
  • Select an option

  • Save WizardOfArc/4217987 to your computer and use it in GitHub Desktop.

Select an option

Save WizardOfArc/4217987 to your computer and use it in GitHub Desktop.
A little cutesy command line animation
<?php
/**
* Blinky is a little ASCII animation inspired by
* Shane Harter's "Progress Display for PHP CLI scripts"
* see: https://gist.github.com/4211173
* this one is written by Azi Crawford
**/
function draw_blink ($counter){
$frame = $counter % 12;
switch ($frame) {
case 0:
echo str_repeat("\010", 50);
echo str_pad("O.O", 50, ' ', STR_PAD_LEFT);
break;
case 1:
echo str_repeat("\010", 50);
echo str_pad("O.o", 50, ' ', STR_PAD_LEFT);
break;
case 2:
echo str_repeat("\010", 50);
echo str_pad("O.-", 50, ' ', STR_PAD_LEFT);
break;
case 3:
echo str_repeat("\010", 50);
echo str_pad("O.o", 50, ' ', STR_PAD_LEFT);
break;
case 4:
echo str_repeat("\010", 50);
echo str_pad("O.O", 50, ' ', STR_PAD_LEFT);
break;
case 5:
echo str_repeat("\010", 50);
echo str_pad("o.O", 50, ' ', STR_PAD_LEFT);
break;
case 6:
echo str_repeat("\010", 50);
echo str_pad("-.O", 50, ' ', STR_PAD_LEFT);
break;
case 7:
echo str_repeat("\010", 50);
echo str_pad("o.O", 50, ' ', STR_PAD_LEFT);
break;
case 8:
echo str_repeat("\010", 50);
echo str_pad("O.O", 50, ' ', STR_PAD_LEFT);
break;
case 9:
echo str_repeat("\010", 50);
echo str_pad("o.o", 50, ' ', STR_PAD_LEFT);
break;
case 10:
echo str_repeat("\010", 50);
echo str_pad("-.-", 50, ' ', STR_PAD_LEFT);
break;
case 11:
echo str_repeat("\010", 50);
echo str_pad("o.o", 50, ' ', STR_PAD_LEFT);
break;
}
}
echo str_repeat("\n", 10);
for ($i=0; $i<100; $i++) {
draw_blink($i);
usleep(125000);
}
echo str_repeat("\010", 50);
echo str_pad("O.O", 50, ' ', STR_PAD_LEFT) . "\n";
echo str_repeat(' ', 50) . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment