微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

处理语言的展期

如何解决处理语言的展期

我正在做翻转动画。

如果鼠标光标回到图块时淡出颜色,如何将颜色还原为原始颜色?

在我的代码中,当我将光标移到图块上时,颜色逐渐淡化为白色,然后不再返回

float addColorValue;
boolean clicked = false;

void setup() {
    size(400,400); //pixel size of the program
}
    
void draw() {
    background(255); //setting up the white background
    line(width/2,height,width/2,0); //drawing the vertical line
    line(width,height/2,width/2); //drawing the horizontal line
    if(clicked){
        if(mouseX > 200 && mouseY > 200){   // draws the 4th quadrant 
            fill(255,255,addColorValue+=1); rect(200,200,200); //draws rectangle
            fill(255); textSize(50); text("4TH",250,300); //display which number of the quadrant
        }
        //draws the 3rd quadrant
        else if(mouseX > 0 && mouseY > 200){ 
            fill(addColorValue+=1,addColorValue+=1,255); rect(0,200);
            fill(255); textSize(50); text("3RD",50,300);
        }
        //draws the 2nd quadrant
        else if(mouseX > 200 && mouseY > 0){ 
            fill(addColorValue+=1,200);
            fill(255); textSize(50); text("2ND",100);
        }
        //draws the 1st quadrant
        else if(mouseX > 0 && mouseY > 0){ 
            fill(255,addColorValue+=1); rect(0,200);
            fill(255); textSize(50); text("1ST",100);
        }
    } 
    else{
        background(0);
    }
}
    
//switches on and off the lights of the program
void mousepressed() { 
    clicked = !clicked; 
}

解决方法

将每个四边形与一个索引相关联,并将该索引存储在全局变量(quad)中。获取当前四边形(new_quad)的索引,并将其与quad进行比较。如果索引已更改,则设置addColorValue = 0。这将重新开始褪色效果:

if (quad != new_quad) {
    quad = new_quad;
    addColorValue = 0;
}

查看示例:

float addColorValue;
boolean clicked = false;
int quad = 0;

void setup() {
    size(400,400); //pixel size of the program
}

void draw() {
  
    if (clicked) {
        background(255); //setting up the white background
        line(width/2,height,width/2,0); //drawing the vertical line
        line(width,height/2,width/2); //drawing the horizontal line
   
        int new_quad = -1; 
        if (mouseX > 200 && mouseY > 200){   
            new_quad = 0;        
            drawRect("4TH",200,color(255,255,addColorValue+=1)); 
        }
        else if(mouseX > 0 && mouseY > 200){ 
            new_quad = 1; 
            drawRect("3RD",color(addColorValue+=1,addColorValue+=1,255)); 
        }
        else if(mouseX > 200 && mouseY > 0){ 
            new_quad = 2;   
            drawRect("2ND",addColorValue+=1)); 
        }
        else if(mouseX > 0 && mouseY > 0) {
            new_quad = 3;   
            drawRect("1ST",addColorValue+=1)); 
        }
        
        if (quad != new_quad) {
            quad = new_quad;
            addColorValue = 0;
        }
    } 
    else{
        background(0);
    }
}

void drawRect(String text,int x,int y,int w,int h,color c) {
    fill(c); 
    rect(x,y,w,h);
    fill(255); 
    textSize(50); 
    text(text,x+50,y+100);
}

//switches on and off the lights of the program
void mousePressed(){ 
    clicked = !clicked; 
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。