@ 2016-01-01T15:05:20Z <?php
<?php
/**
* Ask santa for less fugly code next year
*
* Happy new year from Ignas:)
*/
//Open alternate window
fwrite(STDOUT, "\0337\033[?47h");
$top = "
|
\\ ' /
";
$base = "
>*<
>O<@<
>>>@<<*
>@>*<O<<<
>*>>@<<<@<<
>@>>O<<<*<<@<
>*>>O<<@<<<@<<<
>@>>*<<@<>*<<O<*<
>O>>*<<@<>O><<*<@<<
>*>>@><O<<*>>@><*<O<<
>@>>O<*<O>>@<<O<<<*<@<<
>O>>*<<@>O><*<O><@<<<O<*<
| |
| |
/___\
";
/**
* Add sparkling top
*
* @param $top
* @param int $size
* @return string
*/
function sparkleTop($top, $size = 1)
{
$topLight = '- (@) -';
$topLight = str_repeat(' ', 5 - $size) . preg_replace('/-{1,}/', str_repeat('-', $size), $topLight);
$top = $top . $topLight;
return $top;
}
/**
* Switch toys to add animation
*
* @param $tree
* @param bool|false $reverse
* @return string
*/
function switchToys($tree, $reverse = false)
{
$replace = ["*" => "@", "@" => "*"];
if ($reverse) {
$replace = array_flip($replace);
}
$tree = strtr($tree, $replace);
return $tree;
}
/**
* Color text
*
* @param $text
* @param $color
* @return string
*/
function color($text, $color)
{
$colors = [
'red' => "\033[31m",
'green' => "\033[32m",
'yellow' => "\033[33m"
];
$end = "\033[0m";
$text = $colors[$color] . $text . $end;
return $text;
}
// color all <> symbols green
$base = str_replace(
['<', '>'],
[
color('<', 'green'),
color('>', 'green')
],
$base
);
$reverse = true;
$iteration = 0;
// animate it all
while (true) {
$reverse = !$reverse;
// clear screen
fwrite(STDOUT, "\033[H\033[2J");
$output = $base;
if ($iteration % 3 === 0) {
$base = switchToys($base, $reverse);
$iteration = 0;
}
// color toys
$output = str_replace('*', color('*', 'red'), $base);
$output = str_replace('@', color('@', 'yellow'), $output);
$topping = sparkleTop($top, $iteration);
$output = $topping . $output;
$iteration++;
echo $output;
usleep(500000);
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.0.1 0.013 0.073 20.07 7.0.0 0.007 0.070 20.24 5.6.16 0.003 0.053 20.47 5.6.15 0.007 0.070 18.22 5.6.14 0.007 0.033 18.17 5.6.13 0.010 0.043 18.15 5.6.12 0.003 0.043 21.02 5.6.11 0.007 0.037 21.04 5.6.10 0.003 0.040 20.93 5.6.9 0.010 0.077 20.98 5.6.8 0.000 0.060 20.40 5.5.30 0.003 0.040 17.98 5.5.29 0.010 0.063 18.09 5.5.28 0.007 0.040 20.68 5.5.27 0.007 0.053 20.95 5.5.26 0.003 0.080 20.86 5.5.25 0.013 0.077 20.68 5.5.24 0.017 0.067 20.32
preferences:dark mode live preview
144.53 ms | 1394 KiB | 7 Q