"""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'') # 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'' + "".join(out) + "" # 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'') ins.append(f'') 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'') 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''' {pylons} {cables} ''' 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))