Created
September 17, 2024 01:29
-
-
Save luoyjx/9cec347910ee2f8bb62609a36ca1dbdf to your computer and use it in GitHub Desktop.
AppleIntelligenceScreenColorGlow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct AppleIntelligenceScreenColorGlowView: View { | |
var body: some View { | |
let text = Text("Hello, World!") | |
.bold() | |
.font(.title) | |
.frame(maxWidth: .infinity, maxHeight: .infinity) | |
.ignoresSafeArea() | |
let gradientColors = [ | |
Color("#6831D8"), | |
Color("#52B1F4"), | |
Color("#9548D7"), | |
Color("#F5B542"), | |
Color("#E93E56"), | |
Color("#F07F49"), | |
Color("#6831D8") | |
] | |
let angularGradient = AngularGradient( | |
gradient: Gradient(colors: gradientColors), | |
center: .center, | |
startAngle: .degrees(0), | |
endAngle: .degrees(360) | |
) | |
let circle = Circle().fill(angularGradient) | |
let maskRectangle = RoundedRectangle(cornerRadius: 58) | |
.stroke(lineWidth: 8) | |
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height) | |
.ignoresSafeArea() | |
return text.overlay(alignment: .center) { | |
TimelineView(.animation) { timeline in | |
ZStack(alignment: .center) { | |
ForEach([133, -133], id: \.self) { angle in | |
let rotationEffect1 = circle.rotationEffect(.degrees(timeline.date.timeIntervalSince1970 * 60)) | |
let scaleEffect = rotationEffect1.scaleEffect(2.4) | |
let rotationEffect2 = scaleEffect.rotationEffect(.degrees(timeline.date.timeIntervalSince1970 * Double(angle))) | |
let mask = maskRectangle.blur(radius: angle > 0 ? 12 + 6 * sin(timeline.date.timeIntervalSince1970 * 2) : 5 + 3 * sin(timeline.date.timeIntervalSince1970 * 4)) | |
rotationEffect2.mask(alignment: .center) { | |
mask | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
extension Color { | |
init(_ hex: String) { | |
var hexSanitized = hex.trimmingCharacters(in: .whitespacesAndNewlines) | |
hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "") | |
var rgb: UInt64 = 0 | |
Scanner(string: hexSanitized).scanHexInt64(&rgb) | |
let red = Double((rgb & 0xFF0000) >> 16) / 255.0 | |
let green = Double((rgb & 0x00FF00) >> 8) / 255.0 | |
let blue = Double(rgb & 0x0000FF) / 255.0 | |
self.init(red: red, green: green, blue: blue) | |
} | |
} | |
struct AppleIntelligenceScreenColorGlowView_Previews: PreviewProvider { | |
static var previews: some View { | |
AppleIntelligenceScreenColorGlowView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://x.com/liseami1/status/1834957547414982750?s=12&t=-AKKHS9YxlPUIL0lrRTDYg