SPB Git

Repository Public

Symboles.swift 14.2 KB 268 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : Groupe Ka — app iOS native7// File             : Shared/Symboles.swift8// Module           : Utilities9// Repository       : https://git.spboucher.ai/groupe-ka-ios10// Project Website  : Not specified11// Created          : 2026-12-0312// Last Modified    : 2026-12-0313//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI4243/// Les symboles des six marques, tels que publiés dans leur système de marque, sans retouche44/// (tracés de `src/gabarit.ts` du site ; grille 64 × 64).45/// `g` (0 à 1) anime le geste signature de la marque ; à 0 et à 1 le symbole est exactement celui de la marque.46enum Symbole {47    private static let rad = Double.pi / 18048    private static func sinD(_ d: Double) -> Double { sin(d * rad) }49    private static func cosD(_ d: Double) -> Double { cos(d * rad) }5051    // Tracés fixes, lus une fois.52    private static let loukaCadre = SVGPath.path("M15 60V9a3 3 0 0 1 3-3h28a3 3 0 0 1 3 3v51")53    private static let loukaSol = SVGPath.path("M8 60h48")54    private static let immokaMaison = SVGPath.path("M32 6.5 41.5 15.3V9.5H47v10.9l2.7 2.5c3 2.8 6 4.3 10.1 5a1.8 1.8 0 0 1-.3 3.6H53V58H11V31.5H4.5a1.8 1.8 0 0 1-.3-3.6c4.1-.7 7.1-2.2 10.1-5ZM23 58V29.5a1.5 1.5 0 0 1 1.5-1.5h15a1.5 1.5 0 0 1 1.5 1.5V58Z")55    private static let immokaSol = SVGPath.path("M4 59.5h56")56    private static let vraiprixMaison = SVGPath.path("M26.5 56H11V27L32 8 53 27V56H37.5")57    private static let vraiprixFil = SVGPath.path("M32 11.5V30")58    private static let vraiprixPlomb = SVGPath.path("M29.75 29h4.5v4L39 39.5 32 58.75 25 39.5 29.75 33Z")59    private static let autokaPortiere = SVGPath.path("M14.5 51.5A2.5 2.5 0 0 1 12 49L12 28.71A2 2 0 0 1 12.25 27.75L22.89 8.3A2.5 2.5 0 0 1 25.08 7L50 7A3 3 0 0 1 53 10L53 49A2.5 2.5 0 0 1 50.5 51.5ZM22.4 26.75A1.2 1.2 0 0 1 21.35 24.98L27.56 13.38A1.2 1.2 0 0 1 28.62 12.75L46.5 12.75A1.5 1.5 0 0 1 48 14.25L48 25.55A1.2 1.2 0 0 1 46.8 26.75ZM40 31.5H46.5A1.5 1.5 0 0 1 46.5 34.5H40A1.5 1.5 0 0 1 40 31.5Z")60    private static let autokaSol = SVGPath.path("M6 56H58")61    private static let foodkaProduits = SVGPath.path("M9 17A8.5 8.5 0 1 1 26 17A8.5 8.5 0 1 1 9 17ZM31.5 28V7A2.5 2.5 0 0 1 34 4.5H44A2.5 2.5 0 0 1 46.5 7V28Z")62    private static let foodkaTablette = SVGPath.path("M5.5 28H58.5")63    private static let foodkaEtiquette = SVGPath.path("M23.5 34H54.5A3.5 3.5 0 0 1 58 37.5V54.5A3.5 3.5 0 0 1 54.5 58H23.5A3.5 3.5 0 0 1 20 54.5V37.5A3.5 3.5 0 0 1 23.5 34ZM36.5 39.5H51A2 2 0 0 1 53 41.5V45A2 2 0 0 1 51 47H36.5A2 2 0 0 1 34.5 45V41.5A2 2 0 0 1 36.5 39.5ZM43.75 50H51.25A1.75 1.75 0 0 1 53 51.75V51.75A1.75 1.75 0 0 1 51.25 53.5H43.75A1.75 1.75 0 0 1 42 51.75V51.75A1.75 1.75 0 0 1 43.75 50Z")6465    /// durée du geste signature, en secondes66    static func dureeGeste(_ id: SiteID) -> Double {67        switch id {68        case .louka, .immoka, .autoka: 1.769        case .vraiprix: 2.670        case .foodka: 1.671        case .valoplex: 2.272        }73    }7475    /// angle d'une porte qui s'ouvre grand puis revient à son angle de logo (40°)76    private static func anglePorte(_ g: Double) -> Double {77        if g <= 0 || g >= 1 { return 40 }78        if g < 0.2 { return 40 - 40 * Courbe.vaEtVient(g / 0.2) }79        if g < 0.72 { return 86 * Courbe.seuil((g - 0.2) / 0.52) }80        return 86 - 46 * Courbe.vaEtVient((g - 0.72) / 0.28)81    }8283    private static func pendule(_ g: Double, _ amp: Double, _ tours: Double) -> Double {84        amp * sin(2 * .pi * tours * g) * (1 - g) * (1 - g)85    }8687    /// Dessine le symbole de `id` dans `rect` (carré).88    static func dessiner(_ id: SiteID, dans contexte: GraphicsContext, rect: CGRect, g: Double = 0,89                         encre: Color? = nil, couleur: Color? = nil) {90        var ctx = contexte91        let grille: CGFloat = 6492        ctx.translateBy(x: rect.minX, y: rect.minY)93        ctx.scaleBy(x: rect.width / grille, y: rect.height / grille)94        let e = encre ?? id.encre, c = couleur ?? id.couleur95        let rond = StrokeStyle(lineWidth: 3, lineCap: .round)9697        switch id {98        case .louka:99            ctx.stroke(loukaCadre, with: .color(c), style: StrokeStyle(lineWidth: 5, lineJoin: .round))100            let a = anglePorte(g), s = sinD(a) / sinD(40)101            let x = 17.5 + (29 * cosD(a)) / (1 - 0.15 * sinD(a))102            var battant = Path()103            battant.move(to: CGPoint(x: 17.5, y: 8.5))104            battant.addLine(to: CGPoint(x: x, y: 8.5 + 4.5 * s))105            battant.addLine(to: CGPoint(x: x, y: 60 - 5.5 * s))106            battant.addLine(to: CGPoint(x: 17.5, y: 60))107            battant.closeSubpath()108            ctx.fill(battant, with: .color(e))109            let px = 17.5 + 0.82 * (x - 17.5)110            ctx.fill(Path(ellipseIn: CGRect(x: px - 1.9, y: 34.5 - 1.9, width: 3.8, height: 3.8)), with: .color(c))111            ctx.stroke(loukaSol, with: .color(e), style: rond)112113        case .immoka:114            ctx.fill(immokaMaison, with: .color(e), style: FillStyle(eoFill: true))115            let a = anglePorte(g), s = sinD(a) / sinD(40)116            let x = 23 + 18 * cosD(a) * 0.979117            let px = 23 + 0.756 * (x - 23), pr = 1.5 * min(1, (x - 23) / 9)118            var battant = Path()119            battant.move(to: CGPoint(x: 23, y: 28))120            battant.addLine(to: CGPoint(x: x, y: 28 + 3.3 * s))121            battant.addLine(to: CGPoint(x: x, y: 58 - 2.8 * s))122            battant.addLine(to: CGPoint(x: 23, y: 58))123            battant.closeSubpath()124            if pr > 0.05 { battant.addEllipse(in: CGRect(x: px - pr, y: 44.2 - 1.5, width: 2 * pr, height: 3)) } // poignée en réserve125            ctx.fill(battant, with: .color(c), style: FillStyle(eoFill: true))126            ctx.stroke(immokaSol, with: .color(e), style: rond)127128        case .vraiprix:129            ctx.stroke(vraiprixMaison, with: .color(e), style: StrokeStyle(lineWidth: 5.5, lineJoin: .miter, miterLimit: 8))130            var p = ctx131            let angle = g <= 0 || g >= 1 ? 0 : pendule(g, 17, 2.25)132            p.translateBy(x: 32, y: 11.5); p.rotate(by: .degrees(angle)); p.translateBy(x: -32, y: -11.5)133            p.stroke(vraiprixFil, with: .color(e), lineWidth: 1.75)134            p.fill(vraiprixPlomb, with: .color(c))135136        case .valoplex:137            dessinerValoPlex(ctx, g: g, encre: e, couleur: c)138139        case .autoka:140            let o = g <= 0 || g >= 1 ? 0 : g < 0.55 ? Courbe.seuil(g / 0.55) : 1 - Courbe.vaEtVient((g - 0.55) / 0.45)141            var p = ctx142            // translate(12 0) skewY(−5o) scale(1 − 0,34o, 1) translate(−12 0) : la portière pivote sur ses charnières avant143            let t = CGAffineTransform(translationX: -12, y: 0)144                .concatenating(CGAffineTransform(scaleX: 1 - 0.34 * o, y: 1))145                .concatenating(CGAffineTransform(a: 1, b: tan(-5 * o * rad), c: 0, d: 1, tx: 0, ty: 0))146                .concatenating(CGAffineTransform(translationX: 12, y: 0))147            p.concatenate(t)148            p.fill(autokaPortiere, with: .color(c), style: FillStyle(eoFill: true))149            ctx.stroke(autokaSol, with: .color(e), style: StrokeStyle(lineWidth: 3.5, lineCap: .round))150151        case .foodka:152            ctx.fill(foodkaProduits, with: .color(e))153            ctx.stroke(foodkaTablette, with: .color(e), style: StrokeStyle(lineWidth: 5, lineCap: .round))154            let x = g <= 0 || g >= 1 ? 0 : g < 0.34 ? -15 * Courbe.vaEtVient(g / 0.34) : -15 * (1 - Courbe.seuil((g - 0.34) / 0.66))155            var p = ctx156            p.translateBy(x: x, y: 0)157            p.fill(foodkaEtiquette, with: .color(c), style: FillStyle(eoFill: true))158        }159    }160161    /// Valo-Plex : la façade d'un plex. Geste : la façade se bâtit. Elle s'efface d'abord (0 → 0,1), puis le mur se162    /// lève du sol, le toit se pose, les ouvertures s'éclairent une à une, la porte en dernier.163    private static func dessinerValoPlex(_ ctx: GraphicsContext, g: Double, encre e: Color, couleur c: Color) {164        let fini = g <= 0 || g >= 1165        func etape(_ a: Double, _ b: Double) -> Double { fini ? 1 : min(1, max(0, (g - a) / (b - a))) }166        let dalle = Color.ka(0x7A2A1E, 0xA23B2A), vitre = Color(hex: 0xFBF8F2)167        // le mur : il descend dans le sol, puis remonte (sol à y = 57,14 ; hauteur : 45,71)168        let h = fini ? 45.71 : g < 0.1 ? 45.71 * (1 - Courbe.vaEtVient(g / 0.1)) : 45.71 * Courbe.seuil(etape(0.12, 0.42))169        if h >= 0.6 {170            let mur = Path(CGRect(x: 6.86, y: 57.14 - h, width: 50.29, height: h))171            ctx.fill(mur, with: .color(c))172            ctx.stroke(mur, with: .color(e), style: StrokeStyle(lineWidth: 3.43, lineJoin: .miter))173        }174        // la dalle paraît quand le mur la dépasse175        if fini || (g > 0.1 && h > 24.5) {176            var l = Path(); l.move(to: CGPoint(x: 6.86, y: 34.29)); l.addLine(to: CGPoint(x: 57.14, y: 34.29))177            ctx.stroke(l, with: .color(dalle), lineWidth: 2.29)178        }179        // le toit : ôté d'un coup, puis posé d'en haut180        let t = fini ? 1 : g < 0.1 ? 1 - etape(0, 0.06) : Courbe.poser(etape(0.38, 0.56))181        if t > 0.005 {182            var toit = ctx183            toit.opacity = t184            toit.fill(Path(CGRect(x: 3.43, y: 5.71 - (fini || g < 0.1 ? 0 : 7 * (1 - t)), width: 57.14, height: 8)), with: .color(e))185        }186        // les quatre ouvertures : rez-de-chaussée, étage, étage, puis la porte187        let fenetres: [CGRect] = [CGRect(x: 14.86, y: 40, width: 11.43, height: 11.43), CGRect(x: 14.86, y: 18.29, width: 11.43, height: 11.43),188                                  CGRect(x: 37.71, y: 18.29, width: 11.43, height: 11.43), CGRect(x: 38.86, y: 40, width: 10.29, height: 17.14)]189        for (k, r) in fenetres.enumerated() {190            let o = fini ? 1 : g < 0.1 ? 1 - etape(0, 0.06) : etape(0.56 + 0.08 * Double(k), 0.62 + 0.08 * Double(k))191            guard o > 0.005 else { continue }192            var w = ctx193            w.opacity = o194            if k == 3 { w.fill(Path(r), with: .color(e)) } else {195                w.fill(Path(r), with: .color(vitre))196                w.stroke(Path(r), with: .color(e), lineWidth: 1.83)197            }198        }199    }200201    /// Symbole du Groupe Ka : la rotonde en plan, six baies, la porte du haut ouverte (grille 64 × 64).202    static func dessinerGroupe(dans contexte: GraphicsContext, rect: CGRect, encre: Color = Ka.encre) {203        var ctx = contexte204        ctx.translateBy(x: rect.minX, y: rect.minY)205        ctx.scaleBy(x: rect.width / 64, y: rect.height / 64)206        let r: CGFloat = 23207        func demi(_ i: Int) -> CGFloat { ((i % 6) + 6) % 6 == 0 ? 14 : 7 }208        var arcs = Path()209        for i in 0..<6 {210            let a0 = Plan.angle(i) + demi(i), a1 = Plan.angle(i + 1) - demi(i + 1)211            arcs.addArc(center: CGPoint(x: 32, y: 32), radius: r, startAngle: .degrees(a0), endAngle: .degrees(a1), clockwise: false)212            arcs.move(to: CGPoint(x: 32 + r * cos((Plan.angle(i + 1) + demi(i + 1)) * .pi / 180), y: 32 + r * sin((Plan.angle(i + 1) + demi(i + 1)) * .pi / 180)))213        }214        ctx.stroke(arcs, with: .color(encre), lineWidth: 6.5)215        let hx = r * cos(-104 * CGFloat.pi / 180), hy = r * sin(-104 * CGFloat.pi / 180), fx = r * cos(-76 * CGFloat.pi / 180)216        var battant = Path()217        battant.move(to: CGPoint(x: 32 + hx, y: 32 + hy - 2))218        battant.addLine(to: CGPoint(x: 32 + hx, y: 32 + hy + (fx - hx)))219        ctx.stroke(battant, with: .color(encre), style: StrokeStyle(lineWidth: 4, lineCap: .round))220    }221}222223/// Le symbole d'une marque, comme vue.224struct SymboleMarque: View {225    let site: SiteID226    var g: Double = 0227228    var body: some View {229        Canvas { ctx, taille in230            let c = min(taille.width, taille.height)231            Symbole.dessiner(site, dans: ctx, rect: CGRect(x: (taille.width - c) / 2, y: (taille.height - c) / 2, width: c, height: c), g: g)232        }233        .aspectRatio(1, contentMode: .fit)234        .accessibilityHidden(true)235    }236}237238/// Le symbole du Groupe Ka, comme vue.239struct SymboleGroupe: View {240    var encre: Color = Ka.encre241    var body: some View {242        Canvas { ctx, taille in243            let c = min(taille.width, taille.height)244            Symbole.dessinerGroupe(dans: ctx, rect: CGRect(x: (taille.width - c) / 2, y: (taille.height - c) / 2, width: c, height: c), encre: encre)245        }246        .aspectRatio(1, contentMode: .fit)247        .accessibilityHidden(true)248    }249}250251/// Le nom d'un site en deux parties : la seconde porte la couleur de la marque (« Lou-Ka »).252struct MotSymbole: View {253    let site: KaSite254    var taille: CGFloat = 24255    var style: UIFont.TextStyle = .title2256    @Environment(\.dynamicTypeSize) private var categorie257258    var body: some View {259        let t = KaFont.echelle(taille, style: style, categorie: categorie, plafond: 1.7)260        (Text(site.nom.0).font(KaFont.police(.serif, t, graisse: 500)).foregroundStyle(Ka.encre)261            + Text("-").font(KaFont.police(.serif, t, graisse: 300)).foregroundStyle(Ka.encre3)262            + Text(site.nom.1).font(KaFont.police(.serif, t, graisse: 500)).foregroundStyle(site.id.couleurTexte))263            .tracking(-0.022 * t)264            .lineLimit(1)265            .accessibilityLabel(site.nomComplet)266    }267}268
Files main
Menu

Theme