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

Re : simple sound reactive ellipse (please help)

$
0
0
actually the code you provided is working almost exactly like i need it to! thank you very much,
now i just the circles to be generated from the center of the screen, i tried doing this on line 32 but is not working:
    1. import ddf.minim.*;
    2.  
    3. Minim minim;
    4. AudioInput in;
    5.  
    6. int reactLast;
    7. int reactBetween = 100;
    8. float soundIntensity = 1;
    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(width/2,height/2,random(width),random(height),255);
    32.   }
    33.   
    34.   for (int i=circles.size()-1; i>=0; i--) {
    35.     Circle c = circles.get(i);
    36.     c.run();
    37.   }
    38. }
    39.  
    40. class Circle {
    41.   PVector pos;
    42.   color c;
    43.   int age;
    44.   
    45.   Circle(PVector _pos, color _c) {
    46.     pos = _pos;
    47.     c = _c;
    48.   }
    49.   
    50.   void run() {
    51.     stroke(c, max(0, 255-age*0.25));
    52.     ellipse(pos.x, pos.y, age*1.5, age*1.5);
    53.     age += 3;
    54.     if (age>600) { 
    55.       circles.remove(this);
    56.     }
    57.   }
    58. }
    59.  
    60. void stop() {
    61.   in.close();
    62.   minim.stop();
    63.   super.stop();
    64. }

    Viewing all articles
    Browse latest Browse all 1768

    Trending Articles