Hanging by a thread

I want to click an object, then a thread appears and the object starts to fall until the thread reaches it’s maximum length, then it just hangs in place, like if you were holding an unraveled yoyo then released it. Thanks for the help!

float x, y, r = 50;
float velX, velY, grav = 0.5;
boolean picked;

void setup() {
  size(600, 600);
  x = width/2;
  y = height/2;

void draw() {
  circle(x, y, r);

  if (mousePressed) {
    if (dist(x, y, mouseX, mouseY) <= 50) {
      picked = true;
  } else {
    picked = false;

  if (picked) {

Welcome back!

  • first of all, get rid of picked = false, because you want the ball to continue after you release the mouse again

  • 2nd: say y++; or y += 2; to make the ball fall. This will influence this line: circle(x, y, r);

  • 3rd: draw a line from ball to initial pos of ball:

    line(x, y,    // current ball pos 
         x, height/2-r);  // initial ball pos / start of thread 
  • 4th: when the thread is long enough, stop the fall:
    if (abs(y-height/2-r)>110) {
      picked = false;
      hasBeenPicked=true;// boolean similar to picked 

Thanks for the reply! Indeed, I haven’t programmed in quite a while, trying to get back to pace! Anyway, that’s almost what I wanted, however I put the picked == false bit because I wanted to make almost like shotput, where you can spin the object around (with gravity) and then release it with the spinning velocity it had. If you see this, feel free to use vectors if you want, would be a pleasure to try and understand them!

1 Like

PVector is easy

before setup say:

PVector pos = new PVector(0,0);

you can use it like

circle (pos.x, pos.y, 10); // use a dot . between the PVector pos and its fields x and y

PVector is a class that holds a point, in 2D x,y and in 3D x,y,z

see PVector / Processing.org