p5.js exercise: an Object with functions

Reminder: all of my p5.js exercises are available here.

This week in creative coding our assignment was to put together a piece of art, game or other coding project that included at least one object with two functions. I decided to create a simple game with a Venus Fly Trap “eating” flies as they go by. The greatest challenge in this assignment, it turns out, wasn’t working with objects (in this case, each fly was an instance of the FlyBug object) but instead simply manipulating the angles that made up the ‘mouth’ of the plant!

screenshot of plant game

The arcs were challenging because of the way rotating shapes works in p5.js. I wanted the top of the venus fly trap to open and close to eat the flies, but when I rotated the top arc, it would turn in relationship to the 0,0 point of the entire canvas, not the corner of the shape itself. In the end the solution was to draw the shape at the 0,0 point, rotate it, and then translate it to the correct location.

Moving forward there are many possibilities that I could follow to expand on the game. For example, I could add more directions for the flies to travel, and have them move in irregular patterns instead of a straight line left to right. I could also expand on the game aspect of the project by adding a way to win the game, or maybe by making the plant grow as it eats more flies. It would be fun to add more controls, where different keys being pressed would influence the game in different ways.

This project was an exciting one to complete, because many things that I have learned in Creative Coding came together in one project, including interactivity, objects, functions, and randomness. My goal for the coming weeks is to incorporate more patterns and paths that mimic nature into my project, instead of sticking to straight lines and right angles. For example, I had the thought for this venus fly trap project to include roots in the plant drawing, but I wasn’t able to recreate them in a convincing, nature-mimicking way. For the next project, I hope to introduce at least a little bit of irregularity in the shapes and lines.

Until then, I’m enjoying playing with my venus fly trap game!

Leave a Reply

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