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

 

Recreating computer graphics and art

This homework assignment was very challenging for me. I used a source from open processing to do this, but the code was not working, so I had to go through it and learn what needs to change and be added to make it function. The difference with the original is that when the mouse clicks (mousePressed () ) on it, the direction of the lines change by rotating randomly at 0, 120, and 240 degrees.

int width = 600;
int height = 700;
int _size = 20;     // hexagon radius

void setup() {
  
  size(600,700);
  noLoop();
  
  background(25, 150, 180, 20);
  noFill();
  stroke(0);
  strokeWeight(2);

}

void draw() {

  // clear background
  background(25, 150, 170, 20);
  
  // line length (hypotenuse)
  float h = sin(THIRD_PI) * _size;
  
  for (int i = 0; i <= width / (_size * 3); i++) {
    for (int j = 0; j <= (height / h) + 1; j++) {

      // reference points (centre of each hexagon)
      float x = i * _size * 3 + (_size / 2);
      float y = j * h;
      // offset each odd row
      if (j % 2 > 0) {
        x += _size * 1.5;
      }

      pushMatrix();
      
        translate(x, y);
        
        // random hexagon rotation (0, 120, 240 degrees)
        rotate(int(random(0, 3)) * THIRD_PI);
    
        // draw line
        line(0, -h, 0, h);
  
        // draw arcs
        arc(-_size, 0, _size, _size, -THIRD_PI,     THIRD_PI);
        arc( _size, 0, _size, _size,  THIRD_PI * 2, THIRD_PI * 4); 
      popMatrix();}
  }
}
      void mousePressed() {
  
  redraw();
  }

Casey Reas’ Eyeo talk response

This video was interesting for me to watch because it talked more about the artistic side of code. I’ve never really been a fan of machine made art and “randomness” because I believe that art is more than just about the art, it’s also about the artist, the humanity, creativity, emotion, and ideas behind the piece. If some machine makes random lines or dots that form an image, it might look interesting, but there is nothing to connect to, no intention to interpret. However randomness can be useful when an entire piece is not just about the randomness itself, but the randomness is used to achieve something by the artist, such as the dots (27:12) moving randomly in a specific area determined by the artist. Reas’ ideas about order vs. chaos were interesting to listen to. I found it very thought provoking when he showed how the random images generated did not seem to create any specific image but when duplicated and mirrored, those same random shapes started to “trigger our imagination” and sort of create a familiar image, due to the symmetry. I also really liked the pieces he created dependent on the lines connected between the mid points of the overlapping circles (29:05-29:45). By the end of the video I was very impressed by the things that could be done, in terms of art, using code.

Attractive Things Work Better

As an artist, I liked this text because design, aesthetics, and the arts as a whole are a lot of times not appreciated and their value isn’t recognized as much as should be. In product design, the appealing look of the product can be almost as important as the product functionality. The Visceral, Behavioral and Reflective levels of processing and their effect on our feelings and emotions was interesting to read about. The appearance of a product, as shown in the text, affects the customers’ choice, as well as their experience. In my projects I always tried to make the product look appealing, as I think that’s always very important.

Self portrait in processing

void setup () {
 
size(500, 430);
background(500, 500, 500);
 
}
 
