FINAL PROJECT[mirror booth]

THE IDEA

The final project turned out to be an artistic expression in its true form, developing chaotically and very unexpectedly. The essence of this project is to reflect over your own reflection, viewer by interacting with my project gets to see the distorted, trippy yet witty images of the face. This goes to display that we live in a world where the grimace that you put on may not be the true reflection of one’s identity or perhaps personaity.

Since it’s an arts installation, giving any instruction would ruin the mystery that the project holds. Any uniform shapes or identically consistent styles would ruin the whole aesthetics as the exhibition of mirrors projects and celebrates the diversity and the will to think outside the box. Not only it challenges the audience to render many untrivial ideas, but also immerses the audience into the galaxy of unknown and unseen.

While doing the project, I got inspired by many things, but what had finally set my thoughts on the project was the combination of psychic TV shows where psychic would force her patients to believe in something that they are not, and also the many apps like Photo Booth, Snapchat or even Instagram that has filters that alter the way one sees itself.

The main trick is in simplicity. The processing code consists of several stages of realities: starting from distortion, to alienation, to taking a visit to an upside world only to see thriple and frouple of you at the final stage. During this emerging and magical process, the spiral hypnosis adds up to the whole surrealistic moment that was intended to be recreated. The sonic unearthy sound of the motor contributes to making the experience more sensual and industrial.

MIRRORS

THE PROCESSING CODE

import processing.video.*;
import processing.serial.*;
Serial myPort;
int switcher = 0;
int cellSize = 5;
int duration = 155; 
// Number of columns and rows in our system
int cols, rows;
Capture video;
void setup(){
  size(640,480);
  frameRate(20);
  cols = width / cellSize;
  rows = height / cellSize;
  colorMode(RGB, 255, 255, 255, 100);
  printArray(Serial.list());
  String portname=Serial.list()[1];
  println(portname);
  myPort = new Serial(this, portname, 9600);
  myPort.clear();
  myPort.bufferUntil('\n');
  video = new Capture(this, width, height);
  video.start();
  background(0);
}
void draw(){
  tint(256,256,256);
  background(0);
  if (video.available()){
    video.read();
    video.loadPixels();
  }
  if(switcher==0){
    for (int i = 0; i < cols; i++) {
      // Begin loop for rows
      for (int j = 0; j < rows; j++) {
      
        // Where are we, pixel-wise?
        int x = i*cellSize;
        int y = j*cellSize;
        int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image
      
        float r = red(video.pixels[loc]);
        float g = green(video.pixels[loc]);
        float b = blue(video.pixels[loc]);
        // Make a new color with an alpha component

        color c = color(r, g, b, 75); //make smth out of the last number using potentiometer
      
        // Code for drawing a single rect
        // Using translate in order for rotation to work properly
        pushMatrix();
        translate(x+cellSize/2, y+cellSize/2);
        // Rotation formula based on brightness
        rotate((2 * PI * brightness(c) / 255.0));
        rectMode(CENTER);
        fill(c);
        noStroke();
        // Rects are larger than the cell for some overlap
        
       
        ellipse(0, 0, 5, 50);
        
        popMatrix();
      }
    }
    //image(video,0,0);
  }
  else if(switcher == 1){
        background(0,0,255);

        for (int i = 0; i < cols;i++) {
      // Begin loop for rows
      for (int j = 0; j < rows;j++) {

        // Where are we, pixel-wise?
        int x = i * cellSize;
        int y = j * cellSize;
        int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image

        // Each rect is colored white with a size determined by brightness
        color c = video.pixels[loc];
        float sz = (brightness(c) / 255.0) * cellSize;
        rectMode(CENTER);
        fill(255);
        noStroke();
        rect(x + cellSize, y + cellSize, sz, sz);
      }
    }
    //scale(-1,1);
    //image(video,-width,0); 
  }
  else if(switcher == 2){
    
    scale(-1,-1);
    image(video,-width,-height);
  }
  else if(switcher == 3){
  tint(256, 0, 0);
  image(video, 0, 0, width/2, height/2);
  tint(0, 256, 0);
  image(video, width/2, 0, width/2, height/2);
  tint(0, 0, 256);
  image(video, 0, height/2, width/2, height/2);
  tint(256, 0, 256);
  image(video, width/2, height/2, width/2, height/2);
}
  else{
    println("Switcher = 0 again");
    switcher = 0;
  }
}
void mousePressed(){
  switcher++;
}

