We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
https://forum.Processing.org/two/discussions/tagged?Tag=createinput()
My apologies!
Have you looked up method changed()?: :-?
http://p5js.org/reference/#/p5.Element/changed
Here's a more recent discussion about createInput() and callback: :-bd
https://forum.Processing.org/two/discussion/20459/using-a-dom-event-callback-inside-an-object
No I haven't - having some trouble figuring out how I could implement changed() into my code?o.O I simply want to access what is currently in the input-boxes and using them to create a random vector. I tried using the basic java-function Math.random():
But it yielded the same result... Might I just not be using the keywords "width" and "height" correctly?