<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with #reactive - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23reactive</link>
      <pubDate>Sun, 08 Aug 2021 21:17:01 +0000</pubDate>
         <description>Tagged with #reactive - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23reactive/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>particles react on audio</title>
      <link>https://forum.processing.org/two/discussion/10317/particles-react-on-audio</link>
      <pubDate>Tue, 14 Apr 2015 19:20:00 +0000</pubDate>
      <dc:creator>Vriplum</dc:creator>
      <guid isPermaLink="false">10317@/two/discussions</guid>
      <description><![CDATA[<p>I don't know if this is the right place to post this, but I have a code that creates particles ( eclipes) when there is sound.
So it react with the microphone. I found this code on the internet and edited it a little bit.
Now I would like the particles to react on music. ( no microphone) Some words in this code are Dutch, I hope that's not a problem. Sorry for my bad English.</p>

<pre><code>import ddf.minim.*;

AudioPlayer player;
AudioInput input;
Minim minim;
AudioInput in;
float volume = 0;
float volumeF = 0;

int maxParticles=300; // max number of particles. real particles count depends on ppf and its lifetime
int addPPF=2;         // number of particles per frame added
ArrayList particles;

void setup(){
  size(1000,1000);
  frameRate(30);
  smooth();
  background(255);
  noStroke();
      minim = new Minim(this);
  player = minim.loadFile("aventry-fire.mp3", 2048);
  player.play();

  // get a line in from Minim, default bit depth is 16
  in = minim.getLineIn(Minim.MONO, 512);


  particles = new ArrayList();
}

void draw(){
  background(0); // overpaint circles the frame before
  //  for(int i = 0; i &lt; 1; i++)
  //{
     volumeF = in.right.level()*1000;
  volume = 0.7*volume + 0.1*volumeF;
  if(particles.size()&lt;maxParticles){
    /** add particle(s) */
    for(int k=1; k&lt;= volume; k++){
      particles.add(new Particles());
    }
  }
  //}

  /** run trought all Balls and make some action */
  for(int j=0; j&lt;particles.size(); j++){
    Particles particle = (Particles)particles.get(j);
    /** if particle still alive */
    if( particle.alive() ){
      /** update x/y positions */
      particle.position();
      /** now draw as cirle */
      //fill(255,0,0, particle.lt);

     if(key == '1'){
        fill(0,255,0, particle.lt);
        text("verander kleur",10,50);

     }
     if(key == '2'){
        fill(0,255,255, particle.lt);
         text("verander kleur",10,50);
     }
     if(key == '3'){
        fill(255,255,0, particle.lt);
         text("verander kleur",10,50);
     }
     if(key == '4'){
        fill(0,0,255, particle.lt);
         text("verander kleur",10,50);
     }
     if(key == '5'){
        fill(random(255),random(255),random(255), particle.lt);
        text("verander kleur",10,50);
     }
      if(key == '6'){
        fill(random(255),random(255),random(255));
        text("verander kleur",10,50);
     }

     if(key== 'q'){
       text("Reageer op geluid",10,50);
      if(volume&gt;0){
         fill(0,0,255, particle.lt);

       } 
      if(volume&gt;3){
         fill(255,255,255, particle.lt);
       } 
       if(volume&gt;6){
         fill(0,255,255, particle.lt);
       }
       if(volume&gt;9){
         fill(255,0,255, particle.lt);
       }
       if(volume&gt;12){
         fill(255,255,0, particle.lt);
       }
       if(volume&gt;15){
         fill(255,100,100, particle.lt);
       }

      }


     if(key == 'a'){
       text("Vierkantjes",10,50);
       rect(particle.x, particle.y, particle.r, particle.r);}
    else{
     ellipse(particle.x, particle.y, particle.r, particle.r);  
   }


  }else{
      /** if lifetime is running out, delete */
      particles.remove(j);
    }
  }
}


  void stop()
{
  // always close Minim audio classes when you are done with them
  in.close();
  minim.stop();

  super.stop();
}

public class Particles {
  float r, x, y, _x, _y, dx=0, dy=0, lt;

  /** init start-values */
  public Particles() {
    /** start position center */
    x=width/2;
    y=height/2;
    /** now random values to make it non-linear */
    lt=random(50,100);       // lifetime in frames
    r=random(20, 50);        // circle Radius
    _x=random(-0.5, 0.5);    // stepwidth in x-pos (left, right)
    _y=random(-0.5, 0.5);    // stepwidth in y-pos (up, down)

    if(key == 'w'){
    text("Volg muis",10,50);
    x=mouseX;
    y=mouseY;
    }

  if(key == 's'){
    _x=random(-4,-0);    // stepwidth in x-pos (left, right)
    _y=random(-2, 2); 

  }

   if(key == 'd'){
    _x=random(0,4);    // stepwidth in x-pos (left, right)
    _y=random(-4, 4); 

  }
  if(key == 'z'){
    text("verander Snelheid",10,50);
     _x=random(-2.5,4);    // stepwidth in x-pos (left, right)
    _y=random(-2.5,4 ); 
  }
 if(key == 'x'){
   text("verander grootte",10,50);
   r=random(50, 120); 

 }
    }

    void stop(){
  player.close();
  minim.stop();

}

  public void position() {
    /** stepwidth increases, circlespeed is exponential */
    dx+=_x;
    dy+=_y;
    x+=dx;
    y+=dy;
  }

  public boolean alive(){
     if(lt&lt;=0){ return false; }else{ lt--; return true; }
  }


}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>