Archived:A simple random rectangle demo using PySymbian
Aquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.
All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.
All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.
Article Metadata
This example has been modified from The Mobile technology group example : rectangle.py
# random rectangle
from appuifw import *
import e32
from random import randrange
running = 1
def quit():
global running
running = 0
app.exit_key_handler = quit
app.screen = 'large'
app.body = canvas = Canvas()
res_x, res_y = canvas.size
while running:
x1 = randrange(res_x)
x2 = randrange(x1, res_x)
y1 = randrange(res_y)
y2 = randrange(y1, res_y)
color = randrange(0xffffff)
canvas.rectangle((x1, y1, x2, y2), fill=color)
e32.ao_yield()
Here's a variation : It bounces a rectangle round the screen leaving a trail in different colors.
from appuifw import *
import e32
from random import randrange
running = 1
def quit():
global running
running = 0
app.exit_key_handler = quit
app.screen = 'large'
app.body = canvas = Canvas()
res_x, res_y = canvas.size
dy = 1
dx = 1
x1 = 10
y1 = 10
while running:
x1 = x1 + dx
y1 = y1 + dy
x2 = x1 + 10
y2 = y1 + 10
if (x1 < 1):
dx = -1 * dx
if (y1 < 1):
dy = -1 * dy
if (x1 > res_x - 15):
dx = -1 * dx
if (y1 > res_y - 15):
dy = -1 * dy
color = randrange(0xffffff)
canvas.rectangle((x1, y1, x2, y2), fill=color)
e32.ao_yield()
The following does not leave a trailing image.
import e32,random
import time
import appuifw
import graphics
import math
running=1
def quit():
global running
running=0
appuifw.app.exit_key_handler=quit
appuifw.app.screen='large'
can=appuifw.Canvas()
appuifw.app.body=can
j,k=can.size
dx=1
dy=1
x1=10
y1=10
while running:
x1=x1+dx
y1=y1+dy
x2=x1+10
y2=y1+10
if x1<1:
dx=dx*-1
if y1<1:
dy=dy*-1
if x1>j-15:
dx=dx*-1
if y1>k-15:
dy=dy*-1
c=random.randrange(0xffffff)
can.rectangle((x1,y1,x2,y2),outline=None,fill=c)
e32.ao_sleep(.01)
can.clear(0xffffff)
e32.ao_yield()


(no comments yet)