SOLVED Help with rainbow text

I have text that cycles through colors

1637557998109.png

Whenever the text loops through the colors, it stops at red. I am not sure why it does this.

This is the code for the wave and rainbow effect:

GML:
    case 4: //wave AND colour shift
                var so = t + cc;
                var shift = sin(so*pi*freq/room_speed)*amplitude;
                var c1 = make_colour_hsv(t+cc, 255, 255);
                var c2 = make_colour_hsv(t+cc+45, 255, 255);
                draw_text_color(xx + (cx*charSize), yy+(cy*stringHeight)+shift, letter, c1, c1, c2, c2, 1);
                break;
I would appreciate any help!
 
Is t just an increasing number? Or is cc just an increasing number? If either are, you'll have to mod them to make them loop back around to 0 once they are above 255, as the hue argument in make_colour_hsv() only goes up to 255 (which is red). Something like this:
GML:
var c1 = make_colour_hsv((t+cc) mod 256, 255, 255);
var c2 = make_colour_hsv((t+cc+45) mod 256, 255, 255);
If you're unaware of what mod does, it takes an input number and "wraps" it back to 0 at the value you are modding it by. So an example of what would happen with an increasing number is this:

0 mod 3 = 0
1 mod 3 = 1
2 mod 3 = 2
3 mod 3 = 0
4 mod 3 = 1
5 mod 3 = 2
6 mod 3 = 0

As you can see, the number flips back to 0 when it hits the mod value, but it's still able to keep increasing with higher values until it hits a multiple of the mod again, where it flips back to 0 and so on.
 

Sabnock

Member
If you're unaware of what mod does, it takes an input number and "wraps" it back to 0 at the value you are modding it by. So an example of what would happen with an increasing number is this:

0 mod 3 = 0
1 mod 3 = 1
2 mod 3 = 2
3 mod 3 = 0
4 mod 3 = 1
5 mod 3 = 2
6 mod 3 = 0

As you can see, the number flips back to 0 when it hits the mod value, but it's still able to keep increasing with higher values until it hits a multiple of the mod again, where it flips back to 0 and so on.
I thought that mod simply gives the remainder from a division?

so :

18 mod 6 = 0 remainder as 6 goes exactly 3 times in to 18.
18 mod 5 = 3 remainder as 5 goes 3times into 18 with 3 remainder


but yes it will wrap back to 0 each time there is no remainder.
 
I thought that mod simply gives the remainder from a division?

so :

18 mod 6 = 0 remainder as 6 goes exactly 3 times in to 18.
18 mod 5 = 3 remainder as 5 goes 3times into 18 with 3 remainder


but yes it will wrap back to 0 each time there is no remainder.
Hahaha, yes, you are correct. My explanations might be silly because my experience with most maths is on a practical "what does this do for me in a game" level, so I don't usually know the technical maths explanation. Though, I don't think my examples and explanation were incorrect, just unorthodox and perhaps a bit lacking in the technical maths details (I did know that it gives the remainder from division, but I didn't think to mention that when I was typing out the example).
 

Sabnock

Member
I have text that cycles through colors

View attachment 44423

Whenever the text loops through the colors, it stops at red. I am not sure why it does this.

This is the code for the wave and rainbow effect:

GML:
    case 4: //wave AND colour shift
                var so = t + cc;
                var shift = sin(so*pi*freq/room_speed)*amplitude;
                var c1 = make_colour_hsv(t+cc, 255, 255);
                var c2 = make_colour_hsv(t+cc+45, 255, 255);
                draw_text_color(xx + (cx*charSize), yy+(cy*stringHeight)+shift, letter, c1, c1, c2, c2, 1);
                break;
I would appreciate any help!
another way to do this would be to use the sin() or cos() functions like. this gives an interesting colour pattern

GML:
var c1 = make_colour_hsv(abs(cos(c) * 255), 255, 255);
var c2 = make_colour_hsv(abs(sin(c) * 255), 255, 255);
c+=.002;
draw_text_color(0,0, "RAINBOW", c2,c1,c1,c2,1);
But it really all depends on the affect you are looking for;
 
Last edited:

Alice

Darts addict
Forum Staff
Moderator
another way to do this would be to use the sin() or cos() functions like

GML:
    var c1 = make_colour_hsv(sin(c) * 255, 255, 255);
    c+=.01;
Not really:
1. sin/cos have a value range between -1 and 1, so this will produce a hue of -255, and negative numbers are not valid arguments for make_color_hsv
2. Even if it was normalised to something like 127.5 + 127.5 * sin(c), the values will keep bouncing back and forth through the rainbow (red-yellow-green-blue-purple-red-purple-blue-green-yellow-red-...) instead of cycling through it (red-yellow-green-blue-purple-red-yellow-green-...).
3. sin/cos changes aren't uniform - with formula like 127.5 + 127.5 * sin(c), red being around 0 and 255 hue and cyan being around 127.5 hue there will be larger areas of near-red colours and relatively small areas of near-cyan colours. That's because sin/cos functions change faster around 0 values and slower around -1 and 1 values.

So while sin/cos are really nice for things like waves (as shown in the opening post above), they aren't really suited for cycling through colour circle (the modulo aka division reminder method is well suited for that, though).
 

Sabnock

Member
Not really:
1. sin/cos have a value range between -1 and 1, so this will produce a hue of -255, and negative numbers are not valid arguments for make_color_hsv
2. Even if it was normalised to something like 127.5 + 127.5 * sin(c), the values will keep bouncing back and forth through the rainbow (red-yellow-green-blue-purple-red-purple-blue-green-yellow-red-...) instead of cycling through it (red-yellow-green-blue-purple-red-yellow-green-...).
3. sin/cos changes aren't uniform - with formula like 127.5 + 127.5 * sin(c), red being around 0 and 255 hue and cyan being around 127.5 hue there will be larger areas of near-red colours and relatively small areas of near-cyan colours. That's because sin/cos functions change faster around 0 values and slower around -1 and 1 values.

So while sin/cos are really nice for things like waves (as shown in the opening post above), they aren't really suited for cycling through colour circle (the modulo aka division reminder method is well suited for that, though).
you make a fair point. it does work but it's not perfect. i was just spitballing ideas :)
 

bossrush

Member
I would make a variable that rotates from 1 to 6 and somthing reads that variable and then decides the color based off of the number that way you can in the future make text that could be just red if the person is angry you would set the var to 1.
 
I would make a variable that rotates from 1 to 6 and somthing reads that variable and then decides the color based off of the number that way you can in the future make text that could be just red if the person is angry you would set the var to 1.
I would assume that OP already has coloured text if they are implementing the relatively advanced text feature of a rainbow wave effect. Also, they are providing a number that the colour is based off. That's what the t and cc variables are doing. Except instead of hard-coding a limited number of "colour numbers", they are able to use the full range of hues available to computer by slipping the number directly into the make_colour_hsv() function.
 
Is t just an increasing number? Or is cc just an increasing number? If either are, you'll have to mod them to make them loop back around to 0 once they are above 255, as the hue argument in make_colour_hsv() only goes up to 255 (which is red). Something like this:
GML:
var c1 = make_colour_hsv((t+cc) mod 256, 255, 255);
var c2 = make_colour_hsv((t+cc+45) mod 256, 255, 255);
If you're unaware of what mod does, it takes an input number and "wraps" it back to 0 at the value you are modding it by. So an example of what would happen with an increasing number is this:

0 mod 3 = 0
1 mod 3 = 1
2 mod 3 = 2
3 mod 3 = 0
4 mod 3 = 1
5 mod 3 = 2
6 mod 3 = 0

As you can see, the number flips back to 0 when it hits the mod value, but it's still able to keep increasing with higher values until it hits a multiple of the mod again, where it flips back to 0 and so on.
Thanks, not sure how I didn't think of this, but it works!
 
Top