p5 method createVector not working..? o.O

Hi! I'm currently trying to make a vector with the p5 method createVector using defined variables (which change with user input) in conjuction with the random() method, but all I'm getting is a p5.Vector with an x- and y-coordinate in brackets (in red font and for example "84.324567") when I look at it in the webpage console. The result seems to be that it becomes and "invalid" vector and thus not showing up when I try to draw it. Everything works fine though when I hard-code numbers into random() (like "random(20, 380)". Code below.

function setup() {

    paLAmount = createInput("Amount of parallel lines");
      nAmount = createInput("Amount of needles");
      nLength = createInput("Length of needles");
}


    var makeNeedles = function() {

      var setNAmount = nAmount.value();
      var setNLength = nLength.value();

      //Creating random vectors
      for(var j = 0; j < setNAmount; j++) {

         var cx = random(setNLength + 1, (width - setNLength - 1));
         var cy = random(setNLength + 1, (height - setNLength - 1));
         var a = createVector(cx, cy);

         console.log(cx, cy);

         coIndex1.push(a);
   };
}

All help is appreciated!:)

Answers

Sign In or Register to comment.