Messi vs Ronaldo in Python

Messi and Ronaldo are playing chess with each other

Introduction

Messi and Ronaldo are two of the most popular footballers of the current era. When these two play together on the field, people's excitement is at its peak and the popularity of both of them is no less than each other in any part. I am also a big fan of both of them.

So long I wanted to try something a little fun and finally, I got an idea. As a Python programmer, I have created a portrait of two of them (Messi and Ronaldo) through Python programming. In this tutorial, I will show you how I did it and how you can do it too.

Here, we will create Messi vs Ronaldo in Python. So stay tuned till the end and follwfollow each step carefully.

Visit Also: Draw the Sketch of Lionel Messi using a Python Program 

How does the program work?

Before we proceed, we need to find every single x-y coordinate of each point, around each part of the face(eyes, ears, hair, nose, nostril, chin, face outline, etc.) and so on. I've used a python program to find that (Check - How to get Coordinates of the Clicked Points on an Image). Then, we have to store those coordinates in separate text files for different objects(parts of the face) with different names.

Next, the imported turtle of our program will trace those points and draw one after one. We can set a different color for different parts also. I did that in my program.

There is an online website(ImageResizer.com/color-picker) that offers to find out the RGB value of colors by selecting that (color) from an image.

getting the rgb value of a color from an image
Getting the RGB value of a color

I've created a total of 47 text files (which store coordinates list) to replicate Messi vs Ronaldo and these must be required by the program.

Requirements

☛Install sketchpy: pip install sketchpy

Import the modules

Let's create a Python file with the name 'main.py' and start writing the code by importing this module.


from sketchpy import canvas

Create an object

Create an object of canvas.sketch class. I named the object 'Turtle' for matching the name with the working principle.


Turtle = canvas.sketch(x_offset=290, y_offset=320)

messi.py

Create a separate python program file with this name - 'messi.py' and paste the below code there.


def DrawMessi(Turtle):
Turtle.draw_fn("outer-face", co=(226, 190, 183), mode=0)
Turtle.draw_fn("beard-&-hair", co=(42, 42, 39), mode=0)
Turtle.draw_fn("hair-shade1", co=(42, 42, 39), mode=0)
Turtle.draw_fn("lips", co=(188, 154, 146), mode=0)
Turtle.draw_fn("lips-reddish", co=(91, 16, 21), mode=0)
Turtle.draw_fn("nostril", co=(7, 1, 2), mode=0)
Turtle.draw_fn("nose-shade1", co=(146, 63, 60), mode=0)
Turtle.draw_fn("right-eyebrow", co=(80, 44, 36), mode=0)
Turtle.draw_fn("left-eyebrow", co=(79, 45, 36), mode=0)
Turtle.draw_fn("upper-eye-shade", co=(19, 8, 7), mode=0)
Turtle.draw_fn("front-eye-shade", co=(92, 46, 14), mode=0)
Turtle.draw_fn("scelra", co=(252, 252, 253), mode=0)
Turtle.draw_fn("eye-ball", co=(40, 20, 16), mode=0)
Turtle.draw_fn("ear-outer-part", co=(241, 217, 199), mode=0)
Turtle.draw_fn("inner-ear1", co=(58, 26, 19), mode=0)
Turtle.draw_fn("inner-ear2", co=(186, 143, 121), mode=0)
Turtle.draw_fn("inner-ear3", co=(186, 143, 121), mode=0)
Turtle.draw_fn("inner-ear4", co=(186, 143, 121), mode=0)
Turtle.draw_fn("inner-ear5", co=(150, 93, 76), mode=0)
Turtle.draw_fn("inner-ear6", co=(226, 157, 154), mode=0)
Turtle.draw_fn("throat", co=(207, 172, 163), mode=0)
Turtle.draw_fn("beard-shade1", co=(174, 156, 142), mode=0)
Turtle.draw_fn("beard-shade2", co=(98, 77, 60), mode=0)
Turtle.draw_fn("t-shirt", co=(20, 79, 126), mode=0)

Explanation

I create a function there ("DrawMessi(Turtle)") and have taken 'Turtle' object as a parameter passed from the main function.

'draw_fn()' - takes the parameters like this:

draw_fn(file, co = (0,0,0), mode = 0) - Where, file - the path of the file which contains coordinates. I passed several text files as an argument here. I named each file meaningful so that it would be easy to understand.

Important Note - These text files must be placed in the directory where the 'main.py' file is situated. Each text file contains a large number of coordinates lists. You can get those from my GitHub page, through the 'Download' Button below.

co - the color of the line or fill.

mode - mode of drawing (1 - sketch with a line, 0 - fill with color).

ronaldo.py

