[ Video ]
[ About ]
エレクトロニクス・パレード
RGB random walk.
[ 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 30 31 32 33 34 | #pragma once #include "ofMain.h" #include "Particle.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 mouseEntered(int x, int y) {}; 	void mouseExited(int x, int y) {}; 	void windowResized(int w, int h) {}; 	void dragEvent(ofDragInfo dragInfo) {}; 	void gotMessage(ofMessage msg) {}; 	ofShader shader; 	int number_of_targets; 	vector<glm::vec3> colors; 	ofFbo src; 	ofFbo dst; 	vector<Particle> particles; 	vector<ofPoint> locations; 	vector<vector<int>> next_indexes; }; | 
| 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 | #include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofSetWindowTitle("openframeworks"); 	int span = 72; 	for (int x = 0; x <= ofGetWidth(); x += span) { 		for (int y = 0; y <= ofGetHeight(); y += span) { 			this->locations.push_back(ofPoint(x, y)); 		} 	} 	for (int i = 0; i < this->locations.size(); i++) { 		vector<int> next_index = vector<int>(); 		for (int j = 0; j < this->locations.size(); j++) { 			if (i == j) { continue; } 			float distance = this->locations[i].distance(this->locations[j]); 			if (distance <= span) { 				next_index.push_back(j); 			} 		} 		this->next_indexes.push_back(next_index); 	} 	this->number_of_targets = 120; 	for (int i = 0; i < this->number_of_targets; i++) { 		this->particles.push_back(Particle(this->locations, this->next_indexes)); 		glm::vec3  color = glm::vec3(1.0, 1.0, 1.0); 		int color_type = ofRandom(3); 		switch (color_type) { 		case 0: 			color = glm::vec3(0.8, 0.3, 0.3); 			break; 		case 1: 			color = glm::vec3(0.3, 0.8, 0.3); 			break; 		case 2: 			color = glm::vec3(0.3, 0.3, 0.8); 			break; 		} 		this->colors.push_back(color); 	} 	this->src.allocate(ofGetWidth(), ofGetHeight()); 	this->dst.allocate(ofGetWidth(), ofGetHeight()); 	this->shader.load("shader/shader.vert", "shader/shader.frag"); } //-------------------------------------------------------------- void ofApp::update() { 	for (Particle& particle : this->particles) { particle.Upate(); } } //-------------------------------------------------------------- void ofApp::draw() { 	vector<glm::vec2> targets; 	for (int i = 0; i < this->number_of_targets; i++) { 		glm::vec2 p = glm::vec2(this->particles[i].location.x, this->particles[i].location.y); 		targets.push_back(p); 	} 	this->dst.begin(); 	this->shader.begin(); 	this->shader.setUniform1f("time", ofGetElapsedTimef()); 	this->shader.setUniform2f("resolution", ofGetWidth(), ofGetHeight()); 	this->shader.setUniform2fv("targets", &targets[0].x, this->number_of_targets); 	this->shader.setUniform3fv("colors", &this->colors[0].x, this->number_of_targets); 	this->shader.setUniformTexture("fbo", this->src.getTexture(), 1); 	this->src.draw(0, 0); 	this->shader.end(); 	this->dst.end(); 	this->dst.draw(0, 0); 	std::swap(this->src, this->dst); } //-------------------------------------------------------------- int main() { 	ofGLWindowSettings settings; 	settings.setGLVersion(3, 2); 	settings.setSize(720, 720); 	ofCreateWindow(settings); 	ofRunApp(new ofApp()); } | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #pragma once #include "ofMain.h" class Particle { public: 	Particle(vector<ofPoint> locations, vector<vector<int>> next_indexes); 	~Particle(); 	void Upate(); 	void Draw(); 	ofPoint location; private: 	vector<ofPoint> locations; 	vector<vector<int>> next_indexes; 	int locations_index; 	int next_index; }; | 
| 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 | #include "Particle.h" //-------------------------------------------------------------- Particle::Particle(vector<ofPoint> locations, vector<vector<int>> next_indexes) { 	this->locations = locations; 	this->next_indexes = next_indexes; 	while (true) { 		this->locations_index = (int)ofRandom(this->locations.size()); 		if (this->next_indexes[this->locations_index].size() > 0) { 			this->next_index = this->next_indexes[this->locations_index][(int)ofRandom(this->next_indexes[this->locations_index].size())]; 			break; 		} 	} } //-------------------------------------------------------------- Particle::~Particle() { } //-------------------------------------------------------------- void Particle::Upate() { 	int frame_span = 20; 	if (ofGetFrameNum() % frame_span == 0) { 		this->locations_index = this->next_index; 		this->next_index = this->next_indexes[this->locations_index][(int)ofRandom(this->next_indexes[this->locations_index].size())]; 	} 	ofPoint distance = this->locations[this->next_index] - this->locations[this->locations_index]; 	this->location = this->locations[this->locations_index] + distance / frame_span * (ofGetFrameNum() % frame_span); } //-------------------------------------------------------------- void Particle::Draw() { } | 
| 1 2 3 4 5 6 7 8 | #version 150 uniform mat4 modelViewProjectionMatrix; in vec4 position; void main(){ 	gl_Position = modelViewProjectionMatrix * position; } | 
| 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 | #version 150 const int number_of_targets = 100; out vec4 outputColor; uniform float time; uniform vec2 resolution; uniform vec2 targets[number_of_targets]; uniform vec3 colors[number_of_targets]; uniform sampler2DRect fbo; void main() {   vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y);   vec3 color = vec3(0.0);   for(int i = 0; i < number_of_targets; i++){     vec2 t = vec2(targets[i].x, -targets[i].y) / min(resolution.x, resolution.y) * 2.0;     t.xy += vec2(-resolution.x, resolution.y) / min(resolution.x, resolution.y);     float r = 0.01 / length(p - t) * colors[i].x;     float g = 0.01 / length(p - t) * colors[i].y;     float b = 0.01 / length(p - t) * colors[i].z;     vec3 c = vec3(smoothstep(0.05, 1.0, r), smoothstep(0.05, 1.0, g), smoothstep(0.05, 1.0, b));     color += c;   }   vec4 fbo_value = texture(fbo, vec2(gl_FragCoord.x, gl_FragCoord.y));   outputColor = vec4(color, 1.0) + fbo_value * 0.95; } |