[ Video ]
[ About ]
球体の移動ログを輪っかで表す。
Sphere moving log.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#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) {}; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofSetLineWidth(3); ofEnableDepthTest(); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { for (int n = 0; n < 2; n++) { auto noise_seed = glm::vec2(ofRandom(1000), ofRandom(1000)); auto radius = 50; auto len = 15; auto noise_step = 0.005; auto frame_scale = 3; auto base = glm::vec3(ofMap(ofNoise(noise_seed.x, (ofGetFrameNum() + len * frame_scale) * noise_step), 0, 1, 0, ofGetWidth()), ofMap(ofNoise(noise_seed.y, (ofGetFrameNum() + len * frame_scale) * noise_step), 0, 1, n * 360, (n + 1) * 360), 0); ofFill(); ofSetColor(139); ofDrawSphere(base, radius); for (int i = 0; i < len; i++) { base = glm::vec3(ofMap(ofNoise(noise_seed.x, (ofGetFrameNum() + i * frame_scale) * noise_step), 0, 1, 0, ofGetWidth()), ofMap(ofNoise(noise_seed.y, (ofGetFrameNum() + i * frame_scale) * noise_step), 0, 1, n * 360, (n + 1) * 360), 0); auto prev_base = glm::vec3(ofMap(ofNoise(noise_seed.x, (ofGetFrameNum() + i * frame_scale - 1) * noise_step), 0, 1, 0, ofGetWidth()), ofMap(ofNoise(noise_seed.y, (ofGetFrameNum() + i * frame_scale - 1) * noise_step), 0, 1, n * 360, (n + 1) * 360), 0); auto direction = base - prev_base; auto theta = atan2(direction.y, direction.x); ofNoFill(); ofSetColor(39, ofMap(i, 0, len, 32, 255)); ofBeginShape(); for (int deg = 0; deg < 360; deg += 3) { auto point = glm::vec3(radius * 1.2 * cos(deg * DEG_TO_RAD), radius * 1.2 * sin(deg * DEG_TO_RAD), 0); auto rotation_x = glm::rotate(glm::mat4(), (float)(PI * 0.5), glm::vec3(1, 0, 0)); auto rotation_y = glm::rotate(glm::mat4(), (float)(theta + PI * 0.5), glm::vec3(0, 1, 0)); point = base + glm::vec4(point, 0) * rotation_y * rotation_x; ofVertex(point); } ofEndShape(true); } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |