Alien Snake Game

At first I wanted to go with the option of creating an artwork but I didn’t know what would count as an artwork, and satisfy the assignment requirements since a blank canvas could constitute as art. This project took me two whole days to figure out. I did a lot of research to figure out different parts of it, and I watched and followed several tutorials. I sort of created the art aspect of the project while focusing on creating a game. The purple photo is an ‘artwork’ I created while playing with placing random background color in different classes, in this case it cause what ever place that the snake passed through to remain the color of the snake (black). I wanted to do something more than the normal snake game so I experimented with colors and then decided that to make it more interesting I want to use a randomizer. I tried it with the background, which turned out horribly, then I tried it with the Snake and I really liked how it turned out. It gave me alien vibes so I named my game after it. I liked how at first because the snake is so small it just looks likes flashes but as the snake grows you can see all the colors. I really wanted the food to also be a different color each time so that it would be like the different color food is what is causing the shifting colors of the snake, but despite trying out different things, I couldn’t figure it out…

As for the code, I spent a while trying to figure out PVector and ArrayList. I also used Boolean and

int grid = 20; 
int speed = 10;
boolean dead = true;
int highscore = 0;
Snake snake;

void setup() {
  size(500, 500);
  snake = new Snake();
  food = new PVector();
  newFood();
}

void draw() {
  background(0,0,50);
  fill(200,200,200);
  if (!dead) {
    
    if (frameCount % speed == 0) {
      snake.update();
    }
    snake.show();
    snake.eat();
    fill(200,50,100);
    rect(food.x, food.y, grid, grid);
    textAlign(LEFT);
    textSize(15);
    fill(255);
    text("Score: " + snake.len, 10, 20);
  } else {
    textSize(25);
    textAlign(CENTER, CENTER);
    text("Alien snake Game\nAre you up for the challenge?\nClick to start" + "\nHighscore: " + highscore, width/2, height/2);
  }
}

void newFood() {
  food.x = floor(random(width));
  food.y = floor(random(height));
  fill( random(255), random(255), random(255), random(255));
  food.x = floor(food.x/grid) * grid;
  food.y = floor(food.y/grid) * grid;
}

void mousePressed() {
  if (dead) {
    snake = new Snake();
    newFood();
    speed = 10;
    dead = false;
  }
}



//new class tab

class Snake {
  PVector pos;
  PVector vel;
  ArrayList<PVector> hist;
  int len;
  int moveX = 0;
  int moveY = 0;

  Snake() {
    pos = new PVector(0, 0);
    vel = new PVector();
    hist = new ArrayList<PVector>();
    len = 0;
  }

  void update() {
    hist.add(pos.copy());
    pos.x += vel.x*grid;
    pos.y += vel.y*grid;
    moveX = int(vel.x);
    moveY = int(vel.y);

    pos.x = (pos.x + width) % width;
    pos.y = (pos.y + height) % height;

    if (hist.size() > len) {
      hist.remove(0);
    }

    for (PVector p : hist) {
      if (p.x == pos.x && p.y == pos.y) {
        dead = true;
        if (len > highscore) highscore = len;
      }
    }
  }
  
  void eat() {
    if (pos.x == food.x && pos.y == food.y) {
      len++;
      if (speed > 5) speed--;
      newFood();
    }
  }
  
  void show() {
    noStroke();
    fill( random(255), random(255), random(255), random(255));
;
    rect(pos.x, pos.y, grid, grid);
    for (PVector p : hist) {
      rect(p.x, p.y, grid, grid);
    }
  }
}
     void keyPressed() {
  if (keyCode == LEFT && snake.moveX != 1) {
    snake.vel.x = -1;
    snake.vel.y = 0;
  } else if (keyCode == RIGHT && snake.moveX != -1) {
    snake.vel.x = 1;
    snake.vel.y = 0;
  } else if (keyCode == UP && snake.moveY != 1) {
    snake.vel.y = -1;
    snake.vel.x = 0;
  } else if (keyCode == DOWN && snake.moveY != -1) {
    snake.vel.y = 1;
    snake.vel.x = 0;
  }
}

 

 

