[ 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 |
#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(float half_len, int deg); }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(239); ofSetWindowTitle("Insta"); ofSetLineWidth(2); ofSetColor(239, 0, 0); } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2); int radius = 150; int half_len = 300; for (int deg = 0; deg < 360; deg += 2) { ofPoint circle_point = ofPoint(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD)); float noise_value = ofNoise(circle_point.x * 0.015, circle_point.y * 0.015, ofGetFrameNum() * 0.005); ofPoint rect_point = make_rect_point(half_len * noise_value , deg); if (rect_point.length() > radius) { rect_point = make_rect_point(half_len, deg); } else { rect_point = ofPoint(rect_point.length() * cos(deg * DEG_TO_RAD), rect_point.length() * sin(deg * DEG_TO_RAD)); } ofDrawLine(circle_point, rect_point); } } //-------------------------------------------------------------- ofPoint ofApp::make_rect_point(float half_len, int deg) { int param = (deg + 45) / 90; ofPoint point; switch (param % 4) { case 0: return ofPoint(len, ofMap((deg + 45) % 90, 0, 89, -len, len)); case 1: return ofPoint(ofMap((deg + 45) % 90, 0, 89, len, -len), len); case 2: return ofPoint(-len, ofMap((deg + 45) % 90, 0, 89, len, -len)); case 3: return ofPoint(ofMap((deg + 45) % 90, 0, 89, -len, len), -len); default: return ofPoint(0, 0); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |