-
-
Save DarrenHurst/660754bcc427cd108967049025a24408 to your computer and use it in GitHub Desktop.
#SWIFTUITREE
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 Foundation | |
import SwiftUI | |
@available(iOS 16.0, *) | |
struct Tree: View { | |
@State var startAnimation: Bool = false | |
@State private var particleSystem = ParticleView() | |
var body: some View { | |
VStack { | |
buildTree().anyView | |
}.frame(idealWidth:200) | |
} | |
func buildTree() -> any View { | |
VStack { | |
GeometryReader { r in | |
ZStack { | |
Image(systemName: "star.fill").font(.XLarge).offset(y:-10) | |
.foregroundColor(Color.yellow.opacity(startAnimation ? 0.8 : 0.4)) .animation(Animation.easeIn(duration: 0.9) .repeatForever(), value: startAnimation) | |
ForEach(1...85, id: \.self) { index in | |
Circle() | |
.stroke(startAnimation ? LinearGradient(colors: [.clear, .clear, .green, .green], startPoint: .leading, endPoint: .trailing) : LinearGradient(colors: [.white, .white, .green, .green], startPoint: .leading, endPoint: .trailing), style: StrokeStyle(lineWidth: startAnimation ? 1 : 3)) | |
.animation(Animation.easeIn(duration: 0.9) .repeatForever(), value: startAnimation) | |
.opacity(0.5) | |
.transformEffect(.init(scaleX: 6, y: 2)) | |
.frame( height: CGFloat(index * 2) ) | |
.rotationEffect(.degrees(90)) | |
.offset(y: CGFloat(index * 3)) | |
} | |
getOrnament(size: 40, offsetX: -50, offsetY: 380) | |
getOrnament(size: 40, offsetX: -20, offsetY: 130) | |
getOrnament(size: 20, offsetX: -40, offsetY: 190) | |
getOrnament(size: 50, offsetX: 0, offsetY: 300) | |
getOrnament(size: 90, offsetX: 10, offsetY: 600) | |
ZStack { | |
particleSystem.offset(x:100,y:-100) | |
}.offset(y:400) | |
}.offset(x: -70, y: -190) | |
}.onAppear() { | |
startAnimation = true | |
} | |
.background(Color.black.opacity(0.3)) | |
.background(Color.blue) | |
} | |
} | |
func getOrnament(size: CGFloat, offsetX: CGFloat, offsetY: CGFloat) -> some View { | |
Circle() | |
.fill(startAnimation ? | |
RadialGradient(colors: [.gray.opacity(0.1),.white,.clear, .white], center: UnitPoint(x: 0, y:0), startRadius: 5.0, endRadius: 200.0) : | |
RadialGradient(colors: [.clear,.white,.clear, .gray.opacity(0.1)], center: UnitPoint(x: 0, y:0), startRadius: 5.0, endRadius: 100.0)) | |
.frame(height:size) | |
.offset(x: offsetX, y:offsetY) | |
} | |
} | |
@available(iOS 16.0, *) | |
struct TreePreview: PreviewProvider { | |
static var previews: some View { | |
Tree() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tree.mov
Wishing everyone a safe holiday season!.. Hug your dog.