Keep Working

I wanted to keep working on my random ball movement with the new features learnt about Javascript, the objects and constructor functions.

I first tried to change my balls into literal objects. I feel like the objects in Javascript is very similar to the classes in Java, only without the constructor functions.

Luckily it was fairly easy since I already have all the codes modulated as a function so I just needed to copy&paste the codes and do some minor modifications.

Changing it to a constructor function is easy as well since the codes for an object share the same form with the ones of the constructor functions and I only needed to change the syntax.

But I decided to move further. I wanted to add more than just two random moving balls to my design. So I searched and learnt how to store objects in an array. It was not difficult as well since I already had experience in Java.

So I ended up with this:

The interesting thing about this is that if the speeds and diameters are changed it can generate very different patterns.

This is the default setting:

assignment#3

If the speed is changed to 20:

assignment#3(2)

Interesting things will also happen if you change the shape to squares and/or diameter to 1 or 2 and/or speed to more than 100.

assignment#3(4)

assignment#3(5)

Assignment#3(6)
 

Leave a Reply

Your email address will not be published. Required fields are marked *