2012年3月11日 星期日

Homwork 5-1

From this project I have learnt hot to zoom in and zoom out a picture, fade in and fade out picture,  and animate a picture by using a keyboard.

PImage img;
int i;
int j;
int t;
int dragY;
int dragX;
int z;
int size = 60;      
float xpos, ypos;    // Starting position of shape
void setup()
{
 size(1000, 500);
 i=0;
 j=0;
 z=255;
 t=10;
 xpos = width/2;
 ypos = height/2;

 img = loadImage("35b.jpg");
 frameRate(20);
}
void draw()
{
 
 background(255);

int xdirection = 1;  // Left or Right
int ydirection = 1;
float xspeed = 2.8;  // Speed of the shape
float yspeed = 2.2;  // Speed of the shape

  xpos = xpos + ( xspeed * xdirection );
 ypos = ypos + ( yspeed * ydirection );


 if (xpos > width-size || xpos < 0) {
    xdirection *= -1;
  }
  if (ypos > height-size || ypos < 0) {
    ydirection *= -1;
  }
 if ((keyPressed == true) && ( (key == 'A') || (key == 'a')) )
 {
    i = i+20;
   
  }
  if ((keyPressed == true) && ( (key == 'B') || (key == 'b')) )
 {
    i = i-20;   
 }
 if ((keyPressed == true) && ( (key == 'C') || (key == 'c')) )
 {
  i = i+20;
 }
 
  if ((keyPressed == true) && ( (key == 'D') || (key == 'd')) )
 {
  j = j+20;
 
 }
  if ((keyPressed == true) && ( (key == 'f') || (key == 'F')) )
 {
  t = t+20;
 
 }
  if ((keyPressed == true) && ( (key == 'g') || (key == 'G')) )
 {
  t = t-20;
 
 }
 if ((keyPressed == true) && ( (key == 'Z') || (key == 'z')) )
 {
  z = z-20;
 }
  if ((keyPressed == true) && ( (key == 'm') || (key == 'M')) )
 {
  z = z+20;
 }
 image(img, i, 0, t, t);
 if (z>255) z=255;
 if (z<0)z=0;
 tint(z);
}

沒有留言:

張貼留言