Commit c4287214 by doszhang

dos

parent 1f2f8095
......@@ -99,32 +99,39 @@ function updateWorld() {
}
function update() {
if (particles.length < 500 && Math.random() < probability) {
if (particles.length < 200 && Math.random() < probability) {
createFirework();
}
var alive = [];
for (var i = 0; i < particles.length; i++) {
oldParticle = deepClone(particles[i])
if (particles[i].move()) {
alive.push(particles[i]);
particles[i].children.push(oldParticle)
if (particles[i].children.length > 5) {
particles[i].children.splice(0, 1)
}
}
}
particles = alive;
}
function paint() {
// ctx.globalCompositeOperation = 'source-over';
// // ctx.fillStyle = "rgba(0,0,0,0.1)";
// ctx.fillRect(0, 0, w, h);
ctx.globalCompositeOperation = 'lighter';
for (var i = 0; i < particles.length; i++) {
particles[i].draw(ctx);
for (k in particles[i].children) {
particles[i].children[k].w -= 0.205
particles[i].children[k].draw(ctx)
}
}
}
function createFirework() {
xPoint = Math.random() * (w - 200) + 100;
yPoint = Math.random() * (h - 500) + 100;
yPoint = Math.random() * (h - 200) + 100;
var nFire = Math.random() * 50 + 100;
// var nFire = 1;
var c = "rgb(" + (~~(Math.random() * 200 + 55)) + "," +
(~~(Math.random() * 200 + 55)) + "," + (~~(Math.random() * 200 + 55)) + ")";
for (var i = 0; i < nFire; i++) {
......@@ -139,7 +146,7 @@ function createFirework() {
}
function Particle() {
this.w = this.h = Math.random() * 4 + 1;
this.w = this.h = 2;
this.x = xPoint - this.w / 2;
this.y = yPoint - this.h / 2;
......@@ -150,18 +157,20 @@ function Particle() {
this.alpha = Math.random() * .5 + .5;
this.color;
this.children = [];
}
Particle.prototype = {
gravity: 0.01,
gravity: 0.05,
move: function () {
this.x += this.vx;
this.vy += this.gravity;
this.y += this.vy;
this.alpha -= 0.01;
if (this.x <= -this.w || this.x >= canvas.width ||
this.y >= canvas.height ||
if (this.x <= -this.w || this.x >= screen.width ||
this.y >= screen.height ||
this.alpha <= 0) {
this.alpha = 0
return false;
}
return true;
......@@ -169,7 +178,7 @@ Particle.prototype = {
draw: function (c) {
c.save();
c.beginPath();
this.w = this.w >= 0 ? this.w : 0.09
c.translate(this.x + this.w / 2, this.y + this.h / 2);
c.arc(0, 0, this.w, 0, Math.PI * 2);
c.fillStyle = this.color;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment