How can I get the coordinate of one shape

my code as following:

let elli = ellipse(100,100,100,100);

so next how can I get the coordinate of the ellipse?

Well, you already know it since you entered the values manually. You might want to check the doc for ellipse() if you don’t know what the arguments you gave mean.

Thanks for your reply.
In fact, I know what these arguments mean. However in my case, the coordinates may be variables that have been defined in another place, so it is not explicit for me. I just wonder wether there are some property just like ellipse.x or method likeellipse.coordinate(x).

Ok it makes more sense now.

Short answer, you don’t have property like this. The reason is ellipse is not an object but simply a function that draws something on the canvas.

But of course, you have several way to achieve what you want to do.
The simplest way would be to have 2 arrays holding your x and y coordinates. Actually you can have a look at this thread; this solution is implemented there (and I would not be surprised if you both have the same assignement =)

If you want to be a tiny bit more fancy, you can have an arrayList of PVector. It is almost the same as the solution above but instead of having 2 array you only have one.

And if you want to go the extra mile, you can also create your own Ellipse class to hold their coordinate and take care of other logic like drawing them on screen for exemple. Here again using an arrayList of Ellipse object could be the solution.

Thanks for your reply again, the problem has been resolved. :grinning:

1 Like
let elli = ellipse(100,100,100,100);

this is p5.js, so elli is an object here, but it doesn’t hold x and y, just some data

interestingly, you can click on the arrows in the console to expand objects


let a1 =  (255);

function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(220);
  
  fill(a1);
  let elli = ellipse(100,100,100,100);
  
  print(elli);
  print(elli._pixelDensity);
  
  print(elli._setupDone);
  print(_curElement);
  
}

1 Like

oh, it’s cool! :grin:
JS is an object-oriented language.