fixed rainbowComponent not folding back on end of color spectrum, ensuring no sudden color switch
This commit is contained in:
parent
24fbd50c62
commit
70a1740644
@ -6,12 +6,12 @@ import net.kyori.adventure.text.format.TextColor;
|
||||
import java.awt.*;
|
||||
|
||||
public class RainbowComponent {
|
||||
private int hueOffset = 0;
|
||||
private float hueOffset = 0;
|
||||
private final String text;
|
||||
private final int density;
|
||||
private final int speed;
|
||||
private final float speed;
|
||||
|
||||
public RainbowComponent(String text, int density, int speed) {
|
||||
public RainbowComponent(String text, int density, float speed) {
|
||||
this.text = text;
|
||||
this.density = density;
|
||||
this.speed = speed;
|
||||
@ -19,15 +19,16 @@ public class RainbowComponent {
|
||||
|
||||
public Component getRainbowState() {
|
||||
Component builder = Component.empty();
|
||||
int hue = this.hueOffset;
|
||||
for(char c : text.toCharArray()) {
|
||||
TextColor color = TextColor.color(Color.getHSBColor((float) hue / 360, 1, 1).getRGB());
|
||||
float hue = this.hueOffset;
|
||||
for (char c : text.toCharArray()) {
|
||||
float normalizedHue = (hue % 360) / 360;
|
||||
TextColor color = TextColor.color(Color.getHSBColor(normalizedHue, 1, 1).getRGB());
|
||||
builder = builder.append(Component.text(c).color(color));
|
||||
hue += density;
|
||||
}
|
||||
|
||||
if(this.hueOffset > Byte.MAX_VALUE - speed) this.hueOffset = 0;
|
||||
this.hueOffset += (byte) speed;
|
||||
this.hueOffset = (this.hueOffset + speed) % 360;
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user