Calculating a ripening tomato

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Calculating a ripening tomato

Bob Greschke-2
Do you think there is a formula (probably three of them) for calculating the RGB colors for the background color of a widget of a tomato ripening from green to red with, let's say, an input of 0-100%?  It's not just Red 0-255 and green 255-0, because the brown shows up in the middle and doesn't look good at all.  There must be some blue in there somewhere, but I'd like to calculate the values, instead of just looking them up in a list of 100 RGB values.  I'd think there would be something like this for various things somewhere.  Autumn leaves turning colors, sunsets...  I've done widget coloring for things like different elevations and water depths, but for those I just binned the values into 16 or thereabouts bins and looked up the color I wanted to use.  Calculating the values would be more elegant, right? :)

I searched around a little, but just kept getting schooled on how to grow tomatoes.

Bob

_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calculating a ripening tomato

Francesco Bochicchio-2

A quick googling tourned out with this:

http://www.scielo.br/scielo.php?script=sci_arttext&pid=S0102-05362004000300006

Which seems to be related to what you are looking for... only a lot more complex than a simple formula.

I suspect a look-up table does  mot seem so bad, now :-)

Ciao
-------
FB


_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calculating a ripening tomato

Bob Greschke
Hi!

Nice!  That's not a long way off from what I empirically came up with below.  I tried all kinds of combinations of having the red come up at linear or Pct**2 or Pct**3 or Pct**4 rates, with the green going down linearly or at Pct**2 or Pct**3 or Pct**4 rates.  I even had a little blue kicking in when the red and green values were close to each other to try and counteract the formation of brown.  But it all seemed to get much simpler when I used the Pct**2.7 rate for the red.  2.7 being close to e.  I should have known the "natural" log would be involved somehow, even though most tomatoes these days are far from natural.

Why did I need a ripening tomato?  For a Pomodoro Timer, of course. :)

Thanks!

Bob


#! /usr/bin/env python                                                          
# ripe.py                                                                      
# The ripening tomato routine. It's kinda close.                                
# In my program the engine is a count down timer, so this routine counts down  
# from 400 to 0 to simulate it.                                                

from Tkinter import *

Root = Tk()
Stage = 400
R = 0
G = 0
B = 0
for i in xrange(0, 20):
   Sub = Frame(Root)
   for j in xrange(0, 20):
       Pct = Stage/400.0
       Stage -= 1
# 2.7 => e-ish                                                                  
       R = 255-int((Pct**2.7)*255.0)
       G = int(Pct*255.0)
       Label(Sub, text = "   ", bg = "#%02x%02x%02x"% \
               (R, G, B)).pack(side = LEFT)
   Sub.pack(side = TOP)
Root.mainloop()



On 2011-10-17, at 10:18 PM, Francesco Bochicchio wrote:

> A quick googling tourned out with this:
>
> http://www.scielo.br/scielo.php?script=sci_arttext&pid=S0102-05362004000300006
>
> Which seems to be related to what you are looking for... only a lot more complex than a simple formula.
>
> I suspect a look-up table does  mot seem so bad, now :-)
>
> Ciao
> -------
> FB
>

_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calculating a ripening tomato

Gregory Ewing
Bob Greschke wrote:
> 2.7 being close to e. I should have known the "natural" log would be
> involved somehow, even though most tomatoes these days are far from natural.

Resemblance to e probably doesn't have much to do with it --
more likely your formula is just preventing the overall
brightness of the colour from getting too low, thus
avoiding brown.

Another way to approach this might be to do the interpolation
in HSB space, varying the hue angle from red to green while
keeping the brightness constant, and then convert to RGB.

--
Greg
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calculating a ripening tomato

Bob Greschke-2

On Oct 18, 2011, at 00:19, Greg Ewing wrote:

> Bob Greschke wrote:
>> 2.7 being close to e. I should have known the "natural" log would be
>> involved somehow, even though most tomatoes these days are far from natural.
>
> Resemblance to e probably doesn't have much to do with it --
> more likely your formula is just preventing the overall
> brightness of the colour from getting too low, thus
> avoiding brown.
>
> Another way to approach this might be to do the interpolation
> in HSB space, varying the hue angle from red to green while
> keeping the brightness constant, and then convert to RGB.
>
> --
> Greg

Oh, agreed.  That sounds like a better way to do this, but for a quick and dirty approach I messed for quite a while with just red and green rates and tossed in several different if-statements to mess with things here an there, but then just threw all of that out and tried the **2.7 and it all of a sudden was pretty close to what I had in mind.  I've since altered it to start with a bit of red

R = 65+(190-int((Pct**2.718)*190.0))
G = int(Pct*255.0)

It still spends a little too much time in a tanish-orangeish area for my taste, but it's good enough for this exercise.  I wouldn't dismiss e too quickly.  It pops up in some weird places.

Now I'm wondering about being able to calculate things like going from dark green through to white for land elevations, and the colors of the rainbow in the right order, light blue to dark blue for water depths (that one is easy), etc.  I'll have to look into this when I get some time.

Thanks!

Bob


_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calculating a ripening tomato

dsblank
On 10/18/2011 12:15 PM, Bob Greschke wrote:

>
> On Oct 18, 2011, at 00:19, Greg Ewing wrote:
>
>> Bob Greschke wrote:
>>> 2.7 being close to e. I should have known the "natural" log would
>>> be involved somehow, even though most tomatoes these days are far
>>> from natural.
>>
>> Resemblance to e probably doesn't have much to do with it -- more
>> likely your formula is just preventing the overall brightness of
>> the colour from getting too low, thus avoiding brown.
>>
>> Another way to approach this might be to do the interpolation in
>> HSB space, varying the hue angle from red to green while keeping
>> the brightness constant, and then convert to RGB.
>>
>> -- Greg
>
> Oh, agreed.  That sounds like a better way to do this, but for a
> quick and dirty approach I messed for quite a while with just red and
> green rates and tossed in several different if-statements to mess
> with things here an there, but then just threw all of that out and
> tried the **2.7 and it all of a sudden was pretty close to what I had
> in mind.  I've since altered it to start with a bit of red
>
> R = 65+(190-int((Pct**2.718)*190.0)) G = int(Pct*255.0)
>
> It still spends a little too much time in a tanish-orangeish area for
> my taste, but it's good enough for this exercise.  I wouldn't dismiss
> e too quickly.  It pops up in some weird places.
>
> Now I'm wondering about being able to calculate things like going
> from dark green through to white for land elevations, and the colors
> of the rainbow in the right order, light blue to dark blue for water
> depths (that one is easy), etc.  I'll have to look into this when I
> get some time.
>
> Thanks!
>
> Bob

Although this is pretty off-topic for the Tkinter mailing list, I look
forward to seeing where this leads you, so do please make your results
available.

Also, if anyone has first-principle arguments or equations, that would
be interesting.

(Off-list I would also like some pointers on the strange places where e
makes appearances.)

Thanks, and sorry for the additional noise,

-Doug

>
> _______________________________________________ Tkinter-discuss
> mailing list [hidden email]
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>


--
Douglas S. Blank, Associate Professor and Chair
Department of Computer Science, Bryn Mawr College
http://cs.brynmawr.edu/~dblank  (610)526-6501
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calculating a ripening tomato

Gregory Ewing
In reply to this post by Bob Greschke-2
Bob Greschke wrote:

> R = 65+(190-int((Pct**2.718)*190.0))
> G = int(Pct*255.0)
>
> I wouldn't dismiss e too quickly. It pops up in some weird places.

Not as an exponent, though -- usually it's
e**something rather than something**e. That's what
makes me think it's *probably* a coincidence.

--
Greg
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calculating a ripening tomato

Brian Meanley
In reply to this post by Bob Greschke-2

Not that I have a solution for you, but figured that I would share some of my experiences with something similar...

The suggestion of using HSL rather than RGB is a good one, as calculating this in RGB would be rather hit or miss most likely...  However, I think perhaps you might want to try calculating the raw chromaticity as CIE xy coordinates, rather than HSL, and then doing your color conversions from there.  From the papers that were linked to earlier regarding the topic, it seemed that the preferred color-space for calculations was LAB, which would coincide rather nicely to the xyY coordinates.  Many things are calculated along these lines, perhaps the most common being light/color temperature using the Planckian Locus: http://en.wikipedia.org/wiki/Planckian_locus.  Unfortunately as you can see, the algorithms used are rarely 'simple' (at least to calculate initially), and approximations are often used.   Basically, if you can find a 'curve' on on the color-chart that matches the color-ranges that you are after, than it just becomes a matter of figuring out the function(s) that best approximates it.

I have a python/tkinter app that I created that you could take a look at for an implementation of the above color-temperature scale if it would help you out.  I won't post all the code here, but you can download it at the links below.  You'll have to excuse the code however, I make my living as a vfx artist, and I'm rather a hack when it really comes to coding...  Anyways, you can find it here:  http://wiki.brianmeanley.com/wiki/LightTools.py .  For the main code involving the color calculations, look in the 'bhm_color.py' module.  A non-gui version can be found here: http://www.brianmeanley.com/blog/?page_id=349

Color-science is a pretty hefty subject in its' own right, but it can be an extremely interesting and 'fun' one too if you take an interest in it.  I would think that doing a bit of digging into the color temperature examples/links above might give you some insight into what it is that you are hoping to accomplish, as well as the other examples that you mentioned.  I would also highly suggest checking out http://brucelindbloom.com/ for some good info regarding the math behind most color conversions and more.

Good luck! 

-Brian

(PS, sorry if I messed this mailing list thing up, I have never actually posted to this list before...)

_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calculating a ripening tomato

Gregory Ewing
Brian Meanley wrote:
>
> Many things are calculated along these lines, perhaps the
> most common being light/color temperature using the Planckian
> Locus: http://en.wikipedia.org/wiki/Planckian_locus.

Not sure that colour temperature would be all that relevant,
since it's concerned with black body radiation. You would
have to heat your tomatoes to a rather uncomfortable degree
for that to affect their colour...

--
Greg
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calculating a ripening tomato

Bob Greschke-2

On Oct 18, 2011, at 22:48, Greg Ewing wrote:

> Brian Meanley wrote:
>> Many things are calculated along these lines, perhaps the most common being light/color temperature using the Planckian Locus: http://en.wikipedia.org/wiki/Planckian_locus.
>
> Not sure that colour temperature would be all that relevant,
> since it's concerned with black body radiation. You would
> have to heat your tomatoes to a rather uncomfortable degree
> for that to affect their colour...
>
> --
> Greg

Dare I say it?: Gives new meaning to fried green tomatoes.

I better not. Just ignore that line above.

Bob


_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calculating a ripening tomato

Brian Meanley
In reply to this post by Bob Greschke-2
>Not sure that colour temperature would be all that relevant,
>since it's concerned with black body radiation. You would
>have to heat your tomatoes to a rather uncomfortable degree
>for that to affect their colour...

True.  I never meant to imply that it was a bolt-on solution to the problem.  I was merely trying to give a jumping off point for some further research (as the OP also mentioned other situations that he was interested in such as sunsets, etc...).  I think that with a bit of work, the underlying concepts of plotting points in xy, rather than manipulating individual RGB channels, could possibly be adopted to suit the OP's needs.
Anyways, didn't mean to take the talk off topic.

-Brian

_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss