Avatar Generator

avatars4In this challenge we will use Python Turtle to create avatars. (An avatar is an icon representing a particular person in a computer game, Internet forum, etc.)

Try the code below. This code is using a few computing concepts such as:

  • A list to store the different colour codes,
  • (x,y) coordinates to position the turtle on the screen.


In Python, a list is used to save a collection of values. For instance, to save all the different days of the week we could declare a variable called “daysOfTheWeek” and assign a list as follows:

Based on this what do you think len(daysOfTheWeek) would return?
What’s about daysOfTheWeek[0]?
Or daysOfTheWeek[3] ?

In our avatar generator code we use three lists to store all the different colours for the skin, the hair and the eyes:

By using the random library we can access a random value of a list.

(x,y) coordinates using turtle

On this trinket widget the turtle screen is 400 pixels wide. So:

  • the top left corner coordinates are (-200,200)
  • the top right corner coordinates are (200,200)
  • the bottom left corner coordinates are (-200,-200)
  • the bottom right corner coordinates are (200,-200)
  • the centre of the screen coordinates are (0,0)

Look at the canvas below to understand how (x,y) coordinates work:

Avatar Generator

Your Challenge

Start customising the above script to add a random colour for the background. You can select colour codes using www.colorpicker.com.

Then add a T-shirt to your avatar, using random colours too.

Customise your avatar further by adding a beauty spot, different colours of lipstick, a mustache, a beard etc.

Tagged with: , , ,