[work 43] Fractals – circles –
![[work 43] Fractals – circles –](https://i0.wp.com/tsukuru.hayato-works.com/wp-content/uploads/2019/05/outFrameImg0900-2.png?fit=1024%2C576&ssl=1)
Movie
Source code
about
- 円を描く
- 0, 90, 180, 270度の位置に半分の直径の円を描く。これを再帰的に繰り返す。
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(0);
ofSetBackgroundAuto(true);
ofSetVerticalSync(true);
frac = make_shared<Fractals>(ofVec2f(ofGetWidth() / 2, ofGetHeight() / 2), 150);
frac->setup();
}
//--------------------------------------------------------------
void ofApp::update(){
frac->update();
}
//--------------------------------------------------------------
void ofApp::draw(){
frac->draw();
}
#ifndef Fractals_hpp
#define Fractals_hpp
#include <stdio.h>
#include "ofMain.h"
struct Circle {
ofVec2f center;
float radius;
ofColor color;
};
class Fractals {
public:
Fractals(ofVec2f c, float r);
~Fractals();
void setup();
void update();
void draw();
private:
void setCircle(ofVec2f c, float r);
ofVec2f center;
float radius;
std::vector<Circle> circles;
int index;
ofFbo fbo;
};
#endif /* Fractals_hpp */
#include "Fractals.hpp"
Fractals::Fractals(ofVec2f c, float r)
{
center = c;
radius = r;
}
Fractals::~Fractals()
{
}
void Fractals::setup()
{
setCircle(center, radius);
index = 0;
fbo.allocate(ofGetWidth(), ofGetHeight());
}
void Fractals::update()
{
for (int i = 0; i < 8; i++) {
if (index < circles.size()) {
fbo.begin();
ofEnableAntiAliasing();
ofSetCircleResolution(100);
ofSetColor(circles.at(index).color);
ofNoFill();
ofDrawCircle(circles.at(index).center, circles.at(index).radius);
fbo.end();
index++;
}
}
}
void Fractals::draw()
{
fbo.draw(0, 0);
}
void Fractals::setCircle(ofVec2f c, float r)
{
Circle circle;
circle.center = c;
circle.radius = r;
circle.color = ofColor(ofRandom(255), ofRandom(255), ofRandom(255));
circles.push_back(circle);
if (r > 4) {
ofVec2f c1 = ofVec2f(c.x + r, c.y);
ofVec2f c2 = ofVec2f(c.x - r, c.y);
ofVec2f c3 = ofVec2f(c.x, c.y + r);
ofVec2f c4 = ofVec2f(c.x, c.y - r);
setCircle(c1, r / 2);
setCircle(c2, r / 2);
setCircle(c3, r / 2);
setCircle(c4, r / 2);
}
}
Link to the reference page
ソースコードで使用したAPIの中から要点になりそうなものをいくつか選んでリストアップしました。
| category | API/Lib |
| openframeworks | ofFbo |
Development environment
- openframeworks 0.10.1
- c++
- macOS
- Xcode