Python program display any message on heart
Last Updated :
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
import pylab
import numpy as np
Xaxis = np.linspace( - 2 , 2 ,
100000 )
Y1axis = np.sqrt( 1 -
( abs (Xaxis) - 1 ) * * 2 )
Y2axis = - 3 * np.sqrt( 1 -
( abs (Xaxis) / 2 ) * * 0.5 )
pylab.fill_between(Xaxis, Y1axis,
color = 'red' )
pylab.fill_between(Xaxis, Y2axis,
color = 'red' )
pylab.xlim([ - 2.5 , 2.5 ])
pylab.axis( "off" )
text = "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
import pylab
import numpy as np
Xaxis = np.linspace( - 2 , 2 ,
100000 )
Y1axis = np.sqrt( 1 -
( abs (Xaxis) - 1 ) * * 2 )
Y2axis = - 3 * np.sqrt( 1 -
( abs (Xaxis) / 2 ) * * 0.5 )
pylab.fill_between(Xaxis, Y1axis,
color = 'pink' )
pylab.fill_between(Xaxis, Y2axis,
color = 'red' )
pylab.xlim([ - 2.5 , 2.5 ])
pylab.axis( "off" )
text = "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
import pylab
import numpy as np
Xaxis = np.linspace( - 2 , 2 ,
100000 )
Y1axis = np.sqrt( 1 -
( abs (Xaxis) - 1 ) * * 2 )
Y2axis = - 3 * np.sqrt( 1 -
( abs (Xaxis) / 2 ) * * 0.5 )
pylab.fill_between(Xaxis, Y1axis,
color = 'pink' )
pylab.fill_between(Xaxis, Y2axis,
color = 'pink' )
pylab.xlim([ - 2.5 , 2.5 ])
pylab.axis( "off" )
text = "Geeksforgeeks - \n Best platform to explore"
pylab.text( 0 , - 0.6 , text,
fontsize = 14 ,
fontweight = 'bold' ,
color = 'red' ,
horizontalalignment = 'center' )
|
Output:
Share your thoughts in the comments
Please Login to comment...