41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
import math, sys
|
|
NAR, AMA = "#f04e23", "#f2b705"
|
|
|
|
def bordes(signo, t0, t1, n=24):
|
|
izq, der = [], []
|
|
for k in range(n + 1):
|
|
t = t0 + (t1 - t0) * k / n
|
|
y = 18 + 79 * t
|
|
a = 5 + 9 * t
|
|
cx = 72 + signo * a * math.cos(2 * math.pi * t)
|
|
w = 3 + 6 * t
|
|
izq.append((cx - w, y)); der.append((cx + w, y))
|
|
return izq, der
|
|
|
|
def linea(pts):
|
|
return "M" + " L".join(f"{x:.1f},{y:.1f}" for x, y in pts)
|
|
|
|
def cinta(signo, t0, t1):
|
|
izq, der = bordes(signo, t0, t1)
|
|
return linea(izq + der[::-1]) + " Z"
|
|
|
|
def farola(ink="#111", fondo=None, nar=NAR, ama=AMA):
|
|
bg = f'<rect width="100" height="100" fill="{fondo}"/>' if fondo else ""
|
|
corte = fondo or "#fff"
|
|
def pieza(col, signo, t0, t1, arriba):
|
|
out = f'<path d="{cinta(signo, t0, t1)}" fill="{col}"/>'
|
|
if arriba:
|
|
izq, der = bordes(signo, t0, t1)
|
|
out += "".join(f'<path d="{linea(e)}" fill="none" stroke="{corte}" stroke-width="1.6" stroke-linecap="round"/>' for e in (izq, der))
|
|
return out
|
|
luz = (pieza(ama, 1, 0, .5, False) + pieza(nar, -1, 0, .5, True)
|
|
+ pieza(nar, -1, .5, 1, False) + pieza(ama, 1, .5, 1, True))
|
|
poste = f'<path d="M24,100 V30 Q24,12 42,12 H58" fill="none" stroke="{ink}" stroke-width="7"/>'
|
|
cabeza = f'<path d="M54,7 H90 Q92,7 91,10 L88,16 H57 L53,10 Q52,7 54,7 Z" fill="{ink}"/>'
|
|
return f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">{bg}{luz}{poste}{cabeza}</svg>\n'
|
|
|
|
if __name__ == "__main__":
|
|
d = sys.argv[1]
|
|
open(f"{d}/simbolo.svg", "w").write(farola())
|
|
open(f"{d}/simbolo-negativo.svg", "w").write(farola("#fff", "#111"))
|
|
open(f"{d}/simbolo-naranja.svg", "w").write(farola("#111", NAR, nar="#fff"))
|