[ Video ]
[ About ]
音と連動して帯が変化。え ͤみ ͫ ͤー ͤん ͛(@emeen231)さんの投稿からインスパイア
[Sound] Band changes with music.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#pragma once #include "ofMain.h" class ofApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed(int key) {}; void keyReleased(int key) {}; void mouseMoved(int x, int y) {}; void mouseDragged(int x, int y, int button) {}; void mousePressed(int x, int y, int button) {}; void mouseReleased(int x, int y, int button) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; ofEasyCam cam; ofSoundPlayer sound; vector<float> fft_smoothed; int n_bands_to_get; glm::vec3 make_point(float radius, float small_radius, float deg, float small_deg); }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetColor(39); ofEnableDepthTest(); ofNoFill(); ofSetLineWidth(2.5); this->sound.load("Cold_Killa_Sting.mp3"); this->sound.play(); this->n_bands_to_get = 60; for (int j = 0; j < this->n_bands_to_get; j++) { this->fft_smoothed.push_back(0); } } //-------------------------------------------------------------- void ofApp::update() { ofSoundUpdate(); float* val = ofSoundGetSpectrum(this->n_bands_to_get); for (int i = 0; i < this->n_bands_to_get; i++) { this->fft_smoothed[i] *= 0.98f; if (this->fft_smoothed[i] < val[i]) { this->fft_smoothed[i] = val[i]; } } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); int radius = 300; int deg_span = 10; int sound_index = 0; for (int deg_start = 0; deg_start < 360; deg_start += deg_span) { int deg = deg_start; vector<glm::vec3> vertices; vector<glm::vec3> sub_vertices; int max_height = this->fft_smoothed[sound_index++] * 150 * (sound_index + 1); for (int height = 0; height < max_height; height += 10) { vertices.push_back(glm::vec3(radius * cos(deg * DEG_TO_RAD), height, radius * sin(deg * DEG_TO_RAD))); sub_vertices.push_back(glm::vec3(radius * cos((deg + deg_span) * DEG_TO_RAD), height, radius * sin((deg + deg_span) * DEG_TO_RAD))); deg += 5; } for (int i = sub_vertices.size() - 1; i > -1; i--) { vertices.push_back(sub_vertices[i]); } ofBeginShape(); ofVertices(vertices); ofEndShape(true); } this->cam.end(); if (!this->sound.getIsPlaying()) { this->sound.play(); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |