39 lines
2.4 KiB
Python
39 lines
2.4 KiB
Python
import sys
|
|
NAR, LUZ, INK, BL = "#f04e23", "#f45a1c", "#111", "#fff"
|
|
|
|
def onda(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
|
|
c1 = (x0 + dx / 3 + px, y0 + dy / 3 + py)
|
|
c2 = (x0 + dx * 2 / 3 - px, y0 + dy * 2 / 3 - py)
|
|
return f"C{c1[0]:.1f},{c1[1]:.1f} {c2[0]:.1f},{c2[1]:.1f} {x1},{y1}"
|
|
|
|
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="M57,33 H77 {onda((77, 33), (98, 92), 3.5)} H36 {onda((36, 92), (57, 33), 3.5)} Z" fill="{luz}" clip-path="url(#c)"/>'
|
|
suelo = f'<ellipse cx="67" cy="86" rx="22" ry="5" fill="{ink}" clip-path="url(#c)" opacity=".25"/>'
|
|
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")))
|