69 lines
1.6 KiB
Python
Executable File
69 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
COORDS = 'coords.txt'
|
|
import copy
|
|
|
|
def load_coords():
|
|
data = []
|
|
with open(COORDS, 'r') as cfh:
|
|
for line in cfh:
|
|
parts = line[:-1].split(" ")
|
|
datum = { "command": parts[0] }
|
|
points = []
|
|
for i in range(int((len(parts) - 1) / 2)):
|
|
points.append((float(parts[1 + i * 2]), float(parts[2 + i * 2])))
|
|
datum["points"] = points
|
|
data.append(datum)
|
|
return data
|
|
|
|
def coords_string(coords):
|
|
return " ".join([ coords["command"] ] + [ f"{x} {y}" for x, y in coords["points"] ])
|
|
|
|
def coords_to_path(coords, i, r, g, b):
|
|
d = " ".join([ coords_string(c) for c in coords ])
|
|
svg = f'<path id="{i}" style="fill: none; stroke: rgb({r}, {g}, {b}); stroke-width:4; opacity: 85%"'
|
|
svg += f' d="{d}" />\n'
|
|
return svg
|
|
|
|
def apply_transform(command, f):
|
|
new_data = {
|
|
"command": command["command"]
|
|
}
|
|
new_data["points"] = [ f((x, y)) for x, y in command["points"] ]
|
|
return new_data
|
|
|
|
data = load_coords()
|
|
|
|
print("""
|
|
<html>
|
|
<head>
|
|
<title>etc.mikelynch.org | Genuary 2026</title>
|
|
<link rel="stylesheet" href="../styles.css" />
|
|
</head>
|
|
<body>
|
|
|
|
<div id="main">
|
|
|
|
<h1>Genuary 2026 - 05</h1>
|
|
|
|
<p>Write "Genuary". Avoid using a font</p>
|
|
|
|
<svg width="400" height="400" xmlns="http://www.w3.org/2000/svg">
|
|
""")
|
|
|
|
for i in range(-100, 100, 5):
|
|
warp = lambda p: (p[0], p[1] + i * 0.02 * p[1])
|
|
new_data = [ apply_transform(command, warp) for command in data ]
|
|
print(coords_to_path(new_data, i, 255, 128 + i, 0))
|
|
|
|
print("""
|
|
</svg>
|
|
|
|
<script src="animate.js">
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|
|
""")
|
|
|