ASCII-Pony/render_parts.php

52 lines
1.2 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-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 ' ';
else
echo "\x1b[$char[color]m$char[char]";
}
echo "\n";
}
echo "\x1b[0m\n";