I am Facing this Problem, my randomPoints array element is getting replaced by push method.
Here is the output of my Console
I don't know why this is happening but if I don't use randomPoint.add, it dosen't replaces and work fine.
randomPoint.add retuns the same Vector object as it would return without it.
var hw
var center
var randomPoints = []
var pointWidth = 20
var points = 300
centerCircleWidth = 300;
pointsOffset = 10
function setup(){
hw = createVector(600,500)
createCanvas(hw.x,hw.y)
center = createVector(hw.x/2,hw.y/2)
var randomPoint = createVector(0,0)
randomPoints.push(randomPoint)
randomPoint = p5.Vector.fromAngle(-radians(120), random(centerCircleWidth/2-pointWidth,centerCircleWidth/2-pointsOffset))
randomPoints.push(randomPoint)
console.log(randomPoint)
randomPoint = randomPoint.add(p5.Vector.fromAngle(radians(60), random(pointsOffset,2*pointsOffset)))
// this here replaces the last element of array by itself and add another element of same type.
randomPoints.push(randomPoint)
console.log(randomPoint)
console.log(randomPoints)
}
function draw(){
translate(center.x, center.y)
background(51);
strokeWeight(0)
fill(255)
ellipse(0,0, centerCircleWidth, centerCircleWidth)
for(i=0;i<randomPoints.length;i++){
fill(10)
ellipse(randomPoints[i].x,randomPoints[i].y,pointWidth,pointWidth)
}
}
var randomPoint = createVector(0,0). Is that supposed to always refer to the same thing or is it supposed to refer tonew createVector(0,0)because that looks like a constructor and if that's the case then you want to have a new one everytime or else you will override your old var reference,createVector(0,0)returns an object with{x: 0,y: 0},p5.Vector.fromAngle()andrandomPoint.add()does the samelet newRandomPt = p5.Vector.fromAngle(); randomPoints.push(newRandomPt);and so on? It's 3 distinct vars, why then make a reference to it with the same var? That's hella confusing.`