Wednesday 21 September 2016

MEDA102 Assessment 2: Digital coding/Processing Sketch



My processing sketch explores the theme of iteration through the repetition of the animation, the condition checks and the fact that the slime cannot escape the screen. Although not very visible in the sketch, my code is evidence of many layers of iteration.
One of the artworks covered in tutorial was George Perec’s The Art of Asking your Boss for a Raise, this artwork is very relatable to my sketch because many different steps are taken with different decisions made along the way. The sketch iterates back to the same point no matter what choices are made. This is encapsulated by the movement and sequence of animations of the slime as it hops around the screen.
Another artist we covered was Sol LeWitt, the somewhat open ended instructions he used in his conceptual art are similar to how the viewer has no set instructions with what to do with the slime, the falling fruit are also limited yet unlimited by this as they are not given a set location in which to fall from.

Screenshots of the sketch and images used (This is an animated sketch which will require pictures, download link for the sketch with images included here: https://drive.google.com/open?id=0B5PsqQISQHqMWWhDSGJ3Nk54azA ):









Code:
//The vast majority of this code is of my own creation
//Declaring all the various global variables
//Generally bad to use global variables but it's easier for Processing
Animation anim1,anim2,fgIMG,bgIMG,idle1,idle2,fruit0,fruit1,fruit2,fruit3,fruit4; //load all the Animation objects
float xpos = 320;
float ypos = 276;
float rXPos = width;
float rYPos = height / 3;
int iLR = 0;
int numFruit = 10; //Limits number of fruit, prevents memory leaks
int iLives = 5;
boolean bIdleLR = true;
Fruit[] fDrop = new Fruit[numFruit]; //Make "numFruit" amount of fruits. In this case, 10


void setup() //Initializes all the animations, the size of the canvas, sets the frame rate and initializes the fruit rain!
{
  size(640, 360);
  frameRate(21);
  anim1 = new Animation("hopL_",6);
  anim2 = new Animation("hopR_",6);
  fgIMG = new Animation("Foreground_",1);
  bgIMG = new Animation("Background_",1);
  idle1 = new Animation("idleL_",10);
  idle2 = new Animation("idleR_",10);
  fruit0 = new Animation("fruit0_",1);
  fruit1 = new Animation("fruit1_",1);
  fruit2 = new Animation("fruit2_",1);
  fruit3 = new Animation("fruit3_",1);
  fruit4 = new Animation("fruit4_",1);
  for(int i = 0;i < fDrop.length;i++) //For the length of Array "fDrop", loop
  {
    fDrop[i] = new Fruit(); //make new Fruit's and fill up the array!
  } 
}

void draw() //Iterates whatever is inside the {} infinitely.
{
  bgIMG.display(-2,0); //Display the background
  for(int i = 0;i < fDrop.length;i++) //Spawn a fruit and drop it as many times as there are fruits stored in the fDrop array
  {
    fDrop[i].Fall();
  }
  if(iLR == 0) //If idle, run idle animation in whichever direction the slime is facing
  {
    if(bIdleLR == true)
    {
      idle1.display(xpos-idle1.getWidth()/2, ypos);
    }
    if(bIdleLR == false)
    {
      idle2.display(xpos-idle2.getWidth()/2, ypos);
    }
  }
  if(iLR == 1) //Hop left
  {
    anim1.display(xpos-anim2.getWidth()/2, ypos);
    xpos = xpos - 4;
  }
  if(iLR == 2) //Hop right
  {
    anim2.display(xpos-anim2.getWidth()/2, ypos);
    xpos = xpos + 4;
  }
  if(xpos < -23) //If slime goes too far left, put slime on other side of screen
  {
    xpos = 660;
  }
  if(xpos > 663) //If slime goes too far right...
  {
    xpos = -20;
  }
  fgIMG.display(-2,298); //Display the foreground
}

void keyPressed()
{
  if(key == CODED) //Checks for predefined key event
  {                //LEFT and RIGHT are such events
    if(keyCode == LEFT)
    {
      bIdleLR = true;  //If the slime was moving left, change idle animation to face left and then keep moving left
      iLR = 1;
    }
    if(keyCode == RIGHT)
    {
      bIdleLR = false;  //Same as above, opposite direction
      iLR = 2;
    }
  }
}

void keyReleased()  //If no keys are pressed, start playing the idle animation
{
    iLR = 0;
}

class Fruit
{
  int randFruit = (int)random(5); //Provides the switch statement with a random number in order to get random fruit
  float xFruit = random(width - 30); //Gives the fruit a random horizontal starting position
  float yFruit = random(-height); //Sets starting height of fruit, its above the top of the screen
 
  void Fall()
  {
    yFruit = yFruit + 7;  //Moves the fruit down by 7px
 
    switch(randFruit) //Assigns a random fruit sprite to the latest iteration of Fall
    {
      case 0:
        fruit0.display(xFruit,yFruit-fruit0.getHeight());
        break;
      case 1:
        fruit1.display(xFruit,yFruit-fruit1.getHeight());
        break;
      case 2:
        fruit2.display(xFruit,yFruit-fruit2.getHeight());
        break;
      case 3:
        fruit3.display(xFruit,yFruit-fruit3.getHeight());
        break;
      case 4:
        fruit4.display(xFruit,yFruit-fruit4.getHeight());
    }
 
    if(yFruit > height)//If the fruit escapes off of the bottom of the screen, put it back on top
    {
      yFruit = 0;
      xFruit = random(width - 30); //Randomizes the horizontal position once fruit has been relocated
    }
  }
}

class Animation  //This class collates all the separate images and turns them into a single animation, I only wrote the last function
{
  PImage[] images;
  int imageCount;
  int frame;
 
  Animation(String imagePrefix, int count) //This constructor collates a series of images into a single animation, stored in an array
  {
    imageCount = count;
    images = new PImage[imageCount]; //Creating a new array of size "imageCount" to hold the individual frames of the animation

    for (int i = 0; i < imageCount; i++)
    {
      //nf() is used to format i into four digits
      String filename = imagePrefix + nf(i, 4) + ".png"; //Setting the read path to: "prefix", then padding i with 0's to the left and finally the file extension.
      images[i] = loadImage(filename);  //Loading the image from the file path and storing it in the appropriate frame
    }
  }

  void display(float xpos, float ypos) //This function plays and displays an animation at a given location (xpos,ypos)
  {
    frame = (frame+1) % imageCount;
    image(images[frame], xpos, ypos);
  } 
  int getWidth()
  {
    return images[0].width; //Provides the width of the first frame
  }
 
  int getHeight()  //This is the only function that I wrote inside this class
  {
    return images[0].height; //Provides the height of the first frame
  }
}

Wednesday 17 August 2016

MEDA102 - Assessment 1: Analogue Coding/ Computational Thinking in the Everyday



The Fax Machine – Translation and transmission
Alexander Bain patented the first facsimile machine design in 1843. In 1850 Frederick Bakewell had obtained a patent for what he called an image telegraph, both of these early attempts were not viable for large scale use due to the fact that they produce poor quality image because they were not properly synchronised. However in 1861 Giovanni Caselli invented the Pantelegraph, and this became the first commercial telefax service between Paris and Lyon. Early facsimile machines, or fax machines, as we know them today involved a rotating drum. The document to be sent was attached to the drum facing outwards where a small photo sensor attached to a moveable arm would move across the paper as the drum rotated. This process is s similar to how a lathe works. Modern fax machines have a bar of photo sensors that enable whole lines to be read at once, while the document is fed through rollers instead of being attached to a drum. 

The sensor reads the paper as it passes by, picks up white or black for a given area and then the information is electronically encoded as binary. White dots are 0’s and black dots are 1’s. The data is then sequentially transmitted via the phone lines to the recipient fax machine, where it is decoded and read. The information is then applied to the paper in the form of black dots via the print head. Fax machines also come in a number of exclusive groups in which they only communicate to others of the same type. These are broken down into four different categories. Groups I and II are extremely low detail, much of the information read and encoded is lost. Group III fax machines are the standard office variety, they are more sensitive and will not lose much detail during the encoding process. Group IV fax machines are the top of the line variety, they are able to recognise and encode a vastly larger amount of detail then the other groups. Group IV’s also need their own special form of phone line in order to communicate the data to the fax machine at the other end.

A single line of a document can be represented bin 1728 bits, a standard group III fax contains 1145 lines and therefore, there is a little under two million bits of information in a single document. To reduce the volume of information that needs to be transmitted the data can be compressed using a number of compression techniques. These techniques are the Modified Huffman, Modified Read and Modified Read Read. These compression algorithms function by looking for groups of black of white bits, this drastically reduces the time in which a document can be transmitted. A fax machine can transmit at 14400bps or bits per second, however depending on the noise of the line in which the information is being transmitted this can go as low as 2400bps. This lowering of the speed of communication ensures that the information transmitted is not lost.

With the advent of the World Wide Web, it has become possible to send documents using fax machines connected to the internet. This requires the information to be encoded differently, using TCP/IP (Transmission Control Protocol/Internet Protocol) which involves reading the whole document, encoding it, compressing it and then transmitting it or RTP (Real-Time Protocol) which allows a documents information to be read, encoded, compressed and sent as soon as it is ready. No matter how a fax machine sends its data, it must know where to send it. For fax machines on the phone lines, a special phone number is required but fax machines connected to the internet only require an IP address.

In the tutorial of week 2 we were given a task to come up with our own encoding and decoding processes for a human fax machine, and while ours wasn’t as complicated as a normal fax machine it was on the right track. We decided to encode the information to be sent as a variable number of sequential taps that represented a coordinate on the piece of paper. Once coordinates had been sent, lines were to be drawn between them. This worked reasonably well, but we lost a lot of detail because we could not encode enough information without taking too much time.



References:
Chris Woodford, 2 January 2016, Fax Machines, viewed 13 August 2016, <http://www.explainthatstuff.com/faxmachines.html>
Marshall Brain, 2 October 2001, How Fax Machines Work, HowStuffWorks.com, viewed 13 August 2016, <http://electronics.howstuffworks.com/gadgets/fax/fax-machine.htm>
O'Hearn, B 1992, 'WHAT TO LOOK FOR WHEN BUYING A FAX', Journal of Accountancy, vol. 174, no. 3, pp. 79-81.
Tebbs, RG 1999, 'Real-Time IP Facsimile: Protocol and Gateway Requirements', Bell Labs Technical Journal (John Wiley & Sons, Inc.), vol. 4, no. 2, p. 128.
Wikipedia, 13 July 2016, Alexander Bain, Wikipedia.org, viewed 13 August 2016, < https://en.wikipedia.org/wiki/Alexander_Bain_(inventor)#Facsimile_machine>

Sunday 7 August 2016

MEDA102 - Tutorial 2

1. The first artwork we sent was "Rainstorm Beneath the Summit" by Hokusai. The second artwork was "The Dog" by Pablo Picasso.
2. Using paint or a pigment applied to a surface, Hokusai has portrayed Mt Fuji in a recognizable fashion. The shape and colour of the mountain and its environment has been retained, while a large portion of the detail has been omitted. Whereas the simple dog portrait that Picasso authored is just a simple continuous line drawing. It lacks colour, and detail yet it is still recognizable as a dog.
3. Our encoding process used a piece of paper divided into quarters and these in turn divided into quarters twice more to get a total of 64 different squares. When given the right information in the form of coordinates, we drew lines between the different points to get an image.
4. We figured that all images can be divided into enough sections that can then be transmitted one at a time. The only elements we encoded were lines and although this omits information, the general idea of an image can still be transmitted.
5. We used tapping and sticky-tape sounds to send a series of coordinates between the teams.
6. Our method of transmitting coordinates and drawing lines between them worked really well.
7. Unsure, we didn't have any trouble.
8. To improve upon our transmission method, we could divide the coordinate system up even more to the point where "pixel" locations are transmitted along with colour information in order to get an almost perfect reproduction of the image. However doing this by hand would take longer the more detail we included.