Assigment 3 – Functions, Arrays, and Object-Oriented Programming

Idea and Inspiration:

My piece of art aims to create an interactive garden where viewers can witness blossoming flowers and fluttering butterflies. I love nature and I wanted to make a tribute to gardens. At home, my mom and I spend hours working in the garden, it is our bonding time. This project is inspired by nature and the delight of immersing in the sensory experiences of a tranquil garden.

Code that I am proud of: 

grow() {
  if (!this.fullGrown) {
    this.size += this.growthRate;
    if (this.size >= 90) {
      this.fullGrown = true;
followMouse() {
   if (mouseIsPressed) {
     let angle = atan2(mouseY - this.y, mouseX - this.x);
     this.vx = cos(angle) * 3;
     this.vy = sin(angle) * 3;

 

Sketch: 

Difficulties: 

First of all, it was complicated to get the classes in order. It was not working as they were all in random positions. I had to change the names to numbers so that it was in the correct order.

Secondly, I wanted the flower to expand. So I searched in the internet the function to do it. “https://editor.p5js.org/amcc/sketches/3ZLqytY_4”

Thirdly, I wanted to do something interactive with the MousePress option. These lines of code use the atan2() function to determine the angle between the butterfly’s current position and the location of the mouse pointer. Next, they calculate the velocity vector’s horizontal and vertical components using the trigonometric functions cos() and sin(). These results are scaled by a factor of three to determine the butterfly’s speed as it follows the mouse pointer.

followMouse() {
   if (mouseIsPressed) {
     let angle = atan2(mouseY - this.y, mouseX - this.x);
     this.vx = cos(angle) * 3;
     this.vy = sin(angle) * 3;

Improvements: 

I am pretty proud of the work. I spend a lot of time figuring everything out. For improvements, I would like the butterflies to look more real. Adding stripes inside the body.

I think it would also be cool if the flowers after a certain amount of time they disappeared.

 

Leave a Reply