Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Canvas Example

DZone's Guide to

Canvas Example

·
Free Resource
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)
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}