[ Video ]
[ About ]
絵文字って丸いよね…と思いついて、物理演算(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 27 28 29 | #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; 	vector<ofColor> circles_color; 	vector<string> words; 	ofxBox2dEdge eage_1, eage_2; }; | 
| 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | #include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofSetWindowTitle("Insta"); 	ofBackground(239); 	ofTrueTypeFontSettings font_settings("fonts/EmojiSymbols-Regular.ttf", 30); 	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(); 	this->eage_1 = ofxBox2dEdge(); 	this->eage_1.addVertex(ofGetWidth() / 2 - 150, ofGetHeight() / 2 + 100); 	this->eage_1.addVertex(ofGetWidth() / 2, ofGetHeight() / 2); 	this->eage_1.create(this->box2d.getWorld()); 	this->eage_2 = ofxBox2dEdge(); 	this->eage_2.addVertex(ofGetWidth() / 2 + 150, ofGetHeight() / 2 + 100); 	this->eage_2.addVertex(ofGetWidth() / 2, ofGetHeight() / 2); 	this->eage_2.create(this->box2d.getWorld()); } //-------------------------------------------------------------- void ofApp::update() { 	if (ofGetFrameNum() % 10 == 0) { 		float radius = 15; 		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); 		ofColor circle_color; 		circle_color.setHsb(ofRandom(255), 255, 239); 		this->circles_color.push_back(circle_color); 		vector<string> emojis = { u8"😁", u8"😍", u8"😂", u8"😱", u8"😎" }; 		this->words.push_back(emojis[(int)ofRandom(emojis.size())]); 	} 	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()); 		ofSetColor(this->circles_color[i]); 		this->font.drawString(this->words[i], -15, 15); 		ofPopMatrix(); 	} 	ofSetColor(39); 	this->eage_1.draw(); 	this->eage_2.draw(); } //======================================================================== int main() { 	ofSetupOpenGL(720, 720, OF_WINDOW); 	ofRunApp(new ofApp()); } |