My random drawing tends to draw a black cross at the 0 axis. How to avoid it?


#1

Hello,

I am creating a drawing based on an algorithm in which many cursors will move according to a pseudo-random path and paint the pixels in their paths with a somewhat transparent color. Multiple passes on the same pixel will render it slightly darker.

Unfortunately, for some reason I still fail to understand, as the drawing evolves, a black orthogonal cross starts to appear at the (0,0) axis.

This suggests that the cursors tend to walk on average more on that cross than everywhere else. But this doesn’t seem to make sense because my cursors move in all directions and they don’t even start at the (0,0) position.

Here it an example of the problem:

And here’s a version of the code which has this problem:
https://github.com/nununo/ofMoldApp/releases/tag/v008-uniform-hyphae

The two classes responsible for this drawing are Hypha and Hyphae.

Thank you.

Regards,
Nuno


#2

Ah! I found the problem. I was rounding the position to int (to not draw the same pixel over and over). Once I started drawing the actual float position the problem disappeared.


#3

So I didn’t find the solution after all. The change I made did remove the black cross. But I am now getting a white cross instead.

My first attempt at correcting this was based on the assumption that this had to be a rounding issue. And my correction did make a difference. But unfortunately the problem is still there, just different.

I’d appreciate any hint in the right direction to help me get rid of this artefact.

Thanks in advance,
Nuno


#4

Welcome to the world of randomness not being random! Pseudo-random generators are not perfect and I’ve noticed them cluster around areas before. And it’s hard to troubleshoot as most random number generators are leveraging something off the hardware and it could be unique on different systems.

I’ve had luck with switching random number distribution systems though and avoiding ofRandom altogether. Check the different generators and distributions available within C++

http://www.cplusplus.com/reference/random/uniform_int_distribution/


#5

I would also debug your code thoroughly, is there anything else that leads to this clumping together? I just did a test with some very simple code - generating 15000 points:

std::vector<glm::vec2> points;

void ofApp::draw(){
    if (points.size() < 15000) {
        glm::vec2 point(ofRandom(0, ofGetScreenWidth()), ofRandom(0, ofGetScreenHeight()));
        points.push_back(point);
    }
    
    ofSetColor(200, 185, 98);
    for (int i = 0; i <points.size(); i++) {
        ofDrawCircle(points[i].x, points[i].y, 2);
    }
}

This leads to a pretty evenly distributed set of points, maybe you can give the random generator an increased range to work with and then scale your results to the range you need to draw?

Attached is a screenshot from the code above.