Python program display any message on heart - GeeksforGeeks

31 May, 2021
This article focuses on discussing how to draw a heart with a beautiful message to your loved ones to express what you feel about them. Three types of variants of the above problem statement will be discussed here:
Red Heart with a message.
Pink-Red Heart with a message.
Pink Heart with a message in a different font and color than in the above two cases.
Program 1: Below is the python code for a simple red heart with a message:
Python3
# Python3 program for the above approach# import libraryimport pylabimport numpy as np  # Width of heartXaxis = np.linspace(-2, 2,                     100000)  # Setting upper y Y1axis = np.sqrt(1 -          (abs(Xaxis) - 1) **2)  # Setting -yY2axis = -3 * np.sqrt(1 -          (abs(Xaxis) / 2) **0.5)  # Adjust colour for upper part # of heratpylab.fill_between(Xaxis, Y1axis,                    color = 'red')  # Adjust colour for lower part # of heartpylab.fill_between(Xaxis, Y2axis,                    color = 'red')    pylab.xlim([-2.5, 2.5])pylab.axis("off")  # Driver Codetext = "Geeksforgeeks"  pylab.text(0, -0.4, text,            fontsize = 24,            fontweight = 'bold',           color = 'white',            horizontalalignment = 'center')
Output:
Program 2: Below is the python code to change the color of a part of the heart to pink and the rest of the heart is red and print a message on the heart:
Python3
# Python3 program for the above approachimport pylabimport numpy as np  # Width of heartXaxis = np.linspace(-2, 2,                     100000)  # Setting upper y Y1axis = np.sqrt(1 -          (abs(Xaxis) - 1) **2)  # Setting -yY2axis = -3 * np.sqrt(1 -          (abs(Xaxis) / 2) **0.5)  # Adjust colour for upper part# of heratpylab.fill_between(Xaxis, Y1axis,                    color = 'pink')  # Adjust colour for lower part # of heartpylab.fill_between(Xaxis, Y2axis,                    color = 'red')  pylab.xlim([-2.5, 2.5])pylab.axis("off")  # Driver Codetext = "Geeksforgeeks"  pylab.text(0, -0.6, text,            fontsize = 24,            fontweight = 'bold',           color = 'grey',            horizontalalignment = 'center')
Output:
Program 3: Below is the python code to implement a pink color heart with a message in different font size and color:
Python3
# Python3 program for the above approachimport pylabimport numpy as np  # Width of heartXaxis = np.linspace(-2, 2,                     100000)  # Setting upper y Y1axis = np.sqrt(1 -          (abs(Xaxis) - 1) **2)  # Setting lower -yY2axis = -3 * np.sqrt(1 -          (abs(Xaxis) / 2) **0.5)   # Adjust colour for upper part # of heratpylab.fill_between(Xaxis, Y1axis,                   color = 'pink')  # Adjust colour for lower part of heartpylab.fill_between(Xaxis, Y2axis,                    color = 'pink')  pylab.xlim([-2.5, 2.5])pylab.axis("off")  # Driver Codetext = "Geeksforgeeks - \n Best platform to explore"  # Explore your change herepylab.text(0, -0.6, text,            fontsize = 14,            fontweight = 'bold',           color = 'red',            horizontalalignment = 'center')  # To save the above image, execute the # line- pylab.savefig('heart.png')
Output:
python
Python
Python Programs
python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
How To Convert Python Dictionary To JSON?
How to drop one or multiple columns in Pandas Dataframe
Check if element exists in list in Python
Python | os.path.join() method
Defaultdict in Python
Python | Split string into list of characters
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python program to check whether a number is Prime or not