[ Video ]
[ About ]
Orb and child orb.
[ 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" 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) {}; int number_of_targets; vector<glm::vec2> target_list; vector<glm::vec3> color_list; ofShader shader; float noise_seed; }; |
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 114 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(0); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); this->number_of_targets = 4 * 5 * 5; for (int i = 0; i < this->number_of_targets; i++) { this->target_list.push_back(glm::vec2()); this->color_list.push_back(glm::vec3()); } this->shader.load("shader/shader.vert", "shader/shader.frag"); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); if (ofGetFrameNum() % 60 < 45) { this->noise_seed += ofMap(ofGetFrameNum() % 60, 0, 45, 0.04, 0); } } //-------------------------------------------------------------- void ofApp::draw() { int range = 100; int radius = 20; for (int i = 0; i < this->number_of_targets; i += 4) { int x = (i / 4) % 5 * 144 + 72; int y = (i / 4) / 5 * 144 + 72; this->target_list[i] = glm::vec2(x + ofMap(ofNoise(ofRandom(1000), this->noise_seed), 0, 1, range * -0.5, range * 0.5), y + ofMap(ofNoise(ofRandom(1000), this->noise_seed), 0, 1, range * -0.5, range * 0.5)); auto r_location = glm::vec2(x + ofMap(ofNoise(ofRandom(1000), this->noise_seed), 0, 1, range * -0.5, range * 0.5), y + ofMap(ofNoise(ofRandom(1000), this->noise_seed), 0, 1, range * -0.5, range * 0.5)); auto g_location = glm::vec2(x + ofMap(ofNoise(ofRandom(1000), this->noise_seed), 0, 1, range * -0.5, range * 0.5), y + ofMap(ofNoise(ofRandom(1000), this->noise_seed), 0, 1, range * -0.5, range * 0.5)); auto b_location = glm::vec2(x + ofMap(ofNoise(ofRandom(1000), this->noise_seed), 0, 1, range * -0.5, range * 0.5), y + ofMap(ofNoise(ofRandom(1000), this->noise_seed), 0, 1, range * -0.5, range * 0.5)); auto r = ofMap(distance(this->target_list[i], r_location), 0, range, 1, 0.1); auto g = ofMap(distance(this->target_list[i], g_location), 0, range, 1, 0.1); auto b = ofMap(distance(this->target_list[i], b_location), 0, range, 1, 0.1); this->color_list[i] = glm::vec3(r, g, b); this->target_list[i + 1] = r_location; this->color_list[i + 1] = glm::vec3(0.3, 0.2, 0.2); this->target_list[i + 2] = g_location; this->color_list[i + 2] = glm::vec3(0.2, 0.3, 0.2); this->target_list[i + 3] = b_location; this->color_list[i + 3] = glm::vec3(0.2, 0.2, 0.3); ofSetColor(this->color_list[i].x * 255, this->color_list[i].y * 255, this->color_list[i].z * 255); auto r_angle = std::atan2(r_location.y - this->target_list[i].y, r_location.x - this->target_list[i].x); auto r_line_location = this->target_list[i] + glm::vec2(radius * cos(r_angle), radius * sin(r_angle)); ofDrawLine(r_location, r_line_location); auto g_angle = std::atan2(g_location.y - this->target_list[i].y, g_location.x - this->target_list[i].x); auto g_line_location = this->target_list[i] + glm::vec2(radius * cos(g_angle), radius * sin(g_angle)); ofDrawLine(g_location, g_line_location); auto b_angle = std::atan2(b_location.y - this->target_list[i].y, b_location.x - this->target_list[i].x); auto b_line_location = this->target_list[i] + glm::vec2(radius * cos(b_angle), radius * sin(b_angle)); ofDrawLine(b_location, b_line_location); } ofFill(); this->shader.begin(); this->shader.setUniform1f("time", ofGetElapsedTimef()); this->shader.setUniform2f("resolution", ofGetWidth(), ofGetHeight()); this->shader.setUniform2fv("targets", &this->target_list[0].x, this->number_of_targets); this->shader.setUniform3fv("colors", &this->color_list[0].x, this->number_of_targets); ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight()); this->shader.end(); for (int i = 0; i < this->number_of_targets; i++) { if (i % 4 == 0) { ofSetColor(this->color_list[i].x * 255, this->color_list[i].y * 255, this->color_list[i].z * 255); ofBeginShape(); for (int deg = 0; deg <= 360; deg += 1) { ofVertex(this->target_list[i] + glm::vec2(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD))); } for (int deg = 360; deg >= 0; deg -= 1) { ofVertex(this->target_list[i] + glm::vec2((radius + 1) * cos(deg * DEG_TO_RAD), (radius + 1) * sin(deg * DEG_TO_RAD))); } ofEndShape(true); } } } //-------------------------------------------------------------- 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 |
#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; uniform float time; uniform vec2 resolution; uniform vec2 targets[number_of_targets]; uniform vec3 colors[number_of_targets]; out vec4 outputColor; 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 v = 0.025 / length(p - t); float r = v * colors[i].x; float g = v * colors[i].y; float b = v * 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; } outputColor = vec4(color, 1.0); } |