Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : simple sound reactive ellipse (please help)

$
0
0
All right, so you have a Circle class which kind of works, except that you don't really use any of the parameters that are set in the constructor, such as position and color. But your audioreactive code is not really there yet. See the examples that come with the Minim library. There are different ways to determine audio and make things audioreactive. For example you can look at frequency or look at the beat detection. Accurate audio detection is pretty hard, so you really have to think about what you want exactly with that. Here is a basic example. When you press the mouse the circles originate there, otherwise they start at random positions. With lines 7 and 8 you can tweak the audioreactive settings a bit.

Adapted Code
  1. import ddf.minim.*;
  2.  
  3. Minim minim;
  4. AudioInput in;
  5.  
  6. int reactLast;
  7. int reactBetween = 100;
  8. float soundIntensity = 40;
  9.  
  10. ArrayList <Circle> circles = new ArrayList <Circle> ();
  11.  
  12. void setup() {
  13.   size(600, 600);
  14.   strokeWeight(3);
  15.   smooth();
  16.   noFill();
  17.  
  18.   minim = new Minim(this);
  19.   in = minim.getLineIn(Minim.MONO, 64);
  20. }
  21.  
  22. void draw() {
  23.   background(0);
  24.  
  25.   float sound = 0; 
  26.   for (int i=0; i<in.bufferSize()-1; i++) {
  27.     sound += in.left.get(i);
  28.   }
  29.   if (abs(sound)>soundIntensity&&millis()-reactLast>reactBetween) {
  30.     reactLast = millis();
  31.     circles.add( new Circle( new PVector(mousePressed?mouseX:random(width),
  32.     mousePressed?mouseY:random(height)), color(random(255), random(255), random(255))) );
  33.   }
  34.  
  35.   for (int i=circles.size()-1; i>=0; i--) {
  36.     Circle c = circles.get(i);
  37.     c.run();
  38.   }
  39. }
  40.  
  41. class Circle {
  42.   PVector pos;
  43.   color c;
  44.   int age;
  45.  
  46.   Circle(PVector _pos, color _c) {
  47.     pos = _pos;
  48.     c = _c;
  49.   }
  50.  
  51.   void run() {
  52.     stroke(c, max(0, 255-age*0.25));
  53.     ellipse(pos.x, pos.y, age*1.5, age*1.5);
  54.     age += 3;
  55.     if (age>600) {
  56.       circles.remove(this);
  57.     }
  58.   }
  59. }
  60.  
  61. void stop() {
  62.   in.close();
  63.   minim.stop();
  64.   super.stop();
  65. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles