[ Video ]
[ About ]
Day 10 Apple
重力で落ちるリンゴ達。リンゴは絵文字🍎、物理エンジンはofxBox2dを使いました。
Apple falling with gravity. Apple is Emoji🍎, And physics engine is ofxBox2d.
[ 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 |
#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) {}; ofTrueTypeFont font; ofxBox2d box2d; vector<shared_ptr<ofxBox2dCircle>> circles; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetColor(239, 39, 39); ofTrueTypeFontSettings font_settings("fonts/EmojiSymbols-Regular.ttf", 32); font_settings.antialiased = true; font_settings.addRanges(ofAlphabet::Emoji); 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 = 16; 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), 15, radius); this->circles.push_back(circle); } this->box2d.update(); } //-------------------------------------------------------------- void ofApp::draw() { 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(u8"🍎", this->circles[i]->getRadius() * -1, this->circles[i]->getRadius()); ofPopMatrix(); } } //======================================================================== int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |