Namespaces
Variants
Actions

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

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 code snippet shows how to use the PySymbian graphics module to draw a rectangle and fill it with random color.

Article Metadata

Tested with
Devices(s): N70, N95 8gb

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

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

Code Snippet

import e32
import random
import time
import appuifw
import graphics
import math
 
appuifw.app.title = u"Random Rectangle-2" #set the application title
can=appuifw.Canvas() #create a canvas class
appuifw.app.body=can #assign the canvas to the body
img=graphics.Image.new(can.size) #create a new image instance
img.clear(0xffffff) #clear the image
 
running=1
 
def quit():
global running
running=0
 
appuifw.app.exit_key_handler=quit
 
while running: # below acript makes the random rectangles
 
for i in range(1,70):
a=random.randrange(255) #defines the position of the rectangles
b=random.randrange(255)
c=random.randrange(255)
j=i+1
x1=(can.size[0]/2)-j #defines the position of the rectangle
y1=(can.size[1]/2)-j
x2=(can.size[0]/2)+j
y2=(can.size[1]/2)+j
img.rectangle((x1,y1,x2,y2),outline=None,fill=(a,b,c))
img.rectangle((x1+10,y1+10,x2-10,y2-10),outline=None,fill=0xffffff)
 
can.blit(img)
e32.ao_sleep(.1)
e32.ao_yield()

Screenshots

The below are some screenshots of the above code snippet

RandomRectangle 1.jpg RandomRectangle3.jpg Screenshot0079.jpg


See also

This page was last modified on 8 May 2013, at 09:23.
245 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