Adding codegen tools
This commit is contained in:
43
codegen/awd-indicator.py
Normal file
43
codegen/awd-indicator.py
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/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, ["capa", "capw", "capd"])
|
||||
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 awd_ident_color = Color (0xFF, 0xF7, 0x00)")
|
||||
print("val awd_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, awd_ident_color)".format(", ".join(map(str, t))), accumulative_range(lines)))))
|
||||
|
||||
|
||||
if has_svgwrite:
|
||||
dwg = svgwrite.Drawing('awd-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()
|
||||
Reference in New Issue
Block a user