我试图让草图的背景每 5 秒变成不同的颜色 2 秒,但我不知道该怎么做。这是我所拥有的简化代码。
time = millis();
color GREEN = #1fa81f;
void setup(){
size(650, 800);
background(0);
}
void draw(){
circle(mouseX,mouseY,);
if (time > 500){
background(GREEN);
time = millis();
}
如果有人可以帮助我,我将非常感激。谢谢!!
试试这个-
int bgColor;
int lastColorChange;
int changeInterval = 5000; // 5 seconds
int colorChangeDuration = 2000; // 2 seconds
void setup() {
size(400, 400);
bgColor = color(random(255), random(255), random(255));
lastColorChange = millis();
}
void draw() {
background(bgColor);
// Check if it's time to change the background color
int elapsedTime = millis() - lastColorChange;
if (elapsedTime >= changeInterval) {
// Change the background color
bgColor = color(random(255), random(255), random(255));
lastColorChange = millis();
}
}