Fundamentals 5 min read

Creative Code Confessions: Generate Love Messages and Heart Art with Python & JavaScript

This tutorial shows how to craft playful romantic messages and visual heart art using Python and JavaScript code snippets, including ASCII‑based text, a one‑line heart generator, QR code creation, and a canvas‑drawn rose, all illustrated with example outputs.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Creative Code Confessions: Generate Love Messages and Heart Art with Python & JavaScript

The article shares playful programming examples for creating romantic messages and visual art, suitable for the Qixi festival.

1. Subtle confession using ASCII letters

Python code builds a string by selecting specific letters from ascii_letters based on indices, inserts spaces, and prints "I love you".

import string
l = string.ascii_letters
s = []
s.append(l[34])
s.append(l[11])
s.append(l[14])
s.append(l[21])
s.append(l[4])
s.append(l[24])
s.append(l[14])
s.append(l[20])
s.insert(1, " ")
s.insert(6, " ")
string = "".join(s)
print(string)  # I love you

The corresponding ASCII codes for the letters are shown below.

# 73, 76, 79, 86, 69, 85 correspond to ASCII
print(chr(73))  # I
print(chr(76))  # L
print(chr(79))  # O
print(chr(86))  # V
print(chr(69))  # E
print(chr(85))  # U

2. One‑line Python heart shape

A nested list comprehension with a mathematical condition prints a heart made of the word "Love".

print('
'.join([''.join([('Love'[(x-y) % len('Love')] if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0 else ' ') for x in range(-30, 30)]) for y in range(30, -30, -1)]))
Heart shape generated by Python
Heart shape generated by Python

3. JavaScript implementation

The same visual can be produced with JavaScript for broader compatibility; the article links to the source code.

// Source: https://c.runoob.com/codedemo/5656

4. Mobile QR‑code version

A QR code image can be saved and sent directly to a loved one.

QR code for love message
QR code for love message

5. Canvas rose illustration

A canvas‑based rose drawing using JavaScript demonstrates another decorative effect, with source link provided.

// Source: https://c.runoob.com/codedemo/5588
Canvas rose animation
Canvas rose animation

The article concludes with a light‑hearted note that coding can be more fun than dating.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaScriptPythonQR codeProgramming tutorialASCII artHeart ShapeCanvas graphics
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.