【Processing】copy()を使ってみる(4)

 

 

 

PImage img; //画像のオブジェクトを宣言
int x = width/2; //ペースト位置x
int y = height/2; //ペースト位置y
int sx = 0; //コピー起点x
int sy = 0; //コピー起点y
int ex = 0; //コピー終点x
int ey = 0; //コピー終点y
      
void setup(){
  img = loadImage("snj.jpg"); //画像をロードする
  size(559,800);   //画面サイズ
  image(img,0,0); //画像を表示
}

void draw(){
  copy(0,0,width/2,height,width,0,-width/2,height);
}

void mousePressed(){
sx = mouseX; //起点を設定
sy = mouseY; //起点を設定
}


void mouseReleased(){
ex = mouseX - sx; //終点を設定
ey = mouseY - sy; //終点を設定

x = mouseX;
y = mouseY;
for(int i = 0 ; i < 20 ; i++ ){
x += int(random(-10.10));
y += int(random(-10,10));
copy(sx,sy,ex,ey,x,y,ex,ey);
}
}