Python script, to print the names of colors
-- in different languages
-- using Unicode
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
unicode_processor.py
Processes a UTF-8 text file line by line.
Uses the 'regex' module for true grapheme cluster handling
so Indic/complex scripts (Telugu, Hindi, etc.) stay intact.
"""
import sys
import unicodedata
import regex as re # must be installed with `pip install regex`
def split_graphemes(s: str):
"""Split into Unicode grapheme clusters using regex \\X."""
return re.findall(r'\X', s)
def describe_codepoints(grapheme: str) -> str:
"""Return a string like (U+0C05 U+0C3E) for a grapheme."""
return " ".join(f"U+{ord(ch):04X}" for ch in grapheme)
def is_visible(grapheme: str) -> bool:
"""Return True if grapheme is not just whitespace/punctuation."""
for ch in grapheme:
cat = unicodedata.category(ch)
if cat.startswith(('L', 'N', 'S')): # Letter, Number, Symbol
return True
return False
def process_file(filename: str):
with open(filename, 'r', encoding='utf-8') as fh:
for raw_line in fh:
line = raw_line.rstrip('\n')
if line == '':
print()
continue
for g in split_graphemes(line):
if not is_visible(g):
continue
cp_desc = describe_codepoints(g)
print(f"{g} [{cp_desc}]: "
f"Angle within a regular polygon of {g}-sides = [({g}-2)/{g}]*(pi); "
f"while summation = 1 + 2 + 3 + ... + ({g}-1) + {g} = {g}*({g}+1)/2;")
print()
if __name__ == '__main__':
infile = sys.argv[1] if len(sys.argv) > 1 else 'list_of_colours.txt'
try:
process_file(infile)
except FileNotFoundError:
print(f"File not found: {infile}", file=sys.stderr)
sys.exit(2)
Colours in English, Telugu, Greek, Hindi =>
cat ./list_of_10_colours.txt
red
blue
green
neon
ఎరుపు
నీలం
ఆకుపచ్చ
నీయాన్
κόκκινο
μπλε
πράσινο
νέον
लाल
नीला
हरा
नियॉन
result =>
r [U+0072]: Angle within a regular polygon of r-sides = [(r-2)/r]*(pi); while summation = 1 + 2 + 3 + ... + (r-1) + r = r*(r+1)/2;
e [U+0065]: Angle within a regular polygon of e-sides = [(e-2)/e]*(pi); while summation = 1 + 2 + 3 + ... + (e-1) + e = e*(e+1)/2;
d [U+0064]: Angle within a regular polygon of d-sides = [(d-2)/d]*(pi); while summation = 1 + 2 + 3 + ... + (d-1) + d = d*(d+1)/2;
b [U+0062]: Angle within a regular polygon of b-sides = [(b-2)/b]*(pi); while summation = 1 + 2 + 3 + ... + (b-1) + b = b*(b+1)/2;
l [U+006C]: Angle within a regular polygon of l-sides = [(l-2)/l]*(pi); while summation = 1 + 2 + 3 + ... + (l-1) + l = l*(l+1)/2;
u [U+0075]: Angle within a regular polygon of u-sides = [(u-2)/u]*(pi); while summation = 1 + 2 + 3 + ... + (u-1) + u = u*(u+1)/2;
e [U+0065]: Angle within a regular polygon of e-sides = [(e-2)/e]*(pi); while summation = 1 + 2 + 3 + ... + (e-1) + e = e*(e+1)/2;
g [U+0067]: Angle within a regular polygon of g-sides = [(g-2)/g]*(pi); while summation = 1 + 2 + 3 + ... + (g-1) + g = g*(g+1)/2;
r [U+0072]: Angle within a regular polygon of r-sides = [(r-2)/r]*(pi); while summation = 1 + 2 + 3 + ... + (r-1) + r = r*(r+1)/2;
e [U+0065]: Angle within a regular polygon of e-sides = [(e-2)/e]*(pi); while summation = 1 + 2 + 3 + ... + (e-1) + e = e*(e+1)/2;
e [U+0065]: Angle within a regular polygon of e-sides = [(e-2)/e]*(pi); while summation = 1 + 2 + 3 + ... + (e-1) + e = e*(e+1)/2;
n [U+006E]: Angle within a regular polygon of n-sides = [(n-2)/n]*(pi); while summation = 1 + 2 + 3 + ... + (n-1) + n = n*(n+1)/2;
n [U+006E]: Angle within a regular polygon of n-sides = [(n-2)/n]*(pi); while summation = 1 + 2 + 3 + ... + (n-1) + n = n*(n+1)/2;
e [U+0065]: Angle within a regular polygon of e-sides = [(e-2)/e]*(pi); while summation = 1 + 2 + 3 + ... + (e-1) + e = e*(e+1)/2;
o [U+006F]: Angle within a regular polygon of o-sides = [(o-2)/o]*(pi); while summation = 1 + 2 + 3 + ... + (o-1) + o = o*(o+1)/2;
n [U+006E]: Angle within a regular polygon of n-sides = [(n-2)/n]*(pi); while summation = 1 + 2 + 3 + ... + (n-1) + n = n*(n+1)/2;
ఎ [U+0C0E]: Angle within a regular polygon of ఎ-sides = [(ఎ-2)/ఎ]*(pi); while summation = 1 + 2 + 3 + ... + (ఎ-1) + ఎ = ఎ*(ఎ+1)/2;
రు [U+0C30 U+0C41]: Angle within a regular polygon of రు-sides = [(రు-2)/రు]*(pi); while summation = 1 + 2 + 3 + ... + (రు-1) + రు = రు*(రు+1)/2;
పు [U+0C2A U+0C41]: Angle within a regular polygon of పు-sides = [(పు-2)/పు]*(pi); while summation = 1 + 2 + 3 + ... + (పు-1) + పు = పు*(పు+1)/2;
నీ [U+0C28 U+0C40]: Angle within a regular polygon of నీ-sides = [(నీ-2)/నీ]*(pi); while summation = 1 + 2 + 3 + ... + (నీ-1) + నీ = నీ*(నీ+1)/2;
లం [U+0C32 U+0C02]: Angle within a regular polygon of లం-sides = [(లం-2)/లం]*(pi); while summation = 1 + 2 + 3 + ... + (లం-1) + లం = లం*(లం+1)/2;
ఆ [U+0C06]: Angle within a regular polygon of ఆ-sides = [(ఆ-2)/ఆ]*(pi); while summation = 1 + 2 + 3 + ... + (ఆ-1) + ఆ = ఆ*(ఆ+1)/2;
కు [U+0C15 U+0C41]: Angle within a regular polygon of కు-sides = [(కు-2)/కు]*(pi); while summation = 1 + 2 + 3 + ... + (కు-1) + కు = కు*(కు+1)/2;
ప [U+0C2A]: Angle within a regular polygon of ప-sides = [(ప-2)/ప]*(pi); while summation = 1 + 2 + 3 + ... + (ప-1) + ప = ప*(ప+1)/2;
చ్ [U+0C1A U+0C4D]: Angle within a regular polygon of చ్-sides = [(చ్-2)/చ్]*(pi); while summation = 1 + 2 + 3 + ... + (చ్-1) + చ్ = చ్*(చ్+1)/2;
చ [U+0C1A]: Angle within a regular polygon of చ-sides = [(చ-2)/చ]*(pi); while summation = 1 + 2 + 3 + ... + (చ-1) + చ = చ*(చ+1)/2;
నీ [U+0C28 U+0C40]: Angle within a regular polygon of నీ-sides = [(నీ-2)/నీ]*(pi); while summation = 1 + 2 + 3 + ... + (నీ-1) + నీ = నీ*(నీ+1)/2;
యా [U+0C2F U+0C3E]: Angle within a regular polygon of యా-sides = [(యా-2)/యా]*(pi); while summation = 1 + 2 + 3 + ... + (యా-1) + యా = యా*(యా+1)/2;
న్ [U+0C28 U+0C4D]: Angle within a regular polygon of న్-sides = [(న్-2)/న్]*(pi); while summation = 1 + 2 + 3 + ... + (న్-1) + న్ = న్*(న్+1)/2;
κ [U+03BA]: Angle within a regular polygon of κ-sides = [(κ-2)/κ]*(pi); while summation = 1 + 2 + 3 + ... + (κ-1) + κ = κ*(κ+1)/2;
ό [U+03CC]: Angle within a regular polygon of ό-sides = [(ό-2)/ό]*(pi); while summation = 1 + 2 + 3 + ... + (ό-1) + ό = ό*(ό+1)/2;
κ [U+03BA]: Angle within a regular polygon of κ-sides = [(κ-2)/κ]*(pi); while summation = 1 + 2 + 3 + ... + (κ-1) + κ = κ*(κ+1)/2;
κ [U+03BA]: Angle within a regular polygon of κ-sides = [(κ-2)/κ]*(pi); while summation = 1 + 2 + 3 + ... + (κ-1) + κ = κ*(κ+1)/2;
ι [U+03B9]: Angle within a regular polygon of ι-sides = [(ι-2)/ι]*(pi); while summation = 1 + 2 + 3 + ... + (ι-1) + ι = ι*(ι+1)/2;
ν [U+03BD]: Angle within a regular polygon of ν-sides = [(ν-2)/ν]*(pi); while summation = 1 + 2 + 3 + ... + (ν-1) + ν = ν*(ν+1)/2;
ο [U+03BF]: Angle within a regular polygon of ο-sides = [(ο-2)/ο]*(pi); while summation = 1 + 2 + 3 + ... + (ο-1) + ο = ο*(ο+1)/2;
μ [U+03BC]: Angle within a regular polygon of μ-sides = [(μ-2)/μ]*(pi); while summation = 1 + 2 + 3 + ... + (μ-1) + μ = μ*(μ+1)/2;
π [U+03C0]: Angle within a regular polygon of π-sides = [(π-2)/π]*(pi); while summation = 1 + 2 + 3 + ... + (π-1) + π = π*(π+1)/2;
λ [U+03BB]: Angle within a regular polygon of λ-sides = [(λ-2)/λ]*(pi); while summation = 1 + 2 + 3 + ... + (λ-1) + λ = λ*(λ+1)/2;
ε [U+03B5]: Angle within a regular polygon of ε-sides = [(ε-2)/ε]*(pi); while summation = 1 + 2 + 3 + ... + (ε-1) + ε = ε*(ε+1)/2;
π [U+03C0]: Angle within a regular polygon of π-sides = [(π-2)/π]*(pi); while summation = 1 + 2 + 3 + ... + (π-1) + π = π*(π+1)/2;
ρ [U+03C1]: Angle within a regular polygon of ρ-sides = [(ρ-2)/ρ]*(pi); while summation = 1 + 2 + 3 + ... + (ρ-1) + ρ = ρ*(ρ+1)/2;
ά [U+03AC]: Angle within a regular polygon of ά-sides = [(ά-2)/ά]*(pi); while summation = 1 + 2 + 3 + ... + (ά-1) + ά = ά*(ά+1)/2;
σ [U+03C3]: Angle within a regular polygon of σ-sides = [(σ-2)/σ]*(pi); while summation = 1 + 2 + 3 + ... + (σ-1) + σ = σ*(σ+1)/2;
ι [U+03B9]: Angle within a regular polygon of ι-sides = [(ι-2)/ι]*(pi); while summation = 1 + 2 + 3 + ... + (ι-1) + ι = ι*(ι+1)/2;
ν [U+03BD]: Angle within a regular polygon of ν-sides = [(ν-2)/ν]*(pi); while summation = 1 + 2 + 3 + ... + (ν-1) + ν = ν*(ν+1)/2;
ο [U+03BF]: Angle within a regular polygon of ο-sides = [(ο-2)/ο]*(pi); while summation = 1 + 2 + 3 + ... + (ο-1) + ο = ο*(ο+1)/2;
ν [U+03BD]: Angle within a regular polygon of ν-sides = [(ν-2)/ν]*(pi); while summation = 1 + 2 + 3 + ... + (ν-1) + ν = ν*(ν+1)/2;
έ [U+03AD]: Angle within a regular polygon of έ-sides = [(έ-2)/έ]*(pi); while summation = 1 + 2 + 3 + ... + (έ-1) + έ = έ*(έ+1)/2;
ο [U+03BF]: Angle within a regular polygon of ο-sides = [(ο-2)/ο]*(pi); while summation = 1 + 2 + 3 + ... + (ο-1) + ο = ο*(ο+1)/2;
ν [U+03BD]: Angle within a regular polygon of ν-sides = [(ν-2)/ν]*(pi); while summation = 1 + 2 + 3 + ... + (ν-1) + ν = ν*(ν+1)/2;
ला [U+0932 U+093E]: Angle within a regular polygon of ला-sides = [(ला-2)/ला]*(pi); while summation = 1 + 2 + 3 + ... + (ला-1) + ला = ला*(ला+1)/2;
ल [U+0932]: Angle within a regular polygon of ल-sides = [(ल-2)/ल]*(pi); while summation = 1 + 2 + 3 + ... + (ल-1) + ल = ल*(ल+1)/2;
नी [U+0928 U+0940]: Angle within a regular polygon of नी-sides = [(नी-2)/नी]*(pi); while summation = 1 + 2 + 3 + ... + (नी-1) + नी = नी*(नी+1)/2;
ला [U+0932 U+093E]: Angle within a regular polygon of ला-sides = [(ला-2)/ला]*(pi); while summation = 1 + 2 + 3 + ... + (ला-1) + ला = ला*(ला+1)/2;
ह [U+0939]: Angle within a regular polygon of ह-sides = [(ह-2)/ह]*(pi); while summation = 1 + 2 + 3 + ... + (ह-1) + ह = ह*(ह+1)/2;
रा [U+0930 U+093E]: Angle within a regular polygon of रा-sides = [(रा-2)/रा]*(pi); while summation = 1 + 2 + 3 + ... + (रा-1) + रा = रा*(रा+1)/2;
नि [U+0928 U+093F]: Angle within a regular polygon of नि-sides = [(नि-2)/नि]*(pi); while summation = 1 + 2 + 3 + ... + (नि-1) + नि = नि*(नि+1)/2;
यॉ [U+092F U+0949]: Angle within a regular polygon of यॉ-sides = [(यॉ-2)/यॉ]*(pi); while summation = 1 + 2 + 3 + ... + (यॉ-1) + यॉ = यॉ*(यॉ+1)/2;
न [U+0928]: Angle within a regular polygon of न-sides = [(न-2)/न]*(pi); while summation = 1 + 2 + 3 + ... + (न-1) + न = न*(न+1)/2;