[ Video ]
[ About ]
中心から決まった距離を避けるように線が描写されます。中心からの距離や線の描写の有無をNoise関数で決めているので、時々で違った形に見えます。
[ 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 |
#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) {}; // Make Method ofPoint make_rect_point(int len, int deg, int z = 0); // Make Member ofEasyCam cam; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(39); ofSetWindowTitle("Insta"); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { float radius = 500 * ofNoise(ofGetFrameNum() * 0.05); ofColor line_color; this->cam.begin(); for (int i = 0; i < 64; i++){ line_color.setHsb(ofRandom(255), 239, 239); int z = ofRandom(-15, 15); ofPoint start = this->make_rect_point(ofGetWidth(), ofRandom(360) + ofNoise((ofRandom(360) + ofGetFrameNum()) * 0.003) * 360, z); ofPoint target = this->make_rect_point(ofGetWidth(), ofRandom(360) + ofNoise((ofRandom(360) + ofGetFrameNum()) * 0.003) * 360, z); ofPoint direction = target - start; float len = direction.length(); direction.normalize(); ofPoint point = start; for (int l = 0; l <= len; l++) { float noise_value = ofNoise(i * 0.5 + l * 0.005 + ofGetFrameNum() * 0.05); if (noise_value > 0.5) { point += direction; continue; } ofSetColor(line_color); if (point.distance(ofPoint()) <= radius) { ofPoint p1 = point.normalized() * radius; ofPoint p2 = (point + direction).normalized() * radius; if (p1.distance(p2) < radius) { ofDrawLine(p1, p2); } } else { ofDrawLine(point, point + direction); } point += direction; } } this->cam.end(); } //-------------------------------------------------------------- ofPoint ofApp::make_rect_point(int len, int deg, int z) { deg += 45; int param = deg / 90; len = len / 2; switch (param % 4) { case 0: return ofPoint(len, ofMap(deg % 90, 0, 89, -len, len), z); case 1: return ofPoint(ofMap(deg % 90, 0, 89, len, -len), len, z); case 2: return ofPoint(-len, ofMap(deg % 90, 0, 89, len, -len), z); case 3: return ofPoint(ofMap(deg % 90, 0, 89, -len, len), -len, z); } return ofPoint(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |