# Random x placement and proportional scaling

**URL:** <https://discourse.processing.org/t/random-x-placement-and-proportional-scaling/3102>\
**Category:** Coding Questions\
**Created:** [August 29, 2018, 9:32pm UTC](https://discourse.processing.org/t/random-x-placement-and-proportional-scaling/3102 "2018-08-29T21:32:00Z")\
**Posts on this page:** 6\
**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 29, 2018, 9:32pm UTC](https://discourse.processing.org/t/random-x-placement-and-proportional-scaling/3102/1 "2018-08-29T21:32:00Z")

</div>

Hello Processors, thank you for your time. I am trying to place video-objects along the same y height but random x position, it works but it moves non stop. Also I am trying to scale, proportionally the object using the scale function unsuccessfully. Please take a look at my code, thank you.

```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);
  for (Video video : videos) {
    //Video.move();
    video.display();
  }
}

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

  float rectX, rectY, rectW, rectH;
  float rectSpeedX, rectSpeedY;
  float y = 0;

  Video (float w, float h) {
    rectW = w;
    rectH = h;
  }

  void display() {
    for (float i = 0; i<0; i++) {
      scale(-5*i);
    }
   image(myMovie, random(5)*50, y, rectW, rectH);
  }
}

```

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [August 29, 2018, 9:47pm UTC](https://discourse.processing.org/t/random-x-placement-and-proportional-scaling/3102/2 "2018-08-29T21:47:28Z")

</div>

What is this `for` loop doing?

> [@tefa](#):
>
> for (float i = 0; i\<0; i++) { scale(-5\*i); }

Anyway, think about this line:

```auto
image(myMovie, random(5)*50, y, rectW, rectH);

```

You’re setting a random position every time your draw it. It sounds like you want to come up with a random position once, then store it in a variable at creation time?

---

<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 29, 2018, 9:50pm UTC](https://discourse.processing.org/t/random-x-placement-and-proportional-scaling/3102/3 "2018-08-29T21:50:19Z")

</div>

the loop is scaling all the images at the same time, that is not what i want. I want random scaling

---

<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 29, 2018, 9:58pm UTC](https://discourse.processing.org/t/random-x-placement-and-proportional-scaling/3102/4 "2018-08-29T21:58:25Z")

</div>

I change it so that a global variable hold a random(1); but the changes are to drastic.

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [August 29, 2018, 10:08pm UTC](https://discourse.processing.org/t/random-x-placement-and-proportional-scaling/3102/5 "2018-08-29T22:08:29Z")

</div>

> [@tefa](#):
>
> the loop is scaling all the images at the same time

Are you sure? Have you tried adding a `println()` statement inside the loop to confirm your assumptions?

> [@tefa](#):
>
> I change it so that a global variable hold a random(1); but the changes are to drastic.

Can you please be more specific? What do you mean by global variable? What do you mean by drastic?

---

<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 29, 2018, 10:11pm UTC](https://discourse.processing.org/t/random-x-placement-and-proportional-scaling/3102/6 "2018-08-29T22:11:07Z")

</div>

Sorry , yes, for scale i made a global variable s= random(1.5); I can see now that it works. Thank you
