
Introduction
Shah Rukh Khan, one of the most popular name in Indian Cinema, known for his iconic acting and numerous unforgettable movies. Probably, It’s hard to find a person in India who don’t familiar with his name. To give him a tribute or just for having some coding fun, in this lesson, we will create a colourful art of Shah Rukh Khan using a Python Code.
To achieve this goal, we’ll use the Python sketchpy module, where the Python Turtle will draw a colorful art of Shah Rukh Khan based on the previously extracted coordinates of face elements (e.g. face outline, hair, eyes, ears, nose, etc.) from an image.
Here, every details are important, so stick around until the end, and let’s bring Shah Rukh Khan into the world of Python programming.
How does the Program work?
Well, for starter, we will need a good quality photo of Shah Rukh Khan. Since our program will give a cartoon outcome, it’s necessary to convert the chosen image into cartoon. You can use many tools available online or, for an extra dose of Python fun, try out our Python application to effortlessly cartoonize an image (Convert an image to a cartoon using Python OpenCV).
Now, we need to find out every single x-y coordinates of the face elements (eyes, ears, hair, nose, nostril, chin, face outline, etc.) from the image. But, how do we achieve this feat, you wonder? I’ve employed a python program to achieve this task (Take a peek at – How to Get Coordinates of Clicked Points on an Image).
But the adventure doesn’t end there. Now, we need to store the coordinates of each face elements into several text files with a corresponding name. Once all the files are ready, Our trusty turtle, imported into the Python program, will gracefully follow these plotted points, bringing the face to life stroke by stroke.
Lastly we need to choose different colors for different facial features to make the sketch more gorgeous. These colors will fill the sketch while the turtle will be drawing. If you’re curious about how the shades I’ve chosen from the image, there’s a handy online tool at your service — visit ImageResizer.com/color-picker. It offers to find out the RGB value of colors by selecting that (color) from an image.
I’ve generated a sum of 85 text files containing lists of coordinates, essential for drawing a colourful portrait of Shah Rukh Khan. The program relies on these files for proper execution. To get these files, please refer to the following sections.
Setting Up the Environment
Please ensure that Python is installed on your system. You can download from the Python official site (https://www.python.org/). Now install a module called `sketchpy` using the following command.
pip install sketchpy
Download the zip file provided below and extracts its contents. Next, create a Python program file named `srk.py` inside the unzipped folder. In this Python file, we will start writing our code.
Import the modules
Let’s start writing the code by importing the `canvas` from the `sketchpy` module and the `time` module.
import time
from sketchpy import canvas
Create an object
Create an object of `canvas.sketch` class with this name `Turtle`.
Turtle = canvas.sketch(x_offset=290, y_offset=320)
Call the Draw Function
In this section, we will call the `draw_fn` function eighty five (85) times. Each call will sketch the outline of individual face elements, utilizing the coordinates presented in the text files.
Turtle.draw_fn("face-outline", co=(253, 223, 195), mode=0)
Turtle.draw_fn("nosetrill-1", co=(36, 19, 19), mode=0)
Turtle.draw_fn("nosetrill-2", co=(36, 19, 19), mode=0)
Turtle.draw_fn("noseline-1", co=(36, 19, 19), mode=0)
Turtle.draw_fn("noseline-2", co=(36, 19, 19), mode=0)
Turtle.draw_fn("lip-line-1", co=(89, 56, 42), mode=0)
Turtle.draw_fn("lip-line-2", co=(209, 160, 131), mode=0)
Turtle.draw_fn("chin-1", co=(67, 43, 21), mode=0)
Turtle.draw_fn("l-ear", co=(253, 222, 194), mode=0)
Turtle.draw_fn("l-ear-1", co=(43, 24, 9), mode=0)
Turtle.draw_fn("r-ear", co=(199, 143, 107), mode=0)
Turtle.draw_fn("r-ear-1", co=(35, 9, 1), mode=0)
Turtle.draw_fn("r-ear-2", co=(35, 9, 1), mode=0)
Turtle.draw_fn("r-ear-3", co=(35, 9, 1), mode=0)
Turtle.draw_fn("hair", co=(38, 17, 10), mode=0)
Turtle.draw_fn("sunglass-1", co=(61, 50, 56), mode=0)
Turtle.draw_fn("sunglass-2", co=(61, 50, 56), mode=0)
Turtle.draw_fn("sunglass-3", co=(61, 50, 56), mode=0)
Turtle.draw_fn("face-shade-1", co=(210, 157, 124), mode=0)
Turtle.draw_fn("face-shade-2", co=(235, 197, 155), mode=0)
Turtle.draw_fn("face-shade-3", co=(254, 241, 217), mode=0)
Turtle.draw_fn("face-shade-4", co=(202, 147, 114), mode=0)
Turtle.draw_fn("face-shade-5", co=(237, 198, 159), mode=0)
Turtle.draw_fn("face-shade-6", co=(237, 196, 156), mode=0)
Turtle.draw_fn("face-shade-7", co=(237, 198, 157), mode=0)
Turtle.draw_fn("nose-shade", co=(247, 229, 200), mode=0)
Turtle.draw_fn("throat", co=(205, 140, 109), mode=0)
Turtle.draw_fn("throat-line", co=(27, 28, 21), mode=0)
Turtle.draw_fn("throat-shade-1", co=(248, 220, 185), mode=0)
Turtle.draw_fn("throat-shade-2", co=(192, 128, 94), mode=0)
Turtle.draw_fn("throat-shade-3", co=(180, 110, 71), mode=0)
Turtle.draw_fn("throat-shade-4", co=(244, 220, 178), mode=0)
Turtle.draw_fn("shirt-left", co=(2, 88, 104), mode=0)
Turtle.draw_fn("shirt-line-1", co=(17, 17, 17), mode=0)
Turtle.draw_fn("shirt-line-2", co=(17, 17, 17), mode=0)
Turtle.draw_fn("shirt-line-3", co=(17, 17, 17), mode=0)
Turtle.draw_fn("hand", co=(250, 219, 185), mode=0)
Turtle.draw_fn("hand-shade-1", co=(214, 158, 127), mode=0)
Turtle.draw_fn("hand-shade-2", co=(238, 191, 155), mode=0)
Turtle.draw_fn("hand-shade-3", co=(239, 197, 157), mode=0)
Turtle.draw_fn("hand-shade-4", co=(241, 197, 158), mode=0)
Turtle.draw_fn("hand-shade-5", co=(210, 157, 129), mode=0)
Turtle.draw_fn("nail-1-line", co=(17, 17, 17), mode=0)
Turtle.draw_fn("nail-1", co=(248, 235, 216), mode=0)
Turtle.draw_fn("hand-line-1", co=(17, 17, 17), mode=0)
Turtle.draw_fn("hand-line-2", co=(17, 17, 17), mode=0)
Turtle.draw_fn("hand-line-3", co=(17, 17, 17), mode=0)
Turtle.draw_fn("hand-line-4", co=(17, 17, 17), mode=0)
Turtle.draw_fn("hand-line-5", co=(17, 17, 17), mode=0)
Turtle.draw_fn("hand-line-6", co=(17, 17, 17), mode=0)
Turtle.draw_fn("hand-line-7", co=(17, 17, 17), mode=0)
Turtle.draw_fn("hand-line-8", co=(17, 17, 17), mode=0)
Turtle.draw_fn("hand-line-9", co=(17, 17, 17), mode=0)
Turtle.draw_fn("hand-line-10", co=(17, 17, 17), mode=0)
Turtle.draw_fn("hand-line-11", co=(17, 17, 17), mode=0)
Turtle.draw_fn("hand-line-12", co=(17, 17, 17), mode=0)
Turtle.draw_fn("hand-band", co=(17, 17, 17), mode=0)
Turtle.draw_fn("t-shirt", co=(36, 88, 148), mode=0)
Turtle.draw_fn("t-shirt-line-1", co=(17, 17, 17), mode=0)
Turtle.draw_fn("t-shirt-line-2", co=(17, 17, 17), mode=0)
Turtle.draw_fn("t-shirt-line-3", co=(17, 17, 17), mode=0)
Turtle.draw_fn("shirt-right-shoulder", co=(2, 101, 120), mode=0)
Turtle.draw_fn("shirt-right", co=(2, 101, 120), mode=0)
Turtle.draw_fn("left-hand", co=(252, 223, 191), mode=0)
Turtle.draw_fn("t-shirt-bottom", co=(36, 88, 148), mode=0)
Turtle.draw_fn("shirt-line-4", co=(17, 17, 17), mode=0)
Turtle.draw_fn("shirt-line-5", co=(17, 17, 17), mode=0)
Turtle.draw_fn("shirt-line-6", co=(17, 17, 17), mode=0)
Turtle.draw_fn("shirt-pocket", co=(17, 17, 17), mode=0)
Turtle.draw_fn("shirt-line-7", co=(17, 17, 17), mode=0)
Turtle.draw_fn("shirt-line-8", co=(17, 17, 17), mode=0)
Turtle.draw_fn("shirt-line-9", co=(17, 17, 17), mode=0)
Turtle.draw_fn("shirt-line-10", co=(17, 17, 17), mode=0)
Turtle.draw_fn("shirt-shade-1", co=(0, 124, 148), mode=0)
Turtle.draw_fn("shirt-shade-2", co=(0, 124, 148), mode=0)
Turtle.draw_fn("shirt-shade-3", co=(0, 124, 148), mode=0)
Turtle.draw_fn("p", co=(59, 86, 224), mode=0)
Turtle.draw_fn("y", co=(59, 86, 224), mode=0)
Turtle.draw_fn("s1", co=(236, 216, 57), mode=0)
Turtle.draw_fn("s2", co=(236, 216, 57), mode=0)
Turtle.draw_fn("e1", co=(236, 216, 57), mode=0)
Turtle.draw_fn("e2", co=(251, 246, 240), mode=0)
Turtle.draw_fn("e3", co=(236, 216, 57), mode=0)
Turtle.draw_fn("e4", co=(251, 246, 240), mode=0)
Turtle.draw_fn("k", co=(236, 216, 57), mode=0)
time.sleep(4)
In the code above, `draw_fn` takes the following parameters:
- `file`: The path of the text file that contains the coordinates.
- `mode`: Mode of drawing (1 – sketch with a line, 0 – fill with color).
- `co`: The color of the line or fill.
- `thickness` (default): Thickness of the line (In our case, we didn’t mention it in the program. By default it takes a value).
- `retain` (default): Retain the image drawn after executing.
Output

Summary
In this tutorial, we crafted a colourful art of an Indian Star, Shah Rukh Khan using a Python Code. We previously stored a total of 85 text files which contain the coordinates of the face elements, and our main program file must needed these text files. In the program, we employed the sketchpy module that further uses the Python turtle to trace the coordinates and draw each face segment and other elements. You can easily get those files through the Download button provided before.
In short, this tutorial invites you to combine creativity and coding. Don’t hesitate—jump into the world of Python-powered sketching and let your imagination flourish on the canvas!
Do you have any burning questions about this topic? Don’t be shy—drop them in the comments below! I’m here and ready to help you out.
Happy Sketching!