[ Video ]
[ About ]
ペンの軌跡を重ならないCircleで埋めています。仕組み的には、ofFbo(メモリ内部)にいったんペンの軌跡を描写、その結果へピクセル単位でアクセス(色情報)して、円を描写するべき範囲かの判定しています。マウスよりもSurfacePenなので直感的に書き書き出来るのがよいですね。
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#pragma once #include "ofMain.h" class ofApp : public ofBaseApp { public: 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 windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; ofFbo fbo; ofPixels pix; vector<tuple<ofColor, ofPoint, float>> circles; int mouse_down_count; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(239); ofSetWindowTitle("Insta"); this->fbo.allocate(ofGetWidth(), ofGetHeight()); this->mouse_down_count = 0; } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); this->fbo.begin(); if (ofGetMousePressed()) { ofSetColor(0); ofDrawCircle(ofGetMouseX(), ofGetMouseY(), 30); this->mouse_down_count++; } this->fbo.end(); this->fbo.readToPixels(this->pix); } //-------------------------------------------------------------- void ofApp::draw() { //this->fbo.draw(0, 0); while (circles.size() < mouse_down_count * 5){ int x = ofRandom(ofGetWidth()); int y = ofRandom(ofGetHeight()); ofColor pix_color = this->pix.getColor(x, y); if (pix_color != ofColor(0)) { continue; } ofColor color; color.setHsb(ofRandom(255), 255, 255); ofPoint point = ofPoint(x, y); float radius = ofRandom(2, 35); bool flag = true; for (int i = 0; i < circles.size(); i++) { if (point.distance(get<1>(circles[i])) < get<2>(circles[i]) + radius) { flag = false; break; } } if (flag) { circles.push_back(make_tuple(color, point, radius)); } } for (int circles_index = 0; circles_index < circles.size(); circles_index++) { ofColor color = get<0>(circles[circles_index]); ofPoint point = get<1>(circles[circles_index]); float radius = get<2>(circles[circles_index]); ofSetColor(color); ofDrawCircle(point, radius); } ofPopMatrix(); } //-------------------------------------------------------------- void ofApp::keyPressed(int key) { this->fbo.begin(); ofClear(0); this->fbo.end(); this->mouse_down_count = 0; this->circles.clear(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(1280, 720, OF_WINDOW); ofRunApp(new ofApp()); } |