Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

How to replicate this Processing example with OF?

$
0
0

@cuinjune wrote:

Hi, I'm trying to replicate this Processing example.
https://processing.org/examples/pattern.html

And here's the code I wrote in OF.

//--------------------------------------------------------------
void ofApp::setup(){

    ofSetBackgroundColor(102);
    ofSetCircleResolution(50);
    ofSetLineWidth(2);

    fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGB);
    fbo.begin();
    ofClear(102,102,102);
    fbo.end();
}

//--------------------------------------------------------------
void ofApp::update(){

    fbo.begin();
    variableEllipse(mouseX, mouseY, pmouseX, pmouseY);
    fbo.end();
}

//--------------------------------------------------------------
void ofApp::draw(){

    fbo.draw(0, 0);
}

void ofApp::variableEllipse(int x, int y, int px, int py) {

    float speed = abs(x-px) + abs(y-py);

    ofSetColor(0);
    ofNoFill();
    ofDrawEllipse(x, y, speed, speed);
    ofSetColor(255);
    ofFill();
    ofDrawEllipse(x, y, speed, speed);
    pmouseX = mouseX;
    pmouseY = mouseY;
}


But currently, there are 2 problems with my code.
  1. A huge circle is drawn in the beginning when I start to move the mouse on OF window.
  2. The stroke is not as soft/clean as Processing's.

I would appreciate if any advice to fix the issues and also would like to hear if there's any better/simpler way to replicate the Processing example.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles