Horje
Python program display any message on heart

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




Reffered: https://www.geeksforgeeks.org


Python

Related
Drop specific rows from multiindex Pandas Dataframe Drop specific rows from multiindex Pandas Dataframe
Scraping Indeed Job Data Using Python Scraping Indeed Job Data Using Python
Track Covid-19 Vaccine Slots using cowin in Python Track Covid-19 Vaccine Slots using cowin in Python
Replace negative values with latest preceding positive value in Pandas DataFrame Replace negative values with latest preceding positive value in Pandas DataFrame
How to Execute Shell Commands in a Remote Machine using Python - Paramiko How to Execute Shell Commands in a Remote Machine using Python - Paramiko

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12