[ Video ]
[ About ]
毎日投稿777日を到達した気がします!
Every day post on 777th day.
[ 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 27 28 |
#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) {}; ofTrueTypeFont font; ofFbo fbo; vector<glm::vec3> y_noise; ofShader shader; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(39); ofSetColor(255); this->font.loadFont("fonts/Kazesawa-Bold.ttf", 280, true, true, true); this->fbo.allocate(ofGetWidth(), ofGetHeight()); for (int i = 0; i < ofGetHeight(); i++) { this->y_noise.push_back(glm::vec3()); } this->shader.load("shader/shader.vert", "shader/shader.frag"); } //-------------------------------------------------------------- void ofApp::update() { this->fbo.begin(); ofClear(0); ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5); ofRotate(ofGetFrameNum()); string word = "777"; font.drawString(word, font.stringWidth(word) * -0.5, font.stringHeight(word) * 0.5); this->fbo.end(); ofSeedRandom(39); glm::vec3 noise_value; glm::vec3 noise_seed = glm::vec3(ofRandom(1000), ofRandom(1000), ofRandom(1000)); for (int y = 0; y < this->y_noise.size(); y++) { if (y % 8 == 0) { for (int i = 0; i < 3; i++) { noise_value[i] = ofMap(ofNoise(noise_seed[i], y * 0.03, ofGetFrameNum() * 0.02), 0, 1, -1, 1); if (noise_value[i] > 0.5) { noise_value[i] -= 0.5; } else if (noise_value[i] < -0.5) { noise_value[i] += 0.5; } else { noise_value[i] = 0.0; } } } this->y_noise[y] = noise_value; } } //-------------------------------------------------------------- void ofApp::draw() { this->shader.begin(); this->shader.setUniform1f("time", ofGetElapsedTimef()); this->shader.setUniform2f("resolution", ofGetWidth(), ofGetHeight()); this->shader.setUniformTexture("tex", this->fbo.getTexture(), 1); this->shader.setUniform3fv("y_noise", &this->y_noise[0].x, ofGetHeight()); ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight()); this->shader.end(); ofImage image; image.grabScreen(0, 0, ofGetWidth(), ofGetHeight()); image.saveImage(to_string(ofGetFrameNum()) + ".png"); } //-------------------------------------------------------------- int main() { ofGLWindowSettings settings; settings.setGLVersion(3, 2); settings.setSize(720, 720); ofCreateWindow(settings); ofRunApp(new ofApp()); } |
1 2 3 4 5 6 7 8 |
#version 150 uniform mat4 modelViewProjectionMatrix; in vec4 position; void main(){ gl_Position = modelViewProjectionMatrix * position; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#version 150 uniform float time; uniform vec2 resolution; uniform sampler2DRect tex; uniform vec3 y_noise[720]; out vec4 outputColor; void main() { float drift = 240.0; vec3 color = vec3(1.0); float r = texture(tex, vec2(gl_FragCoord.x + drift * y_noise[int(gl_FragCoord.y)].r, (resolution.y - gl_FragCoord.y))).r; float g = texture(tex, vec2(gl_FragCoord.x + drift * y_noise[int(gl_FragCoord.y)].g, (resolution.y - gl_FragCoord.y))).g; float b = texture(tex, vec2(gl_FragCoord.x + drift * y_noise[int(gl_FragCoord.y)].b, (resolution.y - gl_FragCoord.y))).b; outputColor = vec4(color - vec3(r, g, b), 1.0); } |