Skip to content

Commit 121a240

Browse files
authored
Create SwiftUIChristmas25Tree.swift
1 parent 7b41c31 commit 121a240

File tree

1 file changed

+256
-0
lines changed

1 file changed

+256
-0
lines changed
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
//
2+
// SwiftUIChristmas25Tree.swift
3+
//
4+
// Created by Amos Gyamfi on 22.12.2025.
5+
6+
// ContentView.swift
7+
// SwiftUIChristmasTree
8+
//
9+
10+
import SwiftUI
11+
12+
struct SwiftUIChristmas25Tree: View {
13+
14+
@State private var isSpinning = false
15+
let coral = Color(#colorLiteral(red: 1, green: 0.4941176471, blue: 0.4745098039, alpha: 1))
16+
let peach = Color(#colorLiteral(red: 1, green: 0.831372549, blue: 0.4745098039, alpha: 1))
17+
let lightLimeGreen = Color(#colorLiteral(red: 0.831372549, green: 0.9843137255, blue: 0.4745098039, alpha: 1))
18+
let springGreen = Color(#colorLiteral(red: 0.2862745098, green: 0.9803921569, blue: 0.4745098039, alpha: 1))
19+
let paleAqua = Color(#colorLiteral(red: 0.2862745098, green: 0.9882352941, blue: 0.8392156863, alpha: 1))
20+
let skyBlue = Color(#colorLiteral(red: 0.2901960784, green: 0.8392156863, blue: 1, alpha: 1))
21+
let softLavender = Color(#colorLiteral(red: 0.4784313725, green: 0.5058823529, blue: 1, alpha: 1))
22+
let electricPurple = Color(#colorLiteral(red: 0.8470588235, green: 0.5137254902, blue: 1, alpha: 1))
23+
let olive = Color(#colorLiteral(red: 0.5764705882, green: 0.3529411765, blue: 0, alpha: 1))
24+
let forestGreen = Color(#colorLiteral(red: 0, green: 0.5607843137, blue: 0, alpha: 1))
25+
26+
var body: some View {
27+
NavigationStack {
28+
VStack {
29+
Image(.stream)
30+
.resizable()
31+
.scaledToFit()
32+
.frame(width: 128, height: 128)
33+
.hueRotation(.degrees(isSpinning ? 0 : 150))
34+
.animation(.easeInOut(duration: 5).repeatForever(autoreverses: true).delay(0.5), value: isSpinning)
35+
36+
ZStack {
37+
ZStack {
38+
Circle() // MARK: One. No delay
39+
.stroke(style: StrokeStyle(lineWidth: 1, lineCap: .round, dash: [1, 30]))
40+
.frame(width: 20, height: 20)
41+
.foregroundStyle(coral.gradient)
42+
43+
ForEach(0 ..< 4) {
44+
//Circle()
45+
Text("")
46+
.font(.caption2)
47+
//.hueRotation(.degrees(isSpinning ? Double($0) * 310 : Double($0) * 50))
48+
.offset(y: -10)
49+
.rotationEffect(.degrees(Double($0) * -90))
50+
.rotationEffect(.degrees(isSpinning ? 0 : -180))
51+
.frame(width: 4, height: 4)
52+
.animation(.linear(duration: 1.5).repeatForever(autoreverses: false), value: isSpinning)
53+
}
54+
}
55+
.rotation3DEffect(.degrees(60), axis: (x: 1, y: 0, z: 0))
56+
.offset(y: -160)
57+
58+
ZStack {
59+
Circle() // MARK: Two. 0.1 delay
60+
.stroke(style: StrokeStyle(lineWidth: 2, lineCap: .round, dash: [1, 30]))
61+
.frame(width: 50, height: 50)
62+
.foregroundStyle(peach.gradient)
63+
64+
ForEach(0 ..< 4) {
65+
//Circle()
66+
Text("🌟")
67+
.font(.caption2)
68+
//.hueRotation(.degrees(isSpinning ? Double($0) * 310 : Double($0) * 50))
69+
.offset(y: -25)
70+
.rotationEffect(.degrees(Double($0) * -90))
71+
.rotationEffect(.degrees(isSpinning ? 0 : -180))
72+
.frame(width: 6, height: 6)
73+
.animation(.linear(duration: 1.5).repeatForever(autoreverses: false).delay(0.1), value: isSpinning)
74+
}
75+
}
76+
.rotation3DEffect(.degrees(60), axis: (x: 1, y: 0, z: 0))
77+
.offset(y: -120)
78+
79+
ZStack {
80+
Circle() // Three. 0.2 delay
81+
.stroke(style: StrokeStyle(lineWidth: 3, lineCap: .round, dash: [1, 30]))
82+
.frame(width: 80, height: 80)
83+
.foregroundStyle(lightLimeGreen.gradient)
84+
85+
ForEach(0 ..< 4) {
86+
//Circle()
87+
Text("💫")
88+
.font(.caption2)
89+
//.hueRotation(.degrees(isSpinning ? Double($0) * 310 : Double($0) * 50))
90+
.offset(y: -40)
91+
.rotationEffect(.degrees(Double($0) * -90))
92+
.rotationEffect(.degrees(isSpinning ? 0 : -180))
93+
.frame(width: 8, height: 8)
94+
.animation(.linear(duration: 1.5).repeatForever(autoreverses: false).delay(0.2), value: isSpinning)
95+
}
96+
}
97+
.rotation3DEffect(.degrees(60), axis: (x: 1, y: 0, z: 0))
98+
.offset(y: -80)
99+
100+
ZStack {
101+
Circle() // MARK: Four. 0.3 delay
102+
.stroke(style: StrokeStyle(lineWidth: 5, lineCap: .round, dash: [1, 30]))
103+
.frame(width: 110, height: 110)
104+
.foregroundStyle(springGreen.gradient)
105+
106+
ForEach(0 ..< 4) {
107+
Circle()
108+
.foregroundColor(.red)
109+
//.hueRotation(.degrees(isSpinning ? Double($0) * 310 : Double($0) * 50))
110+
.offset(y: -55)
111+
.rotationEffect(.degrees(Double($0) * -90))
112+
.rotationEffect(.degrees(isSpinning ? 0 : -180))
113+
.frame(width: 8, height: 8)
114+
.animation(.linear(duration: 1.5).repeatForever(autoreverses: false).delay(0.3), value: isSpinning)
115+
}
116+
}
117+
.rotation3DEffect(.degrees(60), axis: (x: 1, y: 0, z: 0))
118+
.offset(y: -40)
119+
120+
ZStack {
121+
Circle() // MARK: Five. 0.4 delay
122+
.stroke(style: StrokeStyle(lineWidth: 5, lineCap: .round, dash: [1, 30]))
123+
.frame(width: 140, height: 140)
124+
.foregroundStyle(paleAqua.gradient)
125+
126+
ForEach(0 ..< 4) {
127+
Circle()
128+
.foregroundStyle(.red.gradient)
129+
//.hueRotation(.degrees(isSpinning ? Double($0) * 310 : Double($0) * 50))
130+
.offset(y: -70)
131+
.rotationEffect(.degrees(Double($0) * -90))
132+
.rotationEffect(.degrees(isSpinning ? 0 : -180))
133+
.frame(width: 10, height: 10)
134+
.animation(.linear(duration: 1.5).repeatForever(autoreverses: false).delay(0.4), value: isSpinning)
135+
}
136+
}
137+
.rotation3DEffect(.degrees(60), axis: (x: 1, y: 0, z: 0))
138+
.offset(y: 0)
139+
140+
ZStack {
141+
Circle() // MARK: Six. 0.5 delay
142+
.stroke(style: StrokeStyle(lineWidth: 5, lineCap: .round, dash: [1, 30]))
143+
.frame(width: 170, height: 170)
144+
.foregroundStyle(skyBlue.gradient)
145+
146+
ForEach(0 ..< 4) {
147+
Circle()
148+
.foregroundStyle(.red.gradient)
149+
//.hueRotation(.degrees(isSpinning ? Double($0) * 310 : Double($0) * 50))
150+
.offset(y: -85)
151+
.rotationEffect(.degrees(Double($0) * -90))
152+
.rotationEffect(.degrees(isSpinning ? 0 : -180))
153+
.frame(width: 8, height: 8)
154+
.animation(.linear(duration: 1.5).repeatForever(autoreverses: false).delay(0.5), value: isSpinning)
155+
}
156+
}
157+
.rotation3DEffect(.degrees(60), axis: (x: 1, y: 0, z: 0))
158+
.offset(y: 40)
159+
160+
ZStack {
161+
Circle() // MARK: Seven. 0.6 delay
162+
.stroke(style: StrokeStyle(lineWidth: 5, lineCap: .round, dash: [1, 30]))
163+
.frame(width: 200, height: 200)
164+
.foregroundStyle(softLavender.gradient)
165+
166+
ForEach(0 ..< 4) {
167+
Image(systemName: "star")
168+
.foregroundStyle(.red.gradient)
169+
//.hueRotation(.degrees(isSpinning ? Double($0) * 310 : Double($0) * 50))
170+
.offset(y: -100)
171+
.rotationEffect(.degrees(Double($0) * -90))
172+
.rotationEffect(.degrees(isSpinning ? 0 : -180))
173+
.animation(.linear(duration: 1.5).repeatForever(autoreverses: false).delay(0.6), value: isSpinning)
174+
}
175+
}
176+
.rotation3DEffect(.degrees(60), axis: (x: 1, y: 0, z: 0))
177+
.offset(y: 80)
178+
179+
ZStack {
180+
Circle() // MARK: Eight. 0.7 delay
181+
.stroke(style: StrokeStyle(lineWidth: 5, lineCap: .round, dash: [1, 30]))
182+
.frame(width: 230, height: 230)
183+
.foregroundStyle(electricPurple.gradient)
184+
185+
ForEach(0 ..< 4) {
186+
Circle()
187+
.foregroundStyle(.red.gradient)
188+
//.hueRotation(.degrees(isSpinning ? Double($0) * 310 : Double($0) * 50))
189+
.offset(y: -115)
190+
.rotationEffect(.degrees(Double($0) * -90))
191+
.rotationEffect(.degrees(isSpinning ? 0 : -180))
192+
.frame(width: 10, height: 10)
193+
.animation(.linear(duration: 1.5).repeatForever(autoreverses: false).delay(0.7), value: isSpinning)
194+
}
195+
}
196+
.rotation3DEffect(.degrees(60), axis: (x: 1, y: 0, z: 0))
197+
.offset(y: 120)
198+
199+
ZStack {
200+
Circle() // MARK: Nine. 0.8 delay
201+
.stroke(style: StrokeStyle(lineWidth: 5, lineCap: .round, dash: [1, 30]))
202+
.frame(width: 260, height: 260)
203+
.foregroundStyle(olive.gradient)
204+
205+
ForEach(0 ..< 4) {
206+
//Circle()
207+
Text("🧧")
208+
.font(.caption2)
209+
//.hueRotation(.degrees(isSpinning ? Double($0) * 310 : Double($0) * 50))
210+
.offset(y: -130)
211+
.rotationEffect(.degrees(Double($0) * -90))
212+
.rotationEffect(.degrees(isSpinning ? 0 : -180))
213+
.frame(width: 12, height: 12)
214+
.animation(.linear(duration: 1.5).repeatForever(autoreverses: false).delay(0.8), value: isSpinning)
215+
}
216+
}
217+
.rotation3DEffect(.degrees(60), axis: (x: 1, y: 0, z: 0))
218+
.offset(y: 160)
219+
220+
221+
ZStack {
222+
Circle() // MARK: Ten. 0.9 delay
223+
.stroke(style: StrokeStyle(lineWidth: 5, lineCap: .round, dash: [1, 30]))
224+
.foregroundStyle(forestGreen.gradient)
225+
226+
ForEach(0 ..< 4) {
227+
Text("💐")
228+
.font(.caption2)
229+
.rotationEffect(.degrees(-45))
230+
//.hueRotation(.degrees(isSpinning ? Double($0) * 310 : Double($0) * 50))
231+
.offset(y: -145)
232+
.rotationEffect(.degrees(Double($0) * -90))
233+
.rotationEffect(.degrees(isSpinning ? 0 : -180))
234+
.animation(.linear(duration: 1.5).repeatForever(autoreverses: false).delay(0.9), value: isSpinning)
235+
}
236+
}
237+
.frame(width: 290, height: 290)
238+
.rotation3DEffect(.degrees(60), axis: (x: 1, y: 0, z: 0))
239+
.offset(y: 200)
240+
}
241+
.navigationTitle(Text("SwiftUI Christmas Tree"))
242+
.navigationBarTitleDisplayMode(.inline)
243+
.hueRotation(.degrees(isSpinning ? 0 : .random(in: 0 ... 270)))
244+
.animation(.linear(duration: 2).repeatForever(autoreverses: true).delay(0.5), value: isSpinning)
245+
.onAppear() {
246+
isSpinning.toggle()
247+
}
248+
}
249+
}
250+
}
251+
}
252+
253+
#Preview {
254+
SwiftUIChristmas25Tree()
255+
.preferredColorScheme(.dark)
256+
}

0 commit comments

Comments
 (0)