[ Video ]
[ About ]
最近購入した書籍「Make Your Own Algorithmic Art」で紹介されていたコードを参考にしてみました。
Innocent Dreams
Rashid, Tariq. Make Your Own Algorithmic Art (ページ575).  . Kindle 版. 
こちらの本はopenProcessing(p5js)を使って書かれています。英語が読めないので、雰囲気で読んだ感想ですが、図解も多く、内容もステップアップで進み、解説もかなり丁寧です。結構、お勧めの書籍です。
[ 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 | #pragma once #include "ofMain.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) {}; 	float alpha; 	vector<int> seed_values; 	void draw_circles(ofPoint range_point, int number_of_circles, int seed_value); }; | 
| 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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | #include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofBackground(239); 	ofSetWindowTitle("Insta"); 	this->alpha = 255; 	this->seed_values = { 0, 0, 0, 0 }; } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { 	// サイクル(増加、停止、フェードアウト)管理 	int number_of_circles = ofGetFrameNum() % 450; 	if (number_of_circles > 400) { 		this->alpha = ofMap(number_of_circles, 400, 450, 255, 0); 		number_of_circles = 350; 	} 	else if (number_of_circles > 350) { 		number_of_circles = 350; 	}else{ 		this->alpha = 255; 	} 	// サイクルが1周したらリセット 	if (number_of_circles == 0) { 		this->seed_values[0] = ofRandom(10, 30); 		this->seed_values[1] = ofRandom(50, 80); 		this->seed_values[2] = ofRandom(100, 130); 		this->seed_values[3] = ofRandom(150, 180); 		return; 	} 	// 4カ所に描写 	this->draw_circles(ofPoint(ofGetWidth() / 4, ofGetHeight() / 4), number_of_circles, this->seed_values[0]); 	this->draw_circles(ofPoint(ofGetWidth() / 4, ofGetHeight() / 4 * 3), number_of_circles, this->seed_values[1]); 	this->draw_circles(ofPoint(ofGetWidth() / 4 * 3, ofGetHeight() / 4), number_of_circles, this->seed_values[2]); 	this->draw_circles(ofPoint(ofGetWidth() / 4 * 3, ofGetHeight() / 4 * 3), number_of_circles, this->seed_values[3]); } //-------------------------------------------------------------- void ofApp::draw_circles(ofPoint range_point, int number_of_circles, int seed_value) { 	ofSeedRandom(seed_value); 	ofPushMatrix(); 	ofTranslate(range_point); 	vector<tuple<ofColor, ofPoint, float>> circles; 	int range_radius = 150; 	// 重ならないCircleをnumber_of_circles数だけ生成 	while (circles.size() < number_of_circles) { 		ofPoint point = ofPoint(ofRandom(-range_radius, range_radius), ofRandom(-range_radius, range_radius)); 		if (point.length() > range_radius) { 			continue; 		} 		ofColor color; 		color.setHsb(ofRandom(seed_value - 10, seed_value + 10), ofRandom(139, 239), ofRandom(139, 239)); 		float radius = ofRandom(2, 35); 		bool flag = true; 		for (int i = 0; i < circles.size(); i++) { 			if (point.distance(get<1>(circles[i])) < get<2>(circles[i]) + radius) { 				flag = false; 				break; 			} 		} 		if (flag) { 			circles.push_back(make_tuple(color, point, radius)); 		} 	} 	// 生成したCircleの描写 	for (int circles_index = 0; circles_index < circles.size(); circles_index++) { 		ofColor color = get<0>(circles[circles_index]); 		ofPoint point = get<1>(circles[circles_index]); 		float radius = get<2>(circles[circles_index]); 		ofSetColor(color, this->alpha); 		ofDrawCircle(point, radius); 	} 	ofPopMatrix(); } //-------------------------------------------------------------- int main() { 	ofSetupOpenGL(720, 720, OF_WINDOW); 	ofRunApp(new ofApp()); } |