function dbg_log($msg) { if (am_debugging()) { echo "{$msg}<br />\n"; } }
function binary_main() { if (isset($_REQUEST['z'])) { $url = ereg_replace('[^a-zA-Z0-9._-]', '', $_REQUEST['z']); $pos = strpos($url, '.'); if ($pos !== false) { $dots = substr($url, $pos); $dots = ereg_replace('[^.]', '', $dots); $url = substr($url, 0, $pos); if (strlen($dots) > 2 || $url == '' && $dots != '') { print "Invalid URL"; return; } } else { $dots = ''; } } else { $url = ''; $dots = ''; } if (!am_debugging()) { header('Content-Type: text/javascript; charset=us-ascii'); } $SQUARE_WIDTH = 256; # $GLOBALS['pixels'] is an array of ints, because php won't let me use ^= on chars. $GLOBALS['pixels'] = array_fill(0, 256 * 256 / 8, 255); $initial_toggle = get_initial_toggle($url, $dots); $shadow = str_repeat("", 128 * 128 / 8); #FIXME switch ($dots) { case '': $shadow = hard_shadow($url); hard_square($url, $shadow); break; case '..': $shadow = medium_shadow($url); medium_square($url, $shadow); break; case '.': $shadow = easy_shadow($url); easy_square($url, $shadow); break; } $color = 0; $out = '['; $cur = 0; for ($i = 0; $i < PIXELS_RB * 256; $i++) { $byte = $GLOBALS['pixels'][$i]; if ($byte == $color) { $cur += 8; } else { for ($bit = 0x80; $bit; $bit >>= 1) { if (($byte & $bit ^ $bit & $color) == 0) { ++$cur; } else { $out .= $cur . ','; $cur = 1; $color ^= 0xff; } } } } $out .= $cur . ']'; print $out; exit; }