Sources:

Code – lines pointing at mouse w/OOP

Code – lines pointing at mouse w/OOP

file:///Users/Downloads/Processing.app/Contents/Java/modes/java/reference/PVector.html

file:///Users/Downloads/Processing.app/Contents/Java/modes/java/reference/ArrayList.html

https://forum.processing.org/topic/random-color-multiple-times

 

Bouncing Yoga Ball

It’s a Yoga Ball,,,,,, and it bounces.

/********* VARIABLES *********/

// We control which screen is active by settings / updating
// gameScreen variable. We display the correct screen according
// to the value of this variable.
//
// 0: Initial Screen
// 1: Game Screen
// 2: Game-over Screen

int gameScreen = 0;
int ballX, ballY;
int ballSize = 70;
int ballColor = color(0);
float gravity = 1;
float ballSpeedVert = 0;
float airfriction = 0.0001;
float friction = 0.1;
color racketColor = color(255,87,93);
float racketWidth = 100;
float racketHeight = 10;
int racketBounceRate = 20;
float ballSpeedHorizon = 10;

//int ballZ, ballM;
//int ballMSize = 60;

/********* SETUP BLOCK *********/

void setup() {
  size(500, 500);
  ballX=width/4;
  ballY=height/5;
}


/********* DRAW BLOCK *********/

void draw() {
  // Display the contents of the current screen
  if (gameScreen == 0) {
    initScreen();
  } else if (gameScreen == 1) {
    gameScreen();
  } else if (gameScreen == 2) {
    gameOverScreen();
  }
}


/********* SCREEN CONTENTS *********/

void initScreen() {
  // codes of initial screen
  background(0);
  textAlign(CENTER);
  text("Click to start", height/2, width/2);
}
void gameScreen() {
    background(244,56,70);
    
    drawBall();
    applyGravity();
    keepInScreen();
    drawRacket();
    watchRacketBounce();
    applyHorizontalSpeed();
    
}
    void applyHorizontalSpeed(){
  ballX += ballSpeedHorizon;
  ballSpeedHorizon -= (ballSpeedHorizon * airfriction);
}
void makeBounceLeft(int surface){
  ballX = surface+(ballSize/2);
  ballSpeedHorizon*=-1;
  ballSpeedHorizon -= (ballSpeedHorizon * friction);
}
void makeBounceRight(int surface){
  ballX = surface-(ballSize/2);
  ballSpeedHorizon*=-1;
  ballSpeedHorizon -= (ballSpeedHorizon * friction);
}



  // codes of game screen



void watchRacketBounce() {
  float overhead = mouseY - pmouseY;
  if ((ballX+(ballSize/2) > mouseX-(racketWidth/2)) && (ballX-(ballSize/2) < mouseX+(racketWidth/2))) {
    if (dist(ballX, ballY, ballX, mouseY)<=(ballSize/2)+abs(overhead)) {
      makeBounceBottom(mouseY);
      // racket moving up
      if (overhead<0) {
        ballY+=overhead;
        ballSpeedVert+=overhead;
      }
    }
  }
}
void applyGravity() {
  ballSpeedVert += gravity;
  ballY += ballSpeedVert;
  ballSpeedVert -= (ballSpeedVert * airfriction);
  
}
void makeBounceBottom(int surface) {
  ballY = surface-(ballSize/2);
  ballSpeedVert*=-1;
  ballSpeedVert -= (ballSpeedVert * friction);
  
}
void makeBounceTop(int surface) {
  ballY = surface+(ballSize/2);
  ballSpeedVert*=-1;
  ballSpeedVert -= (ballSpeedVert * friction);

}

