Skip to content

Instantly share code, notes, and snippets.

@WizardOfArc
Forked from tim-trulia/blinky.php
Created December 5, 2012 20:08
Show Gist options
  • Select an option

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

Select an option

Save WizardOfArc/4219041 to your computer and use it in GitHub Desktop.
A little cutesy command line animation
/**
* 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 forked by Tim Correia forked again by Azi Crawford
* 12/08/2012 -> added ears to blinky
**/
$blinks_array = array( '<O.O>', '<O.o>', '<O.->', '<O.o>', '<O.O>', '<o.O>', '<-.O>', '<o.O>', '<O.O>', '<o.o>', '<-.->', '<o.o>' );
define('SCREEN_WIDTH', `tput cols` - 2);
function draw_blink ($counter){
$screen_width = `tput cols` - 2;
$frame = $counter % 12;
global $blinks_array;
$blink = $blinks_array[$frame];
echo "\r";
echo str_pad($blink, $screen_width, ' ', STR_PAD_BOTH);
}
echo str_repeat("\n", 10);
for ($i=0; $i<144; $i++) {
draw_blink($i);
usleep(125000);
}
echo str_repeat("\010", SCREEN_WIDTH);
echo str_pad("<O.O>", SCREEN_WIDTH, ' ', STR_PAD_BOTH) . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment