Skip to content

Commit 5a1eec1

Browse files
committed
# Update lottery.
1 parent f0292e9 commit 5a1eec1

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

Example/Example/Page/Lottery/LotteryControl.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ import Foundation
1010

1111
class LotteryControl: ObservableObject {
1212
@Published var rotation = 0.0
13-
var index = 8
14-
var angle: Double {
15-
360 / Double(index)
13+
let index = 8
14+
var angle: Double { 360 / Double(index) }
15+
16+
init() {
17+
print("init runed:\(angle)")
18+
Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { (timer) in
19+
self.rotation += 30
20+
}
1621
}
17-
init() {
18-
print("init runed")
19-
Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { (timer) in
20-
self.rotation += 30
21-
}
22-
}
2322
}

Example/Example/Page/Lottery/LotteryView.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,27 @@
99
import SwiftUI
1010

1111
struct LotteryView: View {
12-
13-
@ObservedObject var control = LotteryControl()
12+
13+
@ObservedObject var control = LotteryControl()
1414

1515
let colors = [Color.red, .black, .gray, .green, .blue, .orange, .yellow, .purple]
16-
16+
1717
var body: some View {
1818
ZStack {
1919
ForEach(0..<control.index, id: \.self) { idx in
2020
Path { path in
21-
path.move(to: CGPoint(x: 150, y: 150))
22-
path.addArc(center: CGPoint(x: 150, y: 150), radius: 150, startAngle: Angle(degrees: Double(idx) * self.control.angle), endAngle: Angle(degrees: Double(idx+1) * self.control.angle), clockwise: false)
23-
path.addLine(to: CGPoint(x: 150, y: 150))
21+
path.move(to: CGPoint(x: 150, y: 150))
22+
path.addArc(center: CGPoint(x: 150, y: 150),
23+
radius: 150,
24+
startAngle: Angle(degrees: Double(idx) * self.control.angle),
25+
endAngle: Angle(degrees: Double(idx+1) * self.control.angle),
26+
clockwise: false)
27+
path.addLine(to: CGPoint(x: 150, y: 150))
2428
}.fill(self.colors[idx%self.colors.count])
2529
}
26-
}.frame(width: 300, height: 300, alignment: .center).rotationEffect(.degrees(control.rotation))
30+
}.frame(width: 300, height: 300,
31+
alignment: .center)
32+
.rotationEffect(.degrees(control.rotation))
2733
}
2834
}
2935

0 commit comments

Comments
 (0)