xxxxxxxxxx
45
var fireworks = [];
function setup() {
createCanvas(400, 400);
}
function Firework(x,y){
this.r = 255;
this.g = 0;
this.b = 0;
this.pos = createVector(x,y);
this.vel = createVector(0,random(-5,-10))//random(-10,-5)
this.timeMax = random(30);
this.time = 0;
this.show = function() {
strokeWeight(5);
if (this.time <= this.timeMax){
stroke(this.r,this.g,this.b);
point(this.pos.x,this.pos.y);
this.pos = this.pos.add(this.vel);
this.time++;
this.g += random(20);
}//else{
//for(i = 0; i < 10; i ++;)
//}
}
}
function mousePressed(){
fireworks.push(new Firework(mouseX,mouseY));
}
function draw() {
background(0);
for(i = 0; i < 410; i +=random(10)){
fireworks.push(new Firework(i,400));
}
for (var i = 0; i < fireworks.length; i++) {
var firework = fireworks[i];
firework.show();
}
}