fractalkitty looking for math? fractalkitty.com

early works

parametric_painting

#random#trig#interactive#animation#particles#math#wave#parametric

nParticlespArrayXpArrayYcLimalphastepDmakePArraystepPArray

var a =18, b = 10, c = 11,d =5;//initial coefficients for equations
var nParticles = 3000;
let pArrayX = [];//xcoordinates
let pArrayY = [];//ycoordinates
let cLim = 10;
var alpha = 4;
var stepD = 10;
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);//origin at center
  background(0,0,0,alpha);//black and transparent
  stepPArray();
}
function mousePressed() {//creates new wave with random equation
    background(255)//white creates fade
    frameCount = 1;//reset frames
    a = round(random(22))//random coefficients a - d
    b = round(random(22))
    c = round(random(22))
    d = round(random(22))
    print(a,b,c,d)//print in console for reproduction
    makePArray()//initialize new particle arrays
}
function makePArray(){
  nParticles = int(random(500,9000))
  cLim = int(random(400,800))
  alpha = random(0.1,20)
  stepD = int(random(8,20))
  pArrayX = [];//clear array
  pArrayY = [];//clear array
  step = frameCount/stepD;//step/speed of wave
  pArrayX[0] = width/4*(cos(a*step)*sin(step)+sin(b*step)/2);//parametric equation for x where step is t
  pArrayY[0] = width/4*(sin(c*step)/2+cos(d*step)*cos(step))
  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)+sin(i*11)+random(-5,5)*cos(i/20)*cos(i)
    pArrayY[i] = pArrayY[0]+random(-50,25)*sin(i*9)*cos(i/11)+random(-5,5)*cos(i/20)*cos(i)
  }
}

function stepPArray(){
  step = frameCount/stepD;//step size for animation
  newX = width/4*(cos(a*step)*sin(step)+sin(b*step)/2);//parametric equation for x where step is t
  newY = width/4*(sin(c*step)/2+cos(d*step)*cos(step));//parametric equation for y where step is t
  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(255)
  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(180-2*(abs(mod1+mod2)),255-0.5*(abs(mod1+mod2)),255-0.5*(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+randomGaussian(0,0.5))+random(-5,5)*cos(i/11)*sin(i)-random(-4,3)*sin(i/20)-mod1*sin(frameCount);
    pArrayY[i] = ( pArrayY[i]-deltaY+randomGaussian(0,0.5))+ random(-5,5)*cos(i/11)*cos(i*9)-mod2*sin(frameCount)
    circle(pArrayX[i],pArrayY[i],1)//plot particle
  }
}