您的位置:首页 > 编程语言

【编程游戏】贺岁放礼花。(点燃续帖1-143楼KiteGirl的焰火)

2009-01-01 14:14 591 查看
function viewPage(html) {
var page = window.open('', '', '');
page.opener = null;
page.document.write(html);
page.document.close();
}

【编程游戏】贺岁放礼花。(第一名奖励10000可用分)
作者:


点燃 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

<html>
<head>
<title></title>
</head>
<body bgcolor="#000000" text="#FFFFFF" style="overflow:hidden;">
<p id="idInsertObject"></p>
</body>
<script type="text/javascript">
function rgb(b, g, r) {
return "#" +
("00" + Math.floor(r).toString(16)).replace(/^.*(/w{2}$)/g, "$1") +
("00" + Math.floor(g).toString(16)).replace(/^.*(/w{2}$)/g, "$1") +
("00" + Math.floor(b).toString(16)).replace(/^.*(/w{2}$)/g, "$1");
}
function $(id){ return document.getElementById(id); }

var pubCellNumber
var pubOrbits_X = new Array(256 * 16);
var pubOrbits_Y = new Array(256 * 16);
var pubOffList = new Array(256);
var pubLimit_X = [];
var pubLimit_Y = [];
var pubSpanObjects = new Array(32 * 16);
var pubColors = new Array(256 * 16)
var pubStepOn = 0;
var pubWorkOn = 0;
var pubX = 0;
var pubY = 0;
var pubScale = 0;
var pubTime = 0;
var pubCellLength = 0;
var pubLightLength = 0;
var pubSpeed = 0;
var pubGLimit = 0;

window.onload = function () {
pubCellLength = 24;
pubLightLength = 15;

CreateObjects(pubCellLength, pubLightLength);
CreateColors();
CreateLimits();
NewSkyrocket();
ShowSkyrocket();
}
function NewSkyrocket() {
pubX = Math.floor(Math.random() * 640);
pubY = Math.floor(Math.random() * 480);
pubScale = Math.random() * 1 + 1;
pubStepOn = 10;
for (var tIndex = 0; tIndex <= pubCellLength; tIndex++) {
pubOffList[tIndex] = Math.floor(Math.random() * 20) + 44;
}
CellsClear();
CreateColors();
CreateLimits();
pubTime = setTimeout("ShowSkyrocket();", 10);
}

function ShowSkyrocket() {
if (pubWorkOn < 64) {
pubWorkOn++;
if (pubSpeed > 3) pubSpeed = pubSpeed - 2;
ViewObjects(pubCellLength, pubLightLength, pubScale, pubX, pubY);
CellsMove(pubOrbits_X, pubOrbits_Y, pubLimit_X, pubLimit_Y, pubCellLength, pubLightLength, pubSpeed);
pubTime = setTimeout("ShowSkyrocket();", 1);
} else {
pubWorkOn = 0;
pubSpeed = 24;
NewSkyrocket();
}
}

function ViewObjects(pCellLength, pLightLength, pScale, pX, pY) {
for (var tIndex = 0; tIndex <= pCellLength; tIndex++) {
for (var tLight = 0; tLight <= pLightLength; tLight++) {
with (pubSpanObjects[tIndex * 256 + tLight].style) {
if (pubWorkOn > pubOffList[tIndex] + (pLightLength - tLight)) {
color = rgb(0, 0, 0);
} else {
color = pubColors[tIndex * 256 + 15];
tRndBase = (pLightLength - tLight) * pubScale;
top = pubOrbits_Y[tIndex * 256 + tLight] * pubScale + pY + Math.floor(Math.random() * tRndBase) - tRndBase / 2;
tRndBase = (pLightLength - tLight) * pubScale;
left = pubOrbits_X[tIndex * 256 + tLight] * pubScale + pX + Math.floor(Math.random() * tRndBase) - tRndBase / 2;
}
}
}
}
}

