Processing 加工绘制方法慢吗?

Processing 加工绘制方法慢吗?,processing,draw,geometry,Processing,Draw,Geometry,我正在处理语言,并且有这样一个代码: int脂肪度=30; int步长=20; void drawCircle(){ 填充(48139206); 椭圆(宽度-肥胖,高度-肥胖,肥胖,肥胖); } void increaseCircle(){ 肥胖=肥胖+步幅; } 在另一个类中,我想调用increaseCircle()方法。但是我希望它慢慢变大。我的意思是,在我的代码中,step使它变大了20倍,但我希望它变大,即,如果可能的话,用动画使它变大2秒。我该怎么做 编辑:当我从该类定义一个对象并调

我正在处理语言,并且有这样一个代码:

int脂肪度=30;
int步长=20;
void drawCircle(){
填充(48139206);
椭圆(宽度-肥胖,高度-肥胖,肥胖,肥胖);
}
void increaseCircle(){
肥胖=肥胖+步幅;
}
在另一个类中,我想调用
increaseCircle()
方法。但是我希望它慢慢变大。我的意思是,在我的代码中,step使它变大了20倍,但我希望它变大,即,如果可能的话,用动画使它变大2秒。我该怎么做


编辑:当我从该类定义一个对象并调用increaseCircle方法时,它会变得越来越大,不会停止吗?

听起来你需要根据时间更新值

如果存储开始时间,则始终可以使用该函数检查经过的时间

一旦知道经过了多少时间,就可以将差异除以更新变量所需的持续时间(在您的情况下为肥胖)

这将为您提供介于0.0和1.0之间的值,您可以使用该值缩放/乘以变量的最终所需值(例如,脂肪度从20到200)

我的意思是:

int startTime;
int duration = 1000;
float startValue = 20;
float endValue = 200;
float currentValue = startValue;

void setup(){
  size(400,400,P2D);
  ellipseMode(CENTER);
  startTime = millis();
}
void draw(){
  background(255);
  increaseCircle();
  drawCircle();
}
void drawCircle() {  
 fill(48, 139, 206);
 ellipse(width - currentValue, height - currentValue, currentValue, currentValue);
}

void increaseCircle(){
  float progress = (float)(millis()-startTime)/duration;//millis()-startTime = difference in time from start until now
  if(progress <= 1.0) currentValue = startValue + (endValue * progress);//the current value is the final value scaled/multiplied by the ratio between the current duration of the update and the total duration
}
void mousePressed(){//reset value and time
  currentValue = startValue;
  startTime = millis();
}
void keyPressed(){//update duration
  if(key == '-') if(duration > 0) duration -= 100;
  if(key == '=' || key == '+') duration += 100;
  println("duration: " + duration);
}

听起来您需要根据时间更新值

如果存储开始时间,则始终可以使用该函数检查经过的时间

一旦知道经过了多少时间,就可以将差异除以更新变量所需的持续时间(在您的情况下为肥胖)

这将为您提供介于0.0和1.0之间的值,您可以使用该值缩放/乘以变量的最终所需值(例如,脂肪度从20到200)

我的意思是:

int startTime;
int duration = 1000;
float startValue = 20;
float endValue = 200;
float currentValue = startValue;

void setup(){
  size(400,400,P2D);
  ellipseMode(CENTER);
  startTime = millis();
}
void draw(){
  background(255);
  increaseCircle();
  drawCircle();
}
void drawCircle() {  
 fill(48, 139, 206);
 ellipse(width - currentValue, height - currentValue, currentValue, currentValue);
}

void increaseCircle(){
  float progress = (float)(millis()-startTime)/duration;//millis()-startTime = difference in time from start until now
  if(progress <= 1.0) currentValue = startValue + (endValue * progress);//the current value is the final value scaled/multiplied by the ratio between the current duration of the update and the total duration
}
void mousePressed(){//reset value and time
  currentValue = startValue;
  startTime = millis();
}
void keyPressed(){//update duration
  if(key == '-') if(duration > 0) duration -= 100;
  if(key == '=' || key == '+') duration += 100;
  println("duration: " + duration);
}