Mini Project 6: Particle World
Project Link
https://king-raphael.github.io/CClabProjects/11.7/
Brief Description and Concept
In this interactive visual sketch, the user experiences an imaginative scene where the mouse acts as an arrow slicing through the blackness of the night sky. As it moves, it leaves behind a luminous trail resembling a shooting star, accompanied by bubble-like particles that scatter outwards, simulating an ethereal explosion. This project was inspired by natural night-time phenomena, merged with abstract artistic elements, and is developed using Object-Oriented Programming (OOP) principles.
Visual Documentation
Coding
Draw Function:
- Background: Sets the canvas background color to black.
- Object Creation: Adds new
Trail
andBall
objects at the current mouse position. - Lifecycle Management: Removes objects whose lifespan has ended.
Ball class:
- Properties: Position (
x
,y
), color, diameter, speed, lifespan. - Methods: Custom color assignment, movement, age control, boundary checks, and display logic.
Trail Class:
class Trail { constructor(x, y) { this.x = x; this.y = y; this.lifespan = 1.0; this.lifeReduce = 0.02; this.isDone = false; } age() { this.lifespan -= this.lifeReduce; if (this.lifespan <= 0) this.isDone = true; } display() { stroke(lerpColor(color(255, 255, 255), color(100, 100, 255), 1 - this.lifespan)); strokeWeight(2); noFill(); line(this.x, this.y, pmouseX, pmouseY); } }
Behavior: Gradually fades out and disappears, creating a dynamic tail.
Findings / Lessons Learned
- Mastery in integrating OOP with visual arts.
- Importance of lifecycle management for performance optimization.
Reflection Prompts
- What is Object-Oriented Programming (OOP), a Class and an Instance of the Class? Object-Oriented Programming (OOP) is a programming paradigm that organizes code into objects containing properties (attributes) and methods (functions). A class is a blueprint for creating objects (instances) that share common properties and methods. An instance of a class is an actual object created from that class.
- Discuss the effectiveness of OOP. When is OOP useful? In what way can it be utilized? OOP is effective in scenarios where modularity, code reusability, and maintainability are essential. It is useful for complex projects that involve multiple components or objects that share similar characteristics. By using classes, programmers can encapsulate data and behaviors, making code more structured and scalable.
- Describe the objects you have created. What properties and methods were implemented? What kind of behaviors did you create by manipulating them? In this project, two main objects were created:
Ball
andTrail
. TheBall
object has properties such asx
,y
,color
,diameter
,xSpeed
,ySpeed
,lifespan
, andlifeReduce
. It includes methods for movement, aging, boundary checks, and display. TheTrail
object has propertiesx
,y
,lifespan
, andlifeReduce
, with methods for aging and displaying the trail. These objects exhibit behaviors like gradual fading, movement, and lifecycle-based disappearance. -
Please share if there is any challenging and confusing aspect(s) in the OOP concepts and techniques. One of the challenges faced was managing the lifespan of objects to create a natural fade-out effect without abrupt transitions. Balancing object removal logic and understanding the interactions between different objects’ lifecycles also posed initial difficulties, but reinforced the importance of methodical planning in OOP.