We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everybody, I am relatively new to Processing and have come up against a problem that I don't know how to solve. Can anyone please tell me what is the best way to code multiple objects, array of objects, where that object is constructed as a class a manipulate with them through rotation. I wish that every entity individually can be rotated depending on movements of the mouse. Thank you in advance for any help.
Answers
Break it down into steps
Can you make a single rectangle rotate?
Can you make an array of objects ?
See in the section More advanced questions in this link:
https://forum.processing.org/two/discussion/8093/frequently-asked-questions#latest
e.g.
https://forum.processing.org/two/discussion/8080/why-use-arraylist-instead-of-array-with-append
For Rotation
Every rotation is done around the origin (which is 0,0 of the coordinate system).
So you need to use translate() first and then rotate().
To avoid rotating around corner of rectangle instead of its center
To avoid rotating around corner instead of center:
Since rotate() is around origin you want to use
rectMode(CENTER);
OR
Place the object on / over the origin:
rect(-40,-40,80,80);
To let the objects rotate independently make sure the variables like angle are in the class and NOT defined globally/ before
setup ()
.For mouse:
Tutorial:
There is a tutorial on objects (which is also about classes) and one about arrays
Array versus ArrayList
Array is good when you know how many objects you have, otherwise use ArrayList
Post your entire code please, even if it’s not running
Chrisir ;-)
here is an example of a class and an ArrayList of that class:
rotation example