47 lines
2.6 KiB
Python
47 lines
2.6 KiB
Python
import sys
|
|
NAR, LUZ, INK, BL = "#f04e23", "#f45a1c", "#111", "#fff"
|
|
|
|
def ctrl(a, b, amp):
|
|
(x0, y0), (x1, y1) = a, b
|
|
dx, dy = x1 - x0, y1 - y0
|
|
L = (dx * dx + dy * dy) ** .5
|
|
px, py = -dy / L * amp, dx / L * amp
|
|
return (x0 + dx / 3 + px, y0 + dy / 3 + py), (x0 + dx * 2 / 3 - px, y0 + dy * 2 / 3 - py)
|
|
|
|
def c(p1, p2, fin):
|
|
return f"C{p1[0]:.1f},{p1[1]:.1f} {p2[0]:.1f},{p2[1]:.1f} {fin[0]},{fin[1]}"
|
|
|
|
def bandera(a, b, cc, d, amp, amp_b):
|
|
der = ctrl(b, cc, amp)
|
|
izq = ctrl(a, d, amp)
|
|
abajo = ctrl(cc, d, amp_b)
|
|
return (f"M{a[0]},{a[1]} H{b[0]} {c(der[0], der[1], cc)} {c(abajo[0], abajo[1], d)} "
|
|
f"{c(izq[1], izq[0], a)} Z")
|
|
|
|
def farola(estilo="aro", ink=INK, luz=LUZ, fondo=None, papel=BL):
|
|
bg = f'<rect width="100" height="100" fill="{fondo}"/>' if fondo else ""
|
|
if estilo == "aro":
|
|
defs = '<defs><clipPath id="c"><circle cx="50" cy="50" r="42"/></clipPath></defs>'
|
|
cono = f'<path d="{bandera((57, 33), (77, 33), (94, 84), (42, 84), -7, 5)}" fill="{luz}" clip-path="url(#c)"/>'
|
|
suelo = ""
|
|
poste = f'<path d="M37,96 V40 Q37,25 52,25 H60" fill="none" stroke="{ink}" stroke-width="8"/>'
|
|
cabeza = f'<rect x="55" y="21" width="27" height="11" rx="3" fill="{ink}"/>'
|
|
aro = f'<circle cx="50" cy="50" r="45" fill="none" stroke="{ink}" stroke-width="7"/>'
|
|
return defs + cono + suelo + f'<g clip-path="url(#c)">{poste}</g>' + cabeza + aro
|
|
pegatina = f'<circle cx="50" cy="50" r="48" fill="{luz}"/>'
|
|
poste = f'<path d="M33,99 V38 Q33,22 49,22 H58" fill="none" stroke="{ink}" stroke-width="9"/>'
|
|
cabeza = f'<rect x="52" y="17" width="30" height="11" rx="3" fill="{ink}"/>'
|
|
rayos = "".join(f'<path d="M{x0},{y0} L{x1},{y1}" stroke="{papel}" stroke-width="4" stroke-linecap="round"/>'
|
|
for x0, y0, x1, y1 in ((58, 35, 50, 52), (67, 36, 67, 56), (76, 35, 84, 52)))
|
|
return f'<defs><clipPath id="c"><circle cx="50" cy="50" r="48"/></clipPath></defs>{pegatina}<g clip-path="url(#c)">{poste}</g>{cabeza}{rayos}'
|
|
|
|
def svg(cuerpo, fondo=None):
|
|
bg = f'<rect width="100" height="100" fill="{fondo}"/>' if fondo else ""
|
|
return f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">{bg}{cuerpo}</svg>\n'
|
|
|
|
if __name__ == "__main__":
|
|
d = sys.argv[1]
|
|
open(f"{d}/simbolo.svg", "w").write(svg(farola()))
|
|
open(f"{d}/simbolo-negativo.svg", "w").write(svg(farola(ink=BL, papel=INK), INK))
|
|
open(f"{d}/simbolo-naranja.svg", "w").write(svg(farola(luz=BL, papel=NAR), NAR))
|
|
open(f"{d}/simbolo-pegatina.svg", "w").write(svg(farola("pegatina")))
|