Archive - Mar 30, 2007

Date

(Simple version)Matrix like animated dropping character effect in PHP

This code is only for monospaced typefaces, else it will look strange. This is a simplified version of the dropping down characters(or Matrix Digital Rain), I will create more complex ones later.
The end result is something like this
Matrix like animated dropping character effect
Like most animated effects I will ever make, it needs GIFEncoder class.

The basic idea:
On a screen, when one pixel is activated, it lights up. Here, instead of a pixel, it is a character, so I just have to construct a character grid and light them when it is activated.

Although I did not use any code from Nazmul Hassan's PHP Matrix, he is the one who inspired me to make a animated version, and he is especially kindly to give the source code to me.

include('GIFEncoder.class.php');
ob_start();
$msg = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*()-_=+`[]{};:?/.,<>\\|"';
$length = strlen($msg);
$max_x = 400; //image x size
$max_y = 400; //image y size
$font_file = 'cour.ttf';//font, best monospace
$font_size = 10;//font site
$grid = 10;//gridient of the fonts
$measuer = imagettfbbox(10,0,$font_file,'1');
$space = 5;//space between letters
$char_height = $measuer[1] - $measuer[7] + $space;
$char_width = $measuer[2] - $measuer[0] + $space;
$i = 1;
$colorimage = imagecreatetruecolor(1,1);
$color[1] = imagecolorallocate($colorimage, 255, 255, 255);
while($i<$grid){
 
	$color[] = imagecolorallocate($colorimage, 0, 255-20*$i, 0);
	++$i;
}
imagedestroy($colorimage);
//ENOUGH TEXT TO FILL THE PAGE.
$width = ceil($max_x/$char_width);
$height = ceil($max_y/$char_height);
 
 
$x = 0;
while($x < $width){
	$y = 0;
	while($y < $height){
		$text[$x][$y] = $msg[rand(0,$length)];
		++$y;
	}
	$drop[$x] = rand(0, $width);
	++$x;
}
$i = 0;
while($i<$height+$grid){
	$image = imagecreatetruecolor($max_x, $max_y);
	$x = 0;
	while($x < $width){
		$y = 0;
 
		while($y < $drop[$x]){
			if($drop[$x]-$y<=$grid){
				imagettftext($image, $font_size, 0, $x*$char_width, ($y+1)*$char_height-$space, $color[$drop[$x]-$y], $font_file, $text[$x][$y]);
			}
			++$y;
		}
		if($drop[$x]<$height+$grid){
			++$drop[$x];
		}else{
			$drop[$x] = 0;
		}
		++$x;
	}
	imagegif($image);
	$imagedata[$i] = ob_get_contents();
	imagedestroy($image);
	ob_clean();
	++$i;
}
 
$gif = new GIFEncoder(
                            $imagedata,
                            100,
                            0,
                            2,
                            0, 0, 0,
                            "bin"
        ); 
Header ( 'Content-type:image/gif' );
echo    $gif->GetAnimation ();

Please download your own true type fonts.

If you want to find a property through the banks, be ready for a detailed scrutiny of your insurance deals as well as credit report.

Bubble Guru

Beta version Bubble Guru is still free and converting more and more webcam videos to Bubble Gurus, small floating bubbles communicate with the site's user with a small video.
Good idea, but this could be just like the annoying microsoft Clippy if get abused. :monk:
Bubble Guru

Honey Pot that kill bots