# Hanging by a thread

**URL:** <https://discourse.processing.org/t/hanging-by-a-thread/42135>\
**Category:** Coding Questions\
**Created:** [June 4, 2023, 3:38pm UTC](https://discourse.processing.org/t/hanging-by-a-thread/42135 "2023-06-04T15:38:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinijoncrafts](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vinijoncrafts/32/14306_2.png) [@vinijoncrafts](https://discourse.processing.org/u/vinijoncrafts)\
**Post date:** [June 4, 2023, 3:38pm UTC](https://discourse.processing.org/t/hanging-by-a-thread/42135/1 "2023-06-04T15:38:59Z")

</div>

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!

```auto
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() {
  background(155);
  ellipseMode(RADIUS);
  circle(x, y, r);

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

  if (picked) {
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 5, 2023, 3:24pm UTC](https://discourse.processing.org/t/hanging-by-a-thread/42135/2 "2023-06-05T15:24:06Z")

</div>

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:

```auto
    stroke(0);
    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:

```auto
    if (abs(y-height/2-r)>110) {
      picked = false;
      hasBeenPicked=true;// boolean similar to picked 
    }

```

---

<div class="post-metadata">

**Author:** ![vinijoncrafts](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vinijoncrafts/32/14306_2.png) [@vinijoncrafts](https://discourse.processing.org/u/vinijoncrafts)\
**Post date:** [June 5, 2023, 5:03pm UTC](https://discourse.processing.org/t/hanging-by-a-thread/42135/3 "2023-06-05T17:03:22Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 5, 2023, 7:28pm UTC](https://discourse.processing.org/t/hanging-by-a-thread/42135/4 "2023-06-05T19:28:03Z")

</div>

`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](https://processing.org/tutorials/pvector)
