For my Creative Coding class, I must create a P5.js sketch that keeps track of user actions via arrays and objects. What does that mean? In programming, an object is a bundle of characteristics and methods that are defined by the programmer. An array is a data structure that allows the programmer to store a collection of any data, including Objects.
In the spirit of Halloween, I would like to create a program that lets a user smash pumpkins in a satisfying way. I have already created a sketch where pumpkin emojis bounce around and each pumpkin’s characteristics are stored and called upon.
I set an arbitrary number of pumpkins, and then, I ran a for loop for that number of times and created a new Pumpkin object. The draw() function in P5 will keep generating that For Loop. The mousePressed() function I defined will allow users to click on a pumpkin (tracking their mouse position in relation to the object’s) and remove it from the array, thereby removing it from the screen. If all pumpkins get removed, 10 new pumpkins will generate.
I have my basic idea laid out in code, but next week, I want to animate this sequence more realistically. How can I make a pumpkin look like it’s being cracked and smashed with code?
Update: I have been told to use the CreateGraphics() function by my professor, John Henry Thompson. I will use that as an investigation to 3D animation. Also, shoutout to my classmate, Beatrice, who showed how to load images into p5 with her sketch. Check out my cool looking pumpkins now!

Leave a comment