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:

daysOfTheWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

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:

skinColors = ["#FCD09D","#FAC47A", "#DBA965", "#CC9D5E","#A3855B","#806645","#665135"]
eyeColors = ["#489CF0","#15A315", "#8C3303"]
hairColors = ["#000000","#8C3303","#F5D907","#580000","#E31E00","#636363","#FFFFFF"]

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

import random #Only use this instruction once at the very beginning of your code

hairColors = ["#000000","#8C3303","#F5D907","#580000","#E31E00","#636363","#FFFFFF"]
hairColorIndex = random.randint(0,6)


(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.

Did you like this challenge?

Click on a star to rate it!

Average rating 4.7 / 5. Vote count: 3

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: , , ,