title: Paper.js - convert `paperscript` to `javascript`
body: <p>I am trying to change this <code>paperscript</code>:</p>
  
  <pre><code>&lt;script type="text/paperscript" canvas="canvas-1"&gt;
  tool.minDistance = 10;
  tool.maxDistance = 45;
  
  var path;
  
  function onMouseDown(event) {
      path = new Path();
      path.fillColor = new Color({ hue: Math.random() * 360, saturation: 1, brightness: 1 });
  
      path.add(event.point);
  }
  
  function onMouseDrag(event) {
      var step = event.delta / 2;
      step.angle += 90;
  
      var top = event.middlePoint + step;
      var bottom = event.middlePoint - step;
  
      path.add(top);
      path.insert(0, bottom);
      path.smooth();
  }
  
  function onMouseUp(event) {
      path.add(event.point);
      path.closed = true;
      path.smooth();
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>to a stand alone <code>javascript</code> like:</p>
  
  <pre><code>paper.install(window);
  
  
  window.onload = function() {
  paper.setup('myCanvas');
  
  tool.minDistance = 10;
  tool.maxDistance = 45;
  
  var path;
  
  function onMouseDown(event) {
      path = new Path();
      path.fillColor = {
          hue: Math.random() * 360,
          saturation: 1,
          brightness: 1
      };
  
      path.add(event.point);
  }
  
  function onMouseDrag(event) {
      var step = event.delta / 2;
      step.angle += 90;
  
      var top = event.middlePoint + step;
      var bottom = event.middlePoint - step;
  
      path.add(top);
      path.insert(0, bottom);
      path.smooth();
  }
  
  function onMouseUp(event) {
      path.add(event.point);
      path.closed = true;
      path.smooth();
  }
  }
  </code></pre>
  
  <p>it give me an error:</p>
  
  <blockquote>
    <p>TypeError: undefined is not an object (evaluating 'tool.minDistance =
    10')</p>
  </blockquote>
  
  <p>What is <code>tool</code> here? I understand that I might need to declare it before I can use it. Any idea how to resolve this?</p>