Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Inverse Proportion and Zero

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
8 replies to this topic

#1 Aluthreney   Members   

275
Like
0Likes
Like

Posted 20 March 2014 - 09:51 AM

For a few days now, I have been trying to find a way in which I can calculate the intensity of each component of an RGB color based on two lengths. To exemplify:

Let us say I am trying to measure the Red component of a color. The minimum length is 0 (which represents 255); the maximum length is 10 (which represents 0); the length I wish to measure is 10.

 

2lkqr1w.jpg

In so far, I have attempted to use the inverse proportion formula, but apparently it does not work well with zeros:

    5/10 = 127.5/x
(=) 10/5 = 127.5/x <- Inverse
(=) x = 5 * 127.5/10
(=) x = 637.5/10
(=) x = 63.75

The, logically, correct answer is 0.

I have been looking for an alternative, but so far I have found nothing. I would be very thankful if someone could point out a formula I could use to calculate the color intensity.


Aluthreney -- the King of sheep.


#2 apatriarca   Members   

2354
Like
1Likes
Like

Posted 20 March 2014 - 09:57 AM

I'm not sure I understood your post. Anyway, what about (10 - x)*25.5 ? It is equal to 255 when x is zero and equal to 0 when x is 10.



#3 Álvaro   Members   

20902
Like
0Likes
Like

Posted 20 March 2014 - 10:00 AM

What are these two lengths you are talking about? Perhaps you can explain what you are trying to do a bit better.



#4 Lactose   GDNet+   

10813
Like
0Likes
Like

Posted 20 March 2014 - 10:05 AM

Assuming I understand what you want...

With a length clamped to [0, 10]

red_intensity = 255.0 - (25.5 * length)

 

Round up/down as you feel appropriate.


Hello to all my stalkers.

#5 Telanor   Members   

1486
Like
2Likes
Like

Posted 20 March 2014 - 10:09 AM

I don't understand what the radius has to do with it, but if you just want a length of 0 = 255 and length of 10 = 0, all you need is (1 - length / 10) * 255

#6 Aluthreney   Members   

275
Like
0Likes
Like

Posted 20 March 2014 - 10:38 AM

I am sorry if I was unclear; I was trying to get to the point quickly. I am trying to create an user interface where, in order to pick a color, the user must click within the area of a circle. Absolute red (255) lies at 90º; Absolute green at 210º; Absolute blue 330º. When the user clicks within the circle's area, the distance between the clicked point and each absolute color node is calculated. Finally, in order to obtain the each color's intensity, I calculate the distances with the circle's diameter.

 

I am having trouble with that last part (calculating the color's intensity).


Aluthreney -- the King of sheep.


#7 Aluthreney   Members   

275
Like
0Likes
Like

Posted 20 March 2014 - 10:44 AM

I don't understand what the radius has to do with it, but if you just want a length of 0 = 255 and length of 10 = 0, all you need is (1 - length / 10) * 255

That's exactly what I needed, thank you very much.

Just one more question: Could you point me to a source of information that discusses the formula you posted? I don't mean to bother, but I always like to have a conceptual understanding of the things I work with.

 

Once again, thank you very much.


Aluthreney -- the King of sheep.


#8 Telanor   Members   

1486
Like
1Likes
Like

Posted 20 March 2014 - 10:47 AM

I am sorry if I was unclear; I was trying to get to the point quickly. I am trying to create an user interface where, in order to pick a color, the user must click within the area of a circle.


That sounds like an HSV color picker. Perhaps you can just use the HSV -> RGB conversion equation? http://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB

Just one more question: Could you point me to a source of information that discusses the formula you posted?


I just came up with it based off your description. X/10 gives you a 0-1 ratio. 1 - ratio inverts it. Multiply by 255 to scale.

#9 Lactose   GDNet+   

10813
Like
0Likes
Like

Posted 20 March 2014 - 11:25 AM

For reference, to show why my suggestion gives the same result as Telanor's, by setting them equal to each other:

255 - (25.5x) = (1 - x / 10) * 255 -- divide both sides by 255
1 - (0.1x) = (1 - x / 10) * 1 -- the "multiply by 1" has no effect, so we remove it
1 - 0.1x = 1 - x / 10

x / 10 = 0.1x, thus they are equal


Hello to all my stalkers.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.