How to call static p5.Vector methods in instance mode

Hi so in instance mode with instance p= new p5(..), I can make a vector v1 = p.createVector() and can then call v1.dist(v2) but I cannot call p5.Vector.dist(v1,v2) nor p.p5.Vector. This may be a general js question but I was wondering how to call p5.Vector functions like angleBetween() or random2D() etc.

Answers

  • edited January 2017

    http://p5js.SketchPad.cc/sp/pad/view/ro.Cp2wk8n$MWzH4r/latest

    https://forum.Processing.org/two/discussions/tagged?Tag=#instance+mode

    "index.html":

    <script src=https://p5js.org/assets/js/p5.min.js></script>
    <script src=sketch.js></script>
    

    "sketch.js":

    /**
     * p5.Vector Instance Test (v1.0)
     * GoToLoop (2017-Jan-28)
     *
     * forum.Processing.org/two/discussion/20509/
     * how-to-call-static-p5-vector-methods-in-instance-mode#Item_1
     *
     * p5js.SketchPad.cc/sp/pad/view/ro.Cp2wk8n$MWzH4r/latest
     */
    
    "use strict";
    
    new p5(p => {
      const TXT_SIZE = 20, BOLD = 1.5, MULT = 10;
      let vec, bg;
    
      p.setup = () => {
        p.createCanvas(1000, 150).mousePressed(newRandomVec);
        p.noLoop(), p.blendMode(p.REPLACE);
    
        p.strokeWeight(BOLD).stroke('red').fill('yellow');
        p.textAlign(p.CENTER, p.CENTER).textSize(TXT_SIZE);
    
        bg = p.color('blue');
        newRandomVec();
      };
    
      p.draw = () => {
        p.background(bg);
        p.text(vec, p.width>>1, p.height>>1);
      };
    
      function newRandomVec() {
        vec = p5.Vector.random3D().mult(MULT);
        console.log(vec);
        p.redraw();
      }
    });
    
Sign In or Register to comment.