import SwiftUI /// The Stacked tide icon drawn in SwiftUI, from the same curves as brand/graphley-icon.svg /// (scripts/icon-waves.py). Use it wherever the app shows its own brand: empty states, About. public struct TideMark: View { let size: CGFloat public init(size: CGFloat = 40) { self.size = size } public var body: some View { ZStack { Tide.brandTide TideWave(offset: 0, spread: 0).fill(Tide.brandFoam) TideWave(offset: 162, spread: 40).fill(Tide.brandLagoon) TideWave(offset: 325, spread: 70).fill(Tide.brandAmber) } .frame(width: size, height: size) .clipShape(RoundedRectangle(cornerRadius: size * 0.225, style: .continuous)) .accessibilityHidden(true) } } /// One band of the icon: everything below a smooth tide line. Coordinates follow the icon's /// 1024 × 1024 viewBox and scale to the shape's rect. public struct TideWave: Shape { let offset: CGFloat, spread: CGFloat public init(offset: CGFloat, spread: CGFloat) { self.offset = offset; self.spread = spread } static let x0: CGFloat = -80, x1: CGFloat = 1104 static func smooth(_ t: CGFloat) -> CGFloat { let t = min(1, max(0, t)); return t * t * t * (t * (6 * t - 15) + 10) } static func crest(_ x: CGFloat) -> CGFloat { let dip = 34 * exp(-pow((x - 300) / 230, 2)) return 585 + dip - 470 * smooth((x - 220) / 1050) } func y(_ x: CGFloat) -> CGFloat { Self.crest(x) + offset + spread * (x - Self.x0) / (Self.x1 - Self.x0) } public func path(in rect: CGRect) -> Path { let k = rect.width / 1024, n = 12 let pts = (0...n).map { i -> CGPoint in let x = Self.x0 + (Self.x1 - Self.x0) * CGFloat(i) / CGFloat(n) return CGPoint(x: rect.minX + x * k, y: rect.minY + y(x) * k) } var p = Path() p.move(to: pts[0]) for i in 0..