Trying to make a perlin noise loop into a Music visualization

please format code with </> button * homework policy * asking questions

int totalFrames = 100;
int counter = 0;
boolean record = false;


Particle[] particles = new Particle[100];

void setup() {
  size(600, 600);
  for (int i = 0; i < particles.length; i++) {
    particles[i] = new Particle();
  frameRate(1000);
    
  }
  
}

void draw() {
   float percent = 0;
  if (record) {
    percent = float(counter) / totalFrames;
  } else {
    percent = float(counter % totalFrames) / totalFrames;
  }
  render(percent);
  if (record) {
    saveFrame("output/gif-"+nf(counter, 3)+".png");
    if (counter == totalFrames-1) {
      exit();
    }
  }
  counter++;
}

void render(float percent) {
  background(10);
  float a = percent * TWO_PI;
  for(Particle p : particles) {
    p.render(a);
  
 
   
   
  }
  
}
class Particle {
  NoiseLoop xNoise;
  NoiseLoop yNoise;
  NoiseLoop dNoise;
  NoiseLoop rNoise;
  NoiseLoop bNoise;

  Particle() {
    xNoise = new NoiseLoop(0.2, 0, width);
    yNoise = new NoiseLoop(0.2, 2, height);
    dNoise = new NoiseLoop(1, 100, 255);
    rNoise = new NoiseLoop(1, 100, 255);
    bNoise = new NoiseLoop(1, 100, 255);
  }

  void render(float a) {
    stroke(0, 0, 255);

    float y = yNoise.value(a);

    float r = rNoise.value(a);
    float b = bNoise.value(a);
    fill(r, 0, b, 5);
    rect(y, y, y, y);

    rect(y, y, -y, -y);
  }
}
class NoiseLoop {
  float diameter;
  float min, max;
  float cx;
  float cy;
  
  NoiseLoop(float diameter, float min, float max) {
    this.diameter = diameter;
    this.min = min;
    this.max = max;
    cx = random(100);
    cy = random(100);
    
  }
  
  float value(float a) {
    float xoff = map(cos(a), -1, 1, cx, cx + diameter);
    float yoff = map(sin(a), -1, 1, cy, cy + diameter);
    float r = noise(xoff, yoff);
    return map(r, 0, 1, min, max);
  }
}

Hey Cub, welcome to the forums. Please include a thorough description of your problem at the top of your post. It’s not enough to have a vague request in the title.

1 Like