merging sketches together
in
Programming Questions
•
3 years ago
hi
i wrote several music visualizer via processing
now i want to merge them together into one sketch
and assign each sketch a butten/key etc.
do i have to rewrite them as classes?
i hope somebody can help me
for example 3 of my sketches:
Sketch1
int actRandomSeed = 0;
int count = 10;
import ddf.minim.*;
Minim minim;
AudioInput in;
void setup() {
size(400,400);
background(0);
smooth();
minim=new Minim(this);
minim.debugOn();
in=minim.getLineIn(Minim.STEREO,512);
frameRate(60);
}
void draw() {
background(0);
noStroke();
//float faderX = (float)mouseX/width;
float angle = radians(360/float(count));
for (int q=0; q<in.bufferSize();q=q+1) {
for (int i=0; i<count; i++) {
// positions
float x = width/2 + cos(angle*i)*q;
float y = height/2 + sin(angle*i)*q;
// float x = lerp(randomX,circleX, faderX);
//float y = lerp(randomY,circleY, faderX);
// fill(0,130,164);
fill(in.right.get(i)*100000,in.right.get(i)*10000,255-in.right.get(i)*100000,50 );
ellipse(x,y,in.left.get(q)*100,in.right.get(q)*100);
}
}
}
void keyPressed() {
if(key==ENTER) {
fill(255);
rect(0,0,width*2,height*2);
}
}
Sketch2
import peasy.*;
import krister.Ess.*;
FFT myfft;
AudioInput myinput;
int bufferSize=512;
PeasyCam cam;
int xCount=6;
int yCount=6;
import processing.opengl.*;
void setup() {
size(500,500,OPENGL);
hint(ENABLE_OPENGL_4X_SMOOTH);
background(255);
smooth();
cam = new PeasyCam(this, 100);
cam.setMinimumDistance(50);
cam.setMaximumDistance(500);
Ess.start(this);
myinput=new AudioInput(bufferSize);
myfft=new FFT(bufferSize*2);
myinput.start();
frameRate(60);
}
void draw() {
float level1 = myfft.getLevel(myinput) * 300;
println(level1);
colorMode(HSB,200,100,100);
lights();
fill(level1*10,level1*50,100);
stroke(255,0,0);
noStroke();
//colorMode(RGB);
background(0);
//scale(5);
scale(level1);
rotateX(level1);
rotateY(level1*4);
//rotateZ(level1*2);
// translate(height/2,width/2);
for (int y=0; y<yCount;y=y+1) {
beginShape(QUAD_STRIP);
for(int x=0;x<xCount;x=x+1) {
float level = myfft.getLevel(myinput) * 300;
println(level);
rotate(level);
float z=sin(sqrt(x*x+y*y));
// float z=sin(sqrt(x*x));
vertex(x,y,z);
z=sin(sqrt(x*x*level+(y+1)*(y+1)));
// z=sin(sqrt(x*x));
vertex(x,y+1,z+level);
}
endShape();
}
}
void keyPressed() {
if(key==ENTER) {
fill(255);
rect(0-height,0-width,width*2,height*2);
box(1000);
}
}
Sketch3
float x = 230;
float y = 150;
float x1=170;
float y2=150;
int a=100;
float q=0;
float w=-0.5;
float leftA=1.5;
float rightA=0;
float wrightA=0;
float wleftA=0;
float f1=180;
float f2=270;
float f12=220;
float f22=270;
float fangle1=0.0;
float fangle2=0.0;
float fangle12=0.0;
float fangle22=0.0;
float angle1 = 0.0;
float angle2 = 0.0;
float angle12=0.0;
float angle22=0.0;
float segLength = 60;
import krister.Ess.*;
FFT myfft;
AudioInput myinput;
int bufferSize=512;
void setup() {
size(400, 450);
smooth();
background(255);
Ess.start(this);
myinput=new AudioInput(bufferSize);
myfft=new FFT(bufferSize*2);
myinput.start();
float level = myfft.getLevel(myinput) * 5000;
}
void draw() {
// background(0,80);
fill(0,a);
rect(-20,-20,360,360);
stroke(255);
colorMode(HSB,100,100,100);
float level = myfft.getLevel(myinput) * 5000;
translate(0,0,-50);
println("level"+level);
println("winkelFeet"+q);
println("rotate"+w);
println("leftA"+leftA);
println("rightA"+rightA);
println("wleftA"+wleftA);
println("wrightA"+wrightA);
translate(0,-level/10);
stroke(random(level),random(level),100,a*2);
//stroke(level,level,100,a*2);
//stroke(0,0,100);
noFill();
strokeWeight(abs(24*a*0.01));
ellipse(200,100,24,24);
strokeWeight(abs(24*a*0.01));
line(200,155,200,240-(level/50));
println("level"+level);
println("a"+a);
angle1 = (level/float(width) +leftA) * -PI;
angle2 = (level*4.5/float(height) - wleftA) * PI;
angle12 = (-level/float(width) -0.5+rightA) * -PI;
angle22 = (-level*(4.5)/float(height) -wrightA) * PI;
fangle1 = (-level/float(width)+w) * -PI;
fangle2 = (-level/float(height)+q ) * PI;
fangle12 = (level/float(width) -w-1) * -PI;
fangle22 = (level/float(height)-q ) * PI;
pushMatrix();
segment(x, y, angle1);
segment(segLength, 0, angle2);
popMatrix();
pushMatrix();
segment(x1, y2, angle12);
segment(segLength, 0, angle22);
popMatrix();
pushMatrix();
segment(f1, f2, fangle1);
segment(segLength, 0, fangle2);
popMatrix();
pushMatrix();
segment(f12, f22, fangle12);
segment(segLength, 0, fangle22);
popMatrix();
}
void segment(float x, float y, float a) {
translate(x, y);
rotate(a);
line(0, 0, segLength, 0);
}
void keyReleased() {
float level = myfft.getLevel(myinput) * 5000;
if(key=='ö') {
w=w-0.1;
}
if(key=='ä') {
w=w+0.1;
}
if(key=='p') {
q=q+0.1;
}
if(key=='ü') {
q=q-0.1;
}
if(key=='w') {
leftA=leftA-0.05;
}
if(key=='q') {
leftA=leftA+0.05;
}
if(key=='s') {
rightA=rightA-0.05;
}
if(key=='a') {
rightA=rightA+0.05;
}
if(key=='t') {
wleftA=wleftA-0.1;
}
if(key=='r') {
wleftA=wleftA+0.1;
}
if(key=='g') {
wrightA=wrightA-0.1;
}
if(key=='f') {
wrightA=wrightA+0.1;
}
}
void keyPressed() {
if(key==ENTER) {
colorMode(RGB);
fill(255);
rectMode(CENTER);
stroke(200000);
ellipse(200,200,2000,2000);
}
if(key=='x') {
a=a+10;
}
if(key=='y') {
a=a-10;
}
if(key=='1') {
a=100;
}
if(key=='2') {
a=200;
}
if(key=='3') {
a=300;
}
if(key=='4') {
a=400;
}
if(key=='5') {
a=500;
}
if(key=='6') {
a=600;
}
if(key=='7') {
a=700;
}
if(key=='8') {
a=800;
}
if(key=='9') {
a=8000;
}
if(key=='0') {
a=10;
}
}
1