[work 49] Fractals – rotation –
![[work 49] Fractals – rotation –](https://i0.wp.com/tsukuru.hayato-works.com/wp-content/uploads/2019/06/outFrameImg0450.png?fit=1024%2C576&ssl=1)
Movie
Source code
about
- 回転するフラクタル
- 線分の両端に線分を追加する
- 線分を追加する時、元の線分に対して0〜179度回転させる
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"
#include "Fractals.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:
std::shared_ptr<Fractals> frac;
};
#include "ofApp.h"
ofApp::ofApp(){
}
ofApp::~ofApp(){
}
//--------------------------------------------------------------
void ofApp::setup(){
double fps = 30;
ofSetFrameRate(fps);
ofBackground(255);
ofSetBackgroundAuto(true);
ofSetVerticalSync(true);
frac = make_shared<Fractals>(ofVec2f(ofGetWidth() / 2, ofGetHeight() / 2));
}
//--------------------------------------------------------------
void ofApp::update(){
frac->update();
}
//--------------------------------------------------------------
void ofApp::draw(){
frac->display();
}
#ifndef Fractals_hpp
#define Fractals_hpp
#include <stdio.h>
#include "ofMain.h"
class Fractals {
public:
Fractals(ofVec2f c);
~Fractals();
void update();
void display();
private:
void drawRecurLine(ofVec2f c, float length, ofVec2f dir);
ofVec2f center;
int angle;
};
#endif /* Fractals_hpp */
#include "Fractals.hpp"
Fractals::Fractals(ofVec2f c)
{
center = c;
angle = -1;
}
Fractals::~Fractals()
{
}
void Fractals::update()
{
angle = (angle + 1) % 180;
}
void Fractals::display()
{
drawRecurLine(center, ofGetWidth() / 2, ofVec2f(1, 0));
}
void Fractals::drawRecurLine(ofVec2f c, float length, ofVec2f dir)
{
if (length >= 1) {
ofVec2f d = dir * (length / 2);
ofVec2f t1 = c + d;
ofVec2f t2 = c - d;
ofSetColor(0);
ofNoFill();
ofSetLineWidth(2);
ofDrawLine(t1, t2);
d = dir.rotate(angle);
drawRecurLine(t1, length * 0.6, d);
drawRecurLine(t2, length * 0.6, d);
}
}
Link to the reference page
ソースコードで使用したAPIの中から要点になりそうなものをいくつか選んでリストアップしました。
| category | API/Lib |
| openframeworks | ofVec2f |
Development environment
- openframeworks 0.10.1
- c++
- macOS
- Xcode