Categories
creative coding lab

Mini Project6: Particle World

Blue Tears

https://calistalu.github.io/ParticleWorld/
https://editor.p5js.org/calistalu/sketches/X0MrgBfje

Brief Description and Concept

I got my inspiration from the splendid natural phenomenon, which has an extremely romantic name: blue tears. It occurs particularly in bays and coastal areas, when certain types of microorganisms in the water emit a blueish glow when disturbed by movement or waves, creating a stunning visual display of blue light at night. 

Demo/Visual Documentation

Coding

for (let i = 0; i < others.length; i++) {
if (i !== particles.indexOf(this)) {
if (this.ron == others[i].ron) {
let distance = this.y - others[i].y;
if (distance > 100) {
this.shouldSlowDown = true;
break;
} else {
this.shouldSlowDown = false;
}
}
}
}

if (this.shouldSlowDown) {
this.spd -= 0.1;
this.spd = constrain(this.spd, 1, 2);
} else {
this.spd = 2;
}
}

the original version

Initially, I had this part of code that measures the distance between each particle and all others. If a particle moved too far away, it would be slowed down, simulating the effect of sea waves. I was thrilled to achieve this interaction between objects. However I later came up with a more beautiful and satisfactory pattern: 

update() {
this.y1 = sin(600 * this.movex1) * 10;
this.y2 = cos(400 * this.movex2) * 30;
this.movex1 += 0.0001;
this.movex2 -= 0.0001;
this.y = this.y1 + this.y2 + this.y3 + 3 * sin(frameCount * 0.1);

this.ns = noise(this.yoff);
this.yoff += 0.01;
this.y3 += this.ns * this.spd;

if (frameCount % 800 == this.time) {
this.y3 = 0;
}
}

The sine wave turned out to be perfect for simulating sea waves, nothing but the parameter of this.y1 and this.y2 were determined after numerous experiments. Furthermore, I used frameCount to control the ‘lifespan’ of each wave, and I integrated the original version to simulate the falling tide.

Reflection

  1. Object-oriented programming (OOP) is to combine group of variables and related functions into a unit. A Class is a blueprint that defines the properties and the methods common to all objects constructed. An Instance of a class is a specific object created from a particular class, which has its unique properties but shares all the methods in that class.

  2. There are two fundamental benefits of OOP: modularity and reusability. All the objects can be easily modified without affecting other parts of the project, because each of these functions can be encapsulated within the class. Additionally, some facilities can be used rather than need to be built again and again. OOP is useful especially when working on a complicated project with multiple objects to organize the code.
  3. I defined two classes for two different objects, Particle1 and Particle2.  The display ( ) method uses the properties of the object to determine its color and draw it on the screen. The properties and methods of these objects are used together to create complex behaviors and interactions. Glow( ) is my favorate method because it grabs the essence of blue tears and brings life to the waves.
  4. I’m still not quite clear about how to achieve interaction between different and separate objects. If I can figure this out, I might be able to create a falling tide that begins where the sea wave disappears, and vanishes when it meets the next wave.

Leave a Reply

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