void drawRacket(){
  fill(racketColor);
  rectMode(CENTER);
  rect(mouseX, mouseY, racketWidth, racketHeight);
}
// keep ball in the screen
void keepInScreen() {
  // ball hits floor
  if (ballY+(ballSize/2) > height) { 
    makeBounceBottom(height);
  }
  // ball hits ceiling
  if (ballY-(ballSize/2) < 0) {
    makeBounceTop(0);
  }
    if (ballX-(ballSize/2) < 0){
    makeBounceLeft(0);
  }
  if (ballX+(ballSize/2) > width){
    makeBounceRight(width);
  }
}

void drawBall() {
  fill(ballColor);
  ellipse(ballX, ballY, ballSize, ballSize);
  //ellipse(ballZ, ballM, ballMSize, ballMSize);
}

void gameOverScreen() {
  // codes for game over screen
}


/********* INPUTS *********/

public void mousePressed() {
  // if we are on the initial screen when clicked, start the game
  if (gameScreen==0) {
    startGame();
  }
}


/********* OTHER FUNCTIONS *********/

// This method sets the necessary variables to start the game  
void startGame() {
  gameScreen=1;
}

referenced from the tutorial in the following link:

https://www.toptal.com/game/ultimate-guide-to-processing-simple-game

Design meets Disability

This reading presents a dilemma in the design of the products that helped people with disabilities. The text presents a comparison between aid objects that have a different level of social acceptance. While in the design of hearing aids objects discretion is one of the most important characteristics, in the design of eyeglasses fashion is almost a must. My guess to explain this phenomenon is that the more common is the disability and the less impact that it has in the person’s life causes to find “normal” certain aid devices. Another main takeaway of this reading is the importance of considering disabilities in the design process of daily objects. Sometimes a bad design of the simplest can really affect people’s life and right now, due to my knee injury and that I am using clutches, I have been able to perceive the bad design of the simplest thing. I am impressed by how much a friendly disabilities design can make life easier.

 

Memory Card Game

For this project, I decided to make a memory card game where the user would be given a set of cards and would have to match two cards in order to get rid of them, until the game ends of course.

I originally got this idea from Meri Engel, so I will leave a link to her youtube channel below.

https://www.youtube.com/channel/UCjBGQA6hPD3SY4G5feqMDFw

So, now on to the procedure.

To do this I first created a class called Cards that would have values of its x-coords, y- coords, FaceValue, etc. Moreover with the certain attributes, the class would also have functions such as faceDown() or displayFront() which would flip the card back and forth.

In the main part of my code, interactions with the cards began. I would have an array that would store two flipped cards, and then check if they were the same. Before that, I had a shuffle function that would randomly shuffle the cards in different order, since without shuffling they would be placed in same order every time. Finally, the mouseClicked() function would serve as where I would click in terms of coordinates and if so what would happen, which of course would be to flip the cards. But even here, I didn’t want to flip more than two cards so I have a switch that flips back the cards.

Below is my code, and below that is the youtube video of me explaining how it works.

Cards[] myCard = new Cards[6];
int[] x = new int[6]; //x coordinate array
int[] y = new int[6]; //y coordinate array
int[] fv = new int[6]; //facevalue array
int[] checkFv = new int[2]; //check face value
int[] cardUp = new int[2]; //check card up
boolean[] clicked = new boolean[8];
PImage flip;
PFont  myFont;
int flipped = 0;
int win = 0;

void setup(){
  int myX = 15; // x coord
  int myY = 15; // y coord
  int myFv = 0;
  int count = 1;
  size(1000,1000);
  myFont =createFont("Verdana",40,true);
  flip = loadImage("flip.png"); // flip button
  
  
  for(int i =0; i<6;i++){   //spacing out the cards
    clicked[i] = false; //can't click card again  
    y[i] = myY;
    x[i] = myX;
    fv[i] = count;
    count += 1;
    if(count == 4){ // number of replicates
      count = 1;
    }
    if(myX <345){
      myX += 250;
    } else if (myX >345){
      myX = 15;
      myY += 400;
      
    }
  }
  
  shuffle();
  for(int i=0;i<6;i++){
    myCard[i] = new Cards(x[i],y[i],fv[i]); //each card is assigned coordinate value
  }
}

