[ Video ]
[ About ]
円の移動に音をつけてみたやつ。
Sound And Circle.
[ 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 |
#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 mouseEntered(int x, int y) {}; void mouseExited(int x, int y) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; vector<ofSoundPlayer> sounds; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("Insta"); ofSetColor(239); ofBackground(39); ofSetLineWidth(3); ofNoFill(); string sound_path_list[] = { "sound/pianoC2.mp3", "sound/pianoB.mp3", "sound/pianoA.mp3", "sound/pianoG.mp3", "sound/pianoF.mp3", "sound/pianoE.mp3", "sound/pianoD.mp3","sound/pianoC.mp3" }; for (int i = 0; i < 8; i++) { ofSoundPlayer sound; sound.load(sound_path_list[i]); sound.setVolume(0.2); sound.setMultiPlay(true); this->sounds.push_back(sound); } } //-------------------------------------------------------------- void ofApp::update() { ofSoundUpdate(); } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5); for (int i = 0; i < 16; i++) { int radius = (i + 1) * 20; int deg_param = (ofGetFrameNum() * 0.25) * (i + 1); ofBeginShape(); for (int deg = deg_param - 30; deg <= deg_param + 30; deg++) { ofVertex(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD)); } ofEndShape(false); if (deg_param % 360 == 0) { this->sounds[i % 8].play(); } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |