var nParticles = 1000;
let pArrayX = [];//xcoordinates
let pArrayY = [];//ycoordinates
let cLim = 40;
var alpha = 4;
var stepD = 3;
function setup() {
createCanvas(600, 600);//canvas size
background(255);//white background creates fade effect
angleMode(DEGREES);//degree mode
makePArray();//initializes particles
noStroke();//no outline
}
function draw() {
translate(width/2,width/2,width/2);//origin at center
background(0,0,0,2);//black and transparent
stepPArray();
}
function mousePressed() {//creates new wave with random equation
background(255)//white creates fade
makePArray()//initialize new particle arrays
frameCount = 1;
}
function makePArray(){
cLim = int(random(5,80))
pArrayX = [];//clear array
pArrayY = [];//clear array
step = frameCount/stepD;//step/speed of wave
pArrayX[0] = mouseX
pArrayY[0] = mouseY
for (let i = 1;i<nParticles;i++){//randomize points around the parametric x,y for nParticles
pArrayX[i] = pArrayX[0]+random(-35,20)*sin(i/9)*cos(i/9)
pArrayY[i] = pArrayY[0]+random(-50,25)*sin(i*9)*cos(i/11)
}
}
function stepPArray(){
step = frameCount/stepD;//step size for animation
newX = mouseX-width/2
newY = mouseY-width/2
deltaX = (pArrayX[0] - newX);//change in x from last point
deltaY = (pArrayY[0] - newY);//change in y from last point
pArrayX[0] = newX;//new x -center point
pArrayY[0] = newY;//new y -center point
fill(0,0,0,10)
circle(pArrayX[0],pArrayY[0],3)//plot point
for (i=1;i<nParticles;i++){//create dispersion of points
mod1 = pArrayX[i]-pArrayX[0]
mod2 = pArrayY[i]-pArrayY[0]//find y dist from center point
fill(0+8*(abs(mod1+mod2)),0+8*(abs(mod1+mod2)),0+8*(abs(mod1+mod2)))//base color on distance from center
if (mod1 < cLim && mod1>-cLim){
mod1 = 0
}
if (mod2 < cLim && mod2>-cLim){
mod2 = 0
}
pArrayX[i] = (pArrayX[i]-deltaX)+random(-1,1)*cos(i/11)*sin(i)-random(-4,3)*sin(i/20)-tan(frameCount)*mod1
pArrayY[i] = ( pArrayY[i]-deltaY)+ random(-1,1)*cos(i/11)*cos(i*9)-mod2*tan(frameCount)
push()
rotate((frameCount/10)%360)
circle(pArrayX[i],pArrayY[i],1)//plot particle
pop()
}
}