-
Notifications
You must be signed in to change notification settings - Fork 4
/
10.FastFoodLogo.swift
186 lines (166 loc) · 7.08 KB
/
10.FastFoodLogo.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//
// 10.FastFoodLogo.swift
// SUIChallenges
//
// Created by Alexander Kraev on 29.10.2022.
//
import SwiftUI
enum Constants {
enum Circle {
enum Radius {
static let scaled: CGFloat = 500
static let basic: CGFloat = 25
}
enum Offset {
static let offseted: CGFloat = 70
static let basic: CGFloat = 0
}
}
}
struct FastFoodLogo: View {
@State var changeMode = false
@State var scaled = true
@State var circleOffseted = true
@State var rotate = false
@State var stripesVisible = false
@State var stripesOffseted = true
@State var textRectVisible = false
@State var textVisible = false
@State var textOffseted = true
@State var isFinished = true
var body: some View {
ZStack {
Color(red: 38/255, green: 74/255, blue: 49/255).zIndex(0)
ZStack(alignment: .center) {
ZStack(alignment: .top) {
Circle()
.fill(.clear)
.frame(width: 300)
.zIndex(1)
Circle()
.fill(Color(red: 231/255, green: 65/255, blue: 15/255))
.aspectRatio(contentMode: changeMode ? .fit : .fill)
.edgesIgnoringSafeArea(.all)
.frame(width: scaled ? Constants.Circle.Radius.scaled * 2 : Constants.Circle.Radius.basic * 2)
.offset(y: circleOffseted ? Constants.Circle.Offset.basic : Constants.Circle.Offset.offseted )
.zIndex(2)
.onTapGesture {
guard isFinished else { return }
isFinished = false
changeMode.toggle()
withAnimation(.linear(duration: 0.5)) {
scaled.toggle()
}
withAnimation(.linear(duration: 1.0).delay(0.5)) {
rotate.toggle()
}
withAnimation(.spring(response: 0.6,
dampingFraction: 0.4,
blendDuration: 0).delay(1.5)) {
circleOffseted.toggle()
}
withAnimation(.linear(duration: 0.2).delay(1.5)) {
textRectVisible.toggle()
}
withAnimation(.linear(duration: 0.2).delay(1.7)) {
stripesVisible.toggle()
}
withAnimation(.spring(response: 0.35,
dampingFraction: 0.25,
blendDuration: 0).delay(1.8)) {
stripesOffseted.toggle()
}
withAnimation(.linear(duration: 0.2).delay(2.3)) {
textVisible.toggle()
}
withAnimation(.linear(duration: 0.4).delay(2.4)) {
textOffseted.toggle()
}
}
}
.rotationEffect(.degrees(rotate ? 270 : 0))
HStack(spacing: 0) {
Rectangle()
.fill(Color(red: 238/255, green: 116/255, blue: 3/255))
.clipShape(Stripe())
.frame(width: 60, height: 120)
.rotationEffect(.degrees(-30))
.offset(x: stripesOffseted ? -12 : 0, y: -30)
Rectangle()
.fill(Color(red: 238/255, green: 116/255, blue: 3/255))
.clipShape(Stripe())
.frame(width: 60, height: 120)
.rotationEffect(.degrees(-30))
.offset(x: stripesOffseted ? -72 : -12, y: -30)
}
.opacity(stripesVisible ? 1 : 0)
VStack(spacing: 0) {
Text("ВКУСНО — И ТОЧКА")
.kerning(0)
.foregroundColor(.white)
.fontWeight(.bold)
.font(.title3)
.offset(y: textOffseted ? 20 : 0)
.opacity(textVisible ? 1 : 0)
.onTapGesture {
isFinished = true
changeMode = false
scaled = true
circleOffseted = true
rotate = false
stripesVisible = false
stripesOffseted = true
textRectVisible = false
textVisible = false
textOffseted = true
}
Rectangle()
.fill(Color(red: 38/255, green: 74/255, blue: 49/255))
.frame(height: 60)
}
.fixedSize()
.offset(y: 100)
.opacity(textRectVisible ? 1 : 0)
}
.zIndex(1)
}
.edgesIgnoringSafeArea(.all)
}
}
struct FastFoodLogo_Previews: PreviewProvider {
static var previews: some View {
FastFoodLogo()
}
}
struct Stripe: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
path.move(to: .init(x: rect.maxX, y: 0))
path.addLine(to: .init(x: rect.maxX, y: rect.maxY - rect.width / 2))
path.addQuadCurve(to: .init(x: rect.midX, y: rect.maxY), control: .init(x: rect.maxX, y: rect.maxY))
path.addLine(to: .init(x: rect.width/2, y: rect.width / 2))
path.addQuadCurve(to: .init(x: rect.maxX, y: 0), control: .init(x: rect.midX, y: 0))
return path
}
}
struct Logo: View {
var body: some View {
HStack(alignment: .bottom, spacing: 0) {
Circle()
.fill(Color(red: 231/255, green: 65/255, blue: 15/255))
.frame(width: 50.0)
Rectangle()
.fill(Color(red: 238/255, green: 116/255, blue: 3/255))
.clipShape(Stripe())
.frame(width: 60, height: 120)
.rotationEffect(.degrees(-30))
.offset(x: -30.0, y: 5)
Rectangle()
.fill(Color(red: 238/255, green: 116/255, blue: 3/255))
.clipShape(Stripe())
.frame(width: 60, height: 120)
.rotationEffect(.degrees(-30))
.offset(x: -40.0, y: 5)
}
}
}