# X and y don't even out

**URL:** https://discourse.processing.org/t/x-and-y-dont-even-out/31214
**Category:** Coding Questions
**Created:** [July 12, 2021, 8:14pm UTC](https://discourse.processing.org/t/x-and-y-dont-even-out/31214 "2021-07-12T20:14:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [July 12, 2021, 8:14pm UTC](https://discourse.processing.org/t/x-and-y-dont-even-out/31214/1 "2021-07-12T20:14:59Z")

</div>

i wrote a code that should, generate a random x, from 1-10 and then make a y the number that it needs to complete 10. it then should try to devide it by something it can be devided by. then it shows a visual for me to see if it lands on the middle eventually and a print to be sure. however it does not work. why?  
and how do i get around it?

```auto
int x=(int(random(10-1)));
int y= 10-x;

void setup(){
   size(10,10);
   print(x);
   print(y);
 }
   
   void draw(){
      background(255,255,255);
      fill(0,0,0);
      if(x==0){x=(int(random(10-1)));}
      
      if(x>y){y=y+(int(y/3));}
      
      if(y>x){x=x+(int(x/3));}
      
      ellipse(width-x, height/2, 1,1);
      
      if(y==x){
         stop();}
      }

```

---

<div class="post-metadata">

### Author: ![Flolo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/flolo/32/13874_2.png) [@Flolo](https://discourse.processing.org/u/Flolo)
#### Post date: [July 12, 2021, 8:25pm UTC](https://discourse.processing.org/t/x-and-y-dont-even-out/31214/2 "2021-07-12T20:25:28Z")

</div>

Hey I don’t quite get it, but I think you could do it like that too:

```auto
int x;
int y;

int target = 10;

void setup() {
  size(200, 200);

  x = int(random(1, 10));

  println("X: " + x);

  y = target-x;

  println("Y: " + y);

  x = x + y;

  println("X: " + x);

  exit();
}

```

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [July 12, 2021, 8:26pm UTC](https://discourse.processing.org/t/x-and-y-dont-even-out/31214/3 "2021-07-12T20:26:16Z")

</div>

i know, but it’s a proof of concept for a real world object and it would not be able to dunction that way

---

<div class="post-metadata">

### Author: ![Flolo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/flolo/32/13874_2.png) [@Flolo](https://discourse.processing.org/u/Flolo)
#### Post date: [July 12, 2021, 8:32pm UTC](https://discourse.processing.org/t/x-and-y-dont-even-out/31214/4 "2021-07-12T20:32:32Z")

</div>

So you want to animate it?

Maybe like that?

```auto
float x, y, tx, ty;

float moveSpeed = 2;
//tx & ty == target

void setup() {
  size(600, 600);
  x = width/2;
  y = height/2;
}
void draw() {
  background(0);
  tx = mouseX;
  ty = mouseY;

  x = lerp(x, tx, moveSpeed / frameRate);
  y = lerp(y, ty, moveSpeed / frameRate);

  fill(255);
  ellipse(x, y, 30, 30);
}

```
