Problem with updating with an if statement

Hi, everyone,

I’m having some problems when trying to create a circle that has an expanding radius.
I have a global variable ‘r’ set to 30. In my update section I create an if statement for if(r == 30); to increment r by 5. When using this form my radius doesn’t change. Doing this limits me from making a properly working radius changing circle. Any help would be appreciated.


paste your code here it will be faster to see what you are missing.
but I guess if your code is correct then your radius will only be incremented once. Is that what you want?

I want my radius to increment to 500 and then once it hits 500 decrement back to 30. I see what the problem is now but I have no idea how to resolve it. Here is the code.

    #include "testApp.h"

void testApp::setup(){


	v2.set(ofGetWindowWidth()*.25, ofGetWindowHeight()*.25);

	r = 30;

void testApp::update(){

	if(r >= 30){
		for(int i = r; i < 500; i = i + 5){
			r = r + 10;

void testApp::draw(){


Ok you need to know that everything you do inside a for loop will happen in one single frame. Therefore you won’t see the circle growing if you process it there. you need to do that directly in the update function.

My approach is a bit different. I create a boolean variable to know if i want to make the circle increase or decrease, and i call that “bGrowing”. then in the update function replace your code by:

bGrowing ? r++ : r--;	
if (r > 500|| r < 0) bGrowing=!bGrowing;

the first line means: if it is growing increase radius, otherwise decrease.
the second line means if radius is more than 500 or less than 0 invert the state of the boolean variable.

hope that helps!

This worked awesomely!

Thank you.