Created
May 11, 2021 19:26
-
-
Save Inncoder/4f52af35f821c27a561436874ce0b487 to your computer and use it in GitHub Desktop.
TewntyK
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 UIKit | |
import SwiftUI | |
struct Fireworks: UIViewControllerRepresentable { | |
// 2. | |
func makeUIViewController(context: Context) -> FireworkViewController { | |
return FireworkViewController() | |
} | |
// 3. | |
func updateUIViewController(_ uiViewController: FireworkViewController, context: Context) { | |
} | |
} | |
class FireworkViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let size = CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height) | |
let host = UIView(frame: CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height)) | |
self.view.addSubview(host) | |
let particlesLayer = CAEmitterLayer() | |
particlesLayer.frame = CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height) | |
host.layer.addSublayer(particlesLayer) | |
host.layer.masksToBounds = true | |
if #available(iOS 14.0, *) { | |
particlesLayer.backgroundColor = Color.clear.cgColor | |
} else { | |
// Fallback on earlier versions | |
} | |
particlesLayer.emitterShape = .point | |
particlesLayer.emitterPosition = CGPoint(x: UIScreen.main.bounds.width / 2, y: UIScreen.main.bounds.height) | |
particlesLayer.emitterSize = CGSize(width: 0.0, height: 0.0) | |
particlesLayer.emitterMode = .outline | |
particlesLayer.renderMode = .additive | |
let cell1 = CAEmitterCell() | |
cell1.name = "Parent" | |
cell1.birthRate = 0.5 | |
cell1.lifetime = 2.5 | |
cell1.velocity = 300.0 | |
cell1.velocityRange = 100.0 | |
cell1.yAcceleration = -100.0 | |
cell1.emissionLongitude = -90.0 * (.pi / 180.0) | |
cell1.emissionRange = 45.0 * (.pi / 180.0) | |
cell1.scale = 0.0 | |
cell1.color = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0).cgColor | |
cell1.redRange = 0.9 | |
cell1.greenRange = 0.9 | |
cell1.blueRange = 0.9 | |
let image1_1 = UIImage(named: "Spark")?.cgImage | |
let subcell1_1 = CAEmitterCell() | |
subcell1_1.contents = image1_1 | |
subcell1_1.name = "Trail" | |
subcell1_1.birthRate = 45.0 | |
subcell1_1.lifetime = 0.5 | |
subcell1_1.beginTime = 0.01 | |
subcell1_1.duration = 1.7 | |
subcell1_1.velocity = 80.0 | |
subcell1_1.velocityRange = 100.0 | |
subcell1_1.xAcceleration = 100.0 | |
subcell1_1.yAcceleration = 350.0 | |
subcell1_1.emissionLongitude = -360.0 * (.pi / 180.0) | |
subcell1_1.emissionRange = 22.5 * (.pi / 180.0) | |
subcell1_1.scale = 0.5 | |
subcell1_1.scaleSpeed = 0.13 | |
subcell1_1.alphaSpeed = -0.7 | |
subcell1_1.color = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0).cgColor | |
let image1_2 = UIImage(named: "Spark")?.cgImage | |
let subcell1_2 = CAEmitterCell() | |
subcell1_2.contents = image1_2 | |
subcell1_2.name = "Firework" | |
subcell1_2.birthRate = 20000.0 | |
subcell1_2.lifetime = 15.0 | |
subcell1_2.beginTime = 1.6 | |
subcell1_2.duration = 0.1 | |
subcell1_2.velocity = 190.0 | |
subcell1_2.yAcceleration = 80.0 | |
subcell1_2.emissionRange = 360.0 * (.pi / 180.0) | |
subcell1_2.spin = 114.6 * (.pi / 180.0) | |
subcell1_2.scale = 0.1 | |
subcell1_2.scaleSpeed = 0.09 | |
subcell1_2.alphaSpeed = -0.7 | |
subcell1_2.color = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0).cgColor | |
cell1.emitterCells = [subcell1_1, subcell1_2] | |
particlesLayer.emitterCells = [cell1] | |
} | |
} |
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 TwentyK: View { | |
@State private var animating = false | |
var body: some View { | |
ZStack { | |
Color.black | |
Fireworks() | |
VStack(spacing: 0) { | |
LinearGradient(gradient: Gradient(colors: [.blue, .green]), startPoint: .top, endPoint: .bottom) | |
.frame(height: 75) | |
.mask( | |
Text("Thank you") | |
.animation(Animation.easeInOut(duration: 1)) | |
.font(.system(size: 50, weight: .bold, design: .rounded))) | |
LinearGradient(gradient: Gradient(colors: [.blue, .green]), startPoint: .top, endPoint: .bottom) | |
.frame(height: 110) | |
.mask( | |
Text("20K") | |
.animation(Animation.easeInOut(duration: 1).delay(0.5)) | |
.font(.system(size: 130, weight: .bold, design: .rounded))) | |
} | |
} | |
.edgesIgnoringSafeArea(.all) | |
.preferredColorScheme(.light) | |
} | |
} | |
struct TwentyK_Previews: PreviewProvider { | |
static var previews: some View { | |
TwentyK() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment