#include "ofApp.h"
void ofApp::setup(){
beat.load("sounds/jdee_beat.mp3");
ow.load("sounds/ow.mp3");
dog.load("sounds/dog.mp3");
rooster.load("sounds/rooster.mp3");
}
void ofApp::update(){
ofBackground(80,80,20);
ofSoundUpdate();
px += vx;
py += vy;
if (px < 0){
px = 0;
vx *= -1;
dog.play();
} else if (px > ofGetWidth()){
px = ofGetWidth();
vx *= -1;
ow.play();
}
if (py < 0 ){
py = 0;
vy *= -1;
rooster.play();
} else if (py > ofGetHeight()){
py = ofGetHeight();
vy *= -1;
beat.play();
}
vx *= 0.996f;
vy *= 0.996f;
float vel = sqrt(vx*vx + vy*vy);
ow.setVolume(MIN(vel/5.0f, 1));
beat.setVolume(MIN(vel/5.0f, 1));
dog.setVolume(MIN(vel/5.0f, 1));
rooster.setVolume(MIN(vel/5.0f, 1));
float * val = ofSoundGetSpectrum(nBandsToGet);
for (int i = 0;i < nBandsToGet; i++){
fftSmoothed[i] *= 0.96f;
if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];
}
}
void ofApp::draw(){
ofEnableAlphaBlending();
ofSetColor(255,255,255,100);
ofDrawRectangle(100,ofGetHeight()-300,5*128,200);
ofDisableAlphaBlending();
ofSetColor(255,255,255,255);
float width = (float)(5*128) / nBandsToGet;
for (int i = 0;i < nBandsToGet; i++){
ofDrawRectangle(100+i*width,ofGetHeight()-100,width,-(fftSmoothed[i] * 200));
}
ofEnableAlphaBlending();
ofSetColor(255,255,255,20);
ofDrawCircle(px, py,50);
ofDisableAlphaBlending();
ofSetHexColor(0xffffff);
ofDrawCircle(px, py,8);
}
void ofApp::keyPressed (int key){
}
void ofApp::keyReleased(int key){
}
void ofApp::mouseMoved(int x, int y ){
}
void ofApp::mouseDragged(int x, int y, int button){
vx += (x - prevx) / 20.0f;
vy += (y - prevy) / 20.0f;
prevx = x;
prevy = y;
}
void ofApp::mousePressed(int x, int y, int button){
prevx = x;
prevy = y;
}
void ofApp::mouseReleased(int x, int y, int button){
}
void ofApp::mouseEntered(int x, int y){
}
void ofApp::mouseExited(int x, int y){
}
void ofApp::windowResized(int w, int h){
}
void ofApp::gotMessage(ofMessage msg){
}
void ofApp::dragEvent(ofDragInfo dragInfo){
}
Comments