2016年12月15日 星期四

Week11 錡洛誼上課筆記

實作:互動餐桌 (https://youtu.be/LXyX-OvZlUg)

PVector [] dish=new PVector[4];
float [] r = {0,0,0,0};
float [] angle = {0,0,0,0};
void setup(){
size(640,480);
dish[0]=new PVector(100,100);
dish[1]=new PVector(540,100);
dish[2]=new PVector(100,380);
dish[3]=new PVector(540,380);
}
void draw(){
background(255);
ellipse(320,240, 400,400);//rotating circle
ellipse(100,100,100,100);
ellipse(540,100,100,100);
ellipse(100,380,100,100);
ellipse(540,380,100,100);
for(int i=0;i<4;i++){
ellipse(dish[i].x, dish[i].y, 90,90);
line(dish[i].x, dish[i].y, 320,240);
}
if(keyPressed){
for(int i=0;i<4;i++){
angle[i] -= 0.01;
dish[i].x= r[i] * cos(angle[i]) + 320;
dish[i].y= r[i] * sin(angle[i]) + 240;
}
}
}
int nowDish=-1;
void mousePressed(){
for(int i=0;i<4;i++){
if( dist(dish[i].x, dish[i].y, mouseX, mouseY) <45 ){
nowDish=i;
}
}
}
void mouseDragged(){
if( nowDish!= -1){
dish[nowDish].x=mouseX;
dish[nowDish].y=mouseY;
r[nowDish] = sqrt( (mouseX-320)*(mouseX-320) + (mouseY-240)*(mouseY-240) );
angle[nowDish] = atan2(mouseY-240, mouseX-320);
}
}
void mouseReleased(){
nowDish = -1;
}

沒有留言:

張貼留言