# Dropping objects

**URL:** <https://discourse.processing.org/t/dropping-objects/3114>\
**Category:** Coding Questions\
**Created:** [August 30, 2018, 2:34pm UTC](https://discourse.processing.org/t/dropping-objects/3114 "2018-08-30T14:34:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tefa](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tefa/32/1181_2.png) [@tefa](https://discourse.processing.org/u/tefa)\
**Post date:** [August 30, 2018, 2:34pm UTC](https://discourse.processing.org/t/dropping-objects/3114/1 "2018-08-30T14:34:00Z")

</div>

Hello Processors, thank you for your time. I have an array of object moving on their y axes until a certain “ground” point. It works fine, but when I scale the objects to be different sizes the objects don’t stop exactly where they should. I want to scale randomly and proportionally these objects.

```auto
import processing.video.*;
Movie myMovie;

int numVideos = 10;
Video[] videos = new Video[numVideos];

float groundY = 580;

void setup() {
  size (640, 640);
  myMovie = new Movie(this, "fogata.mp4");
  myMovie.loop();
  for (int i = 0; i < numVideos; i++) {
    videos[i] = new Video(4096/10, 2160/10);
  }
}

void draw() {
  background(64);
  stroke(255);
  line(0, groundY, width, groundY);
  //imageMode(CENTER);
  for (Video video : videos) {
    video.drop();
    //video.move();
    //video.collide();
    video.display();
  }
}

void movieEvent(Movie m) {
  m.read();
}
class Video {

  float rectW, rectH;
  float rectSpeedX, rectSpeedY;
  float rectY = 0;
  float rectX = random(15)*50;
  float s = random(2);
  
  Video (float w, float h) {
    rectW = w;
    rectH = h;
  }

  void drop() {
    rectY += rectSpeedY;
    if (rectY + rectH > groundY) {
      rectY = groundY - rectH;
      rectSpeedY = 0;
    } else {
      rectSpeedY= rectSpeedY + 150;
    }
  }

  void display() { 
    scale(s);
    image(myMovie, rectX, rectY, rectW, rectH);
  }
}

```

---

<div class="post-metadata">

**Author:** ![tefa](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tefa/32/1181_2.png) [@tefa](https://discourse.processing.org/u/tefa)\
**Post date:** [August 30, 2018, 2:52pm UTC](https://discourse.processing.org/t/dropping-objects/3114/2 "2018-08-30T14:52:34Z")

</div>

> [@tefa](#):
>
> float s = random(2);

fixed

```auto
float s = random(1);
  void drop() {
    rectY += rectSpeedY;
    if (rectY+s + rectH+s > groundY) {
      rectY = groundY - rectH*s;
      rectSpeedY = 0;
    } else {
      rectSpeedY= rectSpeedY + 150;
    }
  }

  void display() { 

    image(myMovie, rectX, rectY, rectW*s, rectH*s);
  }

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 2, 2018, 10:56pm UTC](https://discourse.processing.org/t/dropping-objects/3114/3 "2018-09-02T22:56:41Z")

</div>

Thanks for sharing your solution, @tefa.

Could you say something about what `float s` is doing, and why you needed a [0-1] vs a [0-2] random number?

---

<div class="post-metadata">

**Author:** ![tefa](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tefa/32/1181_2.png) [@tefa](https://discourse.processing.org/u/tefa)\
**Post date:** [September 2, 2018, 11:05pm UTC](https://discourse.processing.org/t/dropping-objects/3114/4 "2018-09-02T23:05:21Z")

</div>

I am randomly changing the image size. When I added the random variable ‘s’ to the drop function the image stopped exactly where I wanted it to stop. Picked random 1 just for aesthetics reasons.
