Week 3: broken hearts game

Inspiration

I wanted to create an easy game to see how I can use all functions, arrays, and OOP we learned during the class. The first thing that came to my mind was the game “Breakout” (1976) by Steve Wozniak.

Image result for Breakout (video game)

Since Valentine’s day is coming, I decided to connect my game with it, and breaking hearts was the most logical thing for me. So my game is the little arrow is destroying hearts on the pink circles. Cute and relevant!

Process

My plan looked like this: create circles as a class > make them randomly move > add a player with an arrow as a class > detect collisions between circles and an arrow > add score > work with the design of the game.

Let me explain in detail every step I had with problems which have arisen and solutions I’ve found.

Classes and OOP

I have 3 classes in total: “Object” which is hearts player breaks, “Player,” and “Bullets” which is an arrow (the first idea was to use bullets, and I called all variables based on that). I used “getter” and “setter” functions to be able to use and manipulate class variables outside of the class.

Random movement

Circled I created in the Object class should move randomly, and making them do so was the first problem I faced making this game. When I’ve just changed the X and Y coordinates, they all moved in the same direction, even though they were allocated randomly on the canvas. The next thing I used was the direction variable, but I couldn’t find a way to randomly change its value between 1 and -1. To make this movement possible, I modified this code. I included variables such as speed, direction, position for both X and Y coordinates, and angle with the offset of the object. Using angle and its sine with cosine functions allowed me to do a random movement.

Collisions and Score

The next problem I had was making bullets “collide” with the objects aka circles. To do it I used an ArrayList of Object class objects (read about them here and here), so I used it for a loop every time I wanted to use a function with an array list.

for (int i=0; i<objects.size(); i++) {
    objects.get(i).RunProgram();
  }

Then, after the program detects collision (with if statement), it removes the object which collided and adds 1 point to the score variable.

for (int i=0; i<objects.size(); i++) {
    
  Object o = objects.get(i);
  if (dist(b.getBulletX(),  b.getBulletY(), o.getObjectPosX(), o.getObjectPosY()) <= b.getBulletRadius() + o.getObjectRadius()) {
    objects.remove(i);
    score++;
  }
  }

Design

As I said before, I decided to make this game in Valentine’s day theme, so I just added an image of the heart to the circles I had before and painted them different shades of pink. I also added a score in the upper left corner to make the interface look more friendly.

void DrawObject() {
    fill(objectColor);
    noStroke();
    circle(posX, posY, objectRadius*2);
    imageMode(CENTER);
    image(img, posX, posY, objectRadius*1.5, objectRadius*1.5);
  }

Result

Code

You can find code here: https://github.com/Alima2104/week-3 

Week 2: Life Under the Palm Trees

Inspiration:

I was sitting near the library when I looked out the window and saw palm trees. I associate them with this place, with summer, with happiness. I remembered how we decided to count them with my friend when we first arrived, and that there are exactly 36 palms. I liked the geometrical arrangement of palms, so I decided to use them as inspiration for my artwork.

 

 

 


 

Process:

I stylized the palms into swirling lines of varying heights using the random function and the for loop to arrange these strokes into a circle. To make them dynamic, I used the rotate function. In order to understand how they work, I watched this video-tutorial.

I divided the screen into identical rectangles, I used two for loops, placed the spinning palms and their trunks in the form of circles there.

It was necessary to do something with the background, and I wanted to add an interactive part. I watched this video to understand how it works. I decided to make a pattern using arc functions, which, if reduced, resembles a tile on the ground, and if increased, it looks like benches located under palm trees. The way the size changes seemed very symbolic to me, and that’s why I called this work “Life under the palm trees”.


Result:


Code:

//ART WORK

float arcSize = 80;
float yStep = 100;


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

void draw() {
  
  background(224, 224, 224);

  mouseX = constrain(mouseX, 10, width);
  mouseY = constrain(mouseY, 10, height);

  yStep = mouseY;
  arcSize = mouseX;

  noFill();
  stroke(160, 160, 160);
  strokeWeight(5);

  for (int y=0; y<height; y+=yStep) {
    for (int x=0; x<width+arcSize; x+=arcSize) {
      arc(x, y, mouseX, mouseY, 0, TWO_PI);
    }
  }
  
 //grid 

  for (int i=-50; i<width+50; i+=100) {
    for (int j =-50; j<height+50; j+=100) {
      noStroke();
      rectMode(CENTER);
      rect(i, j, 100, 100);
      fill(153, 76, 0);
      ellipse(i, j, 20, 20);
      noFill();
      pushMatrix();
      translate(i, j);
      scale(0.25);

  //palms 

      stroke(76, 153, 0);
      for (int a=0; a<360; a+=1) {
        float x = random(30, 80);
        float y = random(80, 130);
        pushMatrix();
        rotate(radians(a));
        strokeCap(ROUND);
        strokeWeight(4);
        line(x, 0, y, 0);
        popMatrix();
      }
      popMatrix();
    }
  }
}

 

