<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>属于你的浪漫</title>
<style>
html,body{
height:100%;
padding:0;
margin:0;
background:hsl(0.0%,0%);
}
canvas{
width:100%;
height:100%;
}
</style>
</head>
<body>
<div style="text-align:center;clear:both">
<script src="/gg_bd_ad_720x90.js" type="text/javascript"></script>
<script src="/follow.js" type="text/javascript"></script>
</div>
<canvas id="pinkboard"></canvas>
<script>
/*
*Settings
*/
var settings={
particles:{
length:500,//maximum amount of particles
duration:2,//particle duration in sec
velocity:100,//particle velocity in pixels/sec
effect:-0.75,//play with this for a nice effect
},
};
/*
* RequestAnimationFrame polyfill by Erik M?ller
*/
(function(){var b=0; var c=["ms","moz","webkit","o"];for(var a=0;a<c.length&&!window.requestAnimationFrame;++a){window.requestAnimation}})
/*
*Point class
*/
var Point=(function(){
function Point(x,y){
this.x=(typeof x !== 'undefined') ? x : 0 ;
this.y =(typeof y !== 'undefined') ? y : 0 ;
}
Point.prototype.clone = function(){
return new Point(this.x, this.y);
};
Point.prototype.length = function(length){
if(typeof length =='undefiened')
return Math.sqrt(this.x * this.x + this.y *this.y);
this.x *=length;
this.y *=length;
return this;
};
Point.prototype.normalize = function() {
var length =this.length();
this.x /= length;
this.y /= length;
return this;
};
return Point;
})();
/*
*Particle class
*/
var Particle = (function(){
function Particle(){
this.position = new Point();
this.velocity = new Point();
this.acceleration = new Point();
this.age = 0;
}
Particle.prototype.initialize = function( x, y, dx, dy){
this.position.x=x;
this.position.y=y;
this.velocity.x=dx;
this.velocity.y=dy;
this.acceleration.x =dx * settings.particles.effect;
this.acceleration.y =dy * settings.particles.effect;
this.age = 0;
};
Particle.prototype.update = function(deltaTime){
this.position.x += this.velocity.x * deltaTime;
this.position.y += this.velocity.y * deltaTime;
this.velocity.x += this.acceleration.x * deltaTime;
this.velocity.y += this.acceleration.y * deltaTime;
this.age += deltaTime;
};
Particle.prototype.draw = function(context,image){
function ease(t) {
return(--t)*t*t+1;
}
var size = image.width *ease(this.age / settings.particles.duration);
context.glpbaAlpha = 1 - this.age /settings.particles.duration;
context.drawImage(image,this.position.x - size /2,this.position.y - size / 2, size, size);
};
return Particle;
})()
/*
* ParticlePool class
*/
var ParticlePool =(function(){
var particles,
firstActive = 0,
firstFree = 0,
duration = settings.particles.duration;
function ParticlePool(length){
//create and populate particle pool
particles = new Array(length);
for(var i = 0; i<particles.length;i++)
particles[i] = new Particle();
}
ParticlePool.prototype.add = function(x, y, dx, dy){
Particles[firstFree].initialize( x, y, dx, dy);
//handle circular queue
firstFree++;
if(firstFree == particles.length) firstfree = 0;
if(firstActive== firstFree ) firstActive++;
if(firstActive == particles.length) firstActive=0;
};
})
</script>
</body>
</html>
笔记123
最新推荐文章于 2024-10-16 00:01:00 发布