1. appear in a different location. 2. spin at a different rate
(I know how to do this via non-OOP coding. But once I reformat as OOP I can’t figure out how to implement push() and pop() to each iteration of the object. I tried to add push() and pop() to the main sketch but that didn’t work. I also tried adding push() and pop() to the display function in the class code – still no success.)
I think I could have stated my initial question better. My apologies.
I would like each ellipse to have it’s own position (point of origin?) on the screen.
Each ellipse is to spin from it’s center / ellipseMode (CENTER)
For example,
object j1 is at x,y (50, 50)
object j2 is at x.y(150,150)
Eventually, I will add more Jellybean objects at random locations (each with their own point of origin).
I understand what you’re saying about syncing and changing the angle to achieve a different spin rate for ea object, however my main question lies with making each object a distinctly separate entity.
Currently j2 revolves around j1. I do not want objects to be linked in such a way that they revolve around each other as though they are paired.
I want each object to spin in place around its own center (x,y)
Using an array is my next step. I wanted to make sure I could get 2 objects to work before applying an array to the mix.
The goal with this project is a very simple game. I will likely have additional questions.
Thank you for posting your code above! It’s very helpful as a novice to see.
I did copy /paste and run it. I got a blank screen until I commented out the last 2 lines:
The last 2 lines (with text()) were there to show the angle as text
The %= line keeps the angle between 0 and two PI (which is the max angle in radians). See % in the reference. When the angle is greater than two PI it gets reset to 0.
the expression %= is a short form similar to +=.
Long form is angle = angle % TWO_PI;
One small warning about push/pop, or pushMatrix/popMatrix. This is the correct way to do it with limited objects – say tens, or hundreds.
However, you are going to have 10,000 or 100,000 jellybeans, then pushing and popping for each one 60 times a second will be a huge performance hit. At the point where you experience performance issues / lag, you may want to do something like this:
Use either an Animation class or the Sprites library to pre-render a few animations or sprites – one for each jellybean color, with a good number of frames.
create jellybean objects that contain pointers to these animations / sprites – e.g. Animation myAni= redAni, or blueAni. The jellybean class also has a frame index that determines the current angle (e.g. currently pointing at frame 3, frame 3 is 45 degrees) and a frame step counter that determines the spin rate (e.g. advance 1 frame at a time, or 3, or 10).