[work 71] Untitled
![[work 71] Untitled](https://i0.wp.com/tsukuru.hayato-works.com/wp-content/uploads/2019/07/outFrameImg0900.png?fit=1024%2C576&ssl=1)
Movie
Source code
about
三角形を2つ組み合わせた四角形を追加していく
三角形は点を2つずつ追加していき、ofMeshのTRIANGLE_STRIPで作る
点の位置はウィンドウ内のランダムな位置とする
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:
vector<ofVec3f> points;
ofFbo fbo;
};
#include "ofApp.h"
ofApp::ofApp(){
}
ofApp::~ofApp(){
}
//--------------------------------------------------------------
void ofApp::setup(){
double fps = 30;
ofSetFrameRate(fps);
ofBackground(255);
ofSetBackgroundAuto(true);
ofSetVerticalSync(true);
fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA, 4);
}
//--------------------------------------------------------------
void ofApp::update(){
float x = ofRandomWidth();
float y = ofRandomHeight();
points.push_back(ofVec3f(x, y, 0));
ofMesh mesh;
fbo.begin();
ofClear(0);
mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
for(unsigned int i = 0; i < points.size(); i++){
points[i].z -= 8;
if (i != 0) {
ofVec3f thisPoint = points[i - 1];
ofVec3f nextPoint = points[i];
ofVec3f direction = (nextPoint - thisPoint);
float distance = direction.length();
ofVec3f unit = direction.getNormalized();
ofVec3f left = unit.getRotated(-90, ofVec3f(0, 0, 1));
ofVec3f right = unit.getRotated(90, ofVec3f(0, 0, 1));
float thickness = ofMap(distance, 0, 200, 30, 2, true);
ofVec3f leftPoint = thisPoint + left * thickness;
ofVec3f rightPoint = thisPoint + right * thickness;
ofColor c = ofColor(0);
c.a = ofMap(thickness, 2, 30, 180, 30);
mesh.addVertex(ofVec3f(leftPoint.x, leftPoint.y, leftPoint.z));
mesh.addVertex(ofVec3f(rightPoint.x, rightPoint.y, rightPoint.z));
mesh.addColor(c);
mesh.addColor(c);
}
}
mesh.draw();
fbo.end();
}
//--------------------------------------------------------------
void ofApp::draw(){
fbo.draw(0, 0);
}
//--------------------------------------------------------------
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の中から要点になりそうなものをいくつか選んでリストアップしました。
Development environment
- openframeworks 0.10.1
- c++
- macOS
- Xcode