Using colors with variables

What I think @jb4x means is that you won’t replace randomCol with circleColor, instead what you’re basically checking, is first, if randomCol is true or not. If it is true, then when you start drawing, it will start drawing at the random color. If you press a key, for example “r”, then you will start drawing red, for example.

Here:

  color col;
  if (randomCol) {
    col = color(random(255), random(255), random(255));
  } else {
    col = color(0);
  }

You are doing that check. If randomCol, do your random color, if not, that color will be black. And then here:

fill(col);
ellipse(mouseX, mouseY, size, size);

Is where you are drawing everything, pay most attention to the line with the fill. Then you have this:

if (key == 'r') {
  randomCol = false; //We don't want random colors anymore
  circleColor = color(255, 0, 0);

I don’t know specifically why we are setting a new color variable here, so forgive me if I’m wrong when I say that you could just do

col = color(255,0,0);

In there, instead of setting a new variable. Of course if you set a new variable you can just make the col variable equal to it somewhere later on in the code, so when you draw your ellipses it comes out as the color that you want it to be.

Hopefully that clarified things a bit?

EnhancedLoop7

1 Like