If this is for an assignment, please tag your post as “Homework” then.
To get back at your code.
First thing, consider using variable names that makes sense, it will help you a lot when working with longer piece of codes.
For example, when I first read mousePos
I thought it was used to store the x and y coordinates of the mouse while in fact it was referring to the number of ellipses that were drawn on the screen. So maybe a better name could be ellipseNb
You got the adding an ellipse part correctly.
I also realized, I did not read your question correctly… What you want is to get rid of the top left ellipse not the first one added.
Let’s take it step by step then.
The first thing you want to do is to identified the top left ellipse. You already understand that for that you need to identify the one with the lower x value. BUT you also need to keep track of which one it is. So you actually need 2 variables: one to keep track of the minimum value and one to keep track of the index corresponding to that minimum value.
Currently you are missing that last variable.
Then, once you have the index corresponding to the top left ellipse, you want to delete it. But since you are working with a simple array, you are not really deleting it, but more overriding its value. Imagine you have 5 ellipses and the following array:
x[0] = 20
x[1] = 50
x[2] = 10
x[3] = 30
x[4] = 40
x[5] = ?? // Can be any value, you have only 5 ellipses so this value is not used
x[6] = ?? // Can be any value, you have only 5 ellipses so this value is not used
...
x[1000] = ?? // Can be any value, you have only 5 ellipses so this value is not used
If you have only 5 ellipses then you also have ellipseNb = 5
so you can do this in draw:
for (int i = 0; i < ellipseNb; i++) {
fill(255);
ellipse(x[i], y[i], SIZE, SIZE);
}
As you can see, ellipse with index 2 is the most left one, so you want to “remove it”. Well first, you know that you will only have 4 ellipse remaining, so you can already write ellipseNb = 4
Because of this you will only draw ellipses 0 through 3 so what you want to have is:
x[0] = 20
x[1] = 50
x[2] = 30 // Previous x[3]
x[3] = 40 // Previous x[4]
x[4] = ?? // Can be any value, you have only 5 ellipses so this value is not used
x[5] = ?? // Can be any value, you have only 5 ellipses so this value is not used
x[6] = ?? // Can be any value, you have only 5 ellipses so this value is not used
...
x[1000] = ?? // Can be any value, you have only 5 ellipses so this value is not used
So all you have to do is slide by one each value starting at the index of the most left ellipse up to the number of ellipses left.
I think you have enough element to start working out a solution now.