Created
June 11, 2017 17:13
-
-
Save arturoc/77949c30364cf1b9683f559989177268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofMain.h" | |
#include "ofApp.h" | |
//======================================================================== | |
int main(){ | |
ofGLFWWindowSettings settings; | |
settings.setGLVersion(3,3); | |
ofCreateWindow(settings); | |
ofRunApp(new ofApp); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
//-------------------------------------------------------------- | |
void ofApp::setup(){ | |
ofSetBackgroundColor(0); | |
auto setFreq = [this](float & freq){ | |
textures.clear(); | |
for(size_t i = 0; i < 10; i++){ | |
ofFloatPixels pixels; | |
auto s = 1024.; | |
pixels.allocate(s, s, OF_PIXELS_GRAY_ALPHA); | |
pixels.set(0); | |
for(auto l: pixels.getLines()){ | |
auto j = 0; | |
for(auto p: l.getPixels()){ | |
auto f = | |
ofNoise(j / s * frequency0 + i * s, l.getLineNum() / s * frequency0 + i * s)/4. + | |
ofNoise(j / s * frequency1 + i * s, l.getLineNum() / s * frequency1 + i * s)/4. + | |
ofNoise(j / s * frequency2 + i * s, l.getLineNum() / s * frequency2 + i * s)/4. + | |
ofNoise(j / s * frequency3 + i * s, l.getLineNum() / s * frequency3 + i * s)/4. | |
; | |
f = ofMap(f, 0.35, 1, 0, 1, true); | |
p[0] = f; | |
p[1] = f; | |
j+=1; | |
} | |
} | |
textures.emplace_back(); | |
textures.back().allocate(pixels); | |
} | |
}; | |
frequency0.ownListener(setFreq); | |
frequency1.ownListener(setFreq); | |
frequency2.ownListener(setFreq); | |
frequency3.ownListener(setFreq); | |
gui.getFloatSlider("frequency0").setUpdateOnReleaseOnly(true); | |
gui.getFloatSlider("frequency1").setUpdateOnReleaseOnly(true); | |
gui.getFloatSlider("frequency2").setUpdateOnReleaseOnly(true); | |
gui.getFloatSlider("frequency3").setUpdateOnReleaseOnly(true); | |
float f; | |
setFreq(f); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update(){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
//textures[0].draw(0,0); | |
//ofEnableBlendMode(OF_BLENDMODE_ADD); | |
camera.begin(); | |
auto i = 0; | |
for(auto & t: textures){ | |
if(i>0){ | |
ofSetColor(255,ofMap(i,0,10,0.6,0)*255.); | |
}else{ | |
auto nextT = glm::vec3(0,0,-textureSeparation*t.getWidth()); | |
auto alpha = glm::distance2(camera.getPosition(), nextT) / (textureSeparation*t.getWidth()*textureSeparation*t.getWidth()); | |
ofSetColor(255,alpha*0.8*255.); | |
} | |
t.draw(-t.getWidth()/2, -t.getWidth()/2, -(i+1)*textureSeparation*t.getWidth()); | |
i++; | |
} | |
camera.end(); | |
gui.draw(); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyPressed(int key){ | |
if(key==OF_KEY_UP){ | |
camera.move(0,0,-10); | |
} | |
auto t = textures.front(); | |
if(camera.getPosition().z < -textureSeparation*t.getWidth()){ | |
textures.erase(textures.begin()); | |
textures.push_back(t); | |
auto p = camera.getPosition(); | |
camera.setPosition(p.x, p.y, p.z + textureSeparation*t.getWidth()); | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyReleased(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseMoved(int x, int y ){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseDragged(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mousePressed(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseReleased(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseEntered(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseExited(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::windowResized(int w, int h){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::gotMessage(ofMessage msg){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::dragEvent(ofDragInfo dragInfo){ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
#include "ofxGui.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); | |
std::vector<ofTexture> textures; | |
ofParameter<float> textureSeparation{"texture separation", 0.05, 0, 1}; | |
ofParameter<float> frequency0{"frequency0", 2, 0, 1000}; | |
ofParameter<float> frequency1{"frequency1", 4, 0, 1000}; | |
ofParameter<float> frequency2{"frequency2", 8, 0, 1000}; | |
ofParameter<float> frequency3{"frequency3", 16, 0, 1000}; | |
ofParameterGroup parameters{ | |
"params", | |
textureSeparation, | |
frequency0, | |
frequency1, | |
frequency2, | |
frequency3, | |
}; | |
ofxPanel gui{parameters}; | |
ofCamera camera; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment