title: Is there a way to only run p5.js once an event happens?
body: <p>I would like to only run the p5.js <code>draw()</code> and <code>setup()</code> functions once three input fields are all not blank and a button is clicked.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function roundNumber(num, decimal_places) {
    if (!("" + num).includes("e")) {
      return +(Math.round(num + "e+" + decimal_places) + "e-" + decimal_places);
    } else {
      var arr = ("" + num).split("e");
      var sig = ""
      if (+arr[1] + scale &gt; 0) {
        sig = "+";
      }
      return +(Math.round(+arr[0] + "e" + sig + (+arr[1] + decimal_places)) + "e-" + decimal_places);
    }
  } /* From https://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-only-if-necessary */
  
  function computeSelection() {
    const expr = document.forms[0].mathExpr.value;
    var tempAns = parseFloat(eval(expr));
    var roundedAnswer = roundNumber(tempAns, 10);
    var answer = roundedAnswer;
    document.getElementById("output").textContent = answer;
  }
  
  function get_x_min_x_max() {
    const x_min = $("#x_min").value;
    const x_max = $("#x_max").value;
    var x_min_x_max = [x_min, x_max];
    return x_min_x_max;
  }
  
  function setup() {
    createCanvas(300, 300);
  }
  
  function draw() {
  
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;body&gt;
    &lt;form&gt;
      &lt;label&gt;Graph y=&lt;/label&gt;
      &lt;input id="mathExpr" type="text" name="mathExpr" value=""&gt;
      &lt;label&gt; from x=&lt;/label&gt;
      &lt;input id="x_min" type="text" name="x_min" value=""&gt;
      &lt;label&gt; to &lt;/label&gt;
      &lt;input id="x_max" type="text" name="x_max" value=""&gt;
      &lt;input type="button" name="result" value="Result" onclick="computeSelection();"&gt;
    &lt;/form&gt;
    &lt;h2&gt;Answer: &lt;span id="output"&gt;&lt;/span&gt;&lt;/h2&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>If this is my code, I only want the draw and setup at the bottom of the js code to run once <code>mathExpr</code>, <code>x_min</code>, and <code>x_max</code> all contain <em>some</em> text and the result button is clicked. How can I do that?</p>