Alima’s self-portrait

This week I finished my first assignment of this class – making a self-portrait using Processing. During the class, we played with shapes and even tried to draw the simplest version of the face using geometrical figures such as circles, rectangles, and ellipses. For this assignment, I’ve decided to take it to the next level and attempted to make a cartoon version of myself.

I started by researching the proportions of a human’s face so the drawing would look like me.

Then, I made few sketches of the portrait and decided on the color scheme. [I won’t put them here because they are messy]

The final version is here. I added blush to my cheeks, and the color changes to more intense when the mouse points to it. Also, the hairstyle and eye shape resemble me. For the background, I asked my friends to choose the color they associate with me, and they chose this shade of purple.

 

Most of the time I used beginShape() and endShape() to draw any shape I needed and to be able to color it with fill(). bezierVertex() and bezier() helped to draw curves with appropriate parameters. I used strokeWeight() to change the width of some lines and emphasize my eyes.

Code:

void setup() {

  size(640, 460); //width, height

}

void draw() {  //looping 
  int faceCenterX=width/2;
  int faceCenterY=height/2-50;
  background(204, 153, 255);

  stroke(51, 25, 0);
  //line(width/2, 0, width/2, height); //main axis
  //line(0, faceCenterY, width, faceCenterY);

  //hair
  fill(51, 25, 0); //hair color
  beginShape();
  vertex(faceCenterX-140, faceCenterY+150);
  bezierVertex(faceCenterX-170, faceCenterY-270, faceCenterX+170, faceCenterY-270, faceCenterX+140, faceCenterY+150);
  endShape();

 //neck
  fill(255, 229, 204);
  beginShape();
  vertex(faceCenterX-60, faceCenterY+40);
  bezierVertex(faceCenterX-50, faceCenterY+140, faceCenterX-50, faceCenterY+180, faceCenterX-120, faceCenterY+180);
  bezierVertex(faceCenterX-100, faceCenterY+200, faceCenterX+80, faceCenterY+200, faceCenterX+120, faceCenterY+180);
  bezierVertex(faceCenterX+50, faceCenterY+180, faceCenterX+50, faceCenterY+140, faceCenterX+60, faceCenterY+40);
  endShape(); 
  
  //longsleeve
  fill(153, 255, 229);
  beginShape();
  vertex(80, height);
  bezierVertex(100, height-50,100, height-50,faceCenterX-120, faceCenterY+180);
  bezierVertex(faceCenterX-100, faceCenterY+200,faceCenterX+80, faceCenterY+200, faceCenterX+120, faceCenterY+180);
  bezierVertex(width-100, height-50, width-100, height-50, width-80, height);
  endShape();

  //face
  fill(255, 229, 204); //skin tone
  beginShape();
  vertex(faceCenterX-100, faceCenterY-10);
  bezierVertex(faceCenterX-100, faceCenterY-200, faceCenterX+100, faceCenterY-200, faceCenterX+100, faceCenterY-10);
  bezierVertex(faceCenterX+140, faceCenterY-50, faceCenterX+140, faceCenterY+30, faceCenterX+100, faceCenterY+40);
  bezierVertex( faceCenterX+30, faceCenterY+170, faceCenterX-30, faceCenterY+170, faceCenterX-100, faceCenterY+40);
  bezierVertex(faceCenterX-140, faceCenterY+30, faceCenterX-140, faceCenterY-50, faceCenterX-100, faceCenterY-10);
  endShape();

  //bangs
  fill(51, 25, 0); //hair color
  beginShape();
  vertex(faceCenterX-100, faceCenterY-10);
  bezierVertex(faceCenterX-40, faceCenterY-30, faceCenterX, faceCenterY-70, faceCenterX, 40);
  bezierVertex(faceCenterX, faceCenterY-70, faceCenterX+40, faceCenterY-30, faceCenterX+100, faceCenterY-10);
  bezierVertex(faceCenterX+100, faceCenterY-200, faceCenterX-100, faceCenterY-200, faceCenterX-100, faceCenterY-10);
  endShape();

  //eyes
  //left eye 
  beginShape();
  fill(255);
  vertex(faceCenterX-30, faceCenterY);
  bezierVertex(faceCenterX-40, faceCenterY+12, faceCenterX-60, faceCenterY+12, faceCenterX-75, faceCenterY);
  bezierVertex(faceCenterX-50, faceCenterY-12, faceCenterX-40, faceCenterY-12, faceCenterX-30, faceCenterY);
  endShape();


  fill(128, 94, 94);
  strokeWeight(1);
  circle(faceCenterX-50, faceCenterY, 16);
  fill(1, 1, 0);
  circle(faceCenterX-50, faceCenterY, 9);

  //eye makeup
  noFill();
  strokeWeight(3);
  bezier(faceCenterX-30, faceCenterY, faceCenterX-40, faceCenterY-12, faceCenterX-50, faceCenterY-12, faceCenterX-75, faceCenterY); 


  strokeWeight(1);
  //right eye
  beginShape();
  fill(255);
  vertex(faceCenterX+30, faceCenterY);
  bezierVertex(faceCenterX+40, faceCenterY+12, faceCenterX+60, faceCenterY+12, faceCenterX+75, faceCenterY);
  bezierVertex(faceCenterX+50, faceCenterY-12, faceCenterX+40, faceCenterY-12, faceCenterX+30, faceCenterY);
  endShape();

  fill(128, 94, 94);
  circle(faceCenterX+50, faceCenterY, 16);
  fill(1, 1, 0);
  circle(faceCenterX+50, faceCenterY, 9);


  //eye makeup
  noFill();
  strokeWeight(3);
  bezier(faceCenterX+30, faceCenterY, faceCenterX+40, faceCenterY-12, faceCenterX+50, faceCenterY-12, faceCenterX+75, faceCenterY);


  strokeWeight(1);
  //eye brows
  beginShape();
  fill(51, 25, 0);
  vertex(faceCenterX-30, faceCenterY-20);
  bezierVertex(faceCenterX-35, faceCenterY-30, faceCenterX-60, faceCenterY-35, faceCenterX-80, faceCenterY-20);
  endShape();

  beginShape();
  fill(51, 25, 0);
  vertex(faceCenterX+30, faceCenterY-20);
  bezierVertex(faceCenterX+35, faceCenterY-30, faceCenterX+60, faceCenterY-35, faceCenterX+80, faceCenterY-20);
  endShape();

  //nose
  noFill();
  stroke(51, 25, 0);
  bezier(faceCenterX-15, faceCenterY+40, faceCenterX-5, faceCenterY+50, faceCenterX+5, faceCenterY+50, faceCenterX+15, faceCenterY+40);

  //mouth
  fill(255, 153, 153);
  stroke(255, 102, 102);
  beginShape();
  vertex(faceCenterX-30, faceCenterY+80);
  bezierVertex(faceCenterX-15, faceCenterY+70, faceCenterX-10, faceCenterY+70, faceCenterX, faceCenterY+75);
  bezierVertex(faceCenterX+10, faceCenterY+70, faceCenterX+15, faceCenterY+70, faceCenterX+30, faceCenterY+80);
  endShape();

  beginShape();
  vertex(faceCenterX+30, faceCenterY+80);
  bezierVertex(faceCenterX+20, faceCenterY+90, faceCenterX-20, faceCenterY+90, faceCenterX-30, faceCenterY+80);
  endShape();

  //blush
  noStroke();
  fill(255, 185, 185);
  circle(faceCenterX-70, faceCenterY+50, 40);
  circle(faceCenterX+70, faceCenterY+50, 40);
  
  
  //extra blush
  if (mouseX > faceCenterX-110 && mouseX < faceCenterX-30){
    if (mouseY > faceCenterY+10 && mouseY < faceCenterY+90){
      fill(255, 102, 102);
      circle(faceCenterX-70, faceCenterY+50, 40);
      circle(faceCenterX+70, faceCenterY+50, 40);
    }
  }
    
  if (mouseX > faceCenterX+30 && mouseX < faceCenterX+110){
    if (mouseY > faceCenterY+10 && mouseY < faceCenterY+90){
      fill(255, 102, 102);
      circle(faceCenterX-70, faceCenterY+50, 40);
      circle(faceCenterX+70, faceCenterY+50, 40);
    }
  }

   
}

Even though I hard-coded numbers, I did it based on my faceCenter X and Y coordinates. In future work, I will avoid hard-coding. This assignment has shown me how useful https://processing.org/ site is and that there are many interesting things available in processing. Now I’m inspired to know how to use them!