void draw(){
  
  textFont(myFont);
  fill(0);
  background(255);
  
  for(int i=0;i<6;i++){
    myCard[i].display();
  }
  
  image(flip,500,750);
  
  if(mousePressed){
    if(mouseX>500 && mouseX<600 && mouseY > 770 && mouseY<880){
      for(int i = 0; i<6;i++){
        myCard[i].faceDown();
        clicked[i]=false;
        flipped=0;
      }
    }
  }
  if(win == 3){
    text("You Win!",500,500);
  }
}
/*
void flipme(){//flipperino
  for(int i=0;i<6;i++){
    if(mouseX>x[i] && mouseX<(x[i]+305) && mouseY > y[i] && mouseY<(y[i]+350)){
      myCard[i].displayFront();
    }
  }
 
}
*/
void mouseClicked(){
  for(int i=0;i<6;i++){
    if(mouseX>x[i] && mouseX<(x[i]+250) && mouseY > y[i] && mouseY<(y[i]+300) && (clicked[i]==false)  ){
      myCard[i].displayFront();
      clicked[i] =true;
      cardUp[flipped] = i;
      
      flipped++;
      println(flipped);
      if(flipped == 2){
        flipped = 0;
        
        if(fv[cardUp[0]] == fv[cardUp[1]]){
          myCard[cardUp[0]].matched();
          myCard[cardUp[1]].matched();
          win += 1;
        }
        /*else if(fv[cardUp[0]] != fv[cardUp[1]]){
          myCard[cardUp[0]].display();
          myCard[cardUp[1]].display();
          myCard[cardUp[0]].faceDown();
          myCard[cardUp[1]].faceDown();
          clicked[i] = false;
          clicked[i+1] = false;
          
        }
        */
        
      }
    }
  }
  }
  
void shuffle(){//shufflerino
  int temp = 0;
  int rand = 0;
  for(int i=0; i<6;i++){
    rand = int(random(0,6));
    temp = fv[i];
    fv[i] = fv[rand];
    fv[rand] = temp;
  }

}
class Cards{

  PImage cardImage;
  int show = 0;
  //int cWidth = 105;
  //int cHeight = 130;
  int cX = 0;
  int cY = 0;
  int faceValue = 0;
  String[] cardName ={"0.png","creep.png","isabelle.png","kk.png","psycho.png","digby.png","tomnook.png"};
  
  Cards(int x, int y, int fv){
    cX = x;
    cY = y;
    faceValue = fv;
  }
  
  void display(){
    cardImage = loadImage(cardName[show]);
    image(cardImage,cX,cY);
  }
  
  void displayFront(){
    show = faceValue;
  }
  
  void faceDown(){
    show = 0;
  }
  void matched(){
    cX = -300;
  }
  
  
}

Response on Design Meets Disability

In the reading, we see that the application of design for disability in the past had a more focus on being invisible. The concept of fashion has just started to appear in the recent decades on these untouched fields. However, it was fascinating to find out the progression of how glasses turned into a wearable from usable and people who wear glasses as wearer rather than patient. The author mentions in the reading that for an eyewear, “the words design and disability are mentioned in the same breath … the exemplar of a product that addresses a disability, yet with little or no social stigma attached” (15). The integration of design in these tools for disability has made the them into items of fashion – where now people use glasses as a fashion item to define themselves. Also, it was interesting to see how, after eliminating the stigma behind glasses, our society presents the old ugly criticized model as vintage and people go crazy for these glasses – once the stigma was removed, the old designs for disability were re-visited.

Good design often requires the courage to value simplicity over being “all things to all people” (85)

The author of this article tries to refute the concept of how products should be designed for everyone. The example of Leckey’s product showed a clear reason to how the attempt to fit everything in the design to satiate everyone can actually be detrimental to the original targeted group – especially in Leckey’s case of designing for disability. The author points out that “too much adjustability and modularity can result in a design that is visually complex … the equipment itself stigmatizes the kids among their new peers.” (76), which shows that it is “better to deny the user a feature that could have been useful, in favor of a better overall experience” (86).

