[work 47] Dotted line
![[work 47] Dotted line](https://i0.wp.com/tsukuru.hayato-works.com/wp-content/uploads/2019/06/outFrameImg0400.png?fit=1024%2C576&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 "Line.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::vector<std::shared_ptr<Line>> lines;
};
#include "ofApp.h"
ofApp::ofApp(){
}
ofApp::~ofApp(){
}
//--------------------------------------------------------------
void ofApp::setup(){
double fps = 30;
ofSetFrameRate(fps);
ofBackground(255);
ofSetBackgroundAuto(true);
ofSetVerticalSync(true);
lines.push_back(make_shared<Line>());
lines.back()->setup();
}
//--------------------------------------------------------------
void ofApp::update(){
if ((int)ofRandom(1, 10) == 1) {
lines.push_back(make_shared<Line>());
lines.back()->setup();
}
for (shared_ptr<Line> l : lines) {
l->update();
}
}
//--------------------------------------------------------------
void ofApp::draw(){
for (shared_ptr<Line> l : lines) {
l->display();
}
}
#ifndef Line_hpp
#define Line_hpp
#include <stdio.h>
#include "ofMain.h"
class Line {
public:
Line();
~Line();
void setup();
void update();
void display();
private:
ofVec2f direction;
float speed;
int length;
std::list<ofVec2f> dots;
ofColor color;
};
#endif /* Line_hpp */
#include "Line.hpp"
Line::Line()
{
}
Line::~Line()
{
}
void Line::setup()
{
int cellSize = 50;
length = 200;
if ((int)ofRandom(0, 2) == 0) {
direction = ofVec2f(1, 0);
int row = (int)ofRandom(1, ofGetHeight() / cellSize);
dots.push_back(ofVec2f(0, row * cellSize));
} else {
direction = ofVec2f(0, 1);
int col = (int)ofRandom(1, ofGetWidth() / cellSize);
dots.push_back(ofVec2f(col * cellSize, 0));
}
speed = ofRandom(1, 4);
direction *= speed;
color = ofColor(ofRandom(255),ofRandom(255),ofRandom(255));
}
void Line::update()
{
ofVec2f d = dots.back();
dots.push_back(d + direction);
if (dots.size() > length) {
dots.pop_front();
}
}
void Line::display()
{
int index = 0;
for (auto itr = dots.rbegin(); itr != dots.rend(); ++itr) {
color.a = (int)ofMap(index, 0, length, 255, 0);
ofSetColor(color);
ofDrawCircle(*itr, 2);
index++;
}
}
Link to the reference page
ソースコードで使用したAPIの中から要点になりそうなものをいくつか選んでリストアップしました。
| category | API/Lib |
| c++ | std::list |
Development environment
- openframeworks 0.10.1
- c++
- macOS
- Xcode