Simulate Matrix Screen with PHP + Javascript

Source: Internet
Author: User

Directly save it as the *. php file and run it.

<?
$ Color_back = "#000000 ";
$ Number_w = 8;
$ Number_h = 6;
$ Space = 1;
$ Font_size = 20;
$ Speed = 0;
?>
<Html>
<Head>
<Title> The Matrix </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">

<Script language = "javascript">
//************************************** ***************************
// Written By Caocao
// Caocao@eastday.com
// Http://caocao.oso.com.cn
//************************************** ***************************
Number_h = <? Echo $ number_h;?>;
Number_w = <? Echo $ number_w;?>;
Step = 5;
Text = new Array ("A", "B", "C", "D", "E", "F", "G", "H ", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R ", "S", "T", "U", "V", "W", "X", "Y", "Z ");
Grad = new Array ("#000000", "#004000", "#008000", "#00C000", "#00FF00 ");

Function line ()
{
This. start = 100;
This. end = 60;
This. restart = 0;
}

Function randchar ()
{
Return (text [Math. round (Math. random () * 25)]);
}

Function initial ()
{
Matrix = new Array ();
Light = new Array ();
For (I = 0; I <number_h; I ++)
{
For (j = 0; j <number_w; j ++)
{
Matrix [I * number_h + j] = "<? Echo $ color_back;?> ";
}
}
For (j = 0; j <number_w; j ++)
{
Light [j] = new line ();
}
}

Function new_light ()
{
For (j = 0; j <number_w; j ++)
{
If (light [j]. restart = 0)
{
Light [j]. start = 0;
Light [j]. end =-10-Math.round (Math. random () * 20 );
Light [j]. restart = light [j]. The end-Math.round (Math. random () * 20 );
}
Else
{
Light [j]. start ++;
Light [j]. end ++;
Light [j]. restart ++;
}
}
}

Function new_color (I, j)
{
If (light [j]. start-I) <5 & (light [j]. start-I)> 0)
{
Return (light [j]. start-I );
}
If (I-light [j]. end) <5 & (I-light [j]. end)> 0)
{
Return (I-light [j]. end );
}
If (I-light [j]. end)> 4 & (light [j]. start-I)> 4)
{
Return (4 );
}
Return (0 );
}

Function display ()
{
For (I = 0; I <number_h; I ++)
{
For (j = 0; j <number_w; j ++)
{
Eval ("w" + I + "h" + j ). innerHTML = "<font color =" + grad [new_color (I, j)] + ">" + randchar () + "</font> ";
}
}
}

Function show ()
{
New_light ();
Display ();
SetTimeout ("show ()", <? Echo $ speed;?> );
}
</Script>
<Style type = "text/css">
<! --
<?
Echo ". size, tr, td {font-size :". $ font_size. "pt; line-height :". $ font_size. "pt; color: #00FF00} n ";
?>
-->
</Style>
</Head>

<?
Echo "<body bgcolor =". $ color_back. "> ";

Echo "<table width =". ($ number_w * $ font_size). "border = 0 cellspacing =". $ space. "cellpadding = 0> ";
For ($ I = 0; $ I <$ number_h; $ I ++)
{
Echo "<tr> ";
For ($ j = 0; $ j <$ number_w; $ j ++)
{
Echo "<td id = w". $ I. "h". $ j. "> M </td> ";
}
Echo "</tr> ";
}
Echo "</table> ";
?>

<Script language = "javascript">
Initial ();
Show ();
</Script>
</Body>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.