Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript p5.js:为什么我的椭圆在闪烁?_Javascript_Processing_P5.js - Fatal编程技术网

Javascript p5.js:为什么我的椭圆在闪烁?

Javascript p5.js:为什么我的椭圆在闪烁?,javascript,processing,p5.js,Javascript,Processing,P5.js,我有一个通过draw()缩放的椭圆,但由于某种原因,它无法控制地闪烁。我似乎不明白为什么。我怀疑这与设置超时有关。我需要它,因为我需要等待10秒,然后才能绘制椭圆。下面是代码: //diameter of ellipse that increments var dia1 = 0; var dia2 = 0; function setup() { createCanvas(400,400); stroke(255); noFill(); frameRate(40); } //draw an

我有一个通过draw()缩放的椭圆,但由于某种原因,它无法控制地闪烁。我似乎不明白为什么。我怀疑这与设置超时有关。我需要它,因为我需要等待10秒,然后才能绘制椭圆。下面是代码:

//diameter of ellipse that increments
var dia1 = 0;
var dia2 = 0;

function setup() {
createCanvas(400,400);
stroke(255);
noFill();
frameRate(40);
}  

//draw and increment ellipse
function circle1() {  
ellipse(width/2,height/2, dia1,dia1);

dia1 = dia1+1;
if (dia1 >= width) {
  dia1 = 0;
}

}
function circle2() {  
ellipse(width/2,height/2, dia2,dia2);
dia2 = dia2+1;
if (dia2 >= width) {
  dia2 = 0;
}

}



function draw() {


background(40,40,40);

//wait 10 seconds before drawing ellipse
setTimeout(function() { circle1(); }, 10000);

circle2();


console.log(dia1);


}

不应使用
setTimeout()
调用绘图函数

如果要计时,请使用
millis()
函数。中提供了更多信息,但基本程序如下所示:

function draw(){
   background(0);
   if(millis() > 10000){
      ellipse(width/2, height/2, 25, 25);
   }
}

不应使用
setTimeout()
调用绘图函数

如果要计时,请使用
millis()
函数。中提供了更多信息,但基本程序如下所示:

function draw(){
   background(0);
   if(millis() > 10000){
      ellipse(width/2, height/2, 25, 25);
   }
}