[ Video ]
[ About ]
渦巻。
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#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) {}; ofMesh mesh; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofSetColor(255); ofSetLineWidth(0.5); ofNoFill(); ofSetCircleResolution(120); this->mesh.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); this->mesh.clear(); int max_radius = 300; for (float deg = 0; deg < 360; deg += 0.2) { int base = ofRandom(max_radius); int speed = ofRandom(2, 10); int tmp_deg = deg + ofGetFrameNum() * speed; auto radius = max_radius - (base + ofGetFrameNum() * speed) % max_radius; auto location_1 = glm::vec3(radius * cos(tmp_deg * DEG_TO_RAD), radius * sin(tmp_deg * DEG_TO_RAD), 0); auto color_1 = ofColor(255, radius > max_radius - 50 ? 255 : radius < 50 ? 0 : ofMap(radius, 50, max_radius - 50, 0, 255)); tmp_deg += speed; radius = max_radius - (base + (ofGetFrameNum() + 2) * speed) % max_radius; auto location_2 = glm::vec3(radius * cos(tmp_deg * DEG_TO_RAD), radius * sin(tmp_deg * DEG_TO_RAD), 0); auto color_2 = ofColor(255, radius > max_radius - 50 ? 255 : radius < 50 ? 0 : ofMap(radius, 50, max_radius - 50, 0, 255)); if (glm::distance(location_1, location_2) < 100) { this->mesh.addVertex(location_1); this->mesh.addVertex(location_2); this->mesh.addColor(color_1); this->mesh.addColor(color_2); this->mesh.addIndex(this->mesh.getNumVertices() - 1); this->mesh.addIndex(this->mesh.getNumVertices() - 2); } } } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWindowSize() * 0.5); this->mesh.drawWireframe(); ofNoFill(); ofSetColor(255); ofDrawCircle(glm::vec2(), 300); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |