Originally Posted by
Hank Bates
Sense the #define Random is storing 3 variables it isn't calling the change color function constantly.
Your RANDOM macro does not store anything. When you write this:
Code:
#define RANDOM generate_random_color()
It merely means that this:
Code:
al_draw_filled_circle(xpos, ypos, radius, RANDOM);
is equivalent to:
Code:
al_draw_filled_circle(xpos, ypos, radius, generate_random_color());
Except that your version is confusing because it looks like RANDOM is a constant when it is actually a function call with a return value that is different on each run. If you write this instead:
Code:
#define RANDOM al_map_rgb(r1, r2, r3)
Then it would be equivalent to:
Code:
al_draw_filled_circle(xpos, ypos, radius, al_map_rgb(r1, r2, r3));
But you have to define r1, r2 and r3 somewhere. If you define them just before that line, i.e.,
Code:
int r1 = (rand() % 256);
int r2 = (rand() % 256);
int r3 = (rand() % 256);
al_draw_filled_circle(xpos, ypos, radius, RANDOM);
then the net effect would be the same as if you had just written:
Code:
al_draw_filled_circle(xpos, ypos, radius, generate_random_color());
Except that your version is confusing because it looks like RANDOM is a constant when it is actually a function call that relies on specially named variables being in scope.
From what I see, the circle has a colour. Therefore, it makes sense to store the colour as a member variable. This member variable can be passed as an argument in a constructor, or set by some member function. In this way, your drawCircle member function would be:
Code:
void MovingCircle::drawCircle()
{
al_draw_filled_circle(xpos, ypos, radius, color);
}
In some other function, e.g., the main function, you might create the MovingCircle with the desired colour:
Code:
MovingCircle circle(STEELBLUE);
// ...
circle.drawCircle();
or with a random colour:
Code:
MovingCircle circle(generate_random_color());
// ...
circle.drawCircle();
This way, no matter how many times drawCircle is called, it will draw the circle with the same colour, as long as the member variable has not been modified.