function make_t128_from_initial_toggles($url, $dots) { $ret = ''; $byte = 0; for ($y = 0; $y < 128; ++$y) { for ($x = 0; $x < 128; ++$x) { # every 16 pixels the first char changes $suf = substr(URL_CHARS, floor($y / 16) * 8 + floor($x / 16), 1); # every 2 pxels the 2nd char changes $suf .= substr(URL_CHARS, floor($y / 2) % 8 * 8 + floor($x / 2) % 8, 1); # every pixel it goes 0, 4, 0, 4, 0, 4, etc $suf .= substr(URL_CHARS, $y * 4 % 8 * 8 + $x * 4 % 8, 1); $tog = get_initial_toggle($url . $suf, $dots); $byte = $byte << 1 | $tog; if ($x % 8 == 7) { $ret .= chr($byte); $byte = 0; } } } return $ret; }
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; }