The main comparison that popped in my head was the difference between the user interface of an iPhone and a Galaxy Series Phone. The number of functionalities in the galaxy phones win without doubt compared to the iPhone – but does everyone use the Galaxy Series? The answer would be no since most people would raise their hands for the iPhone due to its simplicity in UI, smoother UX, and lower learning curve – thus boosting the overall experience compared to the galaxy series..

Keeping the simplicity while maintaining the level of overall experience is a difficult task. And, it brings up the need for consistent communication between the users and the designers in order to attain this simplicity. As interactive media students, it is crucial for us to value simplicity to fit the target persona over use-for-everyone with chaotic functionalities. The “more” is not always good.

The Failure of the Snake

For this week assignment, I decided to build the classic Snake game that used to appear in all Nokia phones before the smartphones were invented. The Idea seemed simple at the beginning to create class Snake with the proper methods that allow the snake to move in a specific direction, eat the apple and increase its size and die if the snake clash against itself.  Creating the methods to move around and eat an apple were simple to make. The struggle came trying to build an increasing size method. When I was planning my algorithm I forgot that arrays cannot increase its size once the code is running, so the solution that I attempted to do was using ArrayList instead of arrays to keep the vector position of the snake. Unfortunately,  I was not able to make ArrayList work the way I wanted, Although I learned how to add and remove elements from ArrayList I did not find a function that Allowed to overwrite the values from the list without altering its size. And when I gave up trying to use ArrayList it was too late to design a whole new algorithm. But I decided to make a piece of art with the leftovers of my snake code.

Credits to this video of the  CodingTrain who helped me to be closer to achieving the game that I wanted to create. But if the purpose was to improve my OOP, it definitely worked.

int scl = 20;
PVector apple;


////////////////////////////////////OPP
class Snake{
int xspeed, yspeed, xdir, ydir;
int x,y;
int total;
PVector vec ;
ArrayList<PVector> tail;

 Snake(){
  x = 0;
  y = 0;
  xspeed = 0;
  yspeed = 0;
  total = 0;
 tail = new ArrayList();
 }

void update(){

  if (total == tail.size()){
 for(int i = 0; i<tail.size();i++){
    tail.remove(i);
  tail.add(i,tail.get(i+1));
  
 }
  }
 vec = new PVector(x,y);
 tail.add(vec);
 
 

 

 for (int i = 0; i< tail.size();i++){
   print("Snake",tail.get(i));
 }
 
  x = x+xspeed*scl;
  y = y+yspeed*scl;
  x = constrain(x,0,width -scl);
  y = constrain(y,0,height -scl); 
}

void show(){

   println("total",total);
   println("size",tail.size());
for(int i = 0; i<tail.size();i++){
  fill(random(255),random(100),random(50));
   rect(tail.get(i).x,tail.get(i).y,scl,scl);
 }
  fill(random(255),random(100),random(50));
  rect(x,y,scl,scl);
  
}
void setdir(int xpass,int ypass){
  xspeed = xpass;
  yspeed = ypass;
  
}

boolean eat(PVector pos){
  float dis = dist(x,y,pos.x,pos.y);
  if(dis<2){
    total++;

    return true ;
  }
  else{
    return false ;
  }
}

}
////////////////////////Main///////////////////////
Snake snake;
void setup(){
  size(640, 480);
  snake = new Snake();
  frameRate(600);
  pickLocation();
 
}

void pickLocation(){
  int cols = int(width/scl);
  int rows = int(height/scl);
  apple = new PVector(int(random(cols)),int( random(rows)));
  apple.mult(scl);
}



void keyPressed(){ 
int four = int(random(4));
  if(four == 0){
    snake.setdir(0,-1);
  }
   else if(four == 1){
     snake.setdir(0,1);
  }
   else if(four == 2){
     snake.setdir(-1,0);
  }
  else if(four == 3){
     snake.setdir(1,0);
  }
}



void draw(){
  background(255);
  keyPressed();
  snake.update();
  snake.show();
  
  if(snake.eat(apple)){
    pickLocation();
  }
  
  fill(254,0,101);
  rect(apple.x, apple.y, scl,scl);  
}

 

i loved this reading

Aaron, you really hit my interests with this one. Surprise, I do like other things other than theater! I grew up with a Speech Therapist Mother, so I was always tagging along to see her patients at work. She worked with children, so I would play with them and help with therapy when I could. Reading this really brought out my childish fun playing with those special needs kids.

I found a lot of connections between this reading and the one we read about how aesthetic can relate to function. How the more simplistic the design, the more aesthetically pleasing it can be and, therefore, it will perform its function better. These connections were great to find between the readings because it really brought together the concepts.

Another thing that fascinated me was the conflicting ideas of simplicity vs. universality and their constant struggle to dominate the world of design and engineering. On one hand, it makes sense to have one thing in your pocket that does every task for you. But then it also makes sense to have highly specialized objects that can perform the task perfectly. It’s a matter of prioritization: performance or space? Universal “platforms” may take up less space in your household than four different objects, but they may also perform the functions worse than the individual objects.

The reading also brought up the culture around disabilities and the progress that humanity seems to be undergoing in regards to such. For example, I didn’t even thin about having to wear glasses as a disability. But it is part of my identity and it’s true, I do look forward to getting new glasses every once in a while. But when I was younger (I got glasses when I was six) it was something I was shamed and ridiculed for. It’s incredible to see how far we’ve come in just the past decade. From bullying a child for wanting to see properly, to selling glasses with fake lenses. I hope this progress continues with the more apparent disabilities. And such, as this progress happens, how does the connotation of the disabilities change? I hope there will be less shame around the culture regarding them, but as for now, it’s already apparent that there’s been extreme progression towards acceptance.

I could probably write 2000 words on this reading about my thoughts and where my mind went while I read it, but I’ll stop here for your sake. I might even send the pdf to my mom!

Response

Graham Pullin’s “Design Meets Disability”

I found this reading extremely interesting because I had never given much thought to how applicable design (in terms of fashion not just functionality) is thought of in specialist products. To me, it seemed intuitive to focus on functionality as opposed to aesthetics when talking in context of disability. However, now that I’ve read this, it makes so much sense to me that fashion should be an integral part of a good design as it truly does explore freedoms beyond the constraints society may hold. Moreover, I strongly agreed with the authors point that discretion in such things just means we are ashamed of them, which should not be the case, e.g. the example of eyewear. I think functionality is of course very important but aesthetics are key too. Many specialist products are extremely intimate to their owners and are part of their identity and experiences.

Lastly, I really liked the author’s point about simple design not necessarily meaning easy design. I think this is something that I overlook a lot. A lot of work can appear simple on the surface but the mechanics behind it run very deep, inversely, some things may appear very complex but are in fact simple and I think that’s all up to how good the design is.

Coding a Game with OOP

I decided to create a (really) simple game using what we learned in Object Oriented Programing. This game’s logic basically entails using the space bar to move the ellipse in order to avoid the barriers or the lines. Yes, I made a very rudimentary version of Flappy Bird. It was… an experience. I learned how to create new objects using the function “new”,  calling functions from classes, and my favorite part – checking for collisions.

Prepare to be amazed:

Code:

int state = 0; 
int score=0;
bird b = new bird();
pillar[] p = new pillar[3];


void setup(){
 size(500,700);
 int i; 
 for (i = 0; i < 3; i++){
   p[i]=new pillar(i);
 };
}

