[SOLVED] How to add ID to a shape (Java)?

Hello I am unsure how to assign an ID to a specific shape. The idea is that every mousePressed will draw a circle in a grid, and I want to be able to tell which circle was drawn 1st, 2nd, 3rd etc. This is because I want to draw a line segment between 2 specific circles I choose. But I’m not sure how to do this.

Perhaps someone could refer me to a handy library to use, or some other method of doing this? I had a thought of using images instead of shapes, but i still don’t know how to assign unique IDs.

For reference, this is an idea of the grid:

Much thanks!

Update: Problem solved with reference to https://processing.org/tutorials/arrays/. :slight_smile:

1 Like

have you tried working with class?

1 Like

Nope. How would I go about using it to assign unique IDs?

how about:
on each mouse click store the position info as
https://processing.org/reference/PVector.html
to a array
https://processing.org/reference/Array.html

the pointer to the array is your ID?


that array you can use to draw for example: shapes…
https://processing.org/reference/PShape_beginShape_.html


in this version you would not need a CLASS ( if that is unwanted )

2 Likes

Interesting suggestion, I’ll try it out. Thanks!