✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
An avatar is a representation of a human on the internet. It could be an icon, or an image, or even an animated 3D model. In this exercise we are going to generate an avatar based on your name.
Write a program avatars.py that accepts one command-line arguments: a name. Write a function called get_hashcode() that converts this name (a String s of length n) to an integer hash using the following algorithm:
Hint: use the function ord() to get the unicode integer representation of the a character.
Next, in your main code, calculate five indices for each of the five body parts of the avatar:
hash % 15 is an integer 0..14 that denotes the body
(hash / 15) % 10 is an integer 0..9 that denotes the fur
(hash / 150) % 15 is an integer 0..14 that denotes the eyes
(hash / 2250) % 10 is an integer 0..9 that denotes the mouth
(hash / 22500) % 20 is an integer 0..19 that denotes an extra accessory
For a body part with index 5, the corresponding image is called body_5.png (or fur_5.png or eyes_5.png or mouth_5.png or extra_5.png). Your program must use stddraw to create a 256x256 pixel window and load and display the body parts in the order given above.
IMPORTANT: You need to add the following line to the top of your file for you to be able to use Picture:
from picture import Picture
Hint: to draw, say for example the body_5.png, at the center of the canvas use:
body_pic = Picture('body_5.png')
stddraw.picture(body_pic, 0.5, 0.5)
Download avatars.zip for the full collection of body parts.
Your program should work as follows:
$ python avatar.py Garfield
$ python avatar.py Odie
$ python avatar.py "Jon Arbuckle"