[work 6] equalizer
![[work 6] equalizer](https://i0.wp.com/tsukuru.hayato-works.com/wp-content/uploads/2019/02/outFrameImg0900-2.png?fit=1280%2C720&ssl=1)
Movie
Source code
about
- 400×300の面を生成(一片20の四角形で構成される)
- 四角形のz座標をパーリンノイズを使用して変化させる
- z座標の値をHSBのHにマッピングさせる
- 動画のカメラワークはマウス操作で行っている
file
- 上部にあるファイル名が表示されているボタンを押すと、表示されるファイルが切り替わります
- 別ウィンドウ表示したい時や行番号などが無いRawMode表示したい時は、コード内右上のボタンを押してください(ボタンはマウスオーバーすると表示されます)
#include "ofMain.h"
#include "ofApp.h"
//=================================
int main( ){
// 4K:4096x2160
// 2K:2048x1080
// FullHD:1920x1080
// HD:1440x1080
// HD720p:1280x720
// DVD:720x480
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"
#include "Landscape.hpp"
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:
ofEasyCam cam;
Landscape *land;
};
#include "ofApp.h"
ofApp::ofApp(){
land = new Landscape();
}
ofApp::~ofApp(){
delete land;
}
//--------------------------------------------------------------
void ofApp::setup(){
double fps = 30;
ofBackground(255, 255, 255);
ofSetBackgroundAuto(true); // clear frame:true
ofSetFrameRate(fps);
land->setup();
}
//--------------------------------------------------------------
void ofApp::update(){
land->update();
}
//--------------------------------------------------------------
void ofApp::draw(){
cam.begin();
land->draw();
cam.end();
}
#ifndef Landscape_hpp
#define Landscape_hpp
#include <stdio.h>
#include "ofMain.h"
class Landscape {
public:
Landscape();
~Landscape();
void setup();
void update();
void draw();
private:
ofMesh mesh;
int cell_size;
int w, h;
int space;
int land_xoff, land_yoff;
int rows, cols;
float xoff, yoff, zoff;
std::vector<std::vector<float>> z;
int min_z, max_z;
};
#endif /* Landscape_hpp */
#include "Landscape.hpp"
Landscape::Landscape()
{
cell_size = 20;
w = 400;
h = 300;
space = 0;
min_z = -30;
max_z = 30;
}
Landscape::~Landscape()
{
}
void Landscape::setup()
{
cols = w / cell_size;
rows = h / cell_size;
land_xoff = -(w / 2);
land_yoff = -(h / 2);
z = std::vector<std::vector<float>>(rows, std::vector<float>(cols, 0));
zoff = 0;
}
void Landscape::update()
{
yoff = 0;
for (int i = 0; i < rows; i ++) {
xoff = 0;
for (int j = 0; j < cols; j++) {
z[i][j] = ofMap(ofSignedNoise(xoff, yoff, zoff), -1, 1, min_z, max_z);
xoff += 0.5;
}
yoff += 0.5;
}
zoff += 0.1;
}
void Landscape::draw()
{
ofPushMatrix();
ofTranslate(land_xoff, land_yoff, 0);
for (int x = 0; x < (cols - 1); x++) {
for (int y = 0; y < (rows - 1); y++) {
int x0 = x * cell_size + (x * space);
int y0 = y * cell_size + (y * space);
ofColor c = ofColor(0);
mesh.addVertex(ofVec3f(x0, y0, z[y][x]));
mesh.addVertex(ofVec3f(x0, y0 + cell_size, z[y][x]));
mesh.addVertex(ofVec3f(x0 + cell_size, y0 + cell_size, z[y][x]));
mesh.addVertex(ofVec3f(x0 + cell_size, y0, z[y][x]));
c.setHsb(ofMap(z[y][x], min_z, max_z, 0, 255), 255, 255);
mesh.addColor(c);
c.setHsb(ofMap(z[y][x], min_z, max_z, 0, 255), 255, 255);
mesh.addColor(c);
c.setHsb(ofMap(z[y][x], min_z, max_z, 0, 255), 255, 255);
mesh.addColor(c);
c.setHsb(ofMap(z[y][x], min_z, max_z, 0, 255), 255, 255);
mesh.addColor(c);
mesh.setMode(OF_PRIMITIVE_LINE_LOOP);
mesh.addIndex(0);
mesh.addIndex(1);
mesh.addIndex(2);
mesh.addIndex(3);
mesh.draw();
mesh.clear();
}
}
ofPopMatrix();
}
Link to the API reference page
ソースコードで使用したAPIの中から要点になりそうなものをいくつか選んでリストアップしました。
| openframeworks | ofEasyCam |
| openframeworks | ofGraphics ofPushMatrix |
| openframeworks | ofGraphics ofPopMatrix |
| openframeworks | ofGraphics ofTranslate |
| openframeworks | ofMesh drawWireframe |