# [Tkinter-discuss] Calculating a ripening tomato

Bob Greschke bob at greschke.com
Tue Oct 18 07:36:07 CEST 2011

```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
>

```