Week 4: Objects + Functions

This week’s task was to better organize one’s code using functions within objects – which I was able to successfully grasp and execute. However, it became slightly difficult for me to execute my idea because I couldn’t understand how to incorporate an array into this new object organization.

View the Sketch

The idea was to have the egg fall, crack and have many ants crawl across the canvas. I found that to do this, I would either need to create an array of ants or a particle system for the same, neither of which I was familiar with. On experimenting a bit with the ‘ParticleSystem’ example on the p5 website, I found I was still unable to understand the code, even though the set example made it easier for me to execute my idea. I decided to resort to an array, as I could understand the concept of it (though still not the code). After a couple of hours of reading, re-reading and trying out examples, I was still unable to understand the logic.

Another thing I could not figure out was how to layer the objects in a manner that the ants appear as if they are behind the cracked egg. For some reason the layering does not apply to objects – they don’t get called in order of their appearance in the code.

Here is my code for the sketch:

Leave a Reply

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