[work 4] radial line
![[work 4] radial line](https://i0.wp.com/tsukuru.hayato-works.com/wp-content/uploads/2019/02/outFrameImg0900-1.png?fit=1024%2C576&ssl=1)
Movie
Source code
about
- 時計回りに放射状の線を描画する
- 移動角度はパーリンノイズを使って決める(マイナスもあり)
- 描画する線の長さはパーリンノイズを使って決める
- 色は色相環と角度をマッピングして決める
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 "Walker.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;
Walker *walker;
};
#include "ofApp.h"
ofApp::ofApp(){
walker = new Walker();
}
ofApp::~ofApp(){
delete walker;
}
//--------------------------------------------------------------
void ofApp::setup(){
double fps = 30;
ofBackground(255, 255, 255);
ofSetBackgroundAuto(false); // clear frame:true
ofSetFrameRate(fps);
walker->setup();
}
//--------------------------------------------------------------
void ofApp::update(){
walker->update();
}
//--------------------------------------------------------------
void ofApp::draw(){
walker->draw();
}
#ifndef Walker_hpp
#define Walker_hpp
#include <stdio.h>
#include "ofMain.h"
class Walker {
public:
Walker();
~Walker();
void setup();
void update();
void draw();
private:
ofVec2f location;
int radius;
int minRadius;
int maxRadius;
int deg;
int minStepDeg;
int maxStepDeg;
float radian;
float tx1;
float tx2;
};
#endif /* Walker_hpp */
#include "Walker.hpp"
Walker::Walker()
{
location = ofVec2f(ofGetWidth() / 2, ofGetHeight() / 2);
radius = 0;
minRadius = 200;
maxRadius = 400;
deg = 0;
minStepDeg = -5;
maxStepDeg = 5;
tx1 = 0;
tx2 = 10000;
}
Walker::~Walker()
{
}
void Walker::setup()
{
}
void Walker::update()
{
radius = ofMap(ofNoise(tx1), 0, 1, minRadius, maxRadius);
tx1 += 0.1;
deg += (int)ceil(ofMap(ofSignedNoise(tx2), -1, 1, minStepDeg, maxStepDeg));
tx2 += 0.1;
radian = (TWO_PI / 360) * (deg % 360);
location.x = radius * cos(radian);
location.y = radius * sin(radian);
}
void Walker::draw()
{
ofColor c;
ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);
c.setHsb(ofMap(radian, 0, TWO_PI, 0, 255), 255, ofMap(radius, minRadius, maxRadius, 0, 255), 60);
ofSetColor(c);
ofDrawLine(0, 0, location.x, location.y);
}
Link to the API reference page
ソースコードで使用したAPIの中から要点になりそうなものをいくつか選んでリストアップしました。
| category | API |
| openframeworks | ofColor setHsb |
| openframeworks | ofGraphics ofDrawLine |