SPB Git

Repository Public MIT

Identity.swift 10.7 KB 239 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Astra9// File             : Packages/AstraDesign/Sources/Identity.swift10// Module           : Packages11// Repository       : https://git.spboucher.ai/orix-astra12// Created          : 2026-11-2113// Last Modified    : 2026-11-2114//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author           : Simon-Pierre Boucher20// Position         : Professor of Finance21// Institution      : Université du Québec en Outaouais (UQO)22// Department       : Département des sciences administratives23// Organization     : SP Boucher24//25// Website          : https://spboucher.ai26// Git              : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General          : info@spboucher.ai33// Professional     : contact@spboucher.ai34// Direct           : simon@spboucher.ai35// Research         : research@spboucher.ai36// Development      : dev@spboucher.ai37// Support          : support@spboucher.ai38// Security/Admin   : admin@spboucher.ai39// Notifications    : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification   : Public66// Distribution     : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License          : Proprietary, all rights reserved (see license file)80// License File     : LICENSE81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import SwiftUI8990/// The Astra glyph: a four-point star held by two tilted orbits. Drawn in code so it is crisp at every size.91public struct AstraGlyph: View {92    public var lineWidth: CGFloat?93    public var monochrome: Bool94    public init(lineWidth: CGFloat? = nil, monochrome: Bool = false) { self.lineWidth = lineWidth; self.monochrome = monochrome }9596    public var body: some View {97        GeometryReader { geo in98            let s = min(geo.size.width, geo.size.height)99            let w = lineWidth ?? max(1, s * 0.045)100            ZStack {101                OrbitShape(tilt: .degrees(-28), flatten: 0.42)102                    .stroke(style: StrokeStyle(lineWidth: w, lineCap: .round))103                    .opacity(0.9)104                OrbitShape(tilt: .degrees(34), flatten: 0.36)105                    .stroke(style: StrokeStyle(lineWidth: w * 0.75, lineCap: .round))106                    .opacity(0.55)107                StarShape(pinch: 0.22).frame(width: s * 0.46, height: s * 0.46)108                Circle().frame(width: s * 0.075, height: s * 0.075).offset(x: s * 0.36, y: -s * 0.19)109            }110            .frame(width: s, height: s)111            .foregroundStyle(monochrome ? AnyShapeStyle(.primary) : AnyShapeStyle(AstraColor.signature))112            .frame(maxWidth: .infinity, maxHeight: .infinity)113        }114        .aspectRatio(1, contentMode: .fit)115        .accessibilityHidden(true)116    }117}118119/// A four-point star with concave sides.120public struct StarShape: Shape {121    public var pinch: CGFloat122    public init(pinch: CGFloat = 0.22) { self.pinch = pinch }123    public func path(in rect: CGRect) -> Path {124        let c = CGPoint(x: rect.midX, y: rect.midY), r = min(rect.width, rect.height) / 2, inner = r * pinch125        var p = Path()126        for i in 0..<4 {127            let a = CGFloat(i) * .pi / 2 - .pi / 2128            let tip = CGPoint(x: c.x + cos(a) * r, y: c.y + sin(a) * r)129            let mid = a + .pi / 4130            let valley = CGPoint(x: c.x + cos(mid) * inner, y: c.y + sin(mid) * inner)131            if i == 0 { p.move(to: tip) } else { p.addLine(to: tip) }132            p.addQuadCurve(to: CGPoint(x: c.x + cos(a + .pi / 2) * r, y: c.y + sin(a + .pi / 2) * r), control: valley)133        }134        p.closeSubpath()135        return p136    }137}138139/// An ellipse rotated about the centre: one orbit.140public struct OrbitShape: Shape {141    public var tilt: Angle142    public var flatten: CGFloat143    public init(tilt: Angle, flatten: CGFloat) { self.tilt = tilt; self.flatten = flatten }144    public func path(in rect: CGRect) -> Path {145        let s = min(rect.width, rect.height) * 0.94146        let ellipse = CGRect(x: -s / 2, y: -s * flatten / 2, width: s, height: s * flatten)147        let t = CGAffineTransform(translationX: rect.midX, y: rect.midY).rotated(by: CGFloat(tilt.radians))148        return Path(ellipseIn: ellipse).applying(t)149    }150}151152/// The deep-space backdrop. Stars are laid out once from a seed and drawn in a single Canvas pass; nothing animates by153/// default, so it costs one draw per layout. With `twinkle` on (and Reduce Motion off) a few stars breathe at 12 fps.154public struct Starfield: View {155    public var density: Double156    public var twinkle: Bool157    public var seed: UInt64158    @Environment(\.accessibilityReduceMotion) private var reduceMotion159    @Environment(\.accessibilityReduceTransparency) private var reduceTransparency160    @Environment(\.colorScheme) private var scheme161162    public init(density: Double = 1, twinkle: Bool = false, seed: UInt64 = 7) { self.density = density; self.twinkle = twinkle; self.seed = seed }163164    public var body: some View {165        ZStack {166            AstraColor.background167            if !reduceTransparency {168                // two soft nebula washes: cheap radial gradients, no blur169                RadialGradient(colors: [AstraColor.violet.opacity(scheme == .dark ? 0.20 : 0.10), .clear], center: .init(x: 0.12, y: 0.02), startRadius: 0, endRadius: 420)170                RadialGradient(colors: [AstraColor.cyan.opacity(scheme == .dark ? 0.12 : 0.07), .clear], center: .init(x: 0.95, y: 0.30), startRadius: 0, endRadius: 360)171            }172            if twinkle && !reduceMotion {173                TimelineView(.periodic(from: .now, by: 1.0 / 12.0)) { context in stars(time: context.date.timeIntervalSinceReferenceDate) }174            } else {175                stars(time: 0)176            }177        }178        .ignoresSafeArea()179        .accessibilityHidden(true)180    }181182    private func stars(time: TimeInterval) -> some View {183        Canvas(opaque: false, rendersAsynchronously: false) { context, size in184            var rng = SplitMix(seed: seed)185            let count = Int(Double(size.width * size.height) / 5200 * density)186            let base: Color = scheme == .dark ? .white : AstraColor.indigo187            for i in 0..<max(0, min(count, 260)) {188                let x = rng.unit() * size.width, y = rng.unit() * size.height189                let magnitude = rng.unit()190                let r = 0.4 + magnitude * magnitude * 1.3191                var alpha = (scheme == .dark ? 0.16 : 0.10) + magnitude * (scheme == .dark ? 0.55 : 0.22)192                if time > 0, i % 9 == 0 { alpha *= 0.55 + 0.45 * (0.5 + 0.5 * sin(time * 1.3 + Double(i))) }193                context.fill(Path(ellipseIn: CGRect(x: x - r, y: y - r, width: r * 2, height: r * 2)), with: .color(base.opacity(alpha)))194            }195        }196    }197}198199struct SplitMix {200    var state: UInt64201    init(seed: UInt64) { state = seed &+ 0x9E3779B97F4A7C15 }202    mutating func next() -> UInt64 {203        state &+= 0x9E3779B97F4A7C15204        var z = state205        z = (z ^ (z >> 30)) &* 0xBF58476D1CE4E5B9206        z = (z ^ (z >> 27)) &* 0x94D049BB133111EB207        return z ^ (z >> 31)208    }209    mutating func unit() -> CGFloat { CGFloat(next() >> 11) / CGFloat(1 << 53) }210}211212/// Stream activity: three dots travelling on an orbit while an answer is on its way. Static dots under Reduce Motion.213public struct OrbitActivity: View {214    public var size: CGFloat215    @Environment(\.accessibilityReduceMotion) private var reduceMotion216    public init(size: CGFloat = 22) { self.size = size }217    public var body: some View {218        Group {219            if reduceMotion { frame(phase: 0.15) }220            else { TimelineView(.animation(minimumInterval: 1.0 / 30.0)) { c in frame(phase: c.date.timeIntervalSinceReferenceDate.truncatingRemainder(dividingBy: 1.6) / 1.6) } }221        }222        .frame(width: size, height: size)223        .accessibilityLabel("Generating")224    }225    private func frame(phase: Double) -> some View {226        Canvas { context, s in227            let c = CGPoint(x: s.width / 2, y: s.height / 2), rx = s.width * 0.42, ry = s.height * 0.20228            context.stroke(Path(ellipseIn: CGRect(x: c.x - rx, y: c.y - ry, width: rx * 2, height: ry * 2)), with: .color(AstraColor.strokeStrong), lineWidth: 1)229            let colors = [AstraColor.violet, AstraColor.indigo, AstraColor.cyan]230            for i in 0..<3 {231                let a = (phase + Double(i) / 3) * 2 * .pi232                let p = CGPoint(x: c.x + cos(a) * rx, y: c.y + sin(a) * ry)233                let r = s.width * (0.07 + 0.035 * (0.5 + 0.5 * sin(a)))234                context.fill(Path(ellipseIn: CGRect(x: p.x - r, y: p.y - r, width: r * 2, height: r * 2)), with: .color(colors[i]))235            }236        }237    }238}239
Files main
Menu

Theme