So this is my function which i am having the issue with, it is using the p5.js library.
function SprayCanTool(){
this.name = "sprayCanTool";
this.icon = "assets/sprayCan.jpg";
var spread ;
var points = 13 ;
this.draw = function(){
var r = random(5,10);
spread = document.getElementById("size-slider").value;
if(mouseIsPressed){
for(var i = 0; i < points; i++){
point(random(mouseX-spread, mouseX + spread),random(mouseY-spread, mouseY+spread));
}
}
};
this.populateOptions = function(){
select(".options").html( " <label>Size of Spray: </label> <input id='size-slider' type='range' min='10' max='200' step='1' value='10'> ");
}
}
就像上面显示的那样,代码不起作用,我无法调整喷雾的大小,并且喷雾根本不会显示在画布上。
As shown above the minimum value spread can be is 10. When i add console.log(spread,points)
into the draw method, the expected 10,13
is outputted into the console.
When i hardcode the value as any number , and remove the spread = document.getElementById("size-slider").value;
part, the code works as i have intended it to work (except off course i can not adjust the size using the slider)
有谁知道是什么引起了这个问题?
好吧,没关系,我的困惑现在已经使自己困惑了。我在错误的位置寻找错误,因为我试图用浮点数添加整数,并使用javascript由于某种原因将它们加在一起,就像它们都是字符串一样。
我设法通过替换解决了我的问题:
与