Source for file ASCII.php
Documentation is available at ASCII.php
define('IMAGE_3D_DRIVER_ASCII_GRAY', 0.01 );
$this->_size = array ($x, $y);
protected function _getColor(Image_3D_Color $color, $alpha = 1. )
$values = $color->getValues ();
return array ($values[0 ], $values[1 ], $values[2 ], (1 - $values[3 ]) * $alpha);
$faktor = (1 - $new[3 ]) * $old[3 ]; // slight speed improvement
$old[0 ] * $faktor + $new[0 ] * $new[3 ],
$old[1 ] * $faktor + $new[1 ] * $new[3 ],
$old[2 ] * $faktor + $new[2 ] * $new[3 ],
$old[3 ] * $old[3 ] + $new[3 ]
for ($x = 0; $x < $this->_size[0 ]; ++ $x) {
for ($y = 0; $y < $this->_size[1 ]; ++ $y) {
protected function _drawLine(Image_3D_Point $p1, Image_3D_Point $p2)
list ($x1, $y1) = $p1->getScreenCoordinates ();
list ($x2, $y2) = $p2->getScreenCoordinates ();
$xdiff = ($x2 - $x1) / $steps;
$ydiff = ($y2 - $y1) / $steps;
for ($i = 0; $i < $steps; ++ $i) {
$points[(int) round($x1 + $i * $xdiff)][(int) round($y1 + $i * $ydiff)] = true;
$last = end($pointArray);
foreach ($pointArray as $point) {
foreach ($line as $x => $row) {
foreach ($row as $y => $height) {
$map[(int) $x][(int) $y] = $height;
foreach ($points as $x => $row) {
for ($y = $start + 1; $y < $end; ++ $y) {
if (in_array($type, array ('png', 'jpeg'))) {
$code = "\033[0;" . (30 + bindec((int) round($color[2 ]) . (int) round($color[1 ]) . (int) round($color[0 ]))) . 'm';
public function save($file)
$asciiWidth = (int) ceil($this->_size[0 ] / 2 );
$asciiHeight = (int) ceil($this->_size[1 ] / 6 );
for ($y = 0; $y < $asciiHeight; ++ $y) {
for ($x = 0; $x < $asciiWidth; ++ $x) {
$charColor = array (0 , 0 , 0 );
for ($xi = 0; $xi < 2; ++ $xi) {
for ($yi = 0; $yi < 3; ++ $yi) {
if (isset ($this->_heigth[$xPos][$yPos])) {
$char |= pow(2 , $yi + ($xi * 3 ));
$charColor[0 ] += $color[0 ];
$charColor[1 ] += $color[1 ];
$charColor[2 ] += $color[2 ];
$lastColor = $this->_getAnsiColorCode(array ($charColor[0 ] / 6 , $charColor[1 ] / 6 , $charColor[2 ] / 6 ), $lastColor);
Documentation generated on Mon, 11 Mar 2019 15:48:13 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|