genuary2026/05/genuary05.py
2026-01-05 08:45:05 +11:00

32 lines
803 B
Python
Executable File

#!/usr/bin/env python
COORDS = 'coords.txt'
def load_coords():
data = []
with open(COORDS, 'r') as cfh:
for line in cfh:
parts = line[:-1].split(" ")
datum = { "command": parts[0] }
datum["points"] = [ float(p) for p in parts[1:] ]
data.append(datum)
return data
def coords_string(coords):
return " ".join([ coords["command"] ] + [ str(f) for f in coords["points"] ])
def coords_to_path(coords, r, g, b):
d = " ".join([ coords_string(c) for c in coords ])
svg = f'<path style="fill: none; stroke: rgb({r}, {g}, {b});"'
svg += f' d="{d}" />\n'
return svg
data = load_coords()
print('<svg width="400" height="400" xmlns="http://www.w3.org/2000/svg">')
print(coords_to_path(data, 255, 0, 0))
print("</svg>")