[ Video ]
[ About ]
令和元日!
REIWA.
[ 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" #include "ofxBox2d.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) {}; int font_size; ofTrueTypeFont font; ofxBox2d box2d; vector<shared_ptr<ofxBox2dCircle>> circles; vector<int> indexes; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetColor(39); ofTrueTypeFontSettings font_settings("fonts/Kazesawa-Bold.ttf", 25); font_settings.antialiased = true; font_settings.addRanges(ofAlphabet::Japanese); this->font.load(font_settings); this->box2d.init(); this->box2d.setGravity(0, 5); this->box2d.createBounds(); this->box2d.setFPS(60); this->box2d.registerGrabbing(); } //-------------------------------------------------------------- void ofApp::update() { if (ofGetFrameNum() % 10 == 0) { float radius = 20; auto circle = make_shared<ofxBox2dCircle>(); circle->setPhysics(1.0, 0.63, 0.1); circle->setup(this->box2d.getWorld(), ofRandom(ofGetWidth() * 0.5 - 50, ofGetWidth() * 0.5 + 50), 20, radius); this->circles.push_back(circle); this->indexes.push_back(ofRandom(2)); } this->box2d.update(); } //-------------------------------------------------------------- void ofApp::draw() { vector<string> words = { u8"令", u8"和", }; for (int i = 0; i < this->circles.size(); i++) { ofPushMatrix(); ofTranslate(this->circles[i]->getPosition().x, this->circles[i]->getPosition().y); ofRotate(this->circles[i]->getRotation()); this->font.drawString(words[this->indexes[i]], -15, 10); ofPopMatrix(); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |