[ Video ]
[ About ]
sin x cos x noise.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#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) {}; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { int span = 30; int radius_max = span * 0.48; int radius_min = span * 0.05; for (int x = span * 0.5; x <= ofGetWidth() - span * 0.5; x += span) { for (int y = span * 0.5; y <= ofGetHeight() - span * 0.5; y += span) { auto sin_value = sin(x * 0.005 + ofGetFrameNum() * 0.05); auto sin_y = ofMap(sin_value, -1, 1, 120, ofGetHeight() - 120); auto location = glm::vec2(x, y); auto sin_location = glm::vec2(x, sin_y); auto distance = glm::distance(location, sin_location); ofSetColor(239, 39, 39); if (distance < 100) { ofDrawCircle(location, ofMap(distance, 0, 100, radius_max, radius_min)); } else { ofDrawCircle(location, radius_min); } auto cos_value = cos(x * 0.005 + ofGetFrameNum() * 0.05); auto cos_y = ofMap(cos_value, -1, 1, 120, ofGetHeight() - 120); location = glm::vec2(x, y); auto cos_location = glm::vec2(x, cos_y); distance = glm::distance(location, cos_location); ofSetColor(39, 39, 239); if (distance < 100) { ofDrawCircle(location, ofMap(distance, 0, 100, radius_max, radius_min)); } else { ofDrawCircle(location, radius_min); } auto noise_value = ofNoise(x * 0.005 + ofGetFrameNum() * 0.03); auto noise_y = ofMap(noise_value, 0, 1, 120, ofGetHeight() - 120); location = glm::vec2(x, y); auto noise_location = glm::vec2(x, noise_y); distance = glm::distance(location, noise_location); ofSetColor(39, 239, 39); if (distance < 100) { ofDrawCircle(location, ofMap(distance, 0, 100, radius_max, radius_min)); } else { ofDrawCircle(location, radius_min); } } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |