Archived:How to draw a circle in PySymbian
Article Metadata
Tested with
Devices(s): Nokia N96
Compatibility
Platform(s): S60 2nd Edition, S60 3rd Edition
Article
Keywords: graphics, canvas
Created: cyke64
(15 Mar 2007)
Last edited: hamishwillee
(11 Jan 2012)
Overview
The article shows how to draw circles on canvas of the application body in Python. Ellipse function can be used for drawing circle, but arguments are not very user friendly. So you can write this new function for drawing a circle easier. Here is a function that will draw yellow circle with black outline.
Code
# from appuifw import *
# c = Canvas()
# app.body = c
def circle(x,y,radius=5, outline=0, fill=0xffff00, width=1):
c.ellipse((x-radius, y-radius, x+radius, y+radius), outline, fill, width)
You may use other default values.
Here's an example using this new circle function to show circles randomly
# import required modules
import e32
from random import randint, choice
from appuifw import *
# Define exit function
def quit():
App_lock.signal()
app.exit_key_handler = quit
app.screen = 'large' # Screen size set to 'large'
c = Canvas()
app.body = c
sleep = e32.ao_sleep
colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xffffff]
# Function which draws circle with given radius at given co-ordinate
def circle(x,y,radius=5, outline=0, fill=0xffff00, width=1):
c.ellipse((x-radius, y-radius, x+radius, y+radius), outline, fill, width)
def rand_circle(n):
c.clear()
for i in range(n):
circle(randint(0,250), randint(0,180), randint(5,20), fill=choice(colors))
sleep(0.1)
# Draw 40 circles
rand_circle(40)
App_lock = e32.Ao_lock()
App_lock.wait() # Wait for exit event