void serialEvent(Serial myPort) {
  String s=myPort.readStringUntil('\n'); //open port, read 
  s=trim(s);
  myPort.write(duration + "\n");
}

ARDUINO CODE

#include <SparkFun_TB6612.h>

#define AIN1 2
#define BIN1 7
#define AIN2 4
#define BIN2 8
#define PWMA 5
#define PWMB 6
#define STBY 9
int duration = 0;

const int offsetA = 1;
const int offsetB = 1;

Motor motor1 = Motor(AIN1, AIN2, PWMA, offsetA, STBY);

void setup() {

  Serial.begin (9600);
  Serial.println("0");

}

void loop() {

 
 
  while (Serial.available()) {

  duration = Serial.parseInt();
      if (Serial.read() == '\n') {
      motor1.drive(duration,1000);
      }
  }

}

THE DISPLAY

THE PROJECT

 

Progress in Final Project

PROGRESS

Once I’m more or less decided on my project, I went to do my little research on the many possibilities that Processing tool has to offer. I found many libraries and examples implemented in Processing, such as Mirror by Daniel Shiffman which quite literally shows ur reflection captured by webcam, or PeasyCam that transforms ur face and shows in three-dimensional space.

CHALLENGES:

I have faced an issue related to the Capture function, the camera is denying access to processing to run the program and open the webcam.

BaseSrc: [avfvideosrc0] : Device video access permission has just been denied 
Could not run the sketch 
(Target VM failed to initialize).

Professor later explained that this has to do with the privacy and security settings of new macOS not letting processing open the camera due to strict security restrictions.

 

CODE:

// daniel shiffman's library on mirror
import processing.video.*;
// Size of each cell in the grid
int cellSize = 20;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;


void setup() {
  size(640, 480);
  frameRate(30);
  cols = width / cellSize;
  rows = height / cellSize;
  colorMode(RGB, 255, 255, 255, 100);

  // This the default video input, see the GettingStartedCapture 
  // example if it creates an error
  video = new Capture(this, width, height);
  
  // Start capturing the images from the camera
  video.start();  
  
  background(0);
}


void draw() { 
  if (video.available()) {
    video.read();
    video.loadPixels();
  
    // Begin loop for columns
    for (int i = 0; i < cols; i++) {
      // Begin loop for rows
      for (int j = 0; j < rows; j++) {
      
        // Where are we, pixel-wise?
        int x = i*cellSize;
        int y = j*cellSize;
        int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image
      
        float r = red(video.pixels[loc]);
        float g = green(video.pixels[loc]);
        float b = blue(video.pixels[loc]);
        // Make a new color with an alpha component
        color c = color(r, g, b, 75);
      
        // Code for drawing a single rect
        // Using translate in order for rotation to work properly
        pushMatrix();
        translate(x+cellSize/2, y+cellSize/2);
        // Rotation formula based on brightness
        rotate((2 * PI * brightness(c) / 255.0));
        rectMode(CENTER);
        fill(c);
        /noStroke();
        // Rects are larger than the cell for some overlap
        ellipse(0, 0, 1, random (20,100));
        popMatrix();
      }
    }
  }
}

VIDEO

Arduino + Processing Game [EXTRA CREDIT]

Project Outline

So for this project, we will be using an Arduino Uno Board and an SR-04 Ultrasonic sensor, a breadboard, and a few wires. So this game is built upon the midterm game that I have created previously, Drowning Diver. But this time around, the game is controlled with an ultrasonic sensor that feels the distance between whatever is put in front of it. When sensor is covered it goes up, when user puts his fingers away that cover sensor the diver goes down and drowns))

To be honest, I really wanted to make a game using screen. Last lesson when we were having a group discussion of our ideas, Alima has mentioned that we have a so-called screen that can display on it. That was the time when I got so excited to working with it, but immediately that idea backfired.

PROCESSING CODE

PImage wall;
PImage character;

