Skip to content
Related Articles

Related Articles

Python program display any message on heart

Improve Article
Save Article
  • Difficulty Level : Expert
  • Last Updated : 31 May, 2021
Improve Article
Save Article

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 library
import pylab
import numpy as np
  
# Width of heart
Xaxis = np.linspace(-2, 2
                    100000)
  
# Setting upper y 
Y1axis = np.sqrt(1 - 
         (abs(Xaxis) - 1) **2)
  
# Setting -y
Y2axis = -3 * np.sqrt(1 - 
         (abs(Xaxis) / 2) **0.5)
  
# Adjust colour for upper part 
# of herat
pylab.fill_between(Xaxis, Y1axis, 
                   color = 'red')
  
# Adjust colour for lower part 
# of heart
pylab.fill_between(Xaxis, Y2axis, 
                   color = 'red')
  
  
pylab.xlim([-2.5, 2.5])
pylab.axis("off")
  
# Driver Code
text = "Geeksforgeeks"
  
pylab.text(0, -0.4, text, 
           fontsize = 24
           fontweight = 'bold',
           color = 'white'
           horizontalalignment = 'center')

Output:

Output#1

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 approach
import pylab
import numpy as np
  
# Width of heart
Xaxis = np.linspace(-2, 2
                    100000)
  
# Setting upper y 
Y1axis = np.sqrt(1 - 
         (abs(Xaxis) - 1) **2)
  
# Setting -y
Y2axis = -3 * np.sqrt(1 - 
         (abs(Xaxis) / 2) **0.5)
  
# Adjust colour for upper part
# of herat
pylab.fill_between(Xaxis, Y1axis, 
                   color = 'pink')
  
# Adjust colour for lower part 
# of heart
pylab.fill_between(Xaxis, Y2axis, 
                   color = 'red')
  
pylab.xlim([-2.5, 2.5])
pylab.axis("off")
  
# Driver Code
text = "Geeksforgeeks"
  
pylab.text(0, -0.6, text, 
           fontsize = 24
           fontweight = 'bold',
           color = 'grey'
           horizontalalignment = 'center')

Output:

Output#2

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 approach
import pylab
import numpy as np
  
# Width of heart
Xaxis = np.linspace(-2, 2
                    100000)
  
# Setting upper y 
Y1axis = np.sqrt(1 - 
         (abs(Xaxis) - 1) **2)
  
# Setting lower -y
Y2axis = -3 * np.sqrt(1 - 
         (abs(Xaxis) / 2) **0.5)
   
# Adjust colour for upper part 
# of herat
pylab.fill_between(Xaxis, Y1axis,
                   color = 'pink')
  
# Adjust colour for lower part of heart
pylab.fill_between(Xaxis, Y2axis, 
                   color = 'pink')
  
pylab.xlim([-2.5, 2.5])
pylab.axis("off")
  
# Driver Code
text = "Geeksforgeeks - \n Best platform to explore"
  
# Explore your change here
pylab.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:

Output#3


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!