ofw-2022–0002 (Mống mắt)
Dec 18 2022
Sở thích và Nghiên cứu về C++ và thuật toán cơ bản của OpenFrameworks. Mã ứng dụng
Sở thích và Nghiên cứu về C++ và thuật toán cơ bản của OpenFrameworks.
mã
ofApp.cpp (Tôi đang định chia sẻ tệp nguồn và tệp AIFF trên Github)
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofSetBackgroundAuto(false);
ofEnableAlphaBlending();
sound.load("ofw-2022-0002.aif");
sound.play();
sound.setLoop(true);
ofSetFrameRate(60);
ofSetLineWidth(1);
fft_a = new float[512];
for (int i = 0; i < 512; i++) {
fft_a[i] = 0;
}
bands = 512;
nextEventSeconds = 0;
ofst = 0;
cnt = 1;
kei = 10000;
kei2 = 10000;
i = 0;
}
//--------------------------------------------------------------
void ofApp::update(){
ofSoundUpdate();
soundSpectrum = ofSoundGetSpectrum(bands);
for (int i = 0; i < bands; i++) {
fft_a[i] *= 0.8;
if (fft_a[i] < soundSpectrum[i]) {
fft_a[i] = soundSpectrum[i];
}
}
ofst += 3;
if (ofst > 1800) {
ofst = 0;
cnt += 1;
}
if (cnt > 5){
kei += ofRandom(-1000, 1000);
kei2 += ofRandom(-1000, 1000);
}
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(0, 0, 0, fft_a[256]*100);
ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight());
ofSetColor(fft_a[256]*kei, fft_a[256]*16000, fft_a[256]*kei2, 192);
// ofTranslate(10,10);
ofTranslate( -500, 0, 500 - ofst);
ofPolyline polyline;
for (int j = 0; j < bands; j++) {
float r = sin(i/2) * 1000;
polyline.addVertex(ofVec3f((ofGetWidth()/2 + sin(i/2) * r) + (sin(i/2) * fft_a[j]), (ofGetHeight()/2 + cos(i/2) * r + ((i / 360 - 2) - fft_a[j] + cos(i/2))), j * (fft_a[j] * 10) ));
i+=0.005*HALF_PI*0.5;
if (i > 720) {
i = 0;
}
}
polyline.draw();
}
DAW : Ableton, Live 11
Beats : Native Instruments, Battery4
Synth : UVI, Falcon
Effector : Flux, McDSP, LEAP, UVI, iZotope, Soundtoys
Thẩm quyền giải quyết
Tôi đã học hình ảnh mã cơ sở từ hướng dẫn tuyệt vời này. Tôi yêu kênh YouTube của anh ấy. Và tôi đã giới thiệu hướng dẫn chính thức về openframeworks để tạo vòng tròn bằng sóng âm thanh.

![Dù sao thì một danh sách được liên kết là gì? [Phần 1]](https://post.nghiatu.com/assets/images/m/max/724/1*Xokk6XOjWyIGCBujkJsCzQ.jpeg)



































