Source

wd_pys60 / wd_canvas.py

Full commit
import math
blobsize=3
import appuifw
from graphics import *
import e32
from key_codes import *
counter=0
appuifw.app.screen='full'
img=None
myfont=u'Sans MT 936_S60'

def handle_event(event):
    
    canvas.text((0,12),u'\u5F53\u524D\u70B9\u51FB\u952E\u503C:',0x008000,myfont)
    return None
def handle_redraw(rect):
    if img:
        canvas.blit(img)
appuifw.app.body=canvas=appuifw.Canvas(
    event_callback=handle_event,
    redraw_callback=handle_redraw)
img=Image.new(canvas.size)

running=1
def quit():
    global running
    running=0
appuifw.app.exit_key_handler=quit

location=[img.size[0]/2,img.size[1]/2]
speed=[0.,0.]
xs,ys=img.size[0]-blobsize,img.size[1]-blobsize
gravity=0.03
acceleration=0.05

import time
start_time=time.clock()
n_frames=0
# To speed things up, we prerender the text.
labeltext=u'Use arrows to move ball'
textrect=img.measure_text(labeltext, font='normal')[0]
text_img=Image.new((textrect[2]-textrect[0],textrect[3]-textrect[1]))
text_img.clear(0)
text_img.text((-textrect[0],-textrect[1]),labeltext,fill=0xffffff,font='normal')
import random
def drawpoint():
    global img
    img.point((random.randint(0,240),random.randint(0,320)),0x00ff00,width=blobsize)
    handle_redraw(())
    print "ii"
    
appuifw.app.body.bind(42,drawpoint)
running=1
while running:
    img.clear(0)
    #img.blit(text_img, (0,0))
    color=random.randint(0,0xffffff)
    r=float(random.randint(1,20))/10.0
    img.arc(((15,15),(220,220)),r*math.pi,(r-1.8)*math.pi,color,width=5) 
    r=random.randint(1,200)
    img.ellipse(((r,r),(222,200)),color,width=5)
    r=random.randint(1,200)
    img.pieslice(((r,r),(222,200)),math.pi,1.2*math.pi,color,width=5)
    r=random.randint(1,200)
    img.rectangle(((r,r),(222,200)),color,width=5)
    r=random.randint(1,200)
    img.polygon(((r,r),(r,r*2),(r,r*7),(222,200)),color,width=5)
    r=random.randint(1,200)
    img.line(((r,r),(222,200)),color,width=5,fill=0x00ff00)
    handle_redraw(())
    e32.ao_sleep(0.005)
    e32.ao_yield()