DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Drawing Circle Function

  • submit to reddit
        Just to make drawing a circle easier.
Here is a function that will draw yellow circle with black outline.
# 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.

Then I create a function to show circles randomly
import e32
from random import randint, choice

sleep = e32.ao_sleep
colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xffffff]

def rand_circle(n):
  for i in range(n):
    circle(randint(0,176), randint(0,144), randint(5,20), fill=choice(colors))

# now show it