Problem with showing and hiding a visual in P5.js

I would like to show and hide this visualization in P5.js with the button that is show, but I do not succeed, even though I tried it the whole evening.

Does someone maybe know how to make this work? (:

This is the code:

Welcome there,

This is the simplest way:

  1. Fix the syntax here (you have created a new block for your code within draw, and there is no reason to):
function draw() {
    translate(width/2+130, height/2);
  for (var i = 0; i < dots.length; i++) {
  1. Add a global variable (I would call it isShowDots), and set it to either true or false (you will decide what the initial value should be, based on what you want)
  2. Wrap the display logic (inside draw) within a statement to do it or not:
if (isShowDots) {
  for (var i = 0...) {...}
  1. Use the showDots function to update the isShowDots variable. This should only be one line, and I will leave you to figure out how to set up the logic so the variable isShowDots can be toggled between true and false.

If you get stuck again, be sure to ask specific questions.

Hope this helps

1 Like

Thank you very much! I tried it out and eventually it worked out (: