Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

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

From Wiki
Jump to: navigation, search

Archived.pngAquivado: 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 06:23.
59 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×