import processing.serial.*;
int DistanceUltra;
int IncomingDistance;
Serial myPort;
String DataIn;
Pipe p1 = new Pipe();
Pipe p2 = new Pipe();
Pipe p3 = new Pipe();
 
//bird height and width location
float birdy = 46;
float birdx = 56;
float gravity = 5;
//float jumpForce = 15;
 
//the speed of the pipes
int speed;
 
//score and game state
boolean gameOver = false;
int score = 0;
int highscore = 0;
 
int point = 1;
 
color birdColor = color(255, 204, 0);
 
 
void setup(){
  size(800,400);
  wall=loadImage("underwater.png");
  character=loadImage("scuba.png");
  p1.x = width + 80;
  p2.x = width + 200;
  p3.x = width + 400;
  printArray(Serial.list());
  String portname=Serial.list()[2];
  println(portname);
  myPort = new Serial(this,portname,9600);
  myPort.bufferUntil(10);
}
void serialEvent (Serial myPort){
DataIn = myPort.readString();
println(DataIn);
IncomingDistance = int(trim(DataIn));
println("incoming distance="+IncomingDistance);
if (IncomingDistance>1 && IncomingDistance<100 ) { DistanceUltra = IncomingDistance; //save the value only if its in the range 1 to 100 } }
}
}
 
void draw(){
 
  background(wall);
  p1.pipe();
  p2.pipe();
  p3.pipe();
 
  fill(birdColor);
  ellipse(birdx, birdy, 55,55);
 // birdy += gravity;
  play();
  success(p1);
  success(p2);
  success(p3);
 
  if (IncomingDistance>10)
  {
    //birdy -= jumpForce;
    birdy -= gravity;
  }    
  else
  {
    birdy += gravity;
  }
  
}
 
 
void play(){
 
  if(gameOver == false)
  {
    speed = 2;
    p1.x -= speed;
    p2.x -= speed;
    p3.x -= speed;
   
    textSize(24);
    fill(255,255,255);
    text(score, width/2, 30);  
  }
 
  if(gameOver == true)
  {
    speed = 0;
    p1.x -= speed;
    p2.x -= speed;
    p3.x -= speed;
   
    if( highscore < score)
    {
       highscore = score;
    }
   
    textSize(16);
    fill(0, 102, 153);
    textAlign(CENTER);
    text("Click : Play Again", width/2, height/2);
    text("Score: " + score, width/2, height/2 - 20);
    text("High-Score: " + highscore, width/2, height/2 - 40);
   
    if (mousePressed)
    {
       delay(900);
       score = 0;
       gameOver = false;
       birdy = 100;
       birdx = 56;
       p1.x = width + 50;
       p2.x = width + 220;
       p3.x = width + 370;
       p1.top = random(height/2);
       p1.bottom = random(height/2);
       p2.top = random(height/2);
       p2.bottom = random(height/2);
       p3.top = random(height/2);
       p3.bottom = random(height/2);
 
    }  
  }
 
}
 
void success(Pipe test){
 
  if(birdy < test.top || birdy > height - test.bottom)
  {
    if(birdx > test.x && birdx < test.x + test.w)
    {
      gameOver = true;
    }
  }
}
class Pipe
{
  float top = random(height/3 + 200);
  float bottom = random(height/3 +200);
 
 
  float x = width + 150;
  float w = 70;
  color pipeColor = color(0, 255, 0);
 
  void pipe()
  {
    fill(pipeColor);
    rect(x, 0, w, top);
    rect(x, height-bottom, w, bottom);
   
    if(x < -100)
    {
     score += point;
     x = width;
     top = random(height/2);
     bottom = random(height/2);
    }
 
   
  }
 
 
}

ARDUINO CODE

