[ Video ]
[ About ]
図形による埋め立て
Landfill by shapes.
[ Source ]
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #pragma once #include "ofMain.h" #include "MyShapes.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) {}; 	vector<unique_ptr<My::Shape>> shapes; }; | 
| 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 | #include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofSetWindowTitle("openFrameworks"); 	ofBackground(239); 	ofSetColor(39); 	ofSetRectMode(ofRectMode::OF_RECTMODE_CENTER); 	while (this->shapes.size() < 800) { 		auto location = glm::vec2(ofRandom(100, ofGetWidth() - 100), ofRandom(100, ofGetHeight() - 100)); 		auto radius = ofRandom(5, 25); 		auto flag = true; 		for(auto& shape : this->shapes){ 			if (glm::distance(location, glm::vec2(shape->location)) < shape->radius + radius) { 				flag = false; 				break; 			} 		} 		if (flag) { 			unique_ptr<My::Shape> shape; 			int r = ofRandom(2); 			switch (r) { 			case 0: 				shape = make_unique<My::Circle>(location, radius); 				break; 			case 1: 				shape = make_unique<My::Rectangle>(location, radius); 				break; 			} 			if (shape) { this->shapes.push_back(move(shape)); } 		} 	} } //-------------------------------------------------------------- void ofApp::update() { 	ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { 	for (auto& shape : this->shapes) { 		shape->draw(); 	} } //-------------------------------------------------------------- int main() { 	ofSetupOpenGL(720, 720, OF_WINDOW); 	ofRunApp(new ofApp()); } | 
| 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 | #pragma once #pragma once #include "ofMain.h" namespace My { 	class Shape { 	public: 		Shape(glm::vec2 location, float radius); 		~Shape() {}; 		virtual void draw() = 0; 		glm::vec2 location; 		float radius; 		bool fill; 	}; 	class Circle : public Shape { 	public: 		Circle(glm::vec2 location, float radius); 		void draw() override; 	private: 		int deg; 	}; 	class Rectangle : public Shape { 	public: 		Rectangle(glm::vec2 location, float radius); 		void draw() override; 	private: 		float len; 		float speed; 		int direction; 	}; } | 
| 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 | #include "MyShapes.h" // Shape My::Shape::Shape(glm::vec2 location, float radius) { 	this->location = location; 	this->radius = radius; 	this->fill = ofRandom(1) < 0.5 ? true : false; } // Circle My::Circle::Circle(glm::vec2 location, float radius) : Shape(location, radius) { 	this->deg = ofRandom(360); } void My::Circle::draw() { 	ofPushMatrix(); 	ofTranslate(this->location); 	ofRotate(this->deg); 	this->fill ? ofFill() : ofNoFill(); 	ofSetColor(39); 	ofDrawCircle(glm::vec2(), this->radius); 	float tmp_radius = ofNoise(this->location.x * 0.005, this->location.y * 0.005, ofGetFrameNum() * 0.005) * this->radius; 	this->fill ? ofSetColor(239) : ofFill(); 	ofBeginShape(); 	for (int deg = 0; deg < 360; deg += 36) { 		if (deg % 72 == 0) { 			ofVertex(tmp_radius * cos(deg * DEG_TO_RAD), tmp_radius * sin(deg * DEG_TO_RAD)); 		} 		else { 			ofVertex(tmp_radius * 0.5 * cos(deg * DEG_TO_RAD), tmp_radius * 0.5 * sin(deg * DEG_TO_RAD)); 		} 	} 	ofEndShape(true); 	ofPopMatrix(); } // Rectangle My::Rectangle::Rectangle(glm::vec2 location, float radius) : Shape(location, radius) { 	this->len = radius * sqrt(2); 	this->speed = ofRandom(0.5, 3); 	this->direction = ofRandom(1) < 0.5 ? -1 : 1; } void My::Rectangle::draw() { 	ofPushMatrix(); 	ofTranslate(this->location); 	ofRotate(ofGetFrameNum() * this->speed * this->direction); 	this->fill ? ofFill() : ofNoFill(); 	ofSetColor(39); 	ofDrawRectangle(glm::vec2(), this->len, this->len); 	ofPopMatrix(); } | 
You made a few nice poinhts there. I did a search on the theme and ound a good number of people will consent
with your blog.