I made a function that rounds numbers to the nearest number of your choice using dist and min, whenever the program does the min math it tells me that min can only receive 2 arguments, but it still works? It’s not a problem just wondering what is going on if anyone knows.
<function setup() {
createCanvas(400, 400);
}
function draw() {
text(roundTo(36,10,20,30,40),200,200);
}
function roundTo(n,op1,op2,op3,op4){
let op1dis = dist(op1,0,n,0);
let op2dis = dist(op2,0,n,0);
let op3dis = dist(op3,0,n,0);
let op4dis = dist(op4,0,n,0);
min(op1dis,op2dis,op3dis);
if(min(op1dis,op2dis,op3dis,op4dis) == op1dis){
n = op1;
}
if(min(op1dis,op2dis,op3dis,op4dis) == op2dis){
n = op2;
}
if(min(op1dis,op2dis,op3dis,op4dis) == op3dis){
n = op3;
}
if(min(op1dis,op2dis,op3dis,op4dis) == op4dis){
n = op4;
}
return n;
}>