# Using variables with existing variables

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");
}
}

1 Like

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

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

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

1 Like

no problem : P happy to help

1 Like