2012年10月23日 星期二

Week07,HW07

1.期中作品

int dogx=0,dogy=0;
int dx=1;
PImage dog;
PImage bg;
PImage []num =new PImage[10];
void setup()
{
size(500,500);
dog = loadImage("dog.png");
bg = loadImage("background.png");
image(bg,0,0,500,500);
num[0]=loadImage("0.png");
num[2]=loadImage("1.png");
num[3]=loadImage("2.png");
for(int i=0;j<10;j++){
  num[i]=loadImage(""+i+".png");
  }
}
void draw(){
//bg = loadImage("background.png");
//background(249,242,226);\
image(bg,0,0,500,500);
if(dogx>400 || dogx<0) dx=-dx;
dogx+=dx;
loadPixels();
for(int Y=dogy;Y>500;Y++)
{
  color c=pixels[Y*500+dogx];
  if(c==color(255,0,0)){
  dogy=Y-100;
  break;
  }
}
stroke(255,0,0);
line(mouseX,mouseY,pmouseX,pmouseY);
save("background.png");
println("X"+dogx+"Y"+dogy);
//loadPixels();
//stroke(255,0,0);
//line(mouseX,mouseY,pmouseX,pmouseY);
image(dog,dogx,dogy,100,100);
//loadPixels();
}

2.視訊

[圖片]



[程式碼] import processing.video.*;
Capture video;
void setup(){
  size(640,480,P2D);
  video = new Capture(this, width, height);
  video.start();
  loadPixels();
}
void draw(){
  if(video.available()){
    video.read();
    video.loadPixels();
    for(int i=0;i<640*480;i++){
      pixels[i]=video.pixels[i];     
    }
    updatePixels();
  }
}

1 則留言: