您的位置:首页 > 其它

processing鼠标移动

2014-09-07 22:44 501 查看
int rectX,rectY;
int rectSize=90;

color rectColor;
color baseColor;

boolean rectOver=false;

void setup(){
size(640,360);
rectColor=color(0);
baseColor=color(102);
rectX=width/2-rectSize/2;
rectY=height/2-rectSize/2;
}

void draw(){
update(mouseX,mouseY);
noStroke();
if(rectOver){
background(rectColor);
}else {
background(baseColor);
}

stroke(255);
fill(rectColor);
rect(rectX,rectY,rectSize,rectSize);
}

void update(int x,int y){
if(overRect(rectX,rectY,rectSize,rectSize)){
rectOver=true;
}else{
rectOver=false;
}
}

boolean overRect(int x,int y,int width,int height){
if(mouseX>=x && mouseX<=x+width &&
mouseY>=y && mouseY<y+height){
return true;
}else{
return false;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息