bottom = 180
color = bottom + rnd( 255-bottom)
"squirreltown" wrote:
Barbaric Coding™
"squirreltown" wrote:
Well i don't know from pretty code or even actual, you know - math like EnTerr, but the Barbaric Coding™ way to pull a random light color would bebottom = 180
color = bottom + rnd( 255-bottom)
"EnTerr" wrote:"dev42" wrote:
... but to be able to have random colors that aren't too dark. I couldn't figure out how to do that in RGB....easily.errr with pretty code! Yeah, that's it.
- Define
lightness = 0.3*R + 0.6*G + 0.1*B- Make sure `lightness` is above some threshold (say 0.5)
- Rejoyce!
Actually there are 101 ways to do that, for example you can use max(R, G, B), R+G+B, R^2+G^2+B^2, min(R,G,B) + max(R,G,B) etc
Credit goes to @SquirrelTown, who draw my attention to the concept of "lightness", which made me read little on it.
"dev42" wrote:
what exactly is bottom? Surely I'm missing something. Because wouldn't we want to be able to have [255,0,0] etc?
colorarray=[ 255, 180 , 255, 180, 255, 180]
ecolor = []
ecolor[0]=colorarray[1]+rnd(colorarray[0]-colorarray[1])
ecolor[1]=colorarray[3]+rnd(colorarray[2]-colorarray[3])
ecolor[2]=colorarray[5]+rnd(colorarray[4]-colorarray[5])
return ecolor
"dev42" wrote:"EnTerr" wrote:
Definelightness = 0.3*R + 0.6*G + 0.1*B...
My head already hurts! Make it stop. Make it stop! 😛 But for the sake of actually learning this... where does "lightness" fit into RGB? Is it just one check against a randomly generated color and it if doesn't past muster just regenerate another color?
R = rnd(256) - 1
B = rnd(256) - 1
minG = (5*255 - 3*R - B)/6: maxG = (10*255 - 3*R - B)/6
if maxG > 255 then maxG = 255
G = minG + rnd(maxG - minG) - 1
"dev42" wrote:
I'm starting to get EnTerr's math... solve the equation -- in this case the Green component -- to guarantee a color with the desired lightness value.
Now, per the OP topic / TheEndless' comment... which method is better?
"Romans_I_XVI" wrote:
@Dev42 - I just used that declaring integer % trick to fix another piece of code I have 😄 . I was fading out transparency, sometimes it worked right and sometimes it gave weird results. Declaring integers while doing the math fixed it 😛 .