Commit c4287214 by doszhang

dos

parent 1f2f8095
...@@ -99,32 +99,39 @@ function updateWorld() { ...@@ -99,32 +99,39 @@ function updateWorld() {
} }
function update() { function update() {
if (particles.length < 500 && Math.random() < probability) { if (particles.length < 200 && Math.random() < probability) {
createFirework(); createFirework();
} }
var alive = []; var alive = [];
for (var i = 0; i < particles.length; i++) { for (var i = 0; i < particles.length; i++) {
oldParticle = deepClone(particles[i])
if (particles[i].move()) { if (particles[i].move()) {
alive.push(particles[i]); alive.push(particles[i]);
particles[i].children.push(oldParticle)
if (particles[i].children.length > 5) {
particles[i].children.splice(0, 1)
}
} }
} }
particles = alive; particles = alive;
} }
function paint() { function paint() {
// ctx.globalCompositeOperation = 'source-over';
// // ctx.fillStyle = "rgba(0,0,0,0.1)";
// ctx.fillRect(0, 0, w, h);
ctx.globalCompositeOperation = 'lighter'; ctx.globalCompositeOperation = 'lighter';
for (var i = 0; i < particles.length; i++) { for (var i = 0; i < particles.length; i++) {
particles[i].draw(ctx); 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() { function createFirework() {
xPoint = Math.random() * (w - 200) + 100; 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 = Math.random() * 50 + 100;
// var nFire = 1;
var c = "rgb(" + (~~(Math.random() * 200 + 55)) + "," + var c = "rgb(" + (~~(Math.random() * 200 + 55)) + "," +
(~~(Math.random() * 200 + 55)) + "," + (~~(Math.random() * 200 + 55)) + ")"; (~~(Math.random() * 200 + 55)) + "," + (~~(Math.random() * 200 + 55)) + ")";
for (var i = 0; i < nFire; i++) { for (var i = 0; i < nFire; i++) {
...@@ -139,7 +146,7 @@ function createFirework() { ...@@ -139,7 +146,7 @@ function createFirework() {
} }
function Particle() { function Particle() {
this.w = this.h = Math.random() * 4 + 1; this.w = this.h = 2;
this.x = xPoint - this.w / 2; this.x = xPoint - this.w / 2;
this.y = yPoint - this.h / 2; this.y = yPoint - this.h / 2;
...@@ -150,18 +157,20 @@ function Particle() { ...@@ -150,18 +157,20 @@ function Particle() {
this.alpha = Math.random() * .5 + .5; this.alpha = Math.random() * .5 + .5;
this.color; this.color;
this.children = [];
} }
Particle.prototype = { Particle.prototype = {
gravity: 0.01, gravity: 0.05,
move: function () { move: function () {
this.x += this.vx; this.x += this.vx;
this.vy += this.gravity; this.vy += this.gravity;
this.y += this.vy; this.y += this.vy;
this.alpha -= 0.01; this.alpha -= 0.01;
if (this.x <= -this.w || this.x >= canvas.width || if (this.x <= -this.w || this.x >= screen.width ||
this.y >= canvas.height || this.y >= screen.height ||
this.alpha <= 0) { this.alpha <= 0) {
this.alpha = 0
return false; return false;
} }
return true; return true;
...@@ -169,7 +178,7 @@ Particle.prototype = { ...@@ -169,7 +178,7 @@ Particle.prototype = {
draw: function (c) { draw: function (c) {
c.save(); c.save();
c.beginPath(); c.beginPath();
this.w = this.w >= 0 ? this.w : 0.09
c.translate(this.x + this.w / 2, this.y + this.h / 2); c.translate(this.x + this.w / 2, this.y + this.h / 2);
c.arc(0, 0, this.w, 0, Math.PI * 2); c.arc(0, 0, this.w, 0, Math.PI * 2);
c.fillStyle = this.color; 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