Hello,
This question may be more to do with my understanding of OOP that the
actual contructs of Ruby so please be patient with me.
I am interested in visualizing data so am teaching myself to Programming
using Ruby via computer graphics. I am steadily building up my knowledge
and experience by writing by and executing rudimentary code around the
new thngs I learn. Now I’m stuck so i’ll make the question as simple as
I can:
I create a window of Ball objects based on a Ball class that I have
written. Each Ball object is instantiated at a randon x,y location on
the screen and has random speed.
Each Ball object is able to reverse its driection (bounce) if it hits
the edge of the window.
If I have two balls and I want to detect whether they instersect with
each other as they move around the screen this is simple enough; the
ball class has an intersect() method which i can use to pass in a
reference to the other ball object. But what if there are are random
number of balls. How do I make it such that any Ball object would be
aware of the location of any other Ball object without having to resort
to nested for loops where I check the location of each Ball against
every other Ball?
Any ideas