Breathe – For() loop

What I found particularly difficult with this assignment is coming up with an idea. Having a lot of freedom resulted in me not knowing where to start. As I was looking for inspiration, I came across a bunch of gifs for breathing and meditation exercises. Here are some examples.

I see these a lot online and have always found them relaxing. So, I decided to recreate the concept using loops.
After some brainstorming, I settled on using the arc function and a for() loop. Here is the process of how I got to my end result.

First, with the map function, I was able to draw an arc progressively from left to right. I then added the for() loop to get multiple arcs filling the space underneath the first one.
Within the for() loop, there are variables changing the size of the arc the further we are in the for() loop. The same thing happens to the speed of the moving arc so that the arcs don’t all get drawn at the same time.

Then, using the translate() and scale() functions, I recreated the same shape going from right to left instead. I made sure to put this block of code between the pushMatrix() and popMatrix() functions to not affect the rest of my code.

I then put the two together and changed them to different colors for visibility. I also shifted each piece 1 pixel to its side to slightly separate the two.

 

To achieve my final piece, I added slight finishing touches.
I changed the speed of the moving arcs to get a more fluid shape, and I added some colors.
I tried to mimic the colors of a sunset/sunrise with the left shape for a more relaxing feel, and I made the right shape grey to give the illusion of something filling up and then emptying out, thus mimicking the rhythm of breathing.

 

Here is my code!

void setup() {
  size(500, 500);
}
 
void draw() {
  background(0);
  //declaring variables for the colors of the arc
  float r1=51;
  float g1=102;
  float b1=154;
  color c1 = color(r1,g1,b1);
  // the speed
  float speed = frameCount*1.2;
  //the size of the ellipse of the arc
  float x= width;
  float y=height;
  
  for(int i=1 ; i<30; i++){  
    float arc1 = map(sin(radians(speed)), -1, 1, 0, 180);
    float arc2 = map(sin(radians(speed)+PI), -1, 1, 0, 180);
    //left shape
    strokeWeight(5);
    noFill();
    stroke(c1);
    arc(width/2-1, height, x, y, PI, PI+radians(arc1), OPEN);
    //right shape
    pushMatrix();
    translate(width/2,height/2);
    scale(-1,1);
    strokeWeight(5);
    noFill();
    stroke(50);
    arc(-1, height/2, x, y, PI, PI+radians(arc2), OPEN);
    popMatrix();
    //changing the size of the arcs and their speed the further we go in the for loop
    speed -=5;
    x -= 20;
    y -= 20;
    r1 += 10;
    g1 += 1;
    b1 -= 3;
    c1 = color(r1,g1,b1);

  }
}

 

 

 

 

 

 

 

Leave a Reply