More Related Content
Similar to デジタルアートセミナー#2 openFrameworksで学ぶ、 クリエイティブ・コーディング Session 3: アドオンを作ろう! (20)
More from Atsushi Tadokoro (20)
デジタルアートセミナー#2 openFrameworksで学ぶ、 クリエイティブ・コーディング Session 3: アドオンを作ろう!
- 18. //--------------------------------------------------------------
void testApp::update(){
curretFps = ofGetFrameRate();
currentMs = (ofGetElapsedTimef() - lastMs) * 1000;
lastMs = ofGetElapsedTimef();
if (int(ofGetElapsedTimef() * 1000) / lapTime > lastLap) {
fpsList.push_front(curretFps);
if (fpsList.size() > width - padding * 2 + 1) {
fpsList.pop_back();
}
msList.push_front(currentMs);
if (msList.size() > width - padding * 2 + 1) {
msList.pop_back();
}
lastLap++;
}
}
//--------------------------------------------------------------
void testApp::draw(){
// sphere animation
ofPushStyle();
ofEnableDepthTest();
ofEnableLighting();
light.enable();
ofSetHexColor(0xcccccc);
アドオンを作ろう!!
‣ まずは、testAppの中で単体で実装してみた
‣ https://github.com/tado/DigitalArtSeminar13/tree/master/03_01statsSketch
- 19. アドオンを作ろう!!
‣ アドオン → 要は、C++のクラス
‣ よくつかう機能を、C++のクラスとして実装すれば、そのまま
アドオンとなる
‣ クラスについての詳細は、セミナー1日目のセッション「構造
をつくる」を参照
‣ http://www.slideshare.net/tado/dac-ws02
- 20. #include "Stats.h"
Stats::Stats():top(0), left(0), width(80), height(48), maxValue(120), lapTime(100),
mode(0){
lastLap = 0;
lastMs = 0;
padding = 3;
}
void Stats::update(){
curretFps = ofGetFrameRate();
currentMs = (ofGetElapsedTimef() - lastMs) * 1000;
lastMs = ofGetElapsedTimef();
if (int(ofGetElapsedTimef() * 1000) / lapTime > lastLap) {
fpsList.push_front(curretFps);
if (fpsList.size() > width - padding * 2 + 1) {
fpsList.pop_back();
}
msList.push_front(currentMs);
if (msList.size() > width - padding * 2 + 1) {
msList.pop_back();
}
lastLap++;
アドオンを作ろう!!
‣ 先程のプログラムのグラフ表示部分のみ、クラスに分割する
‣ https://github.com/tado/DigitalArtSeminar13/tree/master/03_02statsSketch_class
- 22. アドオンを作ろう!!
‣ これで、もうほとんど完成
‣ クラス名を、「Stats 」から「ofxStats」に変更
‣ クラスの説明を、Markdown形式で記述して「README.md」
という名前で保存
‣ クラスの機能をアピールするようなサムネイル画像を以下の
フォーマットで作成
‣ ファイル名「ofxaddons_thumbnail.png」
‣ フォーマット: PNG
‣ ファイルサイズ: 270 x 70
- 27. アドオンをどんどん開発しよう!
‣ アドオンの機能がとても便利な場合
‣ Step 1: openFrameworksの配布パッケージに内包される
‣ ofxKinect, ofxOpenCV ..etc.
‣ Step 2: アドオンではなくコア機能としてとり込まれることも
‣ ofxVectorMath → ofVectorMath
‣ ofxThread → ofThread
‣ ofxShader → ofShader