const int trigPin=11; 
int echoPin=10; 
int safezone=10; 
//int dpin=13;
void setup() 
{
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
//pinMode(dpin,OUTPUT);
//digitalWrite(dpin,LOW);
Serial.begin(9600);
}
void loop()
{
long duration,cm; //DECLARE VARIABLES TO STORE SENSOR O/P
digitalWrite(trigPin,LOW); //MAKE THE TRIG PIN LOW
delayMicroseconds(2); //WAIT FOR FEW MICROSECONDS
digitalWrite(trigPin,HIGH); //NOW SET THE TRIG PIN
delayMicroseconds(5); //WAIT FOR FEW MICROSECONDS UNTIL THE TRIG PULSE IS SENT
digitalWrite(trigPin,LOW); //MAKE THE TRIG PIN LOW AGAIN
duration=pulseIn(echoPin,HIGH); //MAKE ECHO PIN HIGH AND STORE THE BOUNCED PULSE IN VARIABLE DURATION
cm=microsecondsToCentimeters(duration); 
long inch= cm/2.54;
//if(cm<safezone) 
//{
//digitalWrite(dpin,HIGH);
Serial.println(cm);
//delay(500);
//digitalWrite(dpin,LOW);
//}
}
long microsecondsToCentimeters(long microseconds) //SPEED OF SOUND IS 29 uSEC PER CM
{
return microseconds/29/2; //THE PULSE TRAVELS FROM THE SENSOR AND AGAIN COMES BACK SO WE DIVIDE IT BY 2 TO TAKE ONLY HALF OF THE TOTAL DISTANCE
}

SCHEMATICS

VIDEO DEMONSTRATION

THREE ARDUINO EXERCISES

Exercise 1: make something that uses only one sensoron arduino and makes the ellipse in processing move on the horizontal axis, in the middle of the screen, and nothing on arduino is controlled by processing.

PROCESSING_EXERCISE 1

import processing.serial.*;// serial object library
Serial myPort; //local serial object from serial library
int xPos=0;
int yPos=0;
 
void setup(){
  size(960,720);
  printArray(Serial.list());
  String portname=Serial.list()[2]; //link processing to serial port
  println(portname);
  myPort = new Serial(this,portname,9600);
  myPort.clear();
  myPort.bufferUntil('\n');
}
 
void draw(){
  background(255);
  ellipse(xPos,height/2,30,30);
}
 
void serialEvent(Serial myPort){
  String s=myPort.readStringUntil('\n'); //strips data of serial port
  s=trim(s);
  if (s!=null){
    
    println(s);
    int value=int(s);
    
    // locates position of ellipse using potentiometer
    xPos=(int)map(value,0,1023,0, width);
  
  }
  myPort.write("\n");
}

ARDUINO_EXERCISE 1

void setup() {
  //initialize the serial port and data upload
  Serial.begin(9600);
  Serial.println("0");
}
 
void loop() {
  //capture data in arduino 
  int sensor= analogRead(A0);
  //put data in the serial port
  while (Serial.available()) {
    if (Serial.read() == '\n') {
      delay(1);
      //prints the value
      Serial.println(sensor);
    }
  }
}

Exercise 2: make something that controls the LED brightness from processing.

PROCESSING_EXERCISE 2

import processing.serial.*;
Serial myPort;
int xPos=0;
int Sensor=0;
boolean Red=false;
boolean Green=false;
void setup(){
size(960,720);
printArray(Serial.list());
String portname=Serial.list()[2];
println(portname);
myPort = new Serial(this,portname,9600);
myPort.clear();
myPort.bufferUntil('\n');
}
void draw(){
background(255);
ellipse(mouseX,mouseY,30,30);
if ((mouseX >= 400) && (mouseY >= 600)) {
Red =true;
} else Red = false;
if ((mouseX <= 400) && (mouseY <= 600)){
Green =true;
}
else Green = false;

}
void serialEvent(Serial myPort){
String s=myPort.readStringUntil('\n');
s=trim(s);
if (s!=null){
println(s);
int values[]=int(split(s,','));
if (values.length==2){
xPos=(int)map(values[0],0,1023,0, width);

}
}
myPort.write(int(Red)+","+int(Green)+"\n");
print("0,0");
}

ARDUINO_EXERCISE 2

int left = 0;
int right = 0;

void setup() {
Serial.begin(9600);
Serial.println("0,0");
pinMode(2, OUTPUT);
pinMode(5, OUTPUT);
}

void loop() {
while (Serial.available()) {
right = Serial.parseInt();
//left = Serial.parseInt();
if (Serial.read() == '\n') {
digitalWrite(2, right);
//digitalWrite(5, left);
int sensor = analogRead(A0);
delay(1);
//int LDRPIN = analogRead(A1);
//delay(1);
Serial.print(sensor);
//Serial.print(',');
//Serial.println(LDRPIN);
}
}
}

