Files
WearSignalK2/codegen/cog-indicator.py
2023-11-23 23:16:51 +01:00

44 lines
1.3 KiB
Python

#!/usr/bin/python3
import font
from matrix import Vector, Matrix, pi
try:
import svgwrite
has_svgwrite = True
except ImportError:
has_svgwrite = False
gmap = font.glyph_map("rowmans.jhf")
lines = [[Vector(0.0, 0.5), Vector(0.0, 0.4)]]
vglyph, width = font.typeset(gmap, ["capc", "capo", "capg"])
xform = Matrix.rotation(pi/2).multiply(Matrix.scale(0.1/width))
move = Vector(-width/2, 0)
vglyph = move.translate(vglyph)
vglyph = xform.multiply(vglyph)
vglyph = Vector(0.001, 0.35).translate(vglyph)
lines.extend(vglyph)
def accumulative_range(vv):
offset = 0
for v in vv:
yield range(offset, offset+len(v))
offset = offset + len(v)
print("val cog_ident_color = Color(0x00, 0x00, 0xFF)")
print("val cog_ident =")
print(" Design(listOf({}),\n listOf({}))".format(
",\n ".join(map(lambda l: ", ".join(map(lambda v: "Vector({}F, {}F)".format(v.x, v.y), l)), lines)),
",\n ".join(map(lambda t: "Design.Trace(listOf({}), 1.0F, cog_ident_color)".format(", ".join(map(str, t))), accumulative_range(lines)))))
if has_svgwrite:
dwg = svgwrite.Drawing('cog-indicator.svg', size=('1000', '1000'))
for pl in lines:
points = list(map(lambda v: ((v.x + 0.5) * 1000 , (v.y + 0.5) * 1000 ), pl))
dwg.add(dwg.polyline(points, fill='none', stroke='black'))
dwg.save()