[ Video ]
[ About ]
Rotating orbs.
[ 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; bool calculate_angle(glm::vec2 location_1, float radius_1, glm::vec2 location_2, float radius_2, double& theta, double& a); }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); ofSetCircleResolution(72); this->number_of_targets = 360; for (int i = 0; i < this->number_of_targets; i++) { this->target_list.push_back(glm::vec2()); this->color_list.push_back(glm::vec3(1, 1, 1)); } this->shader.load("shader/shader.vert", "shader/shader.frag"); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); int count = 0; int index = 0; int deg_start = ofGetFrameNum(); for (int radius = 150; radius <= 300; radius += 15) { int deg_start = ofMap(ofNoise(radius * 0.005 + ofGetFrameNum() * 0.01), 0, 1, -180, 180); for (int deg = deg_start; deg < deg_start + 360; deg += 10) { this->target_list[index] = glm::vec2(360 + radius * cos(deg * DEG_TO_RAD), 360 + radius * sin(deg * DEG_TO_RAD)); this->color_list[index] = glm::vec3( ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.05), 0, 1, 0.5, 1), ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.05), 0, 1, 0.5, 1), ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.05), 0, 1, 0.5, 1)); index++; } } } //-------------------------------------------------------------- void ofApp::draw() { 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(); } //-------------------------------------------------------------- bool ofApp::calculate_angle(glm::vec2 location_1, float radius_1, glm::vec2 location_2, float radius_2, double& theta, double& a) { auto distance = glm::distance(location_1, location_2); if (distance > radius_1 + radius_2 || distance < radius_1 - radius_2) { return false; } theta = atan2(location_2.y - location_1.y, location_2.x - location_1.x); auto cos_a = (pow(distance, 2) + pow(radius_1, 2) - pow(radius_2, 2)) / (2 * distance * radius_1); a = acos(cos_a); return 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 = 360; 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.015 / 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); } |