3 public struct Tile: View {
5 public let design: TileDesign
6 public var pixelSize: CGFloat = 2.0;
7 public var foregroundColor: Color = .black
8 public var backgroundColor: Color = .white
10 private var pixels: [Int] {
14 public init(design: TileDesign, pixelSize: CGFloat = 2.0, foregroundColor: Color = .black, backgroundColor: Color = .white) {
16 self.pixelSize = pixelSize
17 self.foregroundColor = foregroundColor
18 self.backgroundColor = backgroundColor
21 public var body: some View {
23 ForEach(0 ..< 8) { i in
25 ForEach(0 ..< 8) { j in
27 .frame(width: pixelSize, height: pixelSize)
28 .foregroundColor(pixels[(i % 8) * 8 + j % 8] == 0
39 struct Tile_Previews: PreviewProvider {
40 static var previews: some View {
44 Text("Color override")
45 Tile(design: .balls, foregroundColor: .pink, backgroundColor: .cyan)
46 Text("Pixel size override")
47 Tile(design: .shingles, pixelSize: 8.0)