Hi there!
I'm making a small school project where I'm suposed to create some visual feedback to a wisthle input.
What the sketch does until now is create a few 'branches' (I think I can call them this way...) according with the volume of the whistle.
What I want to do now is turn each of these branches an independent 'object'. I want all of them to have a small float movement. I don't know if I made myself clear, sorry...
So, my questions are: What it's the best way to do it? Do I need to create an array or something?
Thank you all!
Here's my code:
[Key pressed = Cleans background]
- import ddf.minim.*;
- Minim minim;
- AudioInput in;
- int positionX = 350;
- int positionY = 150;
- int soundVol = 0;
- int velocityX;
- int velocityY;
- void setup() {
- size (700, 300);
- background(0);
- smooth();
- frameRate(30);
- minim = new Minim(this);
- minim.debugOn();
- in = minim.getLineIn(Minim.MONO, 512);
- }
- void draw() {
- //backColor();
- dateTime();
- for (int i = 0; i < in.bufferSize() - 1; i++)
- {
- soundVol = int(in.right.get(i)*50) + int(in.left.get(i+1)*50);
- }
- soundVol = constrain(soundVol, 0, 100);
- velocityX = soundVol;
- velocityY = soundVol;
- positionX = width/2;
- positionY = height/2;
- positionX = positionX + velocityX;
- positionY = positionY + velocityY;
- if (soundVol > 1) {
- positionX = positionX + (int (random(soundVol*-2, soundVol*2)));
- positionY = positionY + (int (random(soundVol*-2, soundVol*2)));
- }
- println(soundVol);
- fill(255);
- ellipse (positionX, positionY, 5, 5);
- stroke(255);
- line(width/2, height/2, positionX, positionY);
- if (keyPressed == true) {
- background(0);
- }
- }
- void stop()
- {
- in.close();
- minim.stop();
- super.stop();
- }
- void dateTime () {
- fill(100);
- rect(15, 260, 75, 35);
- fill(255);
- PFont font;
- font = loadFont("Helvetica-Light-48.vlw");
- textFont(font, 12);
- text (year()+" /"+month()+" /"+day(), 20, 275);
- text (hour()+" : "+minute()+" : "+second(), 20, 290);
- }
1