Simple Switching with of Objects

Hi all -
I’m new to OF and new to C++, so I’m working slowly through the book.

Generally, I like to learn by figuring out little modifications to the examples provided.

For example 1_ii_b Bursting_Rect_Brush, I’d like to be able to do two things:

  1. Stop the color from refreshing when the mouse is not pressed.

  2. Randomly toggle between ofDrawRect and ofDrawCircle. The ofDrawRect is located inside of a For loop. I’m imagining there is a way to create an array of modules and some kind of “choose” method, so that each iteration of the For loop makes a selection. I just have no idea how to do this.

Any suggestions?

why is the color refreshing when the mouse is not pressed? When it is not pressed nothing should happen.
Are you using this code ?
for randomly toggling you can use ofRandom() like

if(ofRandomuf() >= 0.5f ){ // ofRandomuf() will return a floating point between 0 and 1
    /// do something, 
    // do somethhing else
1 Like

Thanks - I should’ve known an If statement would cut it!
I’m not entirely sure what is causing the oscillation - it might not be the color refresh, but something is “vibrating” in that code in its resting mode.

I tested it and when the mouse is not pressed nothing happens, as well as from reading the code I can tell that. Did you modified it in any way?