【编程游戏】贺岁放礼花。(点燃续帖1-172楼yonghengdexingxing的焰火)
2009-01-01 22:27
344 查看
function viewPage(html) {
var page = window.open('', '', '');
page.opener = null;
page.document.write(html);
page.document.close();
}
【编程游戏】贺岁放礼花。(第一名奖励10000可用分)
作者:
点燃 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
<html>
<head>
<style type="text/css">
body{
background:#000000;
}
.FireWork{
height:3px;
width:3px;
overflow:hidden;
}
</style>
<script type="text/javascript">
//Position Class
//========================================
function Position(x,y){
this.X = x;
this.Y = y;
}
//Velocity Class
//========================================
function Velocity(vx,vy){
this.Vx = vx;
this.Vy = vy;
}
//FallingBody Class
//========================================
function FallingBody(color,initPosition,initVelocity,initTime,lifeSpan,domNode,explodable){
this.InitPosition = initPosition;
this.InitVelocity = initVelocity;
this.InitTime = initTime;
this.LifeSpan = lifeSpan;
this.DomNode = domNode;
this.Explodable = explodable;
this.Color = color;
}
FallingBody.prototype.Show = function(){
var interval = Environment.Clock - this.InitTime;
if(interval < 0) return true;
if(this.LifeSpan <= interval){
if(this.Explodable) this.Explode(250,0.4);
this.Dispose();
return false;
}
var x = Math.ceil(this.InitPosition.X + this.InitVelocity.Vx * interval);
var y = Math.ceil(this.InitPosition.Y + this.InitVelocity.Vy * interval - Environment.Gravity * interval * interval / 2.0 );
if(!this.Explodable) this.DomNode.style.filter = "alpha(opacity=" + (1-interval/this.LifeSpan)*100 + ")";
this.DomNode.style.display = "block";
this.DomNode.style.left = x;
this.DomNode.style.top = y;
return true;
}
FallingBody.prototype.Dispose = function(){
this.InitPosition = null;
this.InitVelocity = null;
this.InitTime = null;
this.LifeSpan = null;
Environment.Screen.removeChild(this.DomNode);
this.DomNode = null;
}
FallingBody.prototype.Explode = function(velocity,timeSpan){
var interval = Environment.Clock - this.InitTime;
var vx = this.InitVelocity.Vx;
var vy = this.InitVelocity.Vy - Environment.Gravity * interval;
var x = Math.ceil(this.InitPosition.X + this.InitVelocity.Vx * interval);
var y = Math.ceil(this.InitPosition.Y + this.InitVelocity.Vy * interval - Environment.Gravity * interval * interval / 2.0 );
for(var i=0;i<25;i++){
var angle = Math.random()*360;
Environment.AddFireWork(this.Color,new Position(x,y),new Velocity(vx+velocity*Math.cos(angle),vy+velocity*Math.sin(angle)),Environment.Clock,timeSpan,false);
}
}
//Init Envirment
//========================================
var Environment = new Object();
Environment.Colors = ["#ff0000","#00ff00","#000aff","#ff00ff","#ffa500","#ffff00","#00ff00","#ffffff","#fffff0","#ffa500","#55ff66","#ac9dfc","#fff000","#fffff0"];
Environment.AddFireWork = function(color,initPosition,initVelocity,initTime,lifeSpan,explodable){
var div = document.createElement("div");
div.style.position = "absolute";
div.style.display = "none";
Environment.Screen.appendChild(div);
div.className = "FireWork";
div.style.background = color;
var fallingBody = new FallingBody(color,initPosition,initVelocity,initTime,lifeSpan,div,explodable);
Environment.FireWorkArray.push(fallingBody);
}
Environment.ClockTick = function(){
Environment.Clock += Environment.Interval/1000.0;
for(var i=Environment.FireWorkArray.length;i>0;i--){
if(!Environment.FireWorkArray[i-1].Show()) Environment.FireWorkArray.splice(i-1,1);
}
if(Environment.FireWorkArray.length>0) setTimeout(Environment.ClockTick,Environment.Interval);
else{
Environment.Generate();
setTimeout(Environment.ClockTick,Environment.Interval);
}
}
Environment.Generate = function(){
//Environment.AddFireWork(Environment.Colors[Math.floor(Math.random()*Environment.Colors.length)],new Position(300+600*Math.random(),600),new Velocity(100,-330),Environment.Clock,1+Math.random()*0.3,true);
//Environment.AddFireWork(Environment.Colors[Math.floor(Math.random()*Environment.Colors.length)],new Position(300+600*Math.random(),600),new Velocity(0,-300),Environment.Clock,1+Math.random()*0.3,true);
for(var k=0;k<3;k++) Environment.AddFireWork(Environment.Colors[Math.floor(Math.random()*Environment.Colors.length)],new Position(300+2*Math.random(),600),new Velocity(20*Math.random(),-360+100*Math.random()),Environment.Clock,1-Math.random()*0.3,true);
for(var k=0;k<3;k++) Environment.AddFireWork(Environment.Colors[Math.floor(Math.random()*Environment.Colors.length)],new Position(600+2*Math.random(),600),new Velocity(20*Math.random(),-360+100*Math.random()),Environment.Clock,1-Math.random()*0.3,true);
}
window.onload = function(){
Environment.Gravity = -10.0;
Environment.Clock = 0.0;
Environment.Interval = 10; // 0.1 Seconds
Environment.Screen = document.getElementsByTagName("body")[0];
Environment.FireWorkArray = new Array();
Environment.Generate();
setTimeout(Environment.ClockTick,Environment.Interval);
}
</script>
</head>
<body>
</body>
</html>
点燃 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
var page = window.open('', '', '');
page.opener = null;
page.document.write(html);
page.document.close();
}
【编程游戏】贺岁放礼花。(第一名奖励10000可用分)
作者:
点燃 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
<html>
<head>
<style type="text/css">
body{
background:#000000;
}
.FireWork{
height:3px;
width:3px;
overflow:hidden;
}
</style>
<script type="text/javascript">
//Position Class
//========================================
function Position(x,y){
this.X = x;
this.Y = y;
}
//Velocity Class
//========================================
function Velocity(vx,vy){
this.Vx = vx;
this.Vy = vy;
}
//FallingBody Class
//========================================
function FallingBody(color,initPosition,initVelocity,initTime,lifeSpan,domNode,explodable){
this.InitPosition = initPosition;
this.InitVelocity = initVelocity;
this.InitTime = initTime;
this.LifeSpan = lifeSpan;
this.DomNode = domNode;
this.Explodable = explodable;
this.Color = color;
}
FallingBody.prototype.Show = function(){
var interval = Environment.Clock - this.InitTime;
if(interval < 0) return true;
if(this.LifeSpan <= interval){
if(this.Explodable) this.Explode(250,0.4);
this.Dispose();
return false;
}
var x = Math.ceil(this.InitPosition.X + this.InitVelocity.Vx * interval);
var y = Math.ceil(this.InitPosition.Y + this.InitVelocity.Vy * interval - Environment.Gravity * interval * interval / 2.0 );
if(!this.Explodable) this.DomNode.style.filter = "alpha(opacity=" + (1-interval/this.LifeSpan)*100 + ")";
this.DomNode.style.display = "block";
this.DomNode.style.left = x;
this.DomNode.style.top = y;
return true;
}
FallingBody.prototype.Dispose = function(){
this.InitPosition = null;
this.InitVelocity = null;
this.InitTime = null;
this.LifeSpan = null;
Environment.Screen.removeChild(this.DomNode);
this.DomNode = null;
}
FallingBody.prototype.Explode = function(velocity,timeSpan){
var interval = Environment.Clock - this.InitTime;
var vx = this.InitVelocity.Vx;
var vy = this.InitVelocity.Vy - Environment.Gravity * interval;
var x = Math.ceil(this.InitPosition.X + this.InitVelocity.Vx * interval);
var y = Math.ceil(this.InitPosition.Y + this.InitVelocity.Vy * interval - Environment.Gravity * interval * interval / 2.0 );
for(var i=0;i<25;i++){
var angle = Math.random()*360;
Environment.AddFireWork(this.Color,new Position(x,y),new Velocity(vx+velocity*Math.cos(angle),vy+velocity*Math.sin(angle)),Environment.Clock,timeSpan,false);
}
}
//Init Envirment
//========================================
var Environment = new Object();
Environment.Colors = ["#ff0000","#00ff00","#000aff","#ff00ff","#ffa500","#ffff00","#00ff00","#ffffff","#fffff0","#ffa500","#55ff66","#ac9dfc","#fff000","#fffff0"];
Environment.AddFireWork = function(color,initPosition,initVelocity,initTime,lifeSpan,explodable){
var div = document.createElement("div");
div.style.position = "absolute";
div.style.display = "none";
Environment.Screen.appendChild(div);
div.className = "FireWork";
div.style.background = color;
var fallingBody = new FallingBody(color,initPosition,initVelocity,initTime,lifeSpan,div,explodable);
Environment.FireWorkArray.push(fallingBody);
}
Environment.ClockTick = function(){
Environment.Clock += Environment.Interval/1000.0;
for(var i=Environment.FireWorkArray.length;i>0;i--){
if(!Environment.FireWorkArray[i-1].Show()) Environment.FireWorkArray.splice(i-1,1);
}
if(Environment.FireWorkArray.length>0) setTimeout(Environment.ClockTick,Environment.Interval);
else{
Environment.Generate();
setTimeout(Environment.ClockTick,Environment.Interval);
}
}
Environment.Generate = function(){
//Environment.AddFireWork(Environment.Colors[Math.floor(Math.random()*Environment.Colors.length)],new Position(300+600*Math.random(),600),new Velocity(100,-330),Environment.Clock,1+Math.random()*0.3,true);
//Environment.AddFireWork(Environment.Colors[Math.floor(Math.random()*Environment.Colors.length)],new Position(300+600*Math.random(),600),new Velocity(0,-300),Environment.Clock,1+Math.random()*0.3,true);
for(var k=0;k<3;k++) Environment.AddFireWork(Environment.Colors[Math.floor(Math.random()*Environment.Colors.length)],new Position(300+2*Math.random(),600),new Velocity(20*Math.random(),-360+100*Math.random()),Environment.Clock,1-Math.random()*0.3,true);
for(var k=0;k<3;k++) Environment.AddFireWork(Environment.Colors[Math.floor(Math.random()*Environment.Colors.length)],new Position(600+2*Math.random(),600),new Velocity(20*Math.random(),-360+100*Math.random()),Environment.Clock,1-Math.random()*0.3,true);
}
window.onload = function(){
Environment.Gravity = -10.0;
Environment.Clock = 0.0;
Environment.Interval = 10; // 0.1 Seconds
Environment.Screen = document.getElementsByTagName("body")[0];
Environment.FireWorkArray = new Array();
Environment.Generate();
setTimeout(Environment.ClockTick,Environment.Interval);
}
</script>
</head>
<body>
</body>
</html>
点燃 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
相关文章推荐
- 【编程游戏】贺岁放礼花。(点燃续帖1-58楼froole的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖1-141楼YH_Random的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖1-194楼lshdic的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖2-141楼sharp_ice的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖2-145楼KiteGirl的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖2-123楼dh20156的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖2-142楼sharp_ice的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖2-147楼xiuyouxu的焰火)(请在IE下运行)
- 【编程游戏】贺岁放礼花。(点燃续帖1-47楼0009的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖1-142楼KiteGirl的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖2-154楼ZhangYaoxing的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖1-37楼muxrwc的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖1-131楼lshdic的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖1-143楼KiteGirl的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖2-8楼wcwtitxu的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖1-24楼KiteGirl的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖1-116楼cgisir的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖1-145楼KiteGirl的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖1-188楼zswang的焰火)
- 【编程游戏】贺岁放礼花。(点燃续帖1-77楼muxrwc的焰火)