fractalkitty looking for math? fractalkitty.com

sound

heptagon

#random#trig#classes#color#sound#interactive#animation#geometry#music

colorsstarsplayBoolsArrayspectrumwavesfftsoundProcessdotstmp2

let colors =[
  '#5BCEFA',
'#F5A9B8',
  '#FFFFFF'
]
let stars;
let playBool = false;
let sArray = [];
let spectrum;
let waves;
let fft;
let t = 0;
let n = 100;


function preload() {
  userStartAudio();
  stars = loadSound("/assets/heptagon%20-%202_7_25,%2011.49%E2%80%AFAM.m4a");
}
function setup() {
  sArray = [];
  createCanvas(windowWidth, windowHeight);
  stars.amp(0.4);
  describe("sound visualizer with trans flag colors of faded pink larger circles with blue particles.")
  fft = new p5.FFT();
  spectrum = fft.analyze();
  for (let i = 0; i < spectrum.length; i++) {
    sArray.push(new dots(i));
  }
  background(255);
}

function draw() {
noStroke()
  translate(width / 2, height / 2);
  if (playBool) {
    t += 0.00001;
    if (!stars.isPlaying()) {
      stars.play();
    }
  } else {
    stars.pause();
  }
  background(255,255,255, 50);
  soundProcess();
  if (!playBool) {
    push();
    fill(colors[0]);
    triangle(
      -width / 2 + 20,
      height / 2 - 30,
      -width / 2 + 20,
      height / 2 - 50,
      -width / 2 + 40,
      height / 2 - 40
    );
    pop();
  }
}

function soundProcess() {
  spectrum = fft.analyze();
  waves = fft.waveform();
  for (let i = 0; i < spectrum.length; i += 5) {
    for(let j = 0;j<7;j++){
      push()
      noStroke()
      rotate(j*360/7)
       sArray[i].display(spectrum[i] / 10, waves[i]);
      pop()
    }
   
  }
}

class dots {
  constructor(i) {
    this.i = i;
    let c =
      (min(width, height) - (min(width, height) / spectrum.length) * i) * 0.5;
    this.L = random(-c, c);
    this.theta = random(-PI, PI);
    this.x = this.L * sin(this.theta);
    this.y = this.L * cos(this.theta);
    this.t = 1;
    this.dt = random(0.000002);
  }
  display(dt, w) {
    this.t += (10 * sin(this.dt + (abs(w / 100) + abs(dt / 50000)))) / 10;
    this.theta = TWO_PI * sin(this.t);
    this.x = this.L * sin(this.theta)*cos(this.theta-this.L);
    this.y = this.L * cos(this.theta);
    let tmp2 = color(colors[0])
    tmp2.setAlpha(50)
    fill(
      tmp2
    );

    if (this.i % 10 === 0) {
      push();
      let tmp = color(colors[1])
      tmp.setAlpha(5)
      fill(tmp);
      circle(
        this.x * cos(this.t) + this.L * sin(this.t - this.L) * cos(t * this.dt),
        this.y * sin(this.t + t / 2) +
          this.L * cos(this.t + this.L) +
          this.L * this.t * cos(t/10 * this.dt),
        this.x + this.L * sin(this.L / 100 + this.t)
      );
      pop();
    }
    circle(
      this.x * cos(this.t),
      this.y * sin(this.t + t / 20),
      3 + 50 * abs(sin(w + dt / 100))
    );
    let f = width / 2;
    noStroke();
  }
}
function mousePressed() {
  playBool = !playBool;
}
function keyPressed() {
  stars.stop();
  setup();
  draw();
}