[work 59] Handwriting like – circles –
![[work 59] Handwriting like – circles –](https://i0.wp.com/tsukuru.hayato-works.com/wp-content/uploads/2019/06/outFrameImg0900-1.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"
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:
float dtx, vtx, rtx;
ofVec2f direction;
float velocity;
ofVec2f center;
ofVec2f circle;
float radius;
int theta;
std::vector<ofVec2f> points;
};
#include "ofApp.h"
ofApp::ofApp(){
}
ofApp::~ofApp(){
}
//--------------------------------------------------------------
void ofApp::setup(){
double fps = 30;
ofSetFrameRate(fps);
ofBackground(255);
ofSetBackgroundAuto(true);
ofSetVerticalSync(true);
dtx = ofRandom(1000);
vtx = ofRandom(1000);
rtx = ofRandom(1000);
direction = ofVec2f(1, 0);
center = ofVec2f(ofGetWidth() / 2, ofGetHeight() / 2);
circle = ofVec2f(1, 0);
velocity = 0.01;
radius = 100;
theta = 5;
}
//--------------------------------------------------------------
void ofApp::update(){
float angle = 0;
angle = ofMap(ofSignedNoise(dtx), -1, 1, -90, 90);
dtx += 0.1;
velocity = ofMap(ofNoise(vtx), 0, 1, 0.01, 0.1);
vtx += 0.01;
radius = ofMap(ofNoise(rtx), 0, 1, 180, 200);
rtx += 0.01;
center += direction.rotate(angle) * velocity;
circle.rotate(theta);
points.push_back(center + circle * radius);
}
//--------------------------------------------------------------
void ofApp::draw(){
ofNoFill();
ofSetColor(0, 0, 0, 128);
ofBeginShape();
ofVertices(points);
ofEndShape();
}
Link to the reference page
ソースコードで使用したAPIの中から要点になりそうなものをいくつか選んでリストアップしました。
| category | API/Lib |
| openframeworks | ofNoise |
| openframeworks | ofMap |
| openframeworks | ofVertices |
Development environment
- openframeworks 0.10.1
- c++
- macOS
- Xcode