Wind map with Processing

edited January 2017 in Library Questions

Hi there, I'm trying to create some visuals based on a Wind Map. I got the visuals to work with the parameters setting the thickness and turbulence of the particles but I would like to be able to control those parameters through sliders on an interface so I have more control of it.

I added the sliders to control these parameters but It's not changing the visuals live for some reason. I think it might be because of the positioning of the elements in my code, so I will past it here a section of my code and hopefully someone with experience can point me where i'm getting this wrong?

int sParticles = 5000;
int sNoiseScale = 5000;
int sLength = 5;

float sRandomA = .5;
float sRandomB = 2;



int num = sParticles;
Particle[] particles = new Particle[num];
float noiseScale=sNoiseScale, noiseStrength=5; // Turbulence

void setup() {

  cp5 = new ControlP5(this);
  cp5.addSlider("sParticles").setPosition(0,0).setRange(0,10000);
  cp5.addSlider("sNoiseScale").setPosition(160,0).setRange(0,10000);
  cp5.addSlider("sLength").setPosition(330,0).setRange(0,20);

  cp5.addSlider("sRandomA").setPosition(490,0).setRange(0,5);
  cp5.addSlider("sRandomB").setPosition(650,0).setRange(0,5);

  size(1920, 1080);
  noStroke();
  for (int i=0; i<num; i++) { 
    PVector loc = new PVector(random(width*1.2), 
    random(height), random(sRandomA, sRandomB)); // Thickness

    float angle = random(TWO_PI);
    PVector dir = new PVector(cos(angle), sin(angle));
    float speed = random(.5, 2);
    particles[i]= new Particle(loc, dir, speed);
  }
}

Answers

  • hopefully someone with experience can point me where i'm getting this wrong?

    Edit post, highlight code, press ctrl-o

  • Where is your draw method??? Please post a full, runnable example.

  • Sure! here it is.

    import controlP5.*;
    
    ControlP5 cp5;
    
    int sParticles = 5000;
    int sNoiseScale = 5000;
    int sLength = 5;
    
    float sRandomA = .5;
    float sRandomB = 2;
    
    
    
    int num = sParticles;
    Particle[] particles = new Particle[num];
    float noiseScale=sNoiseScale, noiseStrength=5; // Turbulence
    //float noiseScale=5000, noiseStrength=5; // Turbulence
    
    void setup() {
      //size(877, 1241); //loRes Poster
      //size(4962, 7016); //A2 Poster - 300dpi
      size(1920, 1080);
      noStroke();
    
      //Controllers
      cp5 = new ControlP5(this);
      cp5.addSlider("sParticles").setPosition(0,0).setRange(0,10000);
      cp5.addSlider("sNoiseScale").setPosition(160,0).setRange(0,10000);
      cp5.addSlider("sLength").setPosition(330,0).setRange(0,20);
    
      cp5.addSlider("sRandomA").setPosition(490,0).setRange(0,5);
      cp5.addSlider("sRandomB").setPosition(650,0).setRange(0,5);
    
    
      for (int i=0; i<num; i++) { 
        PVector loc = new PVector(random(width*1.2), 
        random(height), random(sRandomA, sRandomB)); // Thickness
        //random(height), 2); // Thickness
        //random(height), 1.5); // Thickness
    
        float angle = random(TWO_PI);
        PVector dir = new PVector(cos(angle), sin(angle));
        float speed = random(.5, 2);
        particles[i]= new Particle(loc, dir, speed);
      }
    }
    
    void draw() {
    
      //background(0);
      fill(0, sLength); // 2nd number controls length of strokes 
      noStroke();
      rect(0, 0, width, height);
      fill(255);  
      for (int i=0; i<particles.length; i++) {
        particles[i].run();
      }
    
      saveFrame("video-output/seq-####");
      //cp5.hide();
    }
    
    class Particle {
    
      PVector loc, dir, vel;
      float speed;
      int d=1; // direction change
      color col;
    
      Particle(PVector _loc, PVector _dir, float _speed) {
        loc = _loc;
        dir = _dir;
        speed = _speed;
      }
    
      void run() {
        move();
        checkEdges();
        update();
      }
    
      void move() {
        float angle=noise(loc.x/noiseScale, loc.y/noiseScale, frameCount/noiseScale)*TWO_PI*noiseStrength;
        dir.x = cos(angle);
        dir.y = sin(angle);
        vel = dir.get();
        vel.mult(speed*d);
        loc.add(vel);
      }
    
      void checkEdges() {
        //float distance = dist(width/2, height/2, loc.x, loc.y);
        //if (distance>150) {
        if (loc.x<0 || loc.x>width || loc.y<0 || loc.y>height) {    
          loc.x = random(width*1.2);
          loc.y = random(height);
        }
      }
    
      void update() {
        fill(255);
        ellipse(loc.x, loc.y, loc.z, loc.z);
      }
    }
    
    void keyPressed() {
      if (key == '0') {
        saveFrame("image-###");
      }
    }
    
Sign In or Register to comment.