NOC – Week 3: Vectors – Katie Pellegrino

Assignment 3

UPDATED ASSIGNMENT 🙂

Link to Assignment

For assignment 3, I tried experimenting with classes and vectors. However, much of the code I couldn’t quite get to work. I think I’m still confused of the best approach between when it’s important to define a method within a class, when to define a new function, or when to simply write a few lines within the draw function. So using the best tactics in coding still confuses me a bit, but practice should help!

For this I defined a particle class made up of square objects. Each object is assigned position, velocity, and acceleration as vectors along with assigned size, rotation speed, scale factor, and color. The program initially creates an object every frame until it reaches 100. At first the objects are simply drawn and rotate in place wherever they are randomly generated. Then, after a mouseClick(), the objects update by adding velocity to their position. After the next mouseClick(), the objects update with acceleration added to the velocity. However, as we did in class, the acceleration must be recent each iteration so it’s not continuously increasing. Finally, after another mouseClick(), I remove acceleration and the objects begin to fluctuate size. 

Throughout, the edges are checked with a simple bounce() method, however, I also wanted to do something fun with color here. So, initially, the objects are assigned random colors in the blue spectrum (setting b value of rgb to 255 and ther est to random). But when they hit a wall, the objects update with a new color in the red spectrum (setting r value to 255, rest to random).

Additionally, I tried adding a rift. So that when the mouseY matches that of the object, the object expands. Additionally, I wanted to add a second class of circle objects that appear after the third click. Finally, I still wanted to try and connect the objects with lines if their distance was close enough to each other. But I still need to practice the distance function more to fully understand it.  

Overall, I have a much better understanding of vectors and they significantly simplify the logic of creating visuals.

UPDATE

The updated program adds an additional 4th update function that first reduces the particles to a uniform size before applying acceleration towards the direction of the mouse.

Leave a Reply