Animation 需要能够看到使用for循环在处理中绘制的矩形

Animation 需要能够看到使用for循环在处理中绘制的矩形,animation,processing,Animation,Processing,对于一个项目,我编写了一个代码,创建了一个带有图标的电脑壁纸。我设置的一个图标在单击时绘制加载条(鼠标按下无效)。我希望能够看到矩形(加载条)使用RectMode(角点)从一个确定的位置开始,并每隔几秒钟增加一次宽度,直到条大约满了3/4,然后停止并保持 请给出建议 这将绘制完成的条形图,但我想在几秒钟内看到每个增量 void setup(){ size(800,600); } void mousePressed(){ if (mousePressed && mouse

对于一个项目,我编写了一个代码,创建了一个带有图标的电脑壁纸。我设置的一个图标在单击时绘制加载条(鼠标按下无效)。我希望能够看到矩形(加载条)使用RectMode(角点)从一个确定的位置开始,并每隔几秒钟增加一次宽度,直到条大约满了3/4,然后停止并保持

请给出建议
这将绘制完成的条形图,但我想在几秒钟内看到每个增量

void setup(){
  size(800,600);
}

void mousePressed(){
  if (mousePressed && mouseX>width/4 && mouseX<width-width/4 && mouseY>height/3 && mouseY<height-    height/3){
  rectMode(CORNER);
  noStroke();
  fill(0,180,0,180);
  for( int r = 0; r <= 7; r++){
    if (r == 1)
      i = 50;
    rect(width/2-348,height/2-35,i,height/8-4);
    if (r == 2)
      i = 150;
    rect(width/2-348,height/2-35,i,height/8-4);
    if (r == 3)
      rect(width/2-348,height/2-35,i,height/8-4);
    i = 250;
    if (r == 4)
      rect(width/2-348,height/2-35,i,height/8-4);
    i = 350;
    if (r == 5)
      rect(width/2-348,height/2-35,i,height/8-4);
    i = 450;
    if (r == 6)
      rect(width/2-348,height/2-35,i,height/8-4);
    i = 550;
    if (r == 7)
      rect(width/2-348,height/2-35,i,height/8-4);
    i = 650;
} 
}

}
void setup(){
规模(800600);
}
void mousePressed(){

如果(mousePressed&&mouseX>width/4&&mouseXheight/3&&mouseY您想这样做吗

int time, myWidth;
boolean loading;

void setup(){
  size(800,600);
  loading = false;
  myWidth = 0;
}

void draw(){
  drawLoadingBar();
}

void drawLoadingBar(){

  if(myWidth < width/3){
    if(loading && millis()-time > 1000){
      rect(20, height/2, myWidth, 30);
      myWidth = myWidth + 10;          
      time = millis();
    }
  }

}

void mousePressed(){
  if(loading == false){
      time = millis();  
      loading = true;
  }
}
int-time,myWidth;
布尔加载;
无效设置(){
规模(800600);
加载=假;
myWidth=0;
}
作废提款(){
drawLoadingBar();
}
void drawLoadingBar(){
如果(myWidth<宽度/3){
如果(加载和毫秒()-时间>1000){
矩形(20,高度/2,我的宽度,30);
myWidth=myWidth+10;
时间=毫秒();
}
}
}
void mousePressed(){
如果(加载==false){
时间=毫秒();
加载=真;
}
}

此代码的工作原理是在第一次鼠标单击后每秒将条形图宽度增加10。

使用循环正在处理中,由函数
loop()
定义,可以通过
noLoop()
停止。此外,我正在使用frameCount(包含自程序启动以来显示的帧数-每次运行
draw())
函数)计算加载进度条的百分比,并根据需要在3/4停止加载

boolean loading = false;
int fillX = 0;

void setup()
{
  size(300,300);
  background(0);
  noLoop();  
}

void draw()
{
  stroke(255);
  fill(0);
  rect(48, 137, 204, 25);
  noStroke();
  fill(255);
  rect(51, 140, fillX, 20);

  if(loading == true)
  {       
    fillX = ((frameCount%301) / 3 * 2);    
    if(frameCount%(300*0.75) == 0)
    {
      loading = false;
      noLoop();
      frameCount = 0;
    }
  }
}

void mousePressed() {
  loading = true;
  loop();
}

RectMode(角点)是默认模式,因此无需指定它,除非您在项目中使用不同的模式。

抱歉,已删除的旧模式没有看到编辑按钮我是新成员