[work 113] Emerge
![[work 113] Emerge](https://i0.wp.com/tsukuru.hayato-works.com/wp-content/uploads/2019/10/outFrameImg0640.png?fit=1024%2C576&ssl=1)
Movie
Source code
about
“HELLO”が浮かび上がる
file
- 上部にあるファイル名が表示されているボタンを押すと、表示されるファイルが切り替わります
- 別ウィンドウ表示したい時や行番号などが無いRawMode表示したい時は、コード内右上のボタンを押してください(ボタンはマウスオーバーすると表示されます)
#include "ofMain.h"
#include "ofApp.h"
//================================
int main( ){
// 4K:4096x2160
// 2K:2048x1080
// FullHD:1920x1080
// HD:1440x1080
// HD720p:1280x720
// DVD:720x480
// setup the GL context
ofSetupOpenGL(1280, 720, OF_WINDOW);
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp( new ofApp());
}
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp{
public:
ofApp();
~ofApp();
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);
private:
int step;
int nofp;
std::vector<ofMesh> mesh;
std::vector<std::vector<ofVec3f>> points;
std::vector<glm::vec3> center;
std::vector<float> radius;
float time;
ofFbo fbo;
ofPixels pix;
ofEasyCam cam;
};
#include "ofApp.h"
ofApp::ofApp(){
}
ofApp::~ofApp(){
}
//--------------------------------------------------------------
void ofApp::setup(){
double fps = 30;
ofSetFrameRate(fps);
ofBackground(255);
ofSetBackgroundAuto(true);
ofSetVerticalSync(true);
ofEnableDepthTest();
ofEnableSmoothing();
ofTrueTypeFont font;
font.load("font/Helvetica.ttc", 10);
ofTexture tex = font.getStringTexture("HELLO");
fbo.allocate(1000, 1000);
fbo.begin();
ofClear(0);
tex.setAnchorPercent(0.5, 0.5);
tex.draw(fbo.getWidth() / 2, fbo.getHeight() / 2, 800, 400);
fbo.end();
fbo.readToPixels(pix);
step = 6;
nofp = 360 / step;
std::vector<ofVec3f> p;
ofVec3f v = ofVec3f(1, 0, 0);
for (int i = 0; i < nofp; i++) {
v.rotate(step, ofVec3f(0, 1, 0));
p.push_back(v);
}
points.assign(2, p);
radius.assign(2, 0);
cam.setPosition(glm::vec3(200, 200, 200));
cam.lookAt(glm::vec3(0, 0, 0));
}
//--------------------------------------------------------------
void ofApp::update(){
for (int i = 0; i < radius.size() - 1; i++) {
radius.at(i) += 1;
}
mesh.clear();
for (int i = 0; i < points.size() - 1; i++) {
for (int j = 0; j < points.at(i).size(); j++) {
points.at(i).at(j).y = 0;
points.at(i).at(j).normalize();
float x = points.at(i).at(j).x * radius.at(i);
float z = points.at(i).at(j).z * radius.at(i);
int index0 = std::round(x + (fbo.getWidth() / 2));
int index1 = std::round(z + (fbo.getHeight() / 2));
float y = 0;
if (pix.getColor(index0, index1) != ofColor(0, 0, 0, 0)) {
y = ofMap(pix.getColor(index0, index1).a, 0, 255, 0, 100);
}
points.at(i).at(j).x = x;
points.at(i).at(j).y = y;
points.at(i).at(j).z = z;
}
}
auto itr = radius.rbegin();
if (*(itr + 1) > 10) {
float y = ofMap(ofSignedNoise(time, time), -1, 1, -100, 100);
radius.push_back(1);
step = 6;
nofp = 360 / step;
std::vector<ofVec3f> p;
ofVec3f v = ofVec3f(1, 0, 0);
for (int i = 0; i < nofp; i++) {
v.rotate(step, ofVec3f(0, 1, 0));
p.push_back(v);
}
points.push_back(p);
}
if (radius.front() >= 500) {
auto rItr = radius.begin();
radius.erase(rItr);
auto pItr = points.begin();
points.erase(pItr);
}
for (int i = 0; i < points.size() - 1; i++) {
ofMesh m;
m.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
for (int j = 0; j <= points.at(i).size(); j++) {
int index = j % points.at(i).size();
m.addVertex(points.at(i).at(index));
m.addVertex(points.at(i + 1).at(index));
ofColor c0, c1;
c0 = ofColor(0);
c1 = ofColor(0);
float a0 = ofMap(radius.at(i), 0, 500, 255, 0);
float a1 = ofMap(radius.at(i + 1), 0, 500, 255, 0);
m.addColor(ofColor(c0, a0));
m.addColor(ofColor(c1, a1));
}
mesh.push_back(m);
}
}
//--------------------------------------------------------------
void ofApp::draw(){
cam.begin();
for (ofMesh m : mesh) {
m.drawWireframe();
}
cam.end();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if (key == 's') {
ofImage img;
img.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
img.save("screenshot.png");
}
}
Link to the reference page
ソースコードで使用したAPIの中から要点になりそうなものをいくつか選んでリストアップしました。
| category | API/Lib |
| openframeworks | ofTrueTypeFont |
| openframeworks | ofFbo |
| openframeworks | ofTexture |
| openframeworks | ofPixels |
| openframeworks | ofMesh |
| c++ | std::vector |
Development environment
- openframeworks 0.10.1
- c++
- macOS
- Xcode