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);

  }
}

 

 

 

 

 

 

 

Self Portrait – Week 1

This is my self-portrait.
My first thought was about which shapes to use to create the hair. My initial plan was to use lines, but then I was worried that filling out the final hair shape would become an issue. So, after some research, I found the beginShape() and endShape() method using vertices.
I proceeded to sketch out a rough desired shape on a piece of paper (as shown below),

then went on to coding and figuring out where each vertex should be.
This included a lot of hardcoding and needed a lot of messing around with the positions, but it was, in my opinion, easier to hardcode in this case specifically, since there were a lot of points/vertices to consider.
The shape I started with was the hair. The head shape (ellipse) and neck(rectangle) followed, and then I added another shape to cover the top of the head with more hair.
I kept the background, the eyes, mouth, and nose simple, by using basic shapes and colors. And I finally decided to add some “animation”, by making each eye close or the mouth smile if the mouse pointer hovers over them.

void setup(){
  size (400,400);
}

void draw(){
  //background color
  background(0,153,153);
  
  //drawing the hair first to be on the bottom layer
  fill(53,36,23);
  stroke(0);
  strokeWeight(1.5);
  beginShape();
  vertex(222,76);
  vertex(192,50);
  vertex(130,48);
  vertex(40,126);
  vertex(68,122);
  vertex(58,174);
  vertex(82,208);
  vertex(57,250);
  vertex(57,350);
  vertex(310,350);
  vertex(310,204);
  vertex(329,225);
  vertex(314,114);
  vertex(270,74);
  vertex(222,76);
  endShape();
  
  //drawing the face shape and the neck
  fill(208, 167, 136);
  stroke(0);
  strokeWeight(1.5);
  rect(175,170,45,160);
  ellipse(190,180,160,200);
  
  //drawing the hair piece to cover the top of the head
  fill(53,36,23);
  noStroke();
  beginShape();
  vertex(110,79);
  vertex(110,170);
  vertex(205,115);
  vertex(280,170);
  vertex(277,79);
  endShape();
  
  //drawing the nose:
  stroke(0);
  strokeWeight(3);
  noFill();
  line(180, 210,178,220);
  line(178,220,188,220);
  
  //drawing the mouth without a smile:
  strokeWeight(5);
  stroke(205, 115, 115);
  line(180, 245, 200, 245);
  //making the mouth smile:
  if (mouseX > 180-5 && mouseX < 200+5){
    if (mouseY > 245-5 && mouseY < 245 +5){
      //this covers the previous mouth with the skin color
      strokeWeight(5);
      stroke(208, 167, 136);
      line(180, 245, 200, 245);
      //this draws on the new smile
      strokeWeight(5);
      stroke(205, 115, 115);
      bezier(170,240,180,250,215,240,215,240);
    }
  }
  
  //drawing the eyes open:
  noStroke();
  fill(255);
  ellipse(160, 180, 35, 35);
  ellipse(220, 180, 35, 35);
  fill(155, 115, 84);
  ellipse(160, 180, 23, 23);
  ellipse(220, 180, 23, 23);
  noStroke();
  fill(0);
  ellipse(160, 180, 10, 10);
  ellipse(220, 180, 10, 10);
 
  //closing the left eye:
    if(mouseX > 160-(35/2) && mouseX < 160+(35/2))
  {
    if(mouseY > 180-(35/2) && mouseY < 180+(35/2))
    {
      //this covers the previous open eye
      fill(208, 167, 136);
      ellipse(160, 180, 38, 38);
      //this draws on the closed eye
      strokeWeight(5);
      stroke(0);
      line(150, 180, 170, 180);
    }
  }
  //closing the right eye:
  if(mouseX > 220-(35/2) && mouseX < 220+(35/2))
  {
    if(mouseY > 180-(35/2) && mouseY < 180+(35/2))
    {
      //this covers the previous open eye
      fill(208, 167, 136);
      ellipse(220, 180, 38, 38);
      //this draws on the closed eye
      strokeWeight(5);
      stroke(0);
      line(210, 180, 230, 180);
    }
  }
}