Creative Coding Week 3: Object-Oriented Programming

Image for post
Image for post

“If there is a Deleuzean abstract machine for our contemporary culture, it is object orientation. Whether manifested as the wildly popular online video game communities World of Warcraft or Second Life, massively trafficked social networking Web sites such as Facebook and MySpace, or even just the incessant daily information-processing workflow of most modern occupations, object orientation increasingly mediates how we work, play, fight, and love.”

Now, if you are not familiar with coding, or just haven’t looked at any codes in a while, you would probably be wondering….. “what is that thing called object-oriented programming? And how does its ubiquity affects our interaction with the computer?” In Objects of Our Affection: How Object Orientation Made Computers a Medium, Casey Alt offers his take on these big questions and explains how the computer has been medialized to its current state from its original incarnation as a mere calculator.

In my understanding, object orientation turns repetitive and lengthy lines of codes into structured sections of codes that work with and talk to each other. In Alt’s chapter, he mentioned that encapsulating codes naturally disrupts the linearity of the program, making each encapsulated commands more compact, efficient, and powerful. This actually makes our communication with the computer more human-like; with objects, humans can pass our common understandings onto the computer so that the conversation becomes less redundant. For instance, to tell the computer to draw a walking cat, I have to let it know the definition of a cat and how to represent it, then explain the action of walking, and finally combining the two and tell it what does “walking” look like on a cat. If I want to then ask the computer to draw a cat playing with a ball, I would have to go through all the process and introducing every basic property of my command. However, with object orientation, I can first establish an understanding of a cat between me and the computer, and then ask it to draw various iterations of that cat without explaining what’s a cat again and again.

I see how codes are medialized with object orientation; before, each line was separated and isolated, and now, under the presence of object orientation, there is communication between codes. Thus, as an approach of systemic restructure, object orientation became a medium that carries information over to each line of code. This allows me, as a programmer, to fully exploit the computer’s functionality and create iterations and/or repetitions of objects on the fly.

An intergalactic dance party created with objects:

Click here to see the full sketch.

Image for post
Image for post

To learn more about the capability of objects, I was asked to create a dance party with class and objects. Inspired by Dua Lipa’s music video, I decided to create an intergalactic dance party with some rotating and flying stars and, of course, a disco ball.

Image for post
Image for post
Screenshot from the music video of ‘Hallucinate’ by Dua Lipa
Image for post
Image for post

Since I have made stars with vertex and for loop before, I decided to first create a class for the yellow rotating stars. Thinking that this step should be relatively easy, I first struggled with not being able to transform and rotate the stars. No matter what function I put inside of the class, nothing happens. Thankfully, with some help from Scott, I realized that I had packed everything into the constructor, which explained my issue with the transform() function.

After fixing my class and got the stars up and running, I started working on my background, which consists of stars flying towards the screen. To make this background, I referenced this video from the Coding Train. I first created a class that will draw a tiny white ellipse, and then populated it using for loop to load and draw an array of objects. With the magical map() function, I was able to create an illusion of a 3D space where stars are directly flying towards the screen. If you want to know how exactly this object was constructed, I have more detailed comments in my sketch.

Last but not least, I drew a radiating disco ball at the center of the screen so that it looks like the stars are dancing in circles around it. I looked at the example provided by Scott and took the discoBackground() function and edited the color, amount of lines, and position to better fit my sketch. Aaaaaand voila! There you have it, an intergalactic dance party.

Some remaining problems: I wanted to use the forloop-array method to load multiple yellow stars, but somehow that messes with the translate function and makes all the stars rotating in an unexpected pattern.

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store