merging two sketches
in
Core Library Questions
•
2 years ago
How do I merge these two sketches to make the expanding circles in the 'RIPPLE' sketch animate according to voice activation, instead of the sine wave image that is in the 'SOUNDSCAPE' sketch now?
Thanks :)
RIPPLE
ArrayList circles = new ArrayList();
void setup() {
size(570,770);
noFill();
smooth();
}
void draw() {
background(0);
for (int i=0; i<circles.size(); i++) {
ExpandingCircle ec = (ExpandingCircle) circles.get(i);
ec.update();
ec.display();
if (ec.transparency <= 0) { circles.remove(i); } // remove invisible circles
}
}
class ExpandingCircle {
int x,y;
float radius;
color c;
boolean transparencyOn;
int transparency;
ExpandingCircle(int x, int y, boolean transparencyOn) {
this.x = x;
this.y = y;
this.transparencyOn = transparencyOn;
c = color(random(255),random(255),random(255));
transparency = 255;
}
void update() {
radius++;
if (transparencyOn && radius >= 50 && transparency > 0) { transparency--; }
}
void display() {
stroke(100);
ellipse(x,y,radius,radius);
}
}
void mousePressed() {
if (mouseButton == LEFT) { circles.add(new ExpandingCircle(mouseX,mouseY,false));
} else { circles.add(new ExpandingCircle(mouseX,mouseY,true)); }
}
void keyPressed() {
if (key == ' ') { circles.clear(); }
}
SOUNDSCAPE
import ddf.minim.*;
Minim minim;
AudioInput in;
void setup()
{
size(512, 200, P3D);
minim = new Minim(this);
minim.debugOn();
// get a line in from Minim, default bit depth is 16
in = minim.getLineIn(Minim.STEREO, 512);
}
void draw()
{
background(0);
stroke(random(255),random(255),random(255));
// draw the waveforms
for(int i = 0; i < in.bufferSize() - 1; i++)
{
line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
}
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.stop();
}
Thanks :)
RIPPLE
ArrayList circles = new ArrayList();
void setup() {
size(570,770);
noFill();
smooth();
}
void draw() {
background(0);
for (int i=0; i<circles.size(); i++) {
ExpandingCircle ec = (ExpandingCircle) circles.get(i);
ec.update();
ec.display();
if (ec.transparency <= 0) { circles.remove(i); } // remove invisible circles
}
}
class ExpandingCircle {
int x,y;
float radius;
color c;
boolean transparencyOn;
int transparency;
ExpandingCircle(int x, int y, boolean transparencyOn) {
this.x = x;
this.y = y;
this.transparencyOn = transparencyOn;
c = color(random(255),random(255),random(255));
transparency = 255;
}
void update() {
radius++;
if (transparencyOn && radius >= 50 && transparency > 0) { transparency--; }
}
void display() {
stroke(100);
ellipse(x,y,radius,radius);
}
}
void mousePressed() {
if (mouseButton == LEFT) { circles.add(new ExpandingCircle(mouseX,mouseY,false));
} else { circles.add(new ExpandingCircle(mouseX,mouseY,true)); }
}
void keyPressed() {
if (key == ' ') { circles.clear(); }
}
SOUNDSCAPE
import ddf.minim.*;
Minim minim;
AudioInput in;
void setup()
{
size(512, 200, P3D);
minim = new Minim(this);
minim.debugOn();
// get a line in from Minim, default bit depth is 16
in = minim.getLineIn(Minim.STEREO, 512);
}
void draw()
{
background(0);
stroke(random(255),random(255),random(255));
// draw the waveforms
for(int i = 0; i < in.bufferSize() - 1; i++)
{
line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
}
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.stop();
}
1