import processing.core.*; 
import processing.xml.*; 

import java.applet.*; 
import java.awt.*; 
import java.awt.image.*; 
import java.awt.event.*; 
import java.io.*; 
import java.net.*; 
import java.text.*; 
import java.util.*; 
import java.util.zip.*; 
import java.util.regex.*; 

public class c_Animation extends PApplet {

PImage[] imgs;
int count = 0;
boolean rev = false;

public void setup() {
  size(300,300);    // window size
  //fill(255);        // shape colors
  stroke(255, 150); // color used to draw lines around shapes and alpha value
  strokeWeight(0);  // sets the width of the strokes
  background(0);    // background color
  frameRate(10);    // frames per second
  
  // draw random points (starts)
  for(int i=0; i<500; i++) {
    point(random(width), random(height)); 
  }
  
  // create array with earth pictures
  imgs = new PImage[18];
  for (int i=1; i<19; i++) {
    if (i<10) imgs[i-1] = loadImage("IMG000" + i + ".GIF");
    if (i>9 & i<100) imgs[i-1] = loadImage("IMG00" + i + ".GIF");
  }
}

// draw method repeats continously until app exit
public void draw() {
  if(count==17) count = 0; 
  if(count==-1) count = 17;
  image(imgs[count], width/2-imgs[count].width/2,height/2-imgs[count].height/2);

   if (rev==false) count++;
   if (rev==true) count--;
}

public void mousePressed() {
  if (rev==false) { 
    rev = true;
  } else {
    rev = false;
  }
}

public void keyPressed() {
  if (key == 's') save("earth.jpg");
}


  static public void main(String args[]) {
    PApplet.main(new String[] { "--bgcolor=#FFFFFF", "c_Animation" });
  }
}

