DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Canvas Example

06.21.2005
| 4495 views |
  • submit to reddit
        A few days ago, I posted an example for py_s60 1.1.0
Now that 1.1.3 is released, here's an updated version.
# mincanvas.py : minimal canvas example
# It draws to screen directly (doesn't use canvas callback)
# this code is for 1.1.3 version

import e32, appuifw, graphics
from key_codes import *

app = appuifw.app
screen_x, screen_y = 176, 208
x = y = 0
vx = vy = 1
running = 1

def set_exit():
    global running
    running = 0

def add_dir(dx, dy):
    global vx, vy
    vx += dx
    vy += dy

# change screen, body
app.screen = 'full'
c = appuifw.Canvas()
app.body = c
draw = graphics.Draw(c)

# bind 6 keys
app.exit_key_handler= set_exit
c.bind(EKeyRightArrow,lambda:add_dir(1, 0))
c.bind(EKeyLeftArrow,lambda:add_dir(-1, 0))
c.bind(EKeyUpArrow,lambda:add_dir(0, -1))
c.bind(EKeyDownArrow,lambda:add_dir(0, 1))
c.bind(EKeyDevice3, draw.clear)  # press joy stick

# main loop
while running:
    # move x, y
    x = (x + vx) % screen_x
    y = (y + vy) % screen_y
    # plot a red dot at (x, y)
    draw.point((x, y), 0xff0000)
    e32.ao_sleep(0.1)