function CreateObjects(pCellLength, pLightLength) {
for (var tIndex = 0; tIndex <= pCellLength; tIndex++) {
for (var tLight = 0; tLight <= pLightLength; tLight++) {
pubSpanObjects[tIndex * 256 + tLight] = document.createElement("SPAN");
with (pubSpanObjects[tIndex * 256 + tLight]) {
innerHTML = ".";
}
with (pubSpanObjects[tIndex * 256 + tLight].style) {
position = "absolute"
color = rgb(0, 0, 0)
}
idInsertObject.appendChild(pubSpanObjects[tIndex * 256 + tLight]);
}
}
}

function CreateColors() {
var tColor = new Array(3);
tColor[0] = Math.random() * 0.5 + 0.5 ;
tColor[1] = Math.random() * 0.5 + 0.5 ;
tColor[2] = Math.random() * 0.5 + 0.5 ;
tColor[Math.floor(Math.random() * 3)] = 1;
for (var tColorIndex = 0; tColorIndex <= pubCellLength; tColorIndex++) {
for (var tLightIndex = 0; tLightIndex <= pubLightLength; tLightIndex++) {
tLightValue = 255 * tLightIndex / pubLightLength;
pubColors[tColorIndex * 256 + tLightIndex] = rgb(tColor[0] * tLightValue, tColor[1] * tLightValue, tColor[2] * tLightValue);
}
}
}

function CellsClear() {
for (var tCellIndex = 0; tCellIndex <= pubCellLength; tCellIndex++) {
for (var tLightIndex = 0; tLightIndex <= pubLightLength; tLightIndex++) {
pubOrbits_X[tCellIndex * 256 + tLightIndex] = 0;
pubOrbits_Y[tCellIndex * 256 + tLightIndex] = 0;
}
}
}

function CellsMove() {
var pGDown = pubWorkOn / 12;
for (var tCellIndex = 0; tCellIndex <= pubCellLength; tCellIndex++) {
for (var tLightIndex = 0; tLightIndex < pubLightLength; tLightIndex++) {
pubOrbits_X[tCellIndex * 256 + tLightIndex] = pubOrbits_X[tCellIndex * 256 + tLightIndex + 1];
pubOrbits_Y[tCellIndex * 256 + tLightIndex] = pubOrbits_Y[tCellIndex * 256 + tLightIndex + 1];
}
pubOrbits_X[tCellIndex * 256 + pubLightLength] = pubOrbits_X[tCellIndex * 256 + pubLightLength] + pubLimit_X[tCellIndex] * pubSpeed;
pubOrbits_Y[tCellIndex * 256 + pubLightLength] = pubOrbits_Y[tCellIndex * 256 + pubLightLength] + pubLimit_Y[tCellIndex] * pubSpeed + pGDown;
}
}

function CreateLimits() {
pubLimit_X = new Array(pubCellLength);
pubLimit_Y = new Array(pubCellLength);
for (var tOrbitsIndex = 0; tOrbitsIndex <= pubCellLength; tOrbitsIndex++) {
tAxis_R = 100;
tAxis_XY = Math.floor(Math.random() * 360);
tAxis_YZ = Math.floor(Math.random() * 360);
tAxis_ZX = Math.floor(Math.random() * 360);
var result = {};
GetOrbits(result, tAxis_XY, tAxis_YZ, tAxis_ZX, tAxis_R);
pubLimit_X[tOrbitsIndex] = result.tOrbits_X / 100;
pubLimit_Y[tOrbitsIndex] = result.tOrbits_Y / 100;
}
}

function GetOrbits(output, pAxis_XY, pAxis_YZ, pAxis_ZX, pAxis_R) {
output.tAxis_XY = RadianGetByAngle(pAxis_XY);
output.tAxis_YZ = RadianGetByAngle(pAxis_YZ);
output.tAxis_ZX = RadianGetByAngle(pAxis_ZX);
output.tOrbits_X = pAxis_R * Math.cos(output.tAxis_XY) * Math.sin(output.tAxis_ZX);
output.tOrbits_Y = pAxis_R * Math.sin(output.tAxis_XY) * Math.cos(output.tAxis_YZ);
}

function RadianGetByAngle(pAngle) {
return pAngle * Math.PI / 180;
}
</script>
</html>

点燃 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