Last active
December 7, 2018 22:40
-
-
Save feehe21/d71d9afc7681811eac5cfff1df20950b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//controls: | |
//click to freeze or unfreeze | |
//click s, w, or b to change stroke color | |
//Imports needed | |
import ddf.minim.analysis.*; | |
import ddf.minim.*; | |
//object needed to access microphone | |
AudioInput input; | |
//works with input to access microphone sound | |
Minim minim; | |
//needed analyze the sound | |
FFT fft; | |
//intitialise variables | |
int bands; | |
int hi; | |
int hi2; | |
int hi3; | |
int w; | |
boolean stop = false; | |
int outline = 0; | |
int shape = 0; | |
float s; | |
float s1; | |
boolean drift = false; | |
double focalPoint = 0; | |
void setup() | |
{ | |
size(513, 480); | |
minim = new Minim(this); | |
input = minim.getLineIn(); | |
//input will be based on your computers input capabilities | |
fft = new FFT(input.bufferSize(), input.sampleRate()); | |
bands = 64; | |
hi = 0; | |
hi2 = 0; | |
hi3 = 0; | |
background(0); | |
} | |
void draw() | |
{ | |
if(!stop){//just paint new noise over previous if frozen | |
background(0); | |
} | |
stroke(255); | |
fft.forward(input.mix); | |
//println(fft.specSize()); | |
for(int i=0; i<fft.specSize(); i++){ | |
if(-fft.getBand(i)*10< -100){//determine up or down | |
s = fft.getBand(i) * 10; | |
}else{ | |
s = fft.getBand(i) * -20; | |
} | |
s1 = fft.getBand(i) * -20; | |
if(drift){ | |
driftColors(i); | |
}else{ | |
heightColors(i); | |
} | |
// | |
fill(hi,hi2,hi3); | |
if(outline == 0){//determine stroke color | |
stroke(hi,hi2,hi3); | |
}else if(outline == 1){ | |
stroke(0); | |
}else{ | |
stroke(255); | |
} | |
if(shape == 0){ | |
bubbles(i); | |
}else if(shape == 1){ | |
ellipses(i); | |
} | |
} | |
focalPoint+= -0.5; | |
} | |
void heightColors(int i){ | |
if(fft.getBand(i)*10 <= height/10){//determine color by height tier | |
hi = 255; | |
hi2 = 0; | |
hi3 = 0; | |
}else if(fft.getBand(i)*10 <= 2*height/10){ | |
hi = 255; | |
hi2 = 242; | |
hi3 = 0; | |
}else if(fft.getBand(i)*10 <= 3*height/10){ | |
hi = 0; | |
hi2 = 255; | |
hi3 = 0; | |
} | |
else if(fft.getBand(i)*10 <= 4*height/10){ | |
hi = 0; | |
hi2 = 182; | |
hi3 = 255; | |
} | |
else{ | |
hi = 123; | |
hi2 = 0; | |
hi3 = 255; | |
} | |
} | |
void driftColors(int i){ | |
i = (int)(i/(width/32) +focalPoint)%width; | |
hi = (int)(Math.sin(0.3*i)*127+128); | |
hi2 = (int)(Math.sin(0.3*i + 2)*127+128); | |
hi3 = (int)(Math.sin(0.3*i + 4)*127+128); | |
} | |
void bubbles(int i){ | |
ellipse(i,height-fft.getBand(i)*10,5,5); | |
} | |
void ellipses(int i){ | |
w = width/bands; | |
ellipse(i,height/2,10,s);//draw middle ellipses | |
ellipse(width-i,height,10,s1);//draw bottom layer | |
ellipse(width-i,0,10,-s1);//draw top layer | |
} | |
void mousePressed(){//if clicked, switch between frozen and not | |
stop = !stop; | |
} | |
void keyPressed(){//change stroke color based on key pressed | |
if(key == 'q'){//key q = stroke is same color as fill | |
outline = 0; | |
}else if(key == 'w'){//key w = stroke is black | |
outline = 1; | |
}else if(key == 'e'){//key e = stroke is white | |
outline = 2; | |
}else if(key == 'a'){//key a = bubbles | |
shape = 0; | |
}else if(key == 's'){//key s = 3 layers of ellipses | |
shape = 1; | |
}else if(key == 'z'){//key z = drift | |
drift = !drift; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment