# Using variables with existing variables

**URL:** <https://discourse.processing.org/t/using-variables-with-existing-variables/26584>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [December 29, 2020, 1:38pm UTC](https://discourse.processing.org/t/using-variables-with-existing-variables/26584 "2020-12-29T13:38:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![felix.west](https://avatars.discourse-cdn.com/v4/letter/f/8baadc/32.png) [@felix.west](https://discourse.processing.org/u/felix.west)\
**Post date:** [December 29, 2020, 1:38pm UTC](https://discourse.processing.org/t/using-variables-with-existing-variables/26584/1 "2020-12-29T13:38:24Z")

</div>

Hi,  
I’d like to use a variable for an ellipse using another variable already written above.  
ex:  
int diameter = 50  
int positionX = 200  
int positionY = 200  
–\> int ellipse1= ellipse(positionX, positionY, dia, dia)

So is there another technique to give the ellipse1 the coordinates (x, y, h, w) written above in the code ?  
Here is the the full code… thank you

int dia = 50;  
int posX=200;  
int posY=200;  
int vitesseX=10; //vitesse de déplacement  
int vitesseY=10; //vitesse de déplacement  
float posX2=200.1;  
float posY2=200.1;  
float vitesseX2=5.5;  
float vitesseY2=5.5;

void setup() {  
size(1000, 540);  
}

void draw() {  
background(235, 186, 52);  
ellipse(posX, posY, dia, dia);  
posX = posX + vitesseX;  
posY = posY + vitesseY;  
if (posX\>1000-dia/2) {  
vitesseX = -vitesseX;  
}  
if (posX\<0+dia/2){  
vitesseX = -vitesseX;  
}  
if (posY\>540-dia/2){  
vitesseY = -vitesseY;  
}  
if (posY\<0+dia/2){  
vitesseY = -vitesseY;  
}  
if(posY\>270){  
ellipse(posX2, posY2, dia, dia);  
posX2 = posX2 + vitesseX2;  
posY2 = posY2 + vitesseY2;  
}  
if (posX2\>1000-dia/2) {  
vitesseX2 = -vitesseX2;  
}  
if (posX2\<0+dia/2){  
vitesseX2 = -vitesseX2;  
}  
if (posY2\>540-dia/2){  
vitesseY2 = -vitesseY2;  
}  
if (posY2\<0+dia/2){  
vitesseY2 = -vitesseY2;  
}  
/_if (mousePressed){ //apparition d’une ellipse quand on clique  
ellipse(mouseX, mouseY, dia, dia);  
mouseX = mouseX +vitesseX;  
mouseY = mouseY +vitesseY;  
}_/  
}

void keyPressed() {  
if (key == ‘S’ || key == ‘s’) {  
save(“monImage”+hour()+minute()+second()+".jpg");  
}  
}

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 29, 2020, 2:28pm UTC](https://discourse.processing.org/t/using-variables-with-existing-variables/26584/2 "2020-12-29T14:28:11Z")

</div>

from what I understand, you want to create two circles bouncing around the screen. In order to do that just create variables

```auto
float x2 = 300,y2 = 300, xs=10,ys=10 //set values to whatever

```

---

<div class="post-metadata">

**Author:** ![felix.west](https://avatars.discourse-cdn.com/v4/letter/f/8baadc/32.png) [@felix.west](https://discourse.processing.org/u/felix.west)\
**Post date:** [December 29, 2020, 3:45pm UTC](https://discourse.processing.org/t/using-variables-with-existing-variables/26584/3 "2020-12-29T15:45:34Z")

</div>

Yeah that’s almost it ! I adapted it. Thank you

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 29, 2020, 3:59pm UTC](https://discourse.processing.org/t/using-variables-with-existing-variables/26584/4 "2020-12-29T15:59:35Z")

</div>

no problem : P happy to help
