Fun Valentine’s Day “Gift” Ideas For Python Programmers | by Yong Cui | Towards Data Science

Valentine’s Day is just around the corner. I’ve not decided what gift I’ll give to my wife. Picking the right gift is usually a very challenging task for me, as I’m just not a creative person in the romance domain. Most of the time, I just send her some flowers with a gift card, because I just didn’t want to make the mistake again by sending her a weight scale, which made her really mad, although I thought a digital stainless steel smart scale supporting Bluetooth was really cool.
This year, I guess that I’ll do something different. In the last couple of years, I’ve started to use Python a lot more than before, and found some interesting projects that can be done with just a few lines of code. In this article, I would like to share three cool mini-projects that can potentially be gift ideas. However, just a quick disclaimer, use them at your own risk, as it’s a recommendation from a so-called “nerd” or “geek”:)
The first easy thing for you to do is to draw a heart shape using the numpy and mtaplotlib libraries. Thus, please first make sure you have both installed on your computer, such as by installing them using the pip tool. Copy and paste the following code in your own Python IDE.
As you can tell, we use the formula (x**2+y**2–1)**3-x**2*y**3=0, in which ** means exponentiation to the power of the number following the symbol, to generate a series of points contributing to the heart shape.
Run the above code, and you’ll see a red heart as below. You can play with the code to change the size, resolution, and even color! I’ll leave these tasks to you if you’re bold enough to use this gift idea :)
Another interesting thing to do is to create animated images using the imageio library, which can generate animated images from individual static images. As above, your computer needs to have the imageio library installed.
In your photo album, find 10 or more images that are appropriate for the Valentine’s Day, and drop them in a folder called “source_images”, for example. Run the following code in your IDE.
Actually, you can also create animated images from a video clip. You can refer to my previous article for further detailed instruction.
The last idea that I’d like to share is that you can create a word cloud for your loved one. To do that, we’ll use the wordcloud, imageio, and matplotlib libraries.
I wrote a function that takes in a string, an image file that provides the mask for the word cloud, and the destination image file for the created word cloud. In addition, I wrote another function that generates random red colors with the same hue, saturation, but different lightness. I chose the red color as that’s the theme color for the Valentine’s Day.
The full code is provided below.
Personally, for the string, I just listed a bunch of cities and countries that we have visited or plan to visit in the near future, and I created a variable called words to store these names. For a proof of concept, I just chose the heart image that we created from the first idea by saving the image calling plt.savefig(‘heart.png’).
>>> words = 'Paris, France, Houston, Vegas, Italy, America, Rome, Austin, Seattle, Miami, London, Boston, Beijing, Shanghai, Macau, Moscow, Venice, Germany, Australia, Netherlands, Detroit'>>> generate_word_cloud(words, 'heart.png', 'word_cloud.png')
After running the above code, a figure like below was created.
The above mini-projects just showed you some fun ideas that can potentially be used for your Valentine’s Day. Please feel free to explore these options by trying different combinations of parameters. In addition, you could combine these ideas together, like I did in the third idea. For example, you can make multiple word clouds and mix them with some real images to create some more personalized animated images.
Happy Valentine’s Day!