Skip to content

Instantly share code, notes, and snippets.

@emin-grbo
Last active April 20, 2022 08:33
Show Gist options
  • Save emin-grbo/dd52207ebee77b24250297b850969664 to your computer and use it in GitHub Desktop.
Save emin-grbo/dd52207ebee77b24250297b850969664 to your computer and use it in GitHub Desktop.
Severance screentest
import SwiftUI
struct ContentView: View {
let rows = Array(repeating: GridItem(), count: 10)
@State var change: Bool = false {
didSet {
toggle()
}
}
var move = (1...9).map( {_ in CGFloat.random(in: -5...6)} )
var nums = Array(0...9).shuffled()
var body: some View {
ZStack {
RadialGradient(colors: [Color(hex: "101D3F"), Color(hex: "040D29")], center: .center, startRadius: 0, endRadius: 400)
LazyHGrid(rows: rows) {
ForEach(1 ..< 140) { item in
Text(nums[Int(item % 9)])
.foregroundColor(Color(hex: "00A6D9"))
.font(.subheadline.monospacedDigit())
.bold()
.padding()
.offset(x: move.randomElement() ?? 0, y: move.randomElement() ?? 0)
.animation(.interpolatingSpring(stiffness: 0.5, damping: 0.5), value: change)
.blur(radius: 1)
// shadow looks really slick, but on simulator it lags quite a bit. Device should be fine.
// .shadow(color: Color(hex: "00A6D9"), radius: 5, x: 0, y: 0)
}
}
.font(.largeTitle)
.onAppear {
change.toggle()
}
}
.edgesIgnoringSafeArea(.all)
}
func toggle() {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
change.toggle()
}
}
}
extension Color {
public init(hex: String) {
var hexSanitized = hex.trimmingCharacters(in: .whitespacesAndNewlines)
hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "")
var rgb: UInt64 = 0
var red: Double = 0.0
var green: Double = 0.0
var blue: Double = 0.0
var opacity: Double = 1.0
let length = hexSanitized.count
guard Scanner(string: hexSanitized).scanHexInt64(&rgb) && length > 5 else { self.init(.displayP3, red: 0, green: 255, blue: 0)
return
}
if length == 6 {
red = Double((rgb & 0xFF0000) >> 16) / 255.0
green = Double((rgb & 0x00FF00) >> 8) / 255.0
blue = Double(rgb & 0x0000FF) / 255.0
} else if length == 8 {
red = Double((rgb & 0xFF000000) >> 24) / 255.0
green = Double((rgb & 0x00FF0000) >> 16) / 255.0
blue = Double((rgb & 0x0000FF00) >> 8) / 255.0
opacity = Double(rgb & 0x000000FF) / 255.0
} else {
self.init(.displayP3, red: 0, green: 255, blue: 0)
}
self.init(.displayP3, red: red, green: green, blue: blue, opacity: opacity)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment