Week 3 : Object Oriented Programming

Originally, I wanted to make the game ‘Space Invaders,’ but with my own kind of twist. I planned to get all the objects working before i look through my digital art designs to see any recurring themes i could implement into the game.

Starting with the set of ‘aliens,’ I initially created a for loop inside a foor loop to create a grid of ‘aliens’ that randomly moved in a uniform manner. The plan was that the bottom row of the ‘aliens’ would be shooting at the players’ character. The player had to miss all the bullets, and also shoot back at the ‘aliens’ to kill them.

After doing the grid, finally getting them to randomly move in a uniform manner, and also getting the player to move their character left to right, I was at a dead end. I had so many bugs, obstacles, and things that I wasn’t sure about. I believe if I had more time, I could have solved it, but I still wanted a working game, so I decided to change it.

After letting my original plan go, I decided to do the basic pong- game. Where balls are falling in random order, and the goal is to catch it with your slider. It took some time for me to transition from the original code to the new one, but I finally reached a conclusion where my game was working. Ideally I could add a time limit and a score, but I guess it would just have to wait till later.

I still faced some difficulties, especially figuring out how to get the ball to bounce back from only the slider, but managed to do it. My only obstacle now is actually playing the game – It appears I’m really bad at it, so forgive me in the video. !

// Calling the player class
Player player;
 
// calling the shooter class as an array
Shooters [] shooters ;


  void setup(){
    size (1000,1000);
    ellipseMode (CENTER);
    shooters = new Shooters [20];
    player = new Player ();
    
    // creating a for loop to create an array of shooters
    for (int i = 0; i<10; i ++){
      shooters [i] = new   Shooters (); 
  }
  }
  
  void draw (){
    background (0, 0, 0);
    player.drawPlayer ();
    player.checkEdge();
    // creating a for loop for the shooters 
    for (int i = 0; i<10; i ++){
      shooters[i].drawShooters();
      shooters[i].update ();
      shooters[i].checkEdge();
    keyPressed();
  }
  }
  
  // to be able to move the rectangle
  void keyPressed (){
    if (keyPressed && keyCode == LEFT) {
      player.playerSpeed = -3;
      player.update();
    }
    
     if (keyPressed && keyCode == RIGHT) {
      player.playerSpeed =3;
      player.update();
 
    }
 
  }
  //////////////////////////////
// Tab Player
class Player {
  float playerX, playerY, w, h; 
  float playerSpeed;
  
  Player(){
    playerX = width/2;
    playerY = height - (height/6);
    w = 100;
    h = 25;
    
  }
  
  void drawPlayer (){
    noStroke();
    fill (255, 255, 255);
    rect (playerX, playerY, w, h);
  }
  
  void update (){
    playerX += playerSpeed;
  }
  
  
  // Honestly, this didnt work. I tried to make the rectangle stop when it reached the edge. 
    void checkEdge (){
    if (playerX > width - 100){
      print("stop");
      playerSpeed = 0 ;
      update();
    }
    }
  

  }
////////////
//Tab Shooters
class Shooters {
  float shootersRadius;
  float locX, locY;
  float y, x, xspeed, yspeed;
  
  // creating the shooters and having them move at a different speed each time
  Shooters(){
    x = 0;
    y = 0; 
    xspeed = random (3,5); 
    yspeed = random (1,3);

  
  }
  
    void update (){
      x = x + xspeed; 
      y = y + yspeed; 
      }
  
  void checkEdge (){
 
    // setting the dimensions
   if (x > width || x <0 ) {
     xspeed = xspeed* -1;
   }
   if ( y < 0 ) {
     yspeed = yspeed*-1;
  }
// creating the boundaries for the rectangle (if it hits the rectangle it bounces)
  if ( y > player.playerY && y < width){
    if (x > player.playerX && x < player.playerX + player.w) {
      xspeed = xspeed* -1;
    yspeed = yspeed*-1;
    }
  }
  }
  
  void drawShooters(){
    noStroke();
    fill ( 255, 215, 0);
    circle ( x, y, 32 );
  }
    }

 

Week 2: ArtWork using For loops

 

My inspiration came from the moving rectangles we drew in class. there was something calming about watching the rectangles move. I knew I wanted to do either an ocean or wave theme, where it would be kind of calming to watch. Although I didn’t have an initial sketch of exactly what I wanted my art to look like, I had an idea. I wanted something with moving triangles as well as overlapping objects.

After doing some reasearch on kinds of images or shapes I could use, I found a 3D sphere which I thought would be perfect. After spending sometime figuring out how to rotate it, and adjusting it to my screen, I ended up with this. 

This was actually a really interesting movement of art. Because I liked it so much, I was set out to create a smaller solid sphere to insert inside, and rotate the other way, so It felt like a energy source. However, I later decided I wanted to stick with my original theme of the ocean and work with that.

When creating a custom moving gradient background failed, I decided to find an image online, and rotate it to look like the water was moving. I made sure to rotate the image in the opposite way. When adding a full image, a lot of the details and sides of the sphere go missing (as shown in the final art) because of the Z coordinates. Although this was heart breaking for me, it was almost perfect to what I had envisioned earlier. I still wish to pursue the ‘ball of energy’ art model, but hopefully that will be for another time.

int w = 8;
int seed = 0 ;
int rectWidth = 8;
float m;
PImage photo;

