Created
October 3, 2015 19:59
-
-
Save Leko/9c012f2d2c0606b87911 to your computer and use it in GitHub Desktop.
三└(┐卍^o^)卍ドゥルルル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drrr; | |
define('FPS', 15); | |
define('LINES', 10); | |
define('WIDTH', (int)`tput cols`); | |
class Loop { | |
private $token; | |
private $len; | |
private $idx = 0; | |
public function __construct($tokens) { | |
$this->tokens = $tokens; | |
$this->len = mb_strlen($tokens); | |
} | |
public function next() { | |
return mb_substr($this->tokens, $this->idx++ % $this->len, 1); | |
} | |
} | |
class Homoo { | |
const HAND_LOOPS = '\|/-'; | |
const FRONT_LEG_LOOPS = '┐┘'; | |
const BACK_LEG_LOOPS = '┌└'; | |
private $x = 0; | |
private $leftHand; | |
private $rightHand; | |
private $leftLeg; | |
private $rightLeg; | |
public function __construct() { | |
$this->leftHand = new Loop(self::HAND_LOOPS); | |
$this->rightHand = new Loop(self::HAND_LOOPS); | |
$this->leftLeg = new Loop(self::BACK_LEG_LOOPS); | |
$this->rightLeg = new Loop(self::FRONT_LEG_LOOPS); | |
} | |
public function reset() { | |
$this->x = 0; | |
} | |
public function next() { | |
$this->x++; | |
$space = str_repeat(' ', $this->x); | |
return "{$space}三{$this->leftLeg->next()}({$this->rightLeg->next()}{$this->rightHand->next()}^o^){$this->leftHand->next()}ドゥルルル"; | |
} | |
} | |
$homoo = new Homoo(); | |
while(1) { | |
$drrr = mb_strimwidth($homoo->next(), 0, WIDTH); | |
echo "\r{$drrr}"; | |
if(preg_match('/^ +$/', $drrr)) $homoo->reset(); | |
usleep((1000 / FPS) * 1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment