We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I've created a functional Path class that I will include below that uses the curve function to generate a smooth random path connected by an array of points I've called Nodes. My goal is to have a shape object follow this path, but I am unsure as to how I can do this. I'm guessing there is some way to get the x and y values of the curve drawn by the curve function that I can then use to influence the movement of the shape. Any suggestions?
class Path {
float startX, startY;
float endX, endY;
Path() {
startX = 50;
startY = 50;
endX = 350;
endY = 100;
}
void show(Node [] nodes) {
stroke(0);
noFill();
beginShape();
for (int i = -2; i < nodes.length + 2; i++) {
if (i < 0)
curveVertex( startX, startY );
else if (i >= nodes.length)
curveVertex( endX, endY );
else
curveVertex( nodes[i].getNodeX(), nodes[i].getNodeY() );
}
endShape();
}
}
Answers
Here is an example of the output. The larger circle on the left is the separate object that I'm looking to move along the curve. The smaller circles are the aforementioned Nodes that are used to create the curve.
https://processing.org/reference/curvePoint_.html
I found that function in between the time of my initial post and yours, and I have gotten to a point where it is mostly functional; however, I am getting a weird effect where some of the points generated by curvePoint deviate from the curve, skewing the path of the object. This image shows each point generated by the curvePoint function to demonstrate this effect:
I created a Step class that creates and keeps track of each point created by the curvePoint function in an array, so here is that code:
Another question I guess I should ask is if there is a more optimal way to create a random smooth path as well as get an object to move along it?
Typo on lines 17 and 18
Thanks! Can't believe I missed that haha.
Would you like to collaborate with me on this?
@jwmccart1101 -- you may also be interested in the Processing example sketch: