From: Ruben Beltran del Rio Date: Wed, 26 Apr 2023 14:25:43 +0000 (+0200) Subject: Add the files X-Git-Tag: 1.0.0~5 X-Git-Url: https://git.r.bdr.sh/rbdr/patterns/commitdiff_plain/8b0b5b394e5eca8538956fecbaa70ca66fdde24b?ds=inline Add the files --- diff --git a/Package.swift b/Package.swift index c967b1d..1456b7d 100644 --- a/Package.swift +++ b/Package.swift @@ -5,6 +5,9 @@ import PackageDescription let package = Package( name: "Patterns", + platforms: [ + .macOS(.v10_15) + ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( diff --git a/Sources/Patterns/Pattern.swift b/Sources/Patterns/Pattern.swift new file mode 100644 index 0000000..1951888 --- /dev/null +++ b/Sources/Patterns/Pattern.swift @@ -0,0 +1,32 @@ +import SwiftUI + +public struct Pattern: View { + + private let pixelSize: CGFloat = 2.0; + + private var patternSize: CGFloat { + pixelSize * 8.0; + } + + @Binding var design: TileDesign; + + public var body: some View { + GeometryReader { gr in + VStack(spacing: 0) { + ForEach(0 ..< 1 + Int(ceil(gr.size.height / patternSize)), id: \.self) { i in + HStack(spacing: 0) { + ForEach(0 ..< Int(ceil(gr.size.width / patternSize)), id: \.self) { j in + Tile(design: design) + } + } + } + } + }.drawingGroup() + } +} + +struct Pattern_Previews: PreviewProvider { + static var previews: some View { + Pattern(design: .constant(TileDesign.grid)) + } +} diff --git a/Sources/Patterns/Patterns.swift b/Sources/Patterns/Patterns.swift deleted file mode 100644 index 52a8771..0000000 --- a/Sources/Patterns/Patterns.swift +++ /dev/null @@ -1,6 +0,0 @@ -public struct Patterns { - public private(set) var text = "Hello, World!" - - public init() { - } -} diff --git a/Sources/Patterns/Tile.swift b/Sources/Patterns/Tile.swift new file mode 100644 index 0000000..c27fcf9 --- /dev/null +++ b/Sources/Patterns/Tile.swift @@ -0,0 +1,35 @@ +import SwiftUI + +struct Tile: View { + + let pixelSize: CGFloat = 2.0; + + let design: TileDesign + + private var pixels: [Int] { + design.pixels() + } + + var body: some View { + VStack(spacing: 0) { + ForEach(0 ..< 8) { i in + HStack(spacing: 0) { + ForEach(0 ..< 8) { j in + Rectangle() + .frame(width: pixelSize, height: pixelSize) + .foregroundColor(pixels[(i % 8) * 8 + j % 8] == 0 + ? .black + : .white + ) + } + } + } + } + } +} + +struct Tile_Previews: PreviewProvider { + static var previews: some View { + Tile(design: .grid) + } +} diff --git a/Sources/Patterns/TileDesign.swift b/Sources/Patterns/TileDesign.swift new file mode 100644 index 0000000..5541102 --- /dev/null +++ b/Sources/Patterns/TileDesign.swift @@ -0,0 +1,163 @@ +public enum TileDesign: CaseIterable { + case grid + case dottedGrid + case stitch + case curvedTile + case brick + case tile + case shadowGrid + case circles + case trees + case shingles + case wicker + case rhombus + case balls + + func pixels() -> [Int] { + switch self { + case .grid: + return [ + 1, 0, 1, 0, 1, 0, 1, 0, + 0, 1, 0, 1, 0, 1, 0, 1, + 1, 0, 1, 0, 1, 0, 1, 0, + 0, 1, 0, 1, 0, 1, 0, 1, + 1, 0, 1, 0, 1, 0, 1, 0, + 0, 1, 0, 1, 0, 1, 0, 1, + 1, 0, 1, 0, 1, 0, 1, 0, + 0, 1, 0, 1, 0, 1, 0, 1 + ] + case .dottedGrid: + return [ + 1, 1, 1, 1, 0, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 1, 0, 1, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 0, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + ] + case .stitch: + return [ + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 0, 1, 1, + 1, 1, 1, 1, 0, 1, 0, 1, + ] + case .curvedTile: + return [ + 1, 1, 1, 1, 1, 1, 1, 0, + 1, 1, 1, 1, 1, 1, 0, 0, + 0, 1, 1, 1, 1, 0, 1, 1, + 1, 0, 1, 1, 0, 1, 1, 1, + 1, 1, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 0, 1, 1, + 1, 1, 1, 1, 1, 1, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 0, + ] + case .brick: + return [ + 0, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 0, 1, 1, 1, + 1, 1, 1, 1, 0, 1, 1, 1, + 1, 1, 1, 1, 0, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, + ] + case .tile: + return [ + 1, 1, 1, 1, 1, 0, 1, 1, + 1, 1, 1, 1, 0, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 1, 1, + 1, 1, 0, 1, 1, 1, 0, 1, + 0, 0, 1, 1, 1, 1, 1, 0, + 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 0, + 1, 1, 1, 1, 1, 1, 0, 1, + ] + case .shadowGrid: + return [ + 1, 1, 1, 1, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, + 1, 1, 1, 1, 0, 1, 0, 0, + 1, 1, 1, 1, 0, 1, 0, 0, + 1, 1, 1, 1, 0, 1, 0, 0, + ] + case .circles: + return [ + 1, 1, 1, 1, 1, 1, 1, 0, + 0, 1, 1, 1, 1, 1, 0, 1, + 1, 0, 1, 1, 1, 0, 1, 1, + 1, 1, 0, 0, 0, 1, 1, 0, + 1, 0, 1, 1, 1, 0, 1, 1, + 0, 1, 1, 1, 1, 1, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 0, + 1, 1, 1, 1, 1, 1, 1, 0, + ] + case .trees: + return [ + 1, 0, 1, 0, 1, 0, 1, 0, + 0, 1, 1, 1, 1, 1, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 0, + 1, 1, 1, 1, 1, 1, 1, 0, + 1, 0, 1, 0, 1, 0, 1, 0, + 1, 1, 0, 1, 0, 1, 1, 1, + 1, 1, 1, 0, 1, 1, 1, 1, + 1, 1, 1, 0, 1, 1, 1, 1, + ] + case .shingles: + return [ + 1, 1, 1, 1, 0, 1, 1, 1, + 1, 1, 1, 1, 0, 1, 1, 1, + 1, 1, 1, 0, 1, 0, 1, 1, + 0, 0, 0, 1, 1, 1, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 1, 1, 1, 1, 1, 0, + 1, 1, 0, 0, 0, 0, 0, 1 + ] + case .wicker: + return [ + 0, 0, 0, 0, 0, 1, 1, 1, + 1, 0, 0, 0, 1, 0, 1, 1, + 1, 1, 0, 1, 1, 1, 0, 1, + 1, 0, 1, 1, 1, 0, 0, 0, + 0, 1, 1, 1, 0, 0, 0, 0, + 1, 1, 1, 0, 1, 0, 0, 0, + 1, 1, 0, 1, 1, 1, 0, 1, + 1, 0, 0, 0, 1, 1, 1, 0 + ] + case .rhombus: + return [ + 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 1, 1, 1, 1, 1, 0, + 0, 1, 0, 1, 1, 1, 0, 1, + 1, 0, 1, 0, 1, 0, 1, 0, + 0, 1, 0, 1, 1, 1, 0, 1, + 1, 0, 1, 1, 1, 1, 1, 0, + 0, 1, 1, 1, 1, 1, 1, 1 + ] + case .balls: + return [ + 1, 0, 0, 0, 1, 0, 0, 0, + 0, 1, 1, 1, 0, 1, 1, 0, + 0, 1, 1, 1, 0, 0, 0, 0, + 0, 1, 1, 1, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, 0, 0, + 0, 1, 1, 0, 0, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 1, 1, + 0, 0, 0, 0, 0, 1, 1, 1 + ] + } + } +} diff --git a/Tests/PatternsTests/DummyTest.swift b/Tests/PatternsTests/DummyTest.swift new file mode 100644 index 0000000..badad26 --- /dev/null +++ b/Tests/PatternsTests/DummyTest.swift @@ -0,0 +1,9 @@ +import XCTest +@testable import Patterns + +final class PatternTests: XCTestCase { + func testExample() throws { + // Should update when I figure out how to best test SwiftUI views + XCTAssertEqual(true, true) + } +} diff --git a/Tests/PatternsTests/PatternsTests.swift b/Tests/PatternsTests/PatternsTests.swift deleted file mode 100644 index d45a6f7..0000000 --- a/Tests/PatternsTests/PatternsTests.swift +++ /dev/null @@ -1,11 +0,0 @@ -import XCTest -@testable import Patterns - -final class PatternsTests: XCTestCase { - func testExample() throws { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct - // results. - XCTAssertEqual(Patterns().text, "Hello, World!") - } -}