Help changing colours in my animation

Hi! I want my 3 triangle to randomly be changing colours throughout the whole animation. I’m a little stuck on where to go next but this is what I have so far.

float x = 0;
float speed = 1;
float r = random(255);
float g = random(255);
float b = random(255);


void setup()
{
  size(700,500);

}

void draw()
{
  background(255);
      
  x = x + speed;
  translate( x,0);
  if ( x > width)    x = -50;
  if (mousePressed) x = 0;
  
 
    
 { 
   fill(0);
line(0,200,700,200);
line(0,300,700,300);
line(0,400,700,400);
   
noStroke();  
fill(#958585); 
rect(50,430,50,30);
triangle(100,425,150,443,100,465);
fill(#0FD2F2);
ellipse(100,445,20,20);
fill(0);
ellipse(63,445,5,5);
ellipse(78,445,5,5);
strokeWeight(255);
fill(#F20F0F);
triangle(30,410,50,430,100,430);
triangle(30,480,50,460,100,460);
fill(r,g,b);
triangle(7,425,50,430,50,460);
triangle(23,437,0,443,50,460);
triangle(30,450,7,462,50,460);
fill(#F74D0A);
triangle(20,430,50,438,50,450);
triangle(35,438,10,443,50,450);
triangle(20,457,35,445,50,450);

  }
    

}
1 Like

you can repeat the
color random inside the

void draw(){
// ...
  r = random(255);
  g = random(255);
  b = random(255);
// ...
}

and your rocket is on fire

HSB mode allows you to use one variable (hue) to cycle through colors, and you don’t need to store it, since it is calculated on the fly.
setup

 colorMode(HSB, 1.0);

draw

fill(random(1.0), 1.0, 1.0);
1 Like