xxxxxxxxxx
float volume = 0;
float volumeF = 0;
int rotacao = 0;
int movimento = 0;
int armAngle = 0;
int legAngle = 0;
int angleChange = 5;
int circulo_tamanho =213;
final int ANGLE_LIMIT = 135;
PShape bichorosa;
PShape bichoverde;
PShape bichovermelho;
PShape bichoamarelo;
PShape cenario;
boolean[] bichoToggle = new boolean[5];
int[] botao_on = {540, 600, 200, 50};
String botao_on_txt = "DISCO MODE ON/OFF"; // texto do botão
boolean botao_on_ligado = false; // se o botao esta ligado
void setup(){
setupAudio ();
size(1280,800 );
bichorosa = loadShape ("bicho.svg");
bichoverde = loadShape ("bicho_verde.svg");
bichovermelho = loadShape ("bicho_vermelho.svg");
bichoamarelo = loadShape ("bicho_amarelo.svg");
cenario = loadShape ("cenario.svg");
frameRate(30);
}
void draw()
{
background(255);
drawBotao();
drawBichoRosa ();
drawBichosJuntos();
fft.forward( in.mix );
}
void drawBotao(){
if (botao_on_ligado) efeitos(); // se o botao esta ligado chama a animacao
blendMode(BLEND); //botoes opacos
// chamamos a função que desenha botões, com os parâmetros:
// array: coordenadas, boolean: se está ligado, String: texto
desenhaBotao(botao_on, botao_on_ligado, botao_on_txt);
if (botao_on_ligado)
player.play();
else
player.rewind();
}
void drawBichosJuntos(){
if(bichoToggle [0]) {
BichoAzul(); }
if(bichoToggle [1]) {
BichoVerde(); }
if(bichoToggle [2]) {
BichoAmarelo(); }
if(bichoToggle [3]) {
BichoVermelho(); }
}
void keyReleased(){
// on/off
if (key == '1') {
bichoToggle[0] = !bichoToggle[0];
}
if (key == '2') {
bichoToggle[1] = !bichoToggle[1];
}
if (key == '3') {
bichoToggle[2] = !bichoToggle[2];
}
if (key == '4') {
bichoToggle[3] = !bichoToggle[3];
}
}
/*
Função desenhaBotao():
Desenha botões, com os parâmetros:
array botao[]: coordenadas, boolean ligado : se está ligado, String texto: texto
*/
void desenhaBotao(int[] botao, boolean ligado, String texto) {
// usa cores diferentes se o botão estiver ligado:
if (ligado) {
fill(#FFFF5F, 192);
} else {
fill(#FFE200, 192);
}
noStroke();
rectMode(CORNER);
// desenha o botão nas coordenadas recebidas através do array
// [0]: x, [1]: y, [2]: largura, [3]: altura
rect(botao[0], botao[1], botao[2], botao[3]);
textSize(15);
textAlign(CENTER, CENTER);
fill(#7D9DF2);
// coloca texto no centro do botão (x + largura/2, y + altura/2)
text(texto, botao[0] + (botao[2]/2), botao[1] + (botao[3]/2));
}
void mouseReleased() {
botao_on_ligado = testaBotao(botao_on, botao_on_ligado);
}
/*
Função testaBotao():
Caso o rato esteja por cima do botão quando a função é chamada (no momento do clique),
devolve o valor do parâmetro 'ligado' invertido. Os parâmetros são:
array botao[]: coordenadas, boolean ligado: se está ligado
*/
boolean testaBotao(int[] botao, boolean ligado) {
// se as coordenadas do rato estão dentro dos limites do botao
// (> x e > y e < x+largura e < y+altura):
if (mouseX > botao[0] && mouseY > botao[1] &&
mouseX <botao[0]+botao[2] && mouseY < botao[1]+botao[3]) {
// inverte o valor da variavel true/false:
ligado = !ligado;
}
// devolve o valor de 'ligado' actualizado
// (daí a função ser de tipo boolean e não 'void'/nulo):
return ligado;
}
void efeitos (){
shape(cenario,0,0, 1280,800);
float amps = 0;
for(int i = 80; i < 180; i++)
{
amps += fft.getFreq(i);
}
if (amps > 40) {
fill(#FFFF5F, 170); //luzes
rect(-10,-10,width+20,height+20);
}
float x;
float y;
for (int i = 0; i < 50; i++)
{
x = random (0, width);
y = random (0, height);
fill (#FC03DC);
ellipse (x,y,5,5); //brilhos
}
}
void drawBichoRosa()
{
translate(441,200);
shape(bichorosa, 50, 50, 300, 300); //corpo
getVolume(); // mic volume
float Y = map(volume, 0,100, 2,100);
fill(#7D9DF2);
ellipse(200,200, 80 ,Y); // boca
noStroke();
fill(255);
ellipse(200,130, 70,70);
fill(#7D9DF2);
noStroke();
ellipse(200,130, 20,20); // olho
fill (#FACFDE); // perna esquerda
rect (220, 275, 20, 60);
fill (#FACFDE); // perna direita
rect (160, 275, 20, 60);
// draw braços
armAngle = (int) map(volume, 0, 100, 3, 180);
if (armAngle > ANGLE_LIMIT || armAngle < 0) // se o braco passa dos limites-direcao oposta dentro dos limites
{
angleChange = -angleChange;
armAngle += angleChange;
}
if (botao_on_ligado){
pushMatrix();
translate(280, 175);
rotate(radians(-armAngle));
fill (#FACFDE);
rect(0, 0, 20, 60);
popMatrix();
pushMatrix();
translate(120, 175);
rotate(radians(armAngle));
fill (#FACFDE);
rect(-20, 0, 20, 60);
popMatrix(); //bracos dancantes
}
else {
pushMatrix();
translate(280, 175);
fill (#FACFDE);
rect(0, 0, 20, 60);
popMatrix();
pushMatrix();
translate(120, 175);
fill (#FACFDE);
rect(-20, 0, 20, 60);
popMatrix(); //bracos imoveis
}
}
void BichoAzul(){
resetMatrix();
translate (200,200);
rotacao = (int) map(volume, 0, 100, 0, 1000);
pushMatrix();
translate(width*0.155, height*0.18);
rotate(rotacao / -100.0); //para rodar tranquilamente por frameCount + 300/ -100.0
fill(#B5DCF3);
noStroke();
polygon(0, 0,95, 6);
popMatrix(); //corpo movente
getVolume(); // (mic volume )
float Y = map(volume, 0,100, 3,180);
fill(#F49FA7);
rect(180,165, 40 ,Y); //boca
noStroke();
fill(255);
ellipse(135,140, 33,33);
fill(#F49FA7);
noStroke();
ellipse(135,140,11,11); // olho esquerdo
noStroke();
fill(255);
ellipse(265,140, 33,33);
fill(#F49FA7);
noStroke();
ellipse(265,140,11,11); // olho direito
fill(#B5DCF3);
rect (100,180,20,40); //braco esquerdo
fill(#B5DCF3);
rect (280,180,20,40); //braco direito
fill(#B5DCF3);
rect (155,230,20,105); //perna esquerda
fill(#B5DCF3);
rect (225,230,20,105); //perna direita
}
void polygon(float x, float y, float radius, int npoints) {
float angle = TWO_PI / npoints;
beginShape();
for (float a = 0; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius;
float sy = y + sin(a) * radius;
vertex(sx, sy);
}
endShape(CLOSE);
}
void BichoVerde(){
resetMatrix();
translate (680,200);
movimento = (int) map(volume, 0, 100, 0, 180);
shape(bichoverde, 50, 50, 300, 300); //corpo
getVolume(); // (mic volume )
float Y = map(volume/2, 0,100, 21,180);
noStroke();
fill(#FFC18F);
ellipse(197,190, 30 ,Y); //boca
noStroke();
fill(255);
ellipse(170,130, 80 - movimento/4 ,80-movimento/4);
fill(#FFC18F);
noStroke();
ellipse(170,130,20-movimento/4 ,20- movimento/4); // olho esquerdo
noStroke();
fill(255);
ellipse(225,130,60-movimento/4,60-movimento/4);
fill(#FFC18F);
noStroke();
ellipse(225,130,15-movimento/4,15-movimento/4); // olho direito
noStroke();
fill(#FFC18F);
ellipse(197,45-movimento,17,17);
noStroke();
fill(#FFC18F);
ellipse(135 - movimento,65 - movimento,17,17);
noStroke();
fill(#FFC18F);
ellipse(255 + movimento,65 - movimento,17,17);
noStroke();
fill(#FFC18F);
ellipse(100 - movimento,115 - movimento,17,17);
noStroke();
fill(#FFC18F);
ellipse(290 + movimento,115 - movimento,17,17);
noStroke();
fill(#FFC18F);
ellipse(100 - movimento,175 + movimento,17,17);
noStroke();
fill(#FFC18F);
ellipse(290 + movimento,175 + movimento,17,17);
noStroke();
fill(#FFC18F);
ellipse(135 - movimento,225 + movimento,17,17);
noStroke();
fill(#FFC18F);
ellipse(255 + movimento,225 + movimento,17,17); //bolinhas
}
void BichoVermelho(){
resetMatrix();
translate(925,205);
movimento = (int) map(volume, 0, 100, 0, 180);
legAngle = (int) map(volume, 0, 100, 3, 180);
fft.forward( in.mix );
if (legAngle > ANGLE_LIMIT || legAngle < 0)
{
angleChange = -angleChange;
legAngle += angleChange;
}
shape(bichovermelho, 50, 50, 300, 300); //corpo
getVolume(); // (mic volume )
float Y = map(volume, 0,100, 10,180);
fill(#FFE272);
ellipse(200,215, 10 ,Y); //boca
noStroke();
fill(255);
ellipse(155,100, 40,40);
fill(#FFE272);
noStroke();
ellipse(155,100,15,15); // olho esquerdo
noStroke();
fill(255);
ellipse(245,100, 40,40);
fill(#FFE272);
noStroke();
ellipse(245,100,15,15); // olho direito
pushMatrix();
translate(240, 299);
rotate(radians(-legAngle));
fill(#FFE272);
rect(0, 0, -20, 30);
popMatrix(); // perna direita
pushMatrix();
translate(160, 299);
rotate(radians(legAngle));
fill(#FFE272);
rect(0, 0, 20, 30);
popMatrix(); // perna esquerda
fill(#FFE272);
rect (90 - movimento,155,30,20); //braco esquerdo
fill(#FFE272);
rect (280 + movimento,155,30,20); //braco direito
}
void BichoAmarelo(){
resetMatrix();
translate (-50,200);
movimento = (int) map(volume, 0, 100, 0, 180);
legAngle = (int) map(volume, 0, 100, 3, 180);
fft.forward( in.mix );
noStroke();
fill(#FCE47A);
shape(bichoamarelo, 50, 50, 300, 300);
noFill();
stroke(#F5A4B8);
strokeWeight(8);
ellipse(200,171.5, circulo_tamanho + movimento, circulo_tamanho + movimento); //corpo
getVolume(); // (mic volume )
float Y = map(volume, 0,100, 17,180);
fill(#F5A4B8);
ellipse(200,195, 17 ,Y); //boca
noStroke();
fill(255);
ellipse(150,120, 26.5,26.5);
fill(#D9BFDC);
noStroke();
ellipse(150,120,15.5,15.5); // olho esquerdo
noStroke();
fill(255);
ellipse(250,120, 26.5,26.5);
fill(#D9BFDC);
noStroke();
ellipse(250,120,15,15); // olho direito
pushMatrix();
translate(250, 300);
rotate(radians(-legAngle));
fill(#D9BFDC);
rect(0, 0, -21, 35);
popMatrix(); // perna direita
pushMatrix();
translate(150, 300);
rotate(radians(legAngle));
fill(#D9BFDC);
rect(0, 0, 21, 35);
popMatrix(); // perna esquerda
}
import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioInput in;
AudioPlayer player;
FFT fft;
//-------------------------------------
void setupAudio () {
minim = new Minim(this);
in = minim.getLineIn(Minim.MONO, 512);
fft = new FFT( in.bufferSize(), in.sampleRate() );
player = minim.loadFile ("Dancing.mp3");
}
//-------------------------------------
void getVolume() {
volumeF = in.mix.level()*1000;
volume = 0.8*volume + 0.2*volumeF;
}
//-------------------------------------
void stop() {
in.close();
minim.stop();
super.stop();
}