Source

wd_pys60 / wd_illusion.py

Full commit
import appuifw
import graphics
i=graphics.screenshot()
backgroundcolor=i.getpixel((230,310))[0]
#backgroundcolor=(0,0,)
backgroundcolor="0x"+"%02x"%backgroundcolor[0]+"%02x"%backgroundcolor[1]+"%02x"%backgroundcolor[2]

print backgroundcolor
backgroundcolor=eval(backgroundcolor)

from graphics import *
import e32
from key_codes import *
import random
PATH=u"C:\\temp.jpg"
def save_wall_paper(path=PATH):
    import wallpaper
    wallpaper.set_wallpaper(path)
class Simulate(object):
    nowSize=7
    nextSize=7
    center=(120,160)
    step=0xffffff/0xff+5
    def __init__(self,center=None,step=None):
        self.center=center or self.center
        self.step=step or self.step
        appuifw.app.screen='full'
        self.img=None
        self.myfont=u'Sans MT 936_S60'
        self.running=1
        self.canvas=appuifw.Canvas(
            event_callback=self._handle_event,
            redraw_callback=self._handle_redraw)
        appuifw.app.body=self.canvas
        self.img=Image.new(self.canvas.size)
        appuifw.app.body.bind(55,lambda:self.quit())
    def quit(self):
        img=graphics.Image.new((240,320))
        img.blit(graphics.screenshot())
        img.save(PATH)
        self.running=0
        save_wall_paper(PATH)
        
    def _handle_redraw(self,rect):
        if self.img:
            self.canvas.blit(self.img)
    def _handle_event(self,event):
        pass
        #print event
        # keyboard_state={}
    def _render(self,size):
        #print size,
        self.nowSize=size
        self.img.clear(backgroundcolor)
        for i in range(0xff,size,-1):
            self.img.point(self.center,i*self.step,width=i*10/size)
        self._handle_redraw(())
        #e32.ao_yield()
    def run(self,cycleTime=0):
        while self.running:
            if self.nextSize==self.nowSize:
                self.nextSize=random.randint(1,70)
                #print "\n@",self.nextSize,"@"
            try:
                self._render(self.nowSize+abs(self.nextSize-self.nowSize)/(self.nextSize-self.nowSize))
            except:
                pass
            e32.ao_yield()

s=Simulate()
s.run()
print s.center
e32.ao_yield()