[Tutor] if and things

elis aeris hunter92383 at gmail.com
Thu Jul 19 03:39:02 CEST 2007


man that looks totally pythonic.

On 7/19/07, Ian Witham <witham.ian at gmail.com> wrote:
>
> try this:
>
> for a in range(10):
>     r, g, b = pixel[1030*(y-a) + x]
>     if g > r and g > b:
>         box += 1
>
> This is an example of "unpacking" a tuple into separate variables, r, g
> and b.
>
> On 7/19/07, elis aeris <hunter92383 at gmail.com> wrote:
> >
> > #  pixel[]  is a list of tuples:   (r,g,b)
> > #  pixel[1030*(y-a) + x][0] = r
> > #  pixel[1030*(y-a) + x][1] = g
> > #  pixel[1030*(y-a) + x][2] = b
> >
> > for a in range(0, 10):
> >     if    pixel[1030*(y-a) + x][1] > pixel[1030*(y-a) + x][0] and
> > pixel[1030*(y-a) + x][1] > pixel[1030*(y-a) + x][2]:
> >         box = box + 1
> >
> > print box
> >
> >
> > i have never used double conditions before, is this correct?
> >
> > I want box++ when  the g is both bigger than r and b.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > import time
> >
> > import ImageGrab  # Part of PIL
> > from ctypes import *
> >
> > # Load up the Win32 APIs we need to use.
> > class RECT(Structure):
> >   _fields_ = [
> >     ('left', c_ulong),
> >     ('top', c_ulong),
> >     ('right', c_ulong),
> >     ('bottom', c_ulong)
> >     ]
> >
> > # time.sleep(2)
> >
> > GetForegroundWindow = windll.user32.GetForegroundWindow
> > GetWindowRect = windll.user32.GetWindowRect
> >
> > # Sleep for 2 seconds - click the window you want to grab.
> > #time.sleep(2)
> >
> >
> >
> > # Grab the foreground window's screen rectangle.
> > rect = RECT()
> > foreground_window = GetForegroundWindow()
> > GetWindowRect(foreground_window, byref(rect))
> > image = ImageGrab.grab((rect.left, rect.top, rect.right, rect.bottom))
> >
> > # Save the screenshot as a BMP.
> > time.sleep(2)
> >
> >
> > image.save("c:\python_codes\screenshot.bmp")
> >
> > # Get the pixel 10 pixels along the top of the foreground window - this
> > # will be a piece of the window border.
> >
> > # print time.time()
> >
> > start = time.time()
> >
> > pixels = image.getdata()
> > for x in xrange(0, 500):
> >   for y in xrange(0, 500):
> >     rgb = pixels[500 * x + y]
> >
> > print pixels[1][0]
> >
> > print ( time.time() - start )
> >
> > # PIL returns colours as RGB values packed into a triple:
> > #print "RGB(%d, %d, %d)" % (rgb[0], rgb[1], rgb[2])  # This prints
> > RGB(0, 74, 216) on my XP machine
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070719/1e412d39/attachment.html 


More information about the Tutor mailing list