[work 26] Noisy Circles
![[work 26] Noisy Circles](https://i0.wp.com/tsukuru.hayato-works.com/wp-content/uploads/2019/04/outFrameImg0000.png?fit=1280%2C720&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
// 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 "NoisyCircle.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:
NoisyCircle nc;
};
#include "ofApp.h"
ofApp::ofApp(){
}
ofApp::~ofApp(){
}
//--------------------------------------------------------------
void ofApp::setup(){
double fps = 30;
ofSetFrameRate(fps);
ofBackground(0);
ofSetBackgroundAuto(true);
nc.setup();
}
//--------------------------------------------------------------
void ofApp::update(){
nc.update();
}
//--------------------------------------------------------------
void ofApp::draw(){
nc.display();
}
#ifndef LoopNoise_hpp
#define LoopNoise_hpp
#include <stdio.h>
#include "ofMain.h"
class LoopNoise {
public:
LoopNoise();
~LoopNoise();
float getLoopNoise(float angle);
float getSignedLoopNoise(float angle);
private:
ofVec2f center;
float radius;
};
#endif /* LoopNoise_hpp */
#include "LoopNoise.hpp"
LoopNoise::LoopNoise()
{
center.x = ofRandom(1000);
center.y = ofRandom(1000);
radius = 10;
}
LoopNoise::~LoopNoise()
{
}
float LoopNoise::getLoopNoise(float angle)
{
return ofNoise(center.x + std::cos(angle) * radius, center.y + std::sin(angle) * radius);
}
float LoopNoise::getSignedLoopNoise(float angle)
{
return ofSignedNoise(center.x + std::cos(angle) * radius, center.y + std::sin(angle) * radius);
}
#ifndef NoisyCircle_hpp
#define NoisyCircle_hpp
#include <stdio.h>
#include "ofMain.h"
#include "LoopNoise.hpp"
#define NC_MAX (7)
class NoisyCircle {
public:
NoisyCircle();
~NoisyCircle();
void setup();
void update();
void display();
private:
std::vector<std::unique_ptr<LoopNoise>> lns;
float radius;
float offset;
float angle;
std::vector<int> rotateDeg;
std::vector<ofColor> colors;
};
#endif /* NoisyCircle_hpp */
#include "NoisyCircle.hpp"
NoisyCircle::NoisyCircle()
{
}
NoisyCircle::~NoisyCircle()
{
}
void NoisyCircle::setup()
{
radius = 200;
offset = 20;
angle = 0;
for (int i = 0; i < NC_MAX; i++) {
lns.push_back(std::make_unique<LoopNoise>());
rotateDeg.push_back(0);
}
}
void NoisyCircle::update()
{
int step = 1;
for (int &a : rotateDeg) {
a += step;
step *= -1;
}
}
void NoisyCircle::display()
{
for (int i = 0; i < NC_MAX; i++) {
ofSetColor(255 - 20 * i);
ofFill();
ofSetPolyMode(OF_POLY_WINDING_NONZERO);
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
ofRotateDeg(rotateDeg[i]);
ofBeginShape();
for (int deg = 0; deg < 360; deg+=3) {
angle = TWO_PI * ((float)deg / 360);
float r = (radius - 30 * i) + lns[i]->getSignedLoopNoise(angle) * offset;
float x = std::cos(angle) * r;
float y = std::sin(angle) * r;
ofVertex(x, y);
}
ofEndShape();
ofPopMatrix();
}
}
Link to the reference page
ソースコードで使用したAPIの中から要点になりそうなものをいくつか選んでリストアップしました。
| category | API/Lib |
| openframeworks | ofGraphics ofSetPolyMode |
| openframeworks | ofGraphics ofVertex |
| openframeworks | ofGraphics ofBeginShape |
| openframeworks | ofGraphics ofEndShape |
Development environment
- openframeworks 0.10.1
- c++
- macOS
- Xcode