Create an another python program file for Ronaldo with this name - 'ronaldo.py' and placed it in the project folder (where 'main.py', 'messi.py', and other text files are situated).

Now paste the code below in the 'ronaldo.py' file.


def DrawRonaldo(Turtle):
Turtle.draw_fn("r-outer-face", co=(212, 170, 130), mode=0)
Turtle.draw_fn("r-hair", co=(37, 28, 23), mode=0)
Turtle.draw_fn("r-ear-outer", co=(193, 131, 86), mode=0)
Turtle.draw_fn("r-ear-shade1", co=(55, 39, 34), mode=0)
Turtle.draw_fn("r-ear-shade2", co=(60, 14, 3), mode=0)
Turtle.draw_fn("r-ear-shade3", co=(99, 26, 10), mode=0)
Turtle.draw_fn("r-eyebrow", co=(15, 10, 8), mode=0)
Turtle.draw_fn("r-eye-outer-scelra", co=(106, 46, 27), mode=0)
Turtle.draw_fn("r-scelra", co=(221, 221, 223), mode=0)
Turtle.draw_fn("r-eyeball", co=(3, 1, 0), mode=0)
Turtle.draw_fn("r-nostril", co=(16, 3, 2), mode=0)
Turtle.draw_fn("r-nose-shade1", co=(164, 110, 55), mode=0)
Turtle.draw_fn("r-lips", co=(133, 62, 41), mode=0)
Turtle.draw_fn("r-mouth", co=(6, 3, 1), mode=0)
Turtle.draw_fn("r-jacket", co=(94, 10, 4), mode=0)
Turtle.draw_fn("r-face-shade1", co=(127, 80, 52), mode=0)
Turtle.draw_fn("r-face-shade2", co=(165, 112, 63), mode=0)
Turtle.draw_fn("r-eye-shade1", co=(106, 47, 5), mode=0)
Turtle.draw_fn("r-forhead-shade1", co=(165, 114, 52), mode=0)
Turtle.draw_fn("r-face-shade3", co=(198, 144, 106), mode=0)

The explanation is exactly the same as what we did earlier.

Get back to main.py again

We successfully created two different program files for Messi and Ronaldo to draw their replicate. Now it's time to call both of them in the main program file. Before that, we have to import both 'messi.py' and 'ronaldo.py' there. Additionally, we will import the time module to use the sleep function at last.


import messi as lm10
import ronaldo as cr7
import time

We already have done some work in the main.py. Now add the below code at last.


lm10.DrawMessi(Turtle)
cr7.DrawRonaldo(Turtle)

So far our program can successfully draw a portrait of Messi and Ronaldo. Now add two more lines to add 'vs' to create a rivalry between the two of them.


Turtle.draw_fn("v", co=(213, 61, 75), mode=0)
Turtle.draw_fn("s", co=(213, 61, 75), mode=0)

Let's add a sleep function to delay in execution of the program for five seconds at the very end.


time.sleep(5)

Finally, our main program is ready to act and it completely looks like the below.


from sketchpy import canvas
import messi as lm10
import ronaldo as cr7
import time

Turtle = canvas.sketch(x_offset=290, y_offset=320)

lm10.DrawMessi(Turtle)
cr7.DrawRonaldo(Turtle)

Turtle.draw_fn("v", co=(213, 61, 75), mode=0)
Turtle.draw_fn("s", co=(213, 61, 75), mode=0)


time.sleep(5)

Output

Output of Messi vs Ronaldo Program
Output

Download the Project File

Get the text files used in the above program, from my GitHub page(https://github.com/subhankar-rakshit) through the download button.

Summary

In this tutorial, we made a replicate of Messi vs Ronaldo using Python Programming. We used the sketchpy module to make this unique idea reality. 

Messi and Ronaldo, no doubt are both legendary footballers and both are my favorites. It was just a fun and show tribute to both of them as a programmer.

I covered the entire topic in several segments. Hope you loved this topic. Please leave your comments below in case of any doubts or problems related to this topic. You will get a reply soon.

To get more lovely python topics, visit the separate page created only for Unique Examples. Some examples are given below.

👉How to Blink Caps Lock using Python Code

👉Wish Your Friends with Stylish Text in Python - pyfiglet, termcolor

👉Python Keylogger - Build a Simple Keylogger in Python

👉 Wish Happy Birthday🎂 in Python Code: The Original Program

Thanks for reading!

PySeek

Subhankar Rakshit

Meet Subhankar Rakshit, a Computer Science postgraduate (M.Sc.) and the creator of PySeek. Subhankar is a programmer, specializes in Python language. With a several years of experience under his belt, he has developed a deep understanding of software development. He enjoys writing blogs on various topics related to Computer Science, Python Programming, and Software Development.

Post a Comment (0)
Previous Post Next Post