[ Video ]
[ About ]
昨日の「再帰で四角」を3Dにしてみました。level変数によって高さが決まるので、面積の大きい四角形は高さが低く、面積の小さい四角は高さが高く描写されています。
フレーム数で伸びるようにしたので、ニョキっと感が出て良いと思います。
[ 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  | 
						#pragma once #include "ofMain.h" #include "RecuRect.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) {}; 	ofEasyCam cam; 	ofLight light; 	RecuRect r_rect; };  | 
					
| 
					 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  | 
						#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofBackground(255); 	ofSetWindowTitle("Insta"); 	ofEnableDepthTest(); 	ofEnableLighting(); 	ofNoFill(); 	this->light.setPosition(ofVec3f(0, 0, 1024)); 	this->light.enable(); } //-------------------------------------------------------------- void ofApp::update() { 	if (ofGetFrameNum() % 180 == 0) { 		ofSetColor(ofRandom(255), ofRandom(255), ofRandom(255)); 		this->r_rect = RecuRect(5, ofVec2f(0, 0), 720, true); 	} 	this->r_rect.update(); } //-------------------------------------------------------------- void ofApp::draw() { 	this->cam.begin(); 	ofRotate(ofGetFrameNum() * 0.25); 	ofNoFill(); 	ofDrawRectangle(ofVec2f(-ofGetWidth() / 2, -ofGetHeight() / 2), ofGetWidth(), ofGetHeight()); 	this->r_rect.draw(); 	this->cam.end(); } //======================================================================== 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  | 
						#pragma once #include "ofMain.h" class RecuRect { public: 	RecuRect(); 	RecuRect(int level, ofVec2f location, float size, bool origin = false); 	~RecuRect(); 	void update(); 	void draw(); private: 	int level; 	ofVec2f location; 	float size; 	int type; 	bool origin; 	float height; 	float height_max; 	std::vector<RecuRect> rects; };  | 
					
| 
					 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  | 
						#include "RecuRect.h" RecuRect::RecuRect() { } RecuRect::RecuRect(int level, ofVec2f location, float size, bool origin) { 	this->type = ofRandom(100); 	if (origin || (level > 0 && this->type > 20)) { 		this->rects.push_back(RecuRect(level - 1, ofVec2f(location.x - size / 4, location.y - size / 4), size / 2)); 		this->rects.push_back(RecuRect(level - 1, ofVec2f(location.x - size / 4, location.y + size / 4), size / 2)); 		this->rects.push_back(RecuRect(level - 1, ofVec2f(location.x + size / 4, location.y - size / 4), size / 2)); 		this->rects.push_back(RecuRect(level - 1, ofVec2f(location.x + size / 4, location.y + size / 4), size / 2)); 	} 	this->level = level; 	this->location = location; 	this->size = size; 	this->origin = origin; 	this->height = 0; 	this->height_max = -1 * (140 - 20 * level); } RecuRect::~RecuRect() { } void RecuRect::update() { 	for (int i = 0; i < this->rects.size(); i++) { 		this->rects[i].update(); 	} 	if (this->height > this->height_max) { 		this->height -= 3; 	} } void RecuRect::draw() { 	for (int i = 0; i < this->rects.size(); i++) { 		this->rects[i].draw(); 	} 	if (this->type > 60) { 		ofFill(); 		ofDrawBox(this->location.x, this->location.y, -this->height / 2, size, size, this->height); 	} }  |