Week 5: Functions

For this week in ICM, I experimented with using functions to compartmentalize my code in three sketches. I found the process to be a lot of fun! Since I always work with multiple objects in my sketches, creating functions that take parameters and return values opens up a lot of possibilities.

I first reworked an existing assignment. In my first week at ICM, I created a cat that consisted of a lot of different shapes. I created the function makeCat, which consisted of all of my code that used to be in my draw function. Afterwards, I created three cats with different scales.

My cats are getting bigger

In my next version, I created a for loop that produced multiple cats. I randomly translated, rotated, and scaled my makeCat function to create a very chaotic sketch.

Link to the sketch: https://editor.p5js.org/nickgran321/sketches/EC5c3Tgi7
Link to my code on Github: https://github.com/nickgran321/Nick-Grant/blob/master/Computational%20Media%20Week%205:%20Functions%20Part%20One

For my second sketch, I desired to create candles that all have a different color, rotation, and scale. I found the image to be very beautiful.

Link to the sketch: https://editor.p5js.org/nickgran321/sketches/YJmx-7Vtm
Link to the code on Github: https://github.com/nickgran321/Nick-Grant/blob/master/Computational%20Media%20Week%205:%20Functions%20Part%20Two

In order to create the sketch, I first created the function candle. Unlike my cat sketch that only had arguments for x and y in the function, the candle function contain an argument for scale(s). My function is returning a value for the scale as a number between 0.25 and 1.5. Unlike my cat sketch, the rotation is a random number multiplied by (2*PI) so my candles are not too chaotic. I implemented a for loop in draw. The frameRate() is 1.

Link to my sketch: https://editor.p5js.org/nickgran321/sketches/3GYWWKHIn
Link to my code on Github: https://github.com/nickgran321/Nick-Grant/blob/master/Computational%20Media%20Week%205:%20Functions%20Part%20Three

For my third sketch, I experimented with text. In my sketch, I created two functions. I created the function theText, which consists of the parameters textArgument, x_position, y_position, r_color, g_color, b_color. The size of the text is defined in this function too. Each time the text is called, the textArgument, x_position, and y_position are also called. The text is filled with r_color, g_color, and b_color that I may define in my draw function.

In my second function, I actually created a for loop outside of draw. My function forLoop consists of the parameters repeatingLetters, lettersContinue, x_pos, y_pos, r_color, g_color, b_color. I created a for loop and in the line underneath that I defined repeatingLetters as lettersContinue, x_pos+i*150, y_pos+50, r_color, g_color, b_color. Since my previous function contained parameters for the x position, y position, and the colors for r g b, I repeated that information in my for loop function. I could have picked better names than repeatingLetters and lettersContinue.

In my draw function, an example of a line of text is “forLoop(theText, “LIVE”, 16, -10, 200, 120, 255).” The forLoop is actually calling my for loop function while theText calls the size of the text, x position, y position, and color. I researched short words that changed meaning when they are backwards. In undergrad I wrote a lot of poetry. I am interested in the ways that technology may provide new meaning in language. While I enjoyed experimenting with text, these sketches slowed down my computer considerably.

Another version.

Link to my sketch: https://editor.p5js.org/nickgran321/sketches/OltBBuCbY
Link to my code on Github: https://github.com/nickgran321/Nick-Grant/blob/master/Computational%20Media%20Week%205:%20Functions%20Part%20Four

While I attempted to embed a function into an object, and attended an ICM help session to learn more about the skill, I’m still having difficulty wrapping my head around the new information. I question when I would need to embed a function into an object and the instantiation pattern I should follow. I look forward to learning more soon.