Hi I need some help on this one program that draws a mathematical rose where it draws each petal of the rose as a different random color. When I run my code it only draws half of each petal as a random color and the other halves as striped rainbows. I’m pretty new to booleans and I’m unsure how to approach this problem.

```
//constants
final float K = 4; //The factor that controls the number of "petals"
final float RATE = 0.02; //The change in t each frame. Controls speed and smoothness.
final float ROSE_RADIUS = 200; //The radius, in pixels, of the "rose"
//state variables
float t = 0; //The "parameter" t which will slowly change from 0 to 2PI
float prevX;
float prevY;
float distance;
float previousDistance;
boolean moveTowardsCenter;
void setup() {
size(500, 500); //make a 500x500 canvas
background(0); //Use a black background
strokeWeight(2); //make thicker lines
stroke(255); //make lines white
//Precalculate the first point
prevX=width/2+ROSE_RADIUS;
prevY=height/2;
}
void draw() {
//Calculate the new point
float x = cos(K*t)*cos(t)*ROSE_RADIUS+width/2;
float y = cos(K*t)*sin(t)*ROSE_RADIUS+height/2;
distance = sqrt(pow((x-prevX), 2) + pow((y-prevY), 2));
println(distance);
if (distance>previousDistance) {
stroke(random(255), random(255), random(255));
}
previousDistance = distance;
line(prevX, prevY, x, y); //draw the next line
//Keep all the information needed for next time
prevX = x;
prevY = y;
//Advance t
t += RATE;
}
```