void draw(){
  background(0);
  if (state==0){
    // intro state
    text("Click to Play",155,240);
    b.move(p);
  }
  
  else if (state==1){
    // start state 
    b.move(p);
    b.drag();
    b.checkCollisions();
    rect(20,20,100,50);
    fill(255);
    text(score,30,58);
  }
  
  else {
    // end state 
    rect(150,100,200,50);
    rect(150,200,200,50);
    fill(255);
    text("game over",170,140);
    text("score",180,240);
    text(score,280,240);
  }
  
  b.drawBird();
  
  for(int i = 0;i<3;i++){
    p[i].drawPillar();
    p[i].checkPosition();
  }
  
  stroke(255);
  textSize(32);
}
void mousePressed(){
  state = 1;
}

void keyPressed(){
  b.jump();
}

Class:

class bird {
  float xPos, yPos, ySpeed;
  bird(){
    xPos = 250;
    yPos = 400;
  }
  
  void drawBird(){
    stroke(255);
    noFill();
    strokeWeight(2);
    ellipse(xPos, yPos, 20, 20);
  }
  
  void jump(){
    ySpeed=-10;
  }
  
  void drag(){
    ySpeed+=0.5;
  }
  
  void move(pillar[] pillarArray){
    yPos+=ySpeed;
    for (int i = 0; i < 3; i++){
      pillarArray[i].xPos-=3; 
    }
  }
  
  void checkCollisions(){
    if(yPos>800){
      state = 2;
    }
    
    for (int i = 0; i < 3; i++){
      if((xPos< p[i].xPos+10&&xPos>p[i].xPos-10)&&(yPos<p[i].opening-100||yPos>p[i].opening+100)){
        state = 2;
      }
    }
  }
}
    

class pillar {
  float xPos, opening;
  boolean cashed = false;
  pillar(int i){
    xPos = 100+(i*200);
    opening = random(600)+100;
  }
  void drawPillar(){
    line(xPos,0,xPos,opening-100); 
    line(xPos,opening+100,xPos,800);
  }
  void checkPosition(){
    if(xPos<0){
      xPos+=(200*3);
      opening = random(600)+100;
      cashed=false;
    } 
    if(xPos<250&&cashed==false){
      cashed=true;
      score++;
    }
  }
  void reset(){
    state = 0;
    score=0;
    b.yPos=400;
    for(int i = 0;i<3;i++){
      p[i].xPos+=550;
      p[i].cashed = false;
    }
  }
}

 

 

 

Object Oriented Programming Art

For this week’s assignment, we were supposed to create something with OOP. I wanted to create some sort of meditative art work (e.g. snow/rain falling) but along the process of learning how to form a “class” and other programming, I made this. I kind of ended up liking this more (despite its lack of clear purpose).

Drop [] dropCollection = new Drop [70];

 
void setup() {
 size(400, 400);
 smooth();
 
 for ( int n = 0; n < 70; n++) {
 dropCollection[n] = new Drop (random(0,width), random(0,height));
  
}

 }
 
 
void draw() {
   background(187, 178, 255);
   
   for (int n = 0; n < 70; n++) {
   dropCollection[n].run();
   
   
 }
 
}
class Drop{

  float x = 0;
  float y = 0;
  float speedX = 2;
  float speedY = 5;
  float r;
  
  Drop(float _x, float _y) {
    x = _x;
    y = _y;
    r = 8;
    
  }
  
  void run(){
    display();
    move();
    bounce();
    gravity();
    
  }
  
  void gravity(){
  speedY *= 0.2;
  
  }
    
  void bounce() {
    if(x > width) {
      speedX = speedX * -1;  
    }
    if(x < 0) {
      speedX = speedX * -1;  
    }
     if(y > width) {
      speedY = speedY * -1;  
    }
        if(y < 0) {
      speedY = speedY * -1;  
    }
    
  }
  
 void move() {
    
  x += speedX;
  y += speedY;
  
  }
  
    void display() { 
    
    fill( random(255), random(255), random(255), random(255)); 
    noStroke();

    for (int i = 2; i < r; i++ ) {
    ellipse(x, y + i*4, i*2, i*2);
   

  }
  }
}