-
Notifications
You must be signed in to change notification settings - Fork 3
/
ContentView.swift
65 lines (54 loc) · 1.57 KB
/
ContentView.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
//
// ContentView.swift
// P09K Drawing
//
// Created by Julian Moorhouse on 05/03/2021.
//
import SwiftUI
struct Checkerboard: Shape {
var rows: Int
var columns: Int
public var animatableData: AnimatablePair<Double, Double> {
get {
AnimatablePair(Double(rows), Double(columns))
}
set {
self.rows = Int(newValue.first)
self.columns = Int(newValue.second)
}
}
func path(in rect: CGRect) -> Path {
var path = Path()
let rowSize = rect.height / CGFloat(rows)
let columnSize = rect.width / CGFloat(columns)
for row in 0..<rows {
for column in 0..<columns {
if (row + column).isMultiple(of: 2) {
let startX = columnSize * CGFloat(column)
let startY = rowSize * CGFloat(row)
let rect = CGRect(x: startX, y: startY, width: columnSize, height: rowSize)
path.addRect(rect)
}
}
}
return path
}
}
struct ContentView: View {
@State private var rows = 4
@State private var columns = 4
var body: some View {
Checkerboard(rows: rows, columns: columns)
.onTapGesture {
withAnimation(.linear(duration: 3)) {
self.rows = 8
self.columns = 16
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}