I want to make a pendulum. I have a line with a ball fixed to both ends of the line. Ball1 is fixed in place. I want ball2 to "fall" (move down the screen) and I want it to "swing" on the line. AKA I want the ball to move down and I want the line to stay at a constant length forcing the ball to arc and "swing" on the line.
`
Part part1;
Part part2;
Muscle muscle1;
float gravity = 10;
void setup() {
...
}
void draw() {
background(255);
part1.drawpart();
part2.drawpart();
muscle1.drawmuscle(part1, part2);
part2.movepart();
}
class Muscle{
float leftx;
float lefty;
float rightx;
float righty;
float size = 100;
int musclecolor;
...
void drawmuscle(Part obj1, Part obj2) {
strokeWeight(5);
line(obj1.x, obj1.y, obj2.x, obj2.y);
size = sqrt(sq(obj1.x - obj2.x) + sq(obj1.y - obj2.y));
^^ This is the equation to keep the line the same length. Will this equation work if placed in the right location? Or is this method just not possible?
}
}
class Part{
float x;
float y;
float size;
int partcolor;
...
void drawpart() {
...
ellipse(x, y, size, size);
}
void movepart() {
part2.y += gravity;
}
}