[work 99] Wave
![[work 99] Wave](https://i0.wp.com/tsukuru.hayato-works.com/wp-content/uploads/2019/10/outFrameImg0100.png?fit=1024%2C576&ssl=1)
Movie
Source code
about
- 15×15にボックスを並べて波のように動かす
- ボックスごとの初期位相を起点からの距離で決める。
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:
static constexpr int widSize = 15;
float size;
std::array<std::array<ofVec3f, widSize>, widSize> centerPos;
std::array<std::array<int, widSize>, widSize> angle;
ofVec3f center;
ofCamera cam;
};
#include "ofApp.h"
ofApp::ofApp(){
}
ofApp::~ofApp(){
}
//--------------------------------------------------------------
void ofApp::setup(){
double fps = 30;
ofSetFrameRate(fps);
ofBackground(0);
ofSetBackgroundAuto(true);
ofSetVerticalSync(true);
ofEnableDepthTest();
ofEnableSmoothing();
size = 50;
float w = centerPos.size() * size;
center = ofVec3f(w / 2, 0, w / 2);
ofVec3f org = ofVec3f(size / 2, 0, size / 2);
int angleStep = 30;
for (int row = 0; row < centerPos.size(); row++) {
for (int col = 0; col < centerPos.at(row).size(); col++) {
float x = (size / 2) + size * col;
float y = 0;
float z = (size / 2) + size * row;
ofVec3f pos = ofVec3f(x, y, z);
centerPos.at(row).at(col) = pos;
float len = (org - pos).length();
angle.at(row).at(col) = angleStep * len / size;
}
}
cam.setPosition(400, 500, 400);
cam.lookAt(glm::vec3(0, 0, 0));
}
//--------------------------------------------------------------
void ofApp::update(){
for (int row = 0; row < centerPos.size(); row++) {
for (int col = 0; col < centerPos.at(row).size(); col++) {
float rad = ofDegToRad(angle.at(row).at(col));
centerPos.at(row).at(col).y = std::sin(rad) * 100;
angle.at(row).at(col)++;
}
}
}
//--------------------------------------------------------------
void ofApp::draw(){
cam.begin();
ofRotateYDeg((float)ofGetFrameNum() * 0.25);
ofEnableBlendMode(OF_BLENDMODE_SCREEN);
ofPushMatrix();
ofTranslate(-center);
for (int row = 0; row < centerPos.size(); row++) {
for (int col = 0; col < centerPos.at(row).size(); col++) {
ofNoFill();
ofSetColor(255);
ofDrawBox(centerPos.at(row).at(col), size);
ofFill();
ofSetColor(63, 115, 143, 128);
ofDrawBox(centerPos.at(row).at(col), size * 0.8);
}
}
ofPopMatrix();
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 | ofEnableBlendMode |
| openframeworks | ofDrawBox |
| openframeworks | ofCamera |
| c++ | std::array |
Development environment
- openframeworks 0.10.1
- c++
- macOS
- Xcode