void setup() {
  size(640, 640, P3D);
  rectMode(CENTER);
  photo = loadImage("OceanTheme.jpg");
  photo.resize(800,800);
}
void draw(){
  background(255); 
    pushMatrix();
      translate(width/2, height/2);
      rotate(m);
      imageMode(CENTER);
      image(photo, 0, 0);
    popMatrix();
    m-=0.001;
  

  for (int i = 0; i<width; i+=15) {
      float amplitude2 = TWO_PI;
      float speed2 = .005;
      float granular2 = 0.001;
      float freq2 = (frameCount*speed2) + (i * granular2);
      float angle2 = noise(freq2);
       pushMatrix();
        translate(height/2, width/2, -200);
        rotate(angle2);
        noFill();
        stroke(0, 0, 0);
        strokeWeight(1.5);
        sphere(500);
      popMatrix();
 }
}




 

Week 1: Self Portrait

Starting this self portrait was easy. I started off with a rouned rectangle to create the top half of my face, then added an ellipse at the bottom, to closely resemble my face shape.

Moving on to the eyes, I added two ellipses in their respected positions, then added irises, pupils, and my personal favorite, small white circles for highlights. I made the eyes looking to the right to reduce the creepiness of the image, because I’m not sure someone could stomach having this portrait directly staring at them.

I had greater aspirations for the nose, but unfortunately had to settle for two lines that meet to form a pointed nose, as well as the mouth. It was a bit of a hassle trying to understand the arc enough to create a mouth shape, but I finally managed to get it. In my defense, I haven’t taken math in a long time, and was a bit rusty on how pi and radians worked.

Lastly, I had to figure out how to do my hair. After a lot of research, the most I could settle for was creating a sine curve four times. I found a template code online (Cited in the code) on how the sine code was translated to sketch and had to spend some time playing around with it so I could fix the curves and position. After doing this, I was very happy with my curls, but scared for my life, because this was how it looked:

I was determined to keep some curls in, so I decided to add a sort of background hair, and create some bangs. I fiddled with some arcs and pulled out a protractor and finally created some bangs. I also messed around with some rectangle shapes to create a more cohesive bang and background. This leaves the curly strands looking like highlights. It still looks strange, but less creepy, i’ll say.

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

void draw (){
  
  
  // hair- background
    //hair, the background
  stroke(105,80,45);
  fill(105,80,45);
  rect(125, 100, 250, 275, 150, 150, 50, 50);
  
  //drawing the face
  //pushStyle();
  noStroke();
  fill(224, 172, 105);
  rect(150, 100, 200, 200, 150, 150, 50, 50);
  fill(224, 172, 105);
  ellipse( 250, 250, 200, 275);
  //noStroke();
  //popStyle();
  
  // drawing the eyes
    //  white part
  fill(255, 255, 255);
  ellipse(200, 225, 50, 30);
  ellipse(300, 225, 50, 30);
  // iris
  fill(50,30,20);
  ellipse(207, 225, 28, 28);
  ellipse(307, 225, 28, 28);
  //pupil
  fill(0,0,0);
  ellipse(207, 225, 18, 18);
  ellipse(307, 225, 18, 18);  
  //highlight
  fill(255,255,255);
  ellipse(202, 220, 5, 5);
  ellipse(302, 220, 5, 5);  
  
  //attempting the nose
  stroke(112,86,53);  
  strokeWeight(3);
  //arc(250, 250, 20, 30, 50, QUARTER_PI);
  line(255, 245, 270, 275);
  line(270, 275, 255, 277);
  
  //mouth
  noFill();
  arc(250, 310, 80, 60, 0, PI);
 
  // hair -- bangs
  fill(105,80,45);
  stroke(105,80,45);
  rect(160, 100, 180, 50, 600, 300, 0, 0);
  stroke(112,86,53);
  strokeWeight(30);
  noFill();
  arc(335, 100, 160, 120, HALF_PI, PI);
  arc(150, 100, 160, 120,radians(0), radians(90));
  
  // hair -- Trying to make it curly
  // Citation; got this from a online discussion, edited it to make it horizontal 
  //https://stackoverflow.com/questions/2395434/create-a-sin-wave-line-with-processing
  strokeWeight(30);
  float a = 0.0;
  float inc = TWO_PI/25.0;
  float prev_y = 150, prev_x = 130, y, x;

  for(int i=0; i<100; i=i+4) {
    y = i +150;
    x = 130 + sin(a) * 30.0;
    line(prev_x, prev_y, x, y);
    prev_x = x;
    prev_y = y;
    a = a + inc;
  }
    
      strokeWeight(30);
  float prev_yy = 250, prev_xx= 130;

  for(int i=0; i<100; i=i+4) {
    y = i +250;
    x = 130 + sin(a) * 30.0;
    line(prev_xx, prev_yy, x, y);
    prev_xx = x;
    prev_yy = y;
    a = a + inc;
  } 
  float prev_yyy = 160, prev_xxx = 380;

  for(int i=0; i<100; i=i+4) {
    y = i +160;
    x = 380 + sin(a) * 30.0;
    line(prev_xxx, prev_yyy, x, y);
    prev_xxx = x;
    prev_yyy = y;
    a = a + inc;
  }
    
      strokeWeight(30);
  float prev_yyyy = 260, prev_xxxx= 380;

  for(int i=0; i<100; i=i+4) {
    y = i +260;
    x = 380 + sin(a) * 30.0;
    line(prev_xxxx, prev_yyyy, x, y);
    prev_xxxx = x;
    prev_yyyy = y;
    a = a + inc;
}



  
  
}