Files
ichmagmaus111andClaude Opus 5.5 0622057a4f Ghostgram: open-source release
Ghostgram for iOS, rebuilt from scratch on Telegram iOS 13.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 17:57:09 +01:00

40 lines
1.4 KiB
Swift

import Foundation
import CoreGraphics
public struct InteractiveDiamondIntro {
public static let delay = 0.18
public static let duration = 1.2
private static let omega = 2.0 * Double.pi / 0.9
public let progress: CGFloat
public var lift: CGFloat { -48.0 * 4.0 * self.progress * (1.0 - self.progress) }
public var scale: CGFloat { self.scale(from: 6.0) }
public func scale(from initialScale: CGFloat, allowsOvershoot: Bool = false) -> CGFloat {
let remaining = 1.0 - self.progress
let offset: CGFloat
if allowsOvershoot && remaining < 0.0 {
offset = -pow(-remaining, 1.25)
} else {
offset = pow(max(0.0, remaining), 1.25)
}
return 1.0 + (initialScale - 1.0) * offset
}
public init(progress: CGFloat) {
self.progress = progress
}
public init(time: Double?, speed: Double = 1.0, damping: Double = 0.8) {
let duration = Self.delay + (Self.duration - Self.delay) / speed
guard let time, time < duration else {
self.progress = 1.0
return
}
let t = max(time - Self.delay, 0.0) * speed
let decay = damping * Self.omega
let frequency = Self.omega * sqrt(1.0 - damping * damping)
self.progress = CGFloat(1.0 - exp(-decay * t) * (cos(frequency * t) + (decay - 1.2) / frequency * sin(frequency * t)))
}
}