[work 41] Spiral
![[work 41] Spiral](https://i0.wp.com/tsukuru.hayato-works.com/wp-content/uploads/2019/05/outFrameImg0900-1.png?fit=1280%2C720&ssl=1)
Movie
Source code
about
- XY平面上に描いた円をY軸中心に回転させる
- 円の半径の長さをcosカーブに従って変化させる
- 円を描く位置をY軸からだんだん離して螺旋を描く
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:
ofCamera cam;
ofFbo fbo;
float radius;
float ext;
float angle;
float angleVelocity;
ofVec3f point;
};
#include "ofApp.h"
ofApp::ofApp(){
}
ofApp::~ofApp(){
}
//--------------------------------------------------------------
void ofApp::setup(){
double fps = 30;
ofSetFrameRate(fps);
ofBackground(0);
ofSetBackgroundAuto(true);
ofSetVerticalSync(true);
angleVelocity = TWO_PI * 4 / 360;
angle = 0;
ext = 100;
ofVec3f camPos = ofVec3f(2000, 2000, 2000);
ofVec3f at = ofVec3f(0, 0, 0);
cam.setGlobalPosition(camPos);
cam.lookAt(at);
fbo.allocate(ofGetWidth(), ofGetHeight());
}
//--------------------------------------------------------------
void ofApp::update(){
point = ofVec3f(1, 0, 0);
point *= ext;
point.rotateRad(angle, ofVec3f(0, 1, 0));
int n = (int)std::floor(angle / TWO_PI);
radius = ofMap(std::cos((n + 1) * angle), -1, 1, 50, 4);
fbo.begin();
cam.begin();
ofPushMatrix();
ofTranslate(point.x, point.y, point.z);
ofRotateRad(angle, 0, 1, 0);
ofNoFill();
ofSetColor(255);
ofDrawCircle(0, 0, 0, radius);
ofPopMatrix();
cam.end();
fbo.end();
angle += angleVelocity;
ext += 3;
}
//--------------------------------------------------------------
void ofApp::draw(){
fbo.draw(0, 0);
}
Link to the reference page
ソースコードで使用したAPIの中から要点になりそうなものをいくつか選んでリストアップしました。
| category | API/Lib |
| openframeworks | ofCamera |
| openframeworks | ofTranslate |
| openframeworks | ofRotateRad |
Development environment
- openframeworks 0.10.1
- c++
- macOS
- Xcode