Exercise 3: take the gravity wind example and make it so every time the ball bounces one led lights up and then turns off, and you can control the wind from one analog sensor.

PROCESSING_EXERCISE 3

import processing.serial.*;
Serial myPort;
int xPos=0;

int Sensor=0;
boolean Red=false;
boolean Green=false;
PVector velocity;
PVector gravity;
PVector position;
PVector acceleration;
PVector wind;
float drag = 0.99;
float mass = 50;
float hDampening;
void setup(){
size(640,360);
printArray(Serial.list());
String portname=Serial.list()[1];
println(portname);
myPort = new Serial(this,portname,9600);
myPort.clear();
myPort.bufferUntil('\n');
noFill();
position = new PVector(width/2, 0);
velocity = new PVector(0,0);
acceleration = new PVector(0,0);
gravity = new PVector(0, 0.5*mass);
wind = new PVector(0,0);
hDampening=map(mass,15,80,.98,.96);
}
void draw(){
background(255);
if (!keyPressed){
wind.x=0;
velocity.x*=hDampening;
}
applyForce(wind);
applyForce(gravity);
velocity.add(acceleration);
velocity.mult(drag);
position.add(velocity);
acceleration.mult(0);
ellipse(position.x,position.y,mass,mass);
if (position.y > height-mass/2) {
velocity.y *= -0.9; // A little dampening when hitting the bottom
position.y = height-mass/2;
Red = true; 
}
else { Red = false;
}
}
void serialEvent(Serial myPort){
String s=myPort.readStringUntil('\n');
s=trim(s);
if (s!=null){
println(s);
int values[]=int(split(s,','));
if (values.length==2){
xPos=(int)map(values[0],0,1023,0, width);
// yPos=(int)map(values[1],0,1023,0, height);
}
}
myPort.write(int(Red)+","+int(Green)+"\n");
print("0,0");
}
void applyForce(PVector force){
// Newton's 2nd law: F = M * A
// or A = F / M
PVector f = PVector.div(force, mass);
acceleration.add(f);
}

void keyPressed(){
if (keyCode==LEFT){
wind.x=-1;
}
if (keyCode==RIGHT){
wind.x=1;
}
if (key==' '){
mass=random(15,80);
position.y=-mass;
velocity.mult(0);
}
}

ARDUINO_EXERCISE 3

int left = 0;
int right = 0;

void setup() {
Serial.begin(9600);
Serial.println("0,0");
pinMode(2, OUTPUT);
// pinMode(5, OUTPUT);
}

void loop() {
while (Serial.available()) {
right = Serial.parseInt();
left = Serial.parseInt();
if (Serial.read() == '\n') {
digitalWrite(2, right);
// digitalWrite(5, left);
int sensor = analogRead(A0);
//delay(1);
//int LDRPIN = analogRead(A1);
delay(1);
 Serial.print(sensor);
//Serial.print(',');
//Serial.println(LDRPIN);
}
}
}

Preliminary Idea for the Final Project

For the final project, what I’m thinking of is to create some sort of interactive design, so that a person has control over what’s written and displayed on the artwork. Essentially, creating a project, where I would incorporate Web Camera, Arduino, and Processing.

I want to make the project to be the reflection of a person standing behind the webcam so that the content of the artwork is you. So to say, the project will reflect the shape of a person in different geometrical figures and will follow your direction, positions that you change from time to time, and so on. I feel that it would be great to make some sort of distorted mirror of the user’s reflection, which will make the project both entertaining and captivating.

I have attached the video below for the reference.

MUSICAL INSTRUMENT [week 10]

For this week’s assignment, I decided to a piano-like musical instrument. So, basically there are two ways of controlling it. First, without a photoresistor, buttons will play one music, but with a photoresistor, its frequency change to a high-pitched sound.

Buttons are digital input, while a photoresistor is an analog input. Sound is outputted from the buzzor.

VIDEO:

CODE:

int but1 = 3;
int but2 = 4;
int but3 = 5;
int but4 = 6;

