ASCII-Pony/render_parts.php

56 lines
1.3 KiB
PHP
Raw Normal View History

2013-11-06 16:40:27 +01:00
#!/usr/bin/php
<?php
2013-11-06 16:48:33 +01:00
$dir = isset($argv[1]) ? $argv[1] : getcwd();
2013-11-08 17:07:35 +01:00
$print_color = !isset($argv[2]) || $argv[2] != 'nocolor';
2013-11-06 16:40:27 +01:00
$dir_files = scandir($dir);
$files = array();
$maxw = 0;
$maxh = 0;
foreach($dir_files as $file)
{
2013-11-08 10:57:46 +01:00
if ( preg_match("/([0-9]+;)*[0-9]+/",$file) !== false )
2013-11-06 16:40:27 +01:00
{
$curr_file = file("$dir/$file",FILE_IGNORE_NEW_LINES);
$files[$file] = $curr_file;
2013-11-06 16:43:48 +01:00
foreach($curr_file as &$line)
2013-11-06 16:40:27 +01:00
{
2013-11-06 16:43:48 +01:00
$line = rtrim($line);
2013-11-06 16:40:27 +01:00
$w = strlen($line);
if ( $w> $maxw )
$maxw = $w;
}
$h = count($curr_file);
if ( $h > $maxh )
$maxh = $h;
}
}
$chars=array_fill(0,$maxh,array_fill(0,$maxw,null));
foreach ( $files as $color => $lines )
2013-11-06 17:27:36 +01:00
for ( $i = 0; $i < count($lines); $i++ )
2013-11-06 16:40:27 +01:00
{
for ( $j = 0, $l = strlen($lines[$i]); $j < $l; $j++ )
{
if ( $lines[$i][$j] != ' ' )
$chars[$i][$j] = array("color"=>$color,"char"=>$lines[$i][$j]);
}
}
foreach($chars as $line)
{
foreach($line as $char)
{
if ( is_null($char) )
echo ' ';
2013-11-08 17:07:35 +01:00
else if ( $print_color )
2013-11-06 16:40:27 +01:00
echo "\x1b[$char[color]m$char[char]";
2013-11-08 17:07:35 +01:00
else
echo $char['char'];
2013-11-06 16:40:27 +01:00
}
echo "\n";
}
2013-11-08 17:07:35 +01:00
if ( $print_color )
echo "\x1b[0m\n";
2013-11-06 16:40:27 +01:00