PWA three.js + LocAR : pylônes et câbles de la ligne 380 kV sur le tracé projeté, à l'échelle réelle, cachés par le relief (SPW 10 m), les obstacles LiDAR (1/2/4 m) et les bâtiments OpenStreetMap. Photo avant/après, calage de la vue, mini-carte, hors-ligne complet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
143 lines
6.4 KiB
Python
143 lines
6.4 KiB
Python
"""Génère le logo (2 pylônes dans un champ, câbles correctement accrochés) en SVG."""
|
|
import sys
|
|
|
|
def f(v): return f"{v:.2f}"
|
|
|
|
# --- géométrie d'un pylône en unités (0 = sol, 1 = sommet), x relatif à l'axe ---
|
|
LEG = [(0.0, 0.21), (0.55, 0.075), (0.86, 0.055)] # (hauteur, demi-largeur)
|
|
def half(h):
|
|
for (h0, w0), (h1, w1) in zip(LEG, LEG[1:]):
|
|
if h <= h1:
|
|
return w0 + (w1 - w0) * (h - h0) / (h1 - h0)
|
|
return 0.055 * (1 - (h - 0.86) / 0.14)
|
|
|
|
ARMS = [(0.60, 0.33), (0.80, 0.28)] # (hauteur du bras, portée)
|
|
INS = 0.075 # longueur de la chaîne d'isolateurs
|
|
PEAK = 1.0
|
|
|
|
def attach_points(base, H):
|
|
"""Points où les câbles s'accrochent : sommet (câble de garde) + bas des 4 isolateurs."""
|
|
bx, by = base
|
|
pts = [(bx, by - PEAK * H)]
|
|
for h, reach in ARMS:
|
|
for side in (-1, 1):
|
|
pts.append((bx + side * reach * H, by - h * H + INS * H))
|
|
return pts
|
|
|
|
def pylon(base, H, color):
|
|
bx, by = base
|
|
P = lambda x, h: (bx + x * H, by - h * H)
|
|
sw = max(H * 0.024, 1.3)
|
|
out = []
|
|
line = lambda a, b, w=sw: out.append(
|
|
f'<line x1="{f(a[0])}" y1="{f(a[1])}" x2="{f(b[0])}" y2="{f(b[1])}" stroke-width="{f(w)}"/>')
|
|
# jambes
|
|
hs = [0, 0.55, 0.86]
|
|
for s in (-1, 1):
|
|
for h0, h1 in zip(hs, hs[1:]):
|
|
line(P(s * half(h0), h0), P(s * half(h1), h1), sw * 1.5)
|
|
line(P(s * half(0.86), 0.86), P(0, PEAK), sw * 1.3)
|
|
# treillis (croisillons + traverses)
|
|
lev = [0, 0.2, 0.38, 0.53, 0.60, 0.70, 0.80, 0.86]
|
|
for h0, h1 in zip(lev, lev[1:]):
|
|
line(P(-half(h0), h0), P(half(h1), h1))
|
|
line(P(half(h0), h0), P(-half(h1), h1))
|
|
line(P(-half(h1), h1), P(half(h1), h1))
|
|
line(P(-half(0.86), 0.86), P(0, 0.94)); line(P(half(0.86), 0.86), P(0, 0.94))
|
|
# bras (consoles triangulées)
|
|
for h, reach in ARMS:
|
|
for s in (-1, 1):
|
|
w = half(h)
|
|
tip = P(s * reach, h)
|
|
line(P(s * w, h), tip, sw * 1.3) # membrure basse
|
|
line(P(s * w, h + 0.075), tip, sw * 1.3) # membrure haute
|
|
n = 2
|
|
for i in range(n):
|
|
xa = w + (reach - w) * i / n
|
|
xb = w + (reach - w) * (i + 1) / n
|
|
ya = h + 0.075 * (1 - i / n)
|
|
line(P(s * xa, ya), P(s * xb, h))
|
|
line(P(s * xb, h), P(s * xb, h + 0.075 * (1 - (i + 1) / n)))
|
|
g = f'<g stroke="{color}" stroke-linecap="round">' + "".join(out) + "</g>"
|
|
# isolateurs (chaîne de disques)
|
|
ins = []
|
|
for h, reach in ARMS:
|
|
for s in (-1, 1):
|
|
x, y = P(s * reach, h)
|
|
ins.append(f'<line x1="{f(x)}" y1="{f(y)}" x2="{f(x)}" y2="{f(y + INS * H)}" '
|
|
f'stroke="{color}" stroke-width="{f(sw)}"/>')
|
|
ins.append(f'<rect x="{f(x - H * 0.017)}" y="{f(y + INS * H * 0.12)}" width="{f(H * 0.034)}" height="{f(INS * H * 0.8)}" rx="{f(H * 0.012)}" fill="#9fb3bf" stroke="{color}" stroke-width="{f(sw * 0.5)}"/>')
|
|
return g + "".join(ins)
|
|
|
|
def cable(a, b, sag, w):
|
|
mx, my = (a[0] + b[0]) / 2, (a[1] + b[1]) / 2 + sag
|
|
return (f'<path d="M{f(a[0])},{f(a[1])} Q{f(mx)},{f(my)} {f(b[0])},{f(b[1])}" '
|
|
f'fill="none" stroke="#1f2a33" stroke-width="{f(w)}" stroke-linecap="round"/>')
|
|
|
|
def scene():
|
|
V = (740, 300) # point de fuite (hors cadre, à droite)
|
|
B0, H0 = (256, 452), 295
|
|
scales = [1.8, 1.0, 0.5, 0.25] # seul 1.0 est visible ; les autres sont hors du rond
|
|
pyl = []
|
|
for s in scales:
|
|
base = (V[0] + (B0[0] - V[0]) * s, V[1] + (B0[1] - V[1]) * s)
|
|
pyl.append((base, H0 * s))
|
|
parts = []
|
|
# câbles entre pylônes successifs (même point d'accroche -> même point d'accroche)
|
|
for (b1, h1), (b2, h2) in zip(pyl, pyl[1:]):
|
|
p1, p2 = attach_points(b1, h1), attach_points(b2, h2)
|
|
for i, (a, b) in enumerate(zip(p1, p2)):
|
|
span = ((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) ** 0.5
|
|
w = 1.6 + 1.6 * (h1 + h2) / (2 * H0) * (0.75 if i == 0 else 1)
|
|
parts.append(cable(a, b, span * 0.06, min(w, 4.2)))
|
|
pylons = "".join(pylon(b, h, "#34444f") for b, h in [pyl[1]]) # un seul pylône, centré
|
|
return pylons, "".join(parts)
|
|
|
|
def svg(maskable=False):
|
|
S = 512
|
|
c = 256
|
|
R_out = 196 if maskable else 248 # bord extérieur de l'anneau rouge
|
|
ring = R_out * 0.15
|
|
R_in = R_out - ring
|
|
k = R_in / 214 # la scène est dessinée pour un disque de rayon 214
|
|
pylons, cables = scene()
|
|
bar = ring * 0.95
|
|
d = R_in * 0.7071
|
|
return f'''<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {S} {S}" width="{S}" height="{S}">
|
|
<defs>
|
|
<linearGradient id="sky" x1="0" y1="0" x2="0" y2="1">
|
|
<stop offset="0" stop-color="#1e9bf0"/><stop offset="1" stop-color="#c6ecff"/>
|
|
</linearGradient>
|
|
<linearGradient id="field" x1="0" y1="0" x2="0" y2="1">
|
|
<stop offset="0" stop-color="#9ed34a"/><stop offset="1" stop-color="#5daa2c"/>
|
|
</linearGradient>
|
|
<clipPath id="disc"><circle cx="{c}" cy="{c}" r="{f(R_in + 1)}"/></clipPath>
|
|
</defs>
|
|
<rect width="{S}" height="{S}" fill="#ffffff"/>
|
|
<g clip-path="url(#disc)">
|
|
<g transform="translate({c} {c}) scale({f(k)}) translate(-256 -256)">
|
|
<rect x="0" y="0" width="512" height="512" fill="url(#sky)"/>
|
|
<g fill="#ffffff">
|
|
<ellipse cx="380" cy="140" rx="46" ry="16"/><circle cx="366" cy="128" r="18"/><circle cx="392" cy="122" r="22"/>
|
|
<ellipse cx="120" cy="230" rx="40" ry="13"/><circle cx="110" cy="220" r="15"/><circle cx="132" cy="214" r="18"/>
|
|
</g>
|
|
<path d="M0,300 C80,276 160,286 240,296 C320,280 420,274 512,290 L512,512 L0,512 Z" fill="#3f8f3a"/>
|
|
<g fill="#2f7a31">
|
|
<circle cx="60" cy="296" r="24"/><circle cx="90" cy="286" r="28"/><circle cx="120" cy="298" r="20"/>
|
|
<circle cx="430" cy="290" r="16"/><circle cx="452" cy="284" r="20"/><circle cx="476" cy="292" r="16"/>
|
|
</g>
|
|
<path d="M0,312 C120,298 300,300 512,306 L512,512 L0,512 Z" fill="url(#field)"/>
|
|
<path d="M0,420 C140,396 360,400 512,412 L512,512 L0,512 Z" fill="#6cbd33" opacity="0.6"/>
|
|
{pylons}
|
|
{cables}
|
|
</g>
|
|
</g>
|
|
<circle cx="{c}" cy="{c}" r="{f(R_out - ring / 2)}" fill="none" stroke="#e30613" stroke-width="{f(ring)}"/>
|
|
<line x1="{f(c - d)}" y1="{f(c - d)}" x2="{f(c + d)}" y2="{f(c + d)}" stroke="#e30613" stroke-width="{f(bar)}"/>
|
|
</svg>'''
|
|
|
|
if __name__ == "__main__":
|
|
out = sys.argv[1]
|
|
open(f"{out}/logo.svg", "w").write(svg(False))
|
|
open(f"{out}/logo-maskable.svg", "w").write(svg(True))
|