As someone who appreciates both flexibility and structure, I began to value the use of functions in p5.js this week; functions allow for better modularity and organization.

Once I learned that I could create my own functions in code, I was curious to refactor my sketch from the third week of class using this method. In this “Googly Eye” sketch, I had various objects and variables that could be grouped more effectively into functions. I tried to consolidate the eyeball and iris into one function which could be called to create multiple eyeballs. This pared down the long string of code into a smaller block that could be modified, but it did not have the same effect as the original sketch.

I thought that I could easily refactor the effects into functions as well. In the end, I could not figure out how to fold in other effects or events, such as mouse hover or mouse pressed, into existing functions. That is one question I have for class.

To be honest, I am still struggling to grasp many aspects of coding – it still feels foreign. However, I think I am making progress in my understanding of how code works conceptually, and functions certainly helped with this.

Link to Sketch in p5.js

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s