void draw() {

noStroke();
fill(61, 49, 16);
ellipse(200, 210, 256, 384);
ellipse(200, 160, 257, 194);
ellipse(200, 190, 272, 170);
ellipse(200, 230, 277, 177);
ellipse(200, 260, 279, 197);
ellipse(200, 308, 283, 167);
ellipse(200, 348, 287, 167);
ellipse(200, 388, 287, 167);


// face ?
fill(240, 222, 195);
stroke(0,0,0);
ellipse(200, 180, 190, 275);

stroke(61, 49, 16);
strokeWeight(20);
line(150,315, 90, 230);
line(239,329, 310, 236);

//hair
noStroke();
fill(61, 49, 16);
//ellipse(240, 75, 65, 95);
arc(265, 44, 90, 150, 70, 190);
arc(275, 75, 60, 130, 60, 140);
arc(250, 35, 90, 130, 60, 170);
arc(215, 20, 50, 90, 60, 170);
arc(305, 130, 70, 110, 70, 190);
arc(179, 73, 90, 80, 160, 360);
arc(130, 95, 60, 60, 130, 330);

// neck ?
fill(227, 212, 191);
ellipse(200, 320, 100, 180);

//shirt
fill(98, 52, 158);
ellipse(200, 448, 350, 210);

//shirt
fill(227, 212, 191);
arc(200, 340, 110, 40, 20, 160);

fill(240, 222, 195);
ellipse(200, 240, 130, 170);

// nose
stroke(153, 141, 131);
strokeWeight(1);
arc(210, 213, 20, 30, 0, 70);
arc(185, 213, 20, 30, 100, 170);
arc(198, 230, 18, 10, 20, 170);

fill(0,0,0);
ellipse(187, 228, 2, 4);
ellipse(210, 228, 2, 4);

//lips
noStroke();
fill(207, 127, 127);
arc(198, 260, 48, 30, 10, 170);
arc(207, 264, 25, 15, 180, 350);
arc(190, 264, 25, 15, 180, 350);

stroke(61, 49, 16);
strokeWeight(2);
line(260,150, 240, 144);
line(135,150, 148, 145);
line(215,145, 240, 144);
line(148,145, 176, 144);

fill(250, 245, 250);
strokeWeight(1);
ellipse(160, 164, 32, 17);
ellipse(234, 164, 32, 17);

fill(107, 83, 68);
ellipse(234, 164, 18, 14);
ellipse(161, 164, 18, 14);

fill(0,0,0);
ellipse(234, 164, 11, 10);
ellipse(161, 164, 11, 10);

 

Reading response 6 – Physical Computing’s Greatest Hits (and misses)

I feel both the blog posts for this week were very relevant to our current stage in the class. This post talked about how most project we think about have already done, but we shouldn’t let this stop or discourage us. I am completely new to interactive media and physical computing, and I feel like this was very relevant to me because I think a lot about how to make something unique.

In terms of the ideas, I think the video mirrors are quite cool, and I love the mechanical pixels idea. I also think the Scooby-doo idea would be cool to do, maybe with one of my drawings…

Reading response 5 – Making Interactive Art: Set the Stage, Then Shut Up and Listen

The ideas presented in this blog post make a lot of sense to me, but they are also difficult for me to get used to. Reading the explanation the blog post gave about the importance of looking at interactive art as a performance, rather than a finished painting was very interesting to me, because as a visual artist, that’s how I’ve been looking at it, and trying to explain the concept and inspiration behind my work the same way I would have with one of my paintings. I think having read this, I’ll try to keep reminding myself to not explain myself or my work, and instead just present it and let the audience explore and interpret it.

Secret book safe with a gesture lock

For my midterm project I wanted to make something more challenging and thought-out. After a lot of brainstorming, I noticed something that I have several of… secret storage boxes disguised as books.

I decided to make a safe that is disguised as a book, and make it so that it can only be locked/unlocked if a combination of gestures were done. I was at first going to use wood for the entire safe, but decided to use a combination of wood, cardboard, and transparent acrylic to make it more interesting. The paper part of the book is made from acrylic, so that if someone picked up the book from a shelf, they would see that it is not a normal book. So the transparent acrylic I decided to use is a twist to the point of safes, which is to keep objects hidden safe, in secret. The transparent barrier would let them see the money and valuables inside it, but no matter what they tried, they would not be able to open it, because only its owner would know the correct combination of gestures. This project was inspired by a combination of my love for Harry Potter and Sherlock Holmes. I didn’t notice this when I actually made it, but the safe box is a combination of the two storage boxes in the first image above. Although I had originally not thought of using transparency, the final result of my work was somehow subconsciously a mix of the two boxes, using the book-like shape of one and the transparent sides and solid top and bottom of the other.

I thought of adding a buzzer to make a sound when the person got the code wrong or an alarm after 3 wrong tries, but I thought that that wouldn’t make as much sense for my idea, because I want people to think that the box does not open, and a buzzer would give it away, and encourage them to try again. For this reason I also decided not to use any LEDs. I initially had a different combination of gestures, also using an up gesture, but decided to not use it as results were inconsistent with the up gesture.

materials/equipment:

-wood

-handsaw

-cardboard

-transparent acrylic

-laser cutter (for the 3 acrylic pieces)

-servo

-ZX gesture sensor

-Breadboard

-Redboard

-Jumper wires

-Glue (I mainly used acrylic glue, super glue, and a glue gun)

-paper (for book cover) – I printed and used the cover of the ‘getting started with Arduino’, which was co-written by Michael Shiloh, an NYUAD IM professor. I initially thought of using this cover just as a pleasant and funny surprise for the professor, since I knew he would be there when showing our projects, but this was perfect because not only did the color of the sensor match the color scheme of the cover but there was also a UNO board on it, that I put my sensor on to disguise.

I was a bit worried that because the gesture wasn’t too complex, it would open easily if people did any gesture, but it was great, and very entertaining I might add, to watch everyone try to guess how to open it and not be able to, until they eventually gave up and let me show them how it’s done! The product turned out how I wanted it to, and worked consistently.

#include <Servo.h>
#include <Wire.h>
#include <ZX_Sensor.h>
//const int ZX_ADDR = 0x10;
int gestureSequence[] = {
  0, 1, 2 // 0 is right swipe and 1 is left, 2 is up
};

int index = 0;
const int ZX_ADDR = 0x10;
ZX_Sensor zx_sensor = ZX_Sensor(ZX_ADDR);
bool leftGestureStarted = false;
bool rightGestureStarted = false;
bool upGestureStarted = false;

int prevZ = 240;
uint8_t x_pos = 0;
uint8_t z_pos = 0;

Servo myservo;

void setup() {
  // put your setup code here, to run once:

  uint8_t ver;
  myservo.attach(9);
  Serial.begin(9600);
  Serial.println();
  Serial.println("-----------------------------------");
  Serial.println("SparkFun/GestureSense - safebox");
  Serial.println("-----------------------------------");

  if ( zx_sensor.init() ) {
    Serial.println("ZX Sensor initialization complete");
  } else {
    Serial.println("Something went wrong during ZX Sensor init!");
  }

  ver = zx_sensor.getModelVersion();
  if ( ver == ZX_ERROR ) {
    Serial.println("Error reading model version number");
  } else {
    Serial.print("Model version: ");
    Serial.println(ver);
  }

  if ( ver != ZX_MODEL_VER ) {
    Serial.print("Model version needs to be ");
    Serial.print(ZX_MODEL_VER);
    Serial.print(" to work with this library. Stopping.");
    while (1);
  }
  //
  // Read the register map version and ensure the library will work
  ver = zx_sensor.getRegMapVersion();

  if ( ver == ZX_ERROR ) {
    Serial.println("Error reading register map version number");
  } else {
    Serial.print("Register Map Version: ");
    Serial.println(ver);
  }
  //
  if ( ver != ZX_REG_MAP_VER ) {
    Serial.print("Register map version needs to be ");
    Serial.print(ZX_REG_MAP_VER);
    Serial.print(" to work with this library. Stopping.");
    while (1);
  }
  myservo.attach(9);
}


void loop() {



  // put your main code here, to run repeatedly:
  //gesture stuff
  int gesture = -1;
  if (zx_sensor.positionAvailable()) {
    x_pos = zx_sensor.readX();
    z_pos = zx_sensor.readZ();
    if (x_pos != ZX_ERROR) {
      Serial.print("X: ");
      Serial.print(x_pos);
    }
    if (z_pos != ZX_ERROR) {
      Serial.print(" Z: ");
      Serial.print(z_pos);
    }
    Serial.print(" Index: ");
    Serial.print(index);
    Serial.print(" Left Started: ");
    Serial.print(leftGestureStarted);
    Serial.print(" Right Started: ");
    Serial.print(rightGestureStarted);
    Serial.print(" Up Started: ");
    Serial.println(upGestureStarted);



    // ===================== //

    if (z_pos < 220 && index < 3) {
      //      Serial.println("z less than 100");
      if (leftGestureStarted == false && rightGestureStarted == false && upGestureStarted == false)
      {
        if (x_pos > 130 && x_pos < 200)
        {
          leftGestureStarted = true;
        }
        else if (x_pos < 110 && x_pos > 80) {
          rightGestureStarted = true;
        }
//        else if (x_pos > 110 && x_pos < 170 && z_pos < 40) {
//          upGestureStarted = true;
//        }
      }
    }
  } else {
    leftGestureStarted = false;
    rightGestureStarted =false;
    upGestureStarted = false;
  }

  //then in another if statement
  if (leftGestureStarted == true) {
    if (x_pos < 100)
    {
      gesture = 1;
      leftGestureStarted = false;
    }
  }


  if (rightGestureStarted == true) {
    if (x_pos > 130 )
    {
      gesture = 0;
      rightGestureStarted = false;
    }
  }

//  if (upGestureStarted == true) {
//    if (z_pos > 60)
//    {
//      //Copy and Paste
//      gesture = 2;
//      upGestureStarted = false;
//    }
//  }
  // then check if the gesture is the current correct gesture:
  if (gesture >= 0) {
    if (gestureSequence[index] == gesture) {
      index++;
    } else {
      index = 0;
      Serial.println("wrong gesture");
    }
  }
  if (index == 2) {
    myservo.write(0);
    // 3 in this case because we have 4 gestures so starting from gesture 0=> counting 0,1,2,3
    //    unlock safe
    delay(3000);
    index=0;
  } else myservo.write(90);
  prevZ = z_pos;
}

Midterm idea

I’m still not quite sure what my midterm project is going to be. After having seen Simon’s work, I feel very inspired by him, and might incorporate some element inspired by his work. Also, I’m thinking of doing more of an interactive art project, so I’m exploring the ideas of working with sculpture, paint, laser, or some other form of creating something creative.

Reading response 4 – A brief rant on the future of interaction design (#2)

The writer is very defensive in this one. He completely goes against each comment very directly. To me, his tone and choice of words makes me take him less seriously. I understand his point of view, but I dont fully agree with his comment about voice not being explorable. Especially having seen the way the artist Zimoun explored sound. Also, the comment about the kid being able to use the ipad but not tie their shoelaces is very superficial. A child will know how to use something they practice at. If the child spent as much time practicing tying their laces, they would know how to do that, instead of how to use the ipad. Generally he seemed to be overreacting and illogical in the way he responded to the comments, which almost discredited his article for me…