int LDR=A1;
int buzzer = 13;
int sensorValue;
void setup()
{
  //let's declare the button pins as input
  pinMode(but1,INPUT);
  pinMode(but2,INPUT);
  pinMode(but3,INPUT);
  pinMode(but4,INPUT);

  //declare buzzer pin as output
  pinMode(buzzer,OUTPUT);
    Serial.begin(9600);
  
  
}

void loop()
{
  

  // read the value from buttons
  int b1 = digitalRead(but1);
  int b2 = digitalRead(but2);
  int b3 = digitalRead(but3);
  int b4 = digitalRead(but4);

 int sensorvalue= analogRead(LDR);
Serial.println(sensorvalue);
  if (sensorvalue<680){
  if( b1 == 1 ){
     tone(buzzer,300,100);
     delay(100);
     tone(buzzer,300,100);
     delay(100);
     tone(buzzer,300,100);
     delay(100);
     tone(buzzer,300,100);
  }
    if( b2 == 1 ){
     tone(buzzer,400,100);
      delay(100);
      tone(buzzer,400,100);
       delay(100);
       tone(buzzer,400,100);
        delay(100);
        
         delay(100);
  }
    if( b3 == 1 ){
     tone(buzzer,500,100);
  }
    if( b4 == 1 ){
     tone(buzzer,600,100);
  }
  }

   if (sensorvalue > 680){

  if( b1 == 1 ){
     tone(buzzer,700,100);
  }
    if( b2 == 1 ){
     tone(buzzer,800,100);
  }
    if( b3 == 1 ){
     tone(buzzer,900,100);
  }
    if( b4 == 1 ){
     tone(buzzer,1000,100);
  }
  }

    
  }

 

LED [assignment 1]

For this assignment, I decided to create a game, where the player should navigate the motility, the distance by placing a hand or any object that will create shade in front of the photoresistor. The aim is to light up red and blue and yellow by placing hand and pressing button simultaneously which will light every color one by one thrice. That’s when the game is claimed to be won.

There are three led lights on the breadboard, three controlled by analog input, the photoresistor, which will control the light intensity of red and blue and yellow led lights. The three led lights will be controlled by digital input, the button, and under very specific circumstances. Three LED lights will light one by one when three led lights that are controlled by a photoresistor will light up, otherwise, it will not.

Blue and red LED lights have their own condition: very close to photoresistor or complete darkness makes blue one light up, a bit far from the photoresistor makes red one work, and distance right in the middle of blue and red LEDs’ range makes yellow light work. After both light up, by pressing a yellow button, three LED lights go one by one and it will blink one after the other thrice, indicating the game over condition.

The scheme:

The video:

The code:

int red = 3;  //analogRead          
int blue = 5;   //analogRead
int yellow = 7;  //digitalRead

int LDR = A2;
int SWITCH = A3;
int sensorValue;

void setup() {
  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(yellow, OUTPUT);
  Serial.begin(9600);
}
void blink(){
  digitalWrite(yellow, HIGH);
  delay(100);
  digitalWrite(yellow, LOW);
  
  digitalWrite(red, HIGH);
  delay(100);
  digitalWrite(red, LOW);
  
  digitalWrite(blue, HIGH);
  delay(100);
  digitalWrite(blue, LOW);

  delay(200);
  
}
// the loop routine runs over and over again forever:
void loop() {
  
  sensorValue = analogRead(LDR);
  
  if(sensorValue < 620){
    analogWrite(blue, 255);
    analogWrite(red, 0);
    
  }
  else if(sensorValue > 620 and sensorValue < 660){
    analogWrite(blue, 255);
    analogWrite(red, 255);
    analogWrite(yellow,255);
   
  }
  else if(sensorValue > 660 and sensorValue < 700){
    analogWrite(blue, 0);
    analogWrite(red, 255);
    
  }
  else if(sensorValue > 700 and sensorValue < 800){
    analogWrite(blue, 0);
    analogWrite(red, 0);
    analogWrite(yellow,0);
  }
  else{
    analogWrite(blue, 0);
    analogWrite(red, 0);
    analogWrite(yellow,0);
  }

  
  
  if(digitalRead(SWITCH)==HIGH and digitalRead(yellow)==1 and digitalRead(blue)==1 and digitalRead(red)==1) {
    digitalWrite(yellow, HIGH);
    delay(600);
    blink();
    blink();
    blink();
  }
  else{
    digitalWrite(yellow, LOW);
  }
}

 

 

Drowning Diver-MIDTERM [week 7]

My midterm game has been very much inspired by flappy birds. It follows very much the same concept, the character has to jump and go through the columns not touching them, otherwise, it falls and fails to win the game.  With this game, however, my character was a scuba diver discovering the underwater world, if it gets hit by a column he will drown. There’s no such purpose to what the game does, the main goal is to go as far as possible and collect scores.

The Main Character is a ScobaDiver and the obstacles are the columns. The Main Character is controlled by mousePressed() and jumps on a y-axis, measured by gravity instantiated by vy each time. Even though the game might not have distinct levels, speed increases each time score goes more than 5, 10, and 20. The game keeps track of previous scores and displays the best and the current score, while the user is playing the game.

The interface of the game functions by clicking the game window to start the game, and press the spacebar to restart the game. The picture of the character is animated by sprite sheet and makes it seem as if the diver is swimming underwater while passes by moving background and columns.

https://github.com/zharmakhan-zn/zharmakhan-zn.github.io/tree/main/midterm

 

PImage wall;
PImage character;
PImage columnt,columnb;
int wallx;
int wally;
int chx; 
float chy;
float g;
float Vchy;
int[] columnX, columnY;
int gameCondition;
int score,highScore;

PImage[]sprites;
int direction=1;
int step=0;
int frames_x;
int frames_y;
int speed=3;

import processing.sound.*;
SoundFile file;

void setup(){
size(400,400);
wall=loadImage("underwater.png");
character=loadImage("scuba.png");

sprites= new PImage[8];
int img_w= character.width/8;
int img_h= character.height/1; //animate spritesheet

int index=0;
for(int frames_y=0; frames_y<1; frames_y++){
for(int frames_x=0; frames_x<8; frames_x++){
sprites[index]= character.get(frames_x*img_w,frames_y*img_h,img_w, img_h);
index++;
}
}

columnb=loadImage("pipetop.png");
columnt=loadImage("pipebottom.png");

file= new SoundFile(this, "buble.wav"); //uploaded wav file

chx=50;
chy=50;
g=0.5;

columnX=new int[5];
columnY=new int[columnX.length]; //set columns

for (int i=0; i<columnX.length; i++){
columnX[i]=width+150*i;
columnY[i]= (int)random(-50,0);
}
gameCondition=-1;
}

void draw(){
if (gameCondition==-1){
startScreen();
}
else if (gameCondition==0){
moveBackground();


columnSet();

characterControl();
score();
}
else{

restartScreen();

}
if(mousePressed){
file.stop();
file.play();
Vchy=-5;
direction=1;
frames_x+=speed;

if (frameCount%speed==0) {
step = (step+1) % 8;
//gameCondition=1;
}
}

}
void score(){
if(score>highScore){
highScore=score;
}
textSize(15);
fill(160,160,160,200);
rect(width-100,10,85,60,5);
fill(0);

text("SCORE:"+ score, width-85,30);
text("BEST:"+ highScore, width-85,60);
}
void startScreen(){
image(wall,0,0);
textSize(40);
text("DROWNING DIVER",0+20, height/2);
textSize(20);
text("click to start",width/2-60, height/2+60);
if (mousePressed){
chy=height/2;
gameCondition=0;
}
}

void restartScreen(){
image(wall,0,0);
textSize(40);
text("YOU DROWNED", 60,height/2);
textSize(20);
text("score:"+score, 160, height/2+50);
text("click SPACE to restart", 0+100,height/2+100);
if (keyPressed){
if(key==' '){
chx=50; 
chy=height/2;
for (int i=0; i<columnX.length; i++){
columnX[i]=width+150*i;
columnY[i]= (int)random(-50,0);
}
gameCondition=0;
score=0;
}
}
}


void characterControl(){
scale(direction,1);

image(sprites[step],chx,chy,50,100);
chy=chy+Vchy;
Vchy=Vchy+g;
if (chy>height || chy<0){
gameCondition=1;
}

}
void moveBackground(){
image(wall, wallx,wally);
image(wall, wallx+wall.width,wally);
wallx= wallx-1; 
if(wallx<-wall.width){
wallx=0;
}
}

void columnSet(){
for (int i=0; i<columnX.length; i++){
image(columnt,columnX[i],columnY[i]+300,50,180);
image(columnb,columnX[i],columnY[i],50,180);
columnX[i]-=2;
if(score>5){
columnX[i]--; //speed up when score more than 5
}
if(score>10){
columnX[i]--; //speed up when score more than 10
}
if(score>20){
columnX[i]--; //speed up when score more than 20
}
if (columnX[i]<-200){
columnX[i]=width;
}
//character collision with columns
if (chx> columnX[i]-50 && chx<columnX[i] +50){
if (!(chy> columnY[i] +150 && chy<columnY[i] +(300-40))){
gameCondition=1;
}
else if(chx==columnX[i] || columnX[i]+1==chx)
{
score++;
}
if(gameCondition==1 && gameCondition==-1){
score=0;
}

}
}
}

MIDTERM Progress [week5]

DESCRIPTION

This game is inspired by Google’s famous T-Rex, Run! game where the main objective is to steer clear from all the obstacles. The ‘2020 Saviour’ game follows a similar concept however we have incorporated more elements and features as compared to the original game in order to make it more captivating. 2020 Saviour is an interactive single-player game and the theme is related to the current global issue, the COVID-19 pandemic. Similar to the dinosaur in T-Rex, Run! here we have the main character named Saviour who has the ultimate solution to end the pandemic, the 100% effective vaccine! The main purpose of the game is to deliver the vaccine to the right destination which is the hospital. However, the path towards the hospital is not as easy as it sounds like, because on the way Saviour will encounter numerous amount of coronavirus and infected people who want the vaccination all to themselves, and the player should maneuver Saviour in an effective manner to dodge all the obstacles and while doing so Saviour should collect all the masks on the way in order to protect themselves as well as a move to the next level / win the game.

Main Character: Saviour, controlled by the player

Obstacles: Coronavirus and the infected people

Score increaser: The masks

 

Level 1 : The game starts with the Saviour running towards the right of the screen by itself. Keyboards of UP and DOWN will control the movement of the savior to jump for the masks that add up to the score(i.e. +10) and to slide from the virus objects that can decrease points(i.e. -10). Masks and Virus objects move the opposite way contrary to the Saviour with speed incrementing when Saviour contacts the virus and if Saviour manages to catch the mask speed decreases, i.e 0.25. Saviour can proceeds to Level 2 once the score is equal to 100. If Savior comes in contact with 3 viruses it loses the game, and the screen will display a message saying “Game Over” and in order to restart the game the player should click the start button with the mouse.

Level 2: The game background darkens into a more creepy apocalyptic setup. Now obstacles would be the coronavirus same as in level 1 in addition to the group of infected people standing as an object that player should jump over. This level doesn’t have a decrease in speed, which means it’s harder to reach the final destination as speed will be incremented similar to the first level. If Saviour passes all the obstacles unaffected she will reach the hospital where the cure(vaccine) is needed to end the global pandemic. Game over, Congrats screen will pop up after this indicating the end of the game. The player can restart the game by mouse clicking the start button.

GAME FEATURES.

Board dimensions: board of the game will hold a window size of 1000pixels in width and 600 pixels in height. The background image will include graphics related to the game’s theme: COVID-19, slowly fading from the light and bright urban landscape in Level1 to dark-toned almost apocalyptic background, finally reaching the last departure, hospital with a respective background image.

The game will include at least 6 classes:

1. The Game class holds all the functionalities of every object displayed on the screen.

2. The Creature class, superclass, will initialize all attributes for the latter classes.

3. The Savior class holds the object for the main character of the game, displayed as a female with cure for covid-19 in her hand. Savior class inherits Creature class’ properties.

4. The Obstacle class holds the object for an infected group of people standing still, which the main character jumps through. Obstacle class won’t inherit Creature class’ properties, since it’s static,non-movable object.

5. The Mask class holds the object for masks that are points for the main character that add up to player’s score. Once the score reaches 100, the character moves to Level2. Mask class inherits Creature class’ properties.

6. The Virus class holds the object of an enemy class that can harm the main character and decreases the player’s points when colliding with Savior. Virus class inherits Creature class’ properties.

 

DESIGN.