You can use a timer to change it only from N to N time intervals
static final int NUM_LINES = 30;
float t;
int R, G, B;
long previousTime = 0, currentTime = 0;
void setup() {
background(10);
size (500, 500);
}
void draw() {
background(10);
currentTime = millis();
if(currentTime - previousTime > 1000){ //If the time interval between update is higher than 1s (1000ms) then get the new colors
R = (int)random(0,255);
G = (int)random(0,255);
B = (int)random(0,255);
previousTime = currentTime;
}
stroke(color(R, G, B));
strokeWeight(4);
translate(width/2, height/2);
for (int i = 0; i < NUM_LINES; i++) {
line(x1(t + i), y1(t + i), x2(t + i), y2(t + i));
}
t += 0.4;
}
float x1(float t) {
return sin (-t / 10) * 100 + sin (t / 6) * 20 ;
}
float y1(float t) {
return cos (-t / 10) * 100;
}
float x2(float t) {
return sin (-t / 10) * 100 + sin (t) * 2 ;
}
float y2(float t) {
return cos (-t / 20) * 200 + cos(t / 12) * 20;
}
If you want them to change smoothly I would suggest you look at the lerpColor method. There you can decide the initial and final color and get all the ones in between by setting the amt parameter.