150 lines
8.3 KiB
Python
150 lines
8.3 KiB
Python
# Genera sites/<web>/img/eje-*.svg: un símbolo por eje pintado con spray (relleno en zigzag,
|
|
# trazos con pulso y chorreones), en el color de cada eje (los mismos que los regueros del dibujo).
|
|
import sys, random, math, os
|
|
OUT = sys.argv[1]
|
|
EJES = {"hogar": "#f04e23", "clima": "#14965a", "fronteras": "#f2b705", "pueblos": "#3b5bdb", "igualdad": "#8e44c9"}
|
|
DEFS = ('<defs><filter id="spray" x="-30%" y="-10%" width="160%" height="120%"><feTurbulence type="fractalNoise" baseFrequency="0.8" numOctaves="2" seed="3" result="t"/>'
|
|
'<feDisplacementMap in="SourceGraphic" in2="t" scale="1.6" result="d"/><feGaussianBlur in="d" stdDeviation=".4" result="b"/>'
|
|
'<feGaussianBlur in="SourceGraphic" stdDeviation="2.5" result="n"/><feComponentTransfer in="n" result="n2"><feFuncA type="linear" slope=".3"/></feComponentTransfer>'
|
|
'<feMerge><feMergeNode in="n2"/><feMergeNode in="b"/></feMerge></filter></defs>')
|
|
|
|
def monigote(o, x, y, h, col, brazo=False, paso=False):
|
|
sw = max(1.4, h * .016)
|
|
pts, yy, i, top = [], y - h, 0, y - h
|
|
while yy <= y:
|
|
t = (yy - top) / h
|
|
cx = x
|
|
if t < .13:
|
|
w = h * .055 * math.sin(math.pi * t / .13) ** .6 + sw * .3
|
|
elif t < .16:
|
|
w = h * .01
|
|
else:
|
|
u = (t - .16) / .84
|
|
w = h * (.07 * (1 - u) ** .8 + .016)
|
|
if paso and u > .5:
|
|
cx += (-1 if (i // 2) % 2 else 1) * h * .04 * (u - .5) / .5
|
|
w *= .6
|
|
pts.append((cx + (-1 if i % 2 else 1) * w * random.uniform(.75, 1.25), yy))
|
|
yy += sw * 2.1 * random.uniform(.85, 1.15) * (.55 if t < .13 else 1)
|
|
i += 1
|
|
d = "M" + " L".join(f"{px:.1f},{py:.1f}" for px, py in pts)
|
|
o.append(f'<path d="{d}" fill="none" stroke="{col}" stroke-width="{sw:.1f}" stroke-linejoin="round" stroke-linecap="round" filter="url(#spray)"/>')
|
|
if brazo:
|
|
bx, by = x + h * .06, top + h * .2
|
|
p = [(bx + j / 9 * h * .06 + (-1 if j % 2 else 1) * h * .014, by - j / 9 * h * .3) for j in range(10)]
|
|
o.append(f'<path d="M' + " L".join(f"{px:.1f},{py:.1f}" for px, py in p) + f'" fill="none" stroke="{col}" stroke-width="{sw:.1f}" stroke-linecap="round" filter="url(#spray)"/>')
|
|
|
|
def j(v, a):
|
|
return v + random.uniform(-a, a)
|
|
|
|
def relleno(o, poly, col, paso=2.6, sw=3.6):
|
|
# Zigzag horizontal que rellena un polígono convexo, como una pasada de spray.
|
|
ys = [y for _, y in poly]
|
|
pts, y, i = [], min(ys) + sw * .4, 0
|
|
while y <= max(ys) - sw * .4:
|
|
xs = []
|
|
for (x1, y1), (x2, y2) in zip(poly, poly[1:] + poly[:1]):
|
|
if (y1 <= y < y2) or (y2 <= y < y1):
|
|
xs.append(x1 + (y - y1) * (x2 - x1) / (y2 - y1))
|
|
if len(xs) >= 2:
|
|
a, b = min(xs), max(xs)
|
|
pts.append((j(a if i % 2 else b, 1.2), y))
|
|
i += 1
|
|
y += paso * random.uniform(.85, 1.15)
|
|
o.append(f'<path d="M{" L".join(f"{x:.1f},{y:.1f}" for x, y in pts)}" fill="none" stroke="{col}" stroke-width="{sw:.1f}" stroke-linejoin="round" stroke-linecap="round" filter="url(#spray)"/>')
|
|
|
|
def linea(o, pts, col, sw=5):
|
|
# Trazo con pulso: dos pasadas ligeramente desplazadas.
|
|
for k in range(2):
|
|
d = "M" + " L".join(f"{j(x, 1.1):.1f},{j(y, 1.1):.1f}" for x, y in pts)
|
|
o.append(f'<path d="{d}" fill="none" stroke="{col}" stroke-width="{sw * (1 if k == 0 else .6):.1f}" stroke-linejoin="round" stroke-linecap="round" opacity="{1 if k == 0 else .7}" filter="url(#spray)"/>')
|
|
|
|
def chorreon(o, x, y, largo, col):
|
|
y -= 6
|
|
o.append(f'<path d="M{x:.1f},{y:.1f} L{j(x, .6):.1f},{y + largo:.1f}" stroke="{col}" stroke-width="2.4" stroke-linecap="round" filter="url(#spray)"/>')
|
|
o.append(f'<circle cx="{x:.1f}" cy="{y + largo:.1f}" r="2.2" fill="{col}" filter="url(#spray)"/>')
|
|
|
|
def hogar(o, col):
|
|
# Una casa: tejado, dos muros y el dintel; la puerta queda en blanco.
|
|
relleno(o, [(70, 22), (128, 72), (12, 72)], col)
|
|
relleno(o, [(24, 72), (54, 72), (54, 150), (24, 150)], col)
|
|
relleno(o, [(86, 72), (116, 72), (116, 150), (86, 150)], col)
|
|
relleno(o, [(54, 72), (86, 72), (86, 96), (54, 96)], col)
|
|
linea(o, [(98, 50), (98, 26), (110, 26), (110, 60)], col, 5)
|
|
for x, l in ((30, 22), (47, 14), (92, 28), (110, 16)):
|
|
chorreon(o, x, 150, l, col)
|
|
|
|
def clima(o, col):
|
|
# El planeta que se derrite: anillo en zigzag, meridianos y chorreones.
|
|
cx, cy, r, pts = 70, 72, 52, []
|
|
for i in range(220):
|
|
a = 2 * math.pi * i / 219
|
|
rr = r - (0 if i % 2 else 11) + random.uniform(-1.5, 1.5)
|
|
pts.append((cx + rr * math.cos(a), cy + rr * math.sin(a)))
|
|
o.append(f'<path d="M{" L".join(f"{x:.1f},{y:.1f}" for x, y in pts)}" fill="none" stroke="{col}" stroke-width="3.2" stroke-linejoin="round" filter="url(#spray)"/>')
|
|
linea(o, [(cx + 44 * math.cos(math.pi * k / 20), cy + 44 * math.sin(math.pi * k / 20) * .32) for k in range(21)], col, 4)
|
|
linea(o, [(cx + 44 * math.cos(math.pi * k / 20) * .38, cy - 44 * math.sin(math.pi * k / 20)) for k in range(-10, 11)], col, 4)
|
|
for x, l in ((40, 26), (55, 40), (72, 30), (88, 44), (102, 20)):
|
|
y0 = cy + math.sqrt(max(0, r * r - (x - cx) ** 2)) - 4
|
|
chorreon(o, x, y0, l, col)
|
|
|
|
def fronteras(o, col):
|
|
# Una valla rota: barrotes que se abren en el centro y alambre de espino cortado.
|
|
for x in (14, 32, 108, 126):
|
|
linea(o, [(x, 40), (x, 150)], col, 6)
|
|
linea(o, [(50, 150), (52, 100), (40, 56)], col, 6)
|
|
linea(o, [(90, 150), (88, 100), (100, 56)], col, 6)
|
|
linea(o, [(6, 62), (44, 66)], col, 5)
|
|
linea(o, [(96, 66), (134, 62)], col, 5)
|
|
linea(o, [(6, 112), (54, 114)], col, 5)
|
|
linea(o, [(86, 114), (134, 112)], col, 5)
|
|
for x, y in ((22, 64), (116, 64), (22, 113), (118, 113)):
|
|
linea(o, [(x - 4, y - 4), (x + 4, y + 4)], col, 4)
|
|
linea(o, [(x + 4, y - 4), (x - 4, y + 4)], col, 4)
|
|
|
|
def igualdad(o, col):
|
|
# El símbolo feminista: anillo en zigzag y la cruz de debajo, con chorreones.
|
|
cx, cy, r, pts = 70, 58, 40, []
|
|
for i in range(180):
|
|
a = 2 * math.pi * i / 179
|
|
rr = r - (0 if i % 2 else 11) + random.uniform(-1.5, 1.5)
|
|
pts.append((cx + rr * math.cos(a), cy + rr * math.sin(a)))
|
|
o.append(f'<path d="M{" L".join(f"{x:.1f},{y:.1f}" for x, y in pts)}" fill="none" stroke="{col}" stroke-width="3.2" stroke-linejoin="round" filter="url(#spray)"/>')
|
|
relleno(o, [(63, 96), (77, 96), (77, 160), (63, 160)], col)
|
|
relleno(o, [(46, 120), (94, 120), (94, 134), (46, 134)], col)
|
|
for x, y, l in ((52, 134, 12), (88, 134, 18), (66, 160, 10), (74, 160, 6)):
|
|
chorreon(o, x, y, l, col)
|
|
|
|
def girar(pts, ang, ox, oy, dx, dy):
|
|
ca, sa = math.cos(ang), math.sin(ang)
|
|
return [(ox + (x - ox) * ca - (y - oy) * sa + dx, oy + (x - ox) * sa + (y - oy) * ca + dy) for x, y in pts]
|
|
|
|
def pueblos(o, col):
|
|
# Una bala rota: la punta salta hacia un lado y el casquillo se queda, con chispas en el corte.
|
|
punta = [(70, 30), (76, 35), (81, 43), (84, 52), (85, 62), (85, 80), (78, 77), (72, 82), (64, 76), (55, 79), (55, 62), (56, 52), (59, 43), (64, 35)]
|
|
grieta_a = [(85, 80), (78, 77), (72, 82), (64, 76), (55, 79)]
|
|
casquillo = [(55, 90), (63, 86), (70, 92), (77, 86), (85, 90), (85, 128), (55, 128)]
|
|
grieta_b = [(55, 90), (63, 86), (70, 92), (77, 86), (85, 90)]
|
|
culote = [(52, 132), (88, 132), (88, 150), (52, 150)]
|
|
giro_a = lambda pts: girar(pts, -.38, 70, 80, -4, 6)
|
|
giro_b = lambda pts: girar(pts, .08, 70, 120, 6, 8)
|
|
relleno(o, giro_a(punta), col)
|
|
linea(o, giro_a(punta[10:] + punta[:6]), col, 3)
|
|
linea(o, giro_a(grieta_a), col, 3.5)
|
|
relleno(o, giro_b(casquillo), col)
|
|
relleno(o, giro_b(culote), col)
|
|
linea(o, giro_b([(55, 90), (55, 128), (52, 132), (52, 150), (88, 150), (88, 132), (85, 128), (85, 90)]), col, 3)
|
|
linea(o, giro_b(grieta_b), col, 3.5)
|
|
for a in (-.5, 0, .45):
|
|
linea(o, [(96 + 6 * math.cos(a), 92 + 6 * math.sin(a)), (96 + 20 * math.cos(a), 92 + 20 * math.sin(a))], col, 4)
|
|
for a in (2.7, 3.2):
|
|
linea(o, [(46 + 6 * math.cos(a), 96 + 6 * math.sin(a)), (46 + 18 * math.cos(a), 96 + 18 * math.sin(a))], col, 4)
|
|
for x, l in ((60, 12), (74, 18), (84, 8)):
|
|
chorreon(o, x, 160, l, col)
|
|
|
|
os.makedirs(OUT, exist_ok=True)
|
|
for n, (nombre, col) in enumerate(EJES.items()):
|
|
random.seed(40 + n)
|
|
o = []
|
|
globals()[nombre](o, col)
|
|
open(f"{OUT}/eje-{nombre}.svg", "w").write(f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 140 170" width="140" height="170">{DEFS}' + "".join(o) + "</svg>\n")
|