[ Video ]
[ About ]
パーティクルの座標をパーリンノイズを使って変化、パーティクルは周期的に音を発しますが、X座標によって音階が変わります。
The particle changes position by Perlin Noise, and the sound changes depending on X coordinate.
[ 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 62 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("Insta"); ofSetColor(239); ofBackground(39); ofSetBackgroundAuto(false); ofSetLineWidth(3); string sound_path_list[] = { "sound/pianoC.mp3", "sound/pianoD.mp3", "sound/pianoE.mp3", "sound/pianoF.mp3", "sound/pianoG.mp3", "sound/pianoA.mp3", "sound/pianoB.mp3", "sound/pianoC2.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() { ofSetColor(39, 64); ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight()); ofSetColor(239); for (int i = 1; i <= 6; i++) { float noise_value = ofNoise(i, ofGetFrameNum() * 0.005); ofPoint point = ofPoint(noise_value * ofGetWidth(), i * 102); ofFill(); ofDrawCircle(point, 30); if (ofGetFrameNum() % (i * 15) == 0) { int index = noise_value * 8; this->sounds[index].play(); ofNoFill(); ofDrawCircle(point, 50); } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |