Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When
random red
random green
random blue
it will be random every color dimmed down, brightened and full color not dimmed or brightened

What I have tried:

Had a lot of trouble explaining the problem and couldnt recieve tips
solved it
through it away
found it
lost notes
anyhow, it works fine

I was unable to answer my own question by means of sharing code i couldnt find on web
Python
def DimmColor(dimmer, randrange):

    rgb = [0,0,0]
    randomed = randrange(1,1531,1)

    m = int(randomed/255 - (randomed%255)/255+0.1)#0.1 corrected "tolerance"

    what_plateau = ((-m+2)%3 +(m)%2)%3 #2,2,0,0,1,1
    what_terrace = -(m%3 +(-m)%2)%3 #0,1,1,2,2,0
    what_slot = (-m+1)%3 #gives rgb[slot] slot=1,0,2,1,0,2
    increase_decrease = (m-1)%2 - m%2 #toggles plus and minus to get all finite rgb colors. Increase decrease under terrace. 1 -1 1 -1 1 -1
    factor = m%2 #subtract or not. 0 1 0 1 0 1

    n = int(randomed%255)
        
    rgb[int(what_terrace)] = 255
    rgb[int(what_slot)] = int(255*factor + n*increase_decrease) #Combined alternates +inrease or -decrease +green -red +blue -green +red -blue
   
    if dimmer > 255:#0 to including 254 darkens. 255 changes nothing. 256 to incl 510
        rgb[what_slot] = int(((255-rgb[what_slot])/255)*(dimmer-255)+rgb[what_slot])
        rgb[what_plateau] = int(dimmer-255)
    elif dimmer < 255:
        rgb[what_terrace] = int(dimmer)
        rgb[what_slot] = int((rgb[what_slot]/255)*dimmer)
    elif dimmer == 255:
        pass
    else:
        print("dimm dungeons revolt")
        
    return rgb
Posted
Updated 25-Nov-20 0:49am
v3

1 solution

Take a look at hue saturation and value - Google Search[^] which gives a better explanation of the relationship of colour and intensity.
 
Share this answer
 
Comments
Tjohohan 25-Nov-20 6:50am    
Thanks for telling me about hue

Why dont you atleast look, run and try understand the code and ask if you dont?

There is no more colors than can be plotted as a rectangle since rgb is finite.

Putting colors on wheel adding radius will not achieve any more rgb colors.

Zooming out by increasing radius will not achieve any more colors

The code i wrote include every coleur, kulör in swedish, and saturates or dilutes it dark or bright (dark red with a bit of yellow is brown coleur of orange close to red)

Whats the difference to hue?

How is hue better?

What was your intent in adding your solution?
Richard MacCutchan 25-Nov-20 7:30am    
Mainly because your question was not clear, so I had to take a guess at what you wanted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900