Namespaces
Variants
Actions

Archived:How to make Random Rectangle in PySymbian- Part 1

Jump to: navigation, search
Archived.png
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.

This PySymbian code snippet shows how to use the graphics moduleto draw a random number of randomly coloured rectangles.

Article Metadata

Tested with
Devices(s): N70, N96

Compatibility
Platform(s): S60 1st Edition, S60 2nd Edition, S60 3rd Edition

Platform Security
Signing Required: Self-Signed
Capabilities: None

Article
Keywords: appuifw, time, math, graphics
Created: james1980 (31 Dec 2008)
Last edited: hamishwillee (08 May 2013)

Code Snippet

import e32,random
import time
import appuifw
import graphics
import math
 
appuifw.app.title = u"Random Rectangles" #set the application title
can=appuifw.Canvas() #create a canvas class
appuifw.app.body=can # assign canvas to the application body
img=graphics.Image.new(can.size) #created a new image
img.clear(0xffffff) # cleared the image
 
running=1
def quit():
global running
running=0
appuifw.app.exit_key_handler=quit
 
while running: # below script draws random rectangles
a=random.randrange(255) #defining the colours of rectangles
b=random.randrange(255)
c=random.randrange(255)
j=can.size[0]
k=can.size[1]
 
x1=(random.randrange(j-10)) #defining the position of the rectangles
y1=(random.randrange(j-10))
x2=x1+10
y2=y1+10
img.rectangle((x1,y1,x2,y2),outline=None,fill=(a,b,c)) #drawing rectangles
img.rectangle((x1+10,y1+10,x2-10,y2-10),outline=None,fill=0xffffff)
can.blit(img) #blitting the rectangles on the image
e32.ao_sleep(.1)
e32.ao_yield()

Screenshots

The screenshots below clearly explains the functionality of above code snippet.

Random Rectangle.jpg Random Rectangle 1.jpg

See also

This page was last modified on 8 May 2013, at 09:20.
166 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved