Mouse interaction

Okay so I understand the basic language needed to input a simple mouse click. My main question as a new student in coding is what else needs to be incorporated into this code for it to change from one data visualization graph to another with a mouse click. My current project requires for three different visualizations so im just seeking some insight as to learning this! This may deal with how to “layer” the code itself. Some explanation as to what specifically to include in brackets at a time would be helpful as well! Hopefully this makes sense. Thank you in advance for any help given

1 Like

You’ll need the concept of STATES.

If you’re showing your first graph, you are in state #1.

If you’re showing your second graph, you are in state #2.

If you’re showing your third graph, you are in state #3.

You will need a variable to track which state your sketch is in:
int state = 1;

Now, when you draw something,
void draw(){
You will check to see what the value of your state variable is before you draw anything.

if( state == 1 ){ 
  // draw first graph.
} else if( state == 2 ){ 
  // draw second graph... etc.

Then you can switch between states when you detect the mouse click:

void mousePressed(){
  state = state + 1;
  if( state == 4 ){ state = 1; }
}
2 Likes

just the explanation I was needing! Thank you so much

next level would be
click one area of window --> select one state
click other area of window --> select other state

the whole world of button interactivity is open for you