[ Video ]
[ About ]
青い三角と赤い三角。ノイズ関数でサイズをユラユラ
Blue Triangle & Red Triangle. Size is changing by Perlin noise.
[ 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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofSetColor(39); } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { float radius = 45; int edge_half_length = radius * cos(30 * DEG_TO_RAD); float triangle_height = sqrt(3) / 2 * (edge_half_length * 2); int y_gap = 0; int deg_start = 0; for (int y = 0; y < ofGetHeight() + triangle_height; y += triangle_height) { for (int x = 0; x < ofGetWidth() + edge_half_length; x += edge_half_length) { float triangle_radius = radius * ofNoise(x * 0.005, y * 0.005, ofGetFrameNum() * 0.01); if (x % (edge_half_length * 2) == 0) { deg_start = 270; ofSetColor(69, 69, 239); y_gap = 0; } else { deg_start = 90; ofSetColor(239, 69, 69); y_gap = radius - triangle_height; } ofBeginShape(); for (int deg = deg_start; deg < deg_start + 360; deg += 120) { ofVertex(x + triangle_radius * cos(deg * DEG_TO_RAD), (y + y_gap) + triangle_radius * sin(deg * DEG_TO_RAD)); } ofEndShape(); } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |