xxxxxxxxxx
91
var n;
var smokes;
var d;
var gravity;
function setup() {
//createCanvas(450,450);
createCanvas(windowWidth,windowHeight);
frameRate(60);
reset();
background(0);
}
function draw() {
blendMode(BLEND);
background(0,2);
blendMode(ADD);
fill(255,127);
noStroke();
for(var i=0;i<n;i++){
smokes[i].move();
smokes[i].draw();
}
}
function reset(){
n = 2000;
smokes = [];
d = 2;
gravity = 0;
for(var i=0;i<n;i++){
var rx = 0;
var ry = 0;
//var rx = random(width/6);
//var ry = random(height/6);
smokes[i] = new Smokep(rx,ry);
}
}
function touchStarted(){
reset();
}
class Smokep{
constructor(rx, ry){
this.x = random(width/2-rx,width/2+rx);
this.y = random(height/2-ry,height/2+ry);
this.angle = random(TWO_PI);
this.ax = random(0.5*cos(this.angle));
this.ay = random(0.5*sin(this.angle));
this.vx = 0;
this.vy = 0;
}
move(){
this.vx += this.ax;
this.vy += this.ay;
this.ax *= 0.8;
this.ay *= 0.8;
this.y += gravity;
this.x += this.vx;
this.y += this.vy;
//this.bounce();
this.moveCenter();
}
moveCenter(){
if(0.01>random(1)){
if(this.x<=0||this.x>=width||this.y<=0||this.y>=height){
this.x=width/2;
this.y=height/2;
this.vx *= 0.5;
this.vy *= 0.5;
}
}
}
bounce(){
if(this.x<=0){
this.x=0;this.vx=-this.vx;this.ax=-this.ax;
}else if(this.x>=width){
this.x=width;this.vx=-this.vx;this.ax=-this.ax;
}
if(this.y<=0){
this.y=0;this.vy=-this.vy;this.ay=-this.ay;
}else if(this.y>=height){
this.y=height;this.vy=-this.vy;this.ay=-this.ay;
}
}
draw(){
circle(this.x,this.y,d);
}
}