Like a Touch screen in the air... Like a mouse with a pencil.
Its very simple but very fun!
References
http://www.danilocesar.com/blog/2006/12/03/smartphones-aonde-podemos-parar
If you want to see this working:
http://www.youtube.com/watch?v=sjm_g9MSYPc
1 2 3 ################################################################# 4 # Developed by Danilo Cesar [http://www.danilocesar.com] 5 # Inspired on: http://www.bigbold.com/snippets/posts/show/636 6 ################################################################# 7 8 from appuifw import * 9 from graphics import Image 10 import camera, e32 11 12 app.body = c = Canvas() 13 14 running = 1 15 def quit(): 16 global running 17 running = 0 18 19 app.exit_key_handler=quit 20 app.title = u"O controle" 21 app.screen = 'full' # or 'normal', 'large' 22 23 def getdata(im, bpp=24): 24 import struct, zlib 25 im.save('D:\\pixels.png', bpp=bpp, compression='no') 26 f = open('D:\\pixels.png', 'rb') 27 f.seek(8 +8+13+4) 28 chunk = [] 29 while 1: 30 n = struct.unpack('>L', f.read(4))[0] 31 if n==0: break # 'IEND' chunk 32 f.read(4) # 'IDAT' 33 chunk.append(f.read(n)) 34 f.read(4) # CRC 35 f.close() 36 return zlib.decompress(''.join(chunk)) # '\x00' prefix each line 37 38 39 X = 80 40 Y = 60 41 while running: 42 if X < 0: X = 0 43 if Y< 0: Y = 0 44 if X > 160 - 30: X = 160 - 30 45 if Y > 120 - 30: Y = 120-30 46 im = camera.take_photo('RGB', (160,120)) 47 im.rectangle([(X,Y),(X+30,Y+30)], 0xff0000) # red outline 48 # check hot spot whether active 49 box = Image.new((30,30), 'L') # gray scale 50 box.blit(im, (X,Y,X+30,Y+30)) 51 data = getdata(box, 8) 52 53 # check black 54 for i in range(len(data)): 55 if ord(data[i]) < 30 and ord(data[i]) > 0: 56 X += i%31 - 15 57 Y += int(i/31) - 15 58 break 59 60 c.blit(im, (0,0), (8,12)) # show camera 61 62 63