From 8651471300b037be1cedfcbe7e9399941b865f78 Mon Sep 17 00:00:00 2001 From: Brad Root Date: Thu, 27 Jan 2022 21:42:24 -0800 Subject: [PATCH 1/7] show fps in macos target --- macOS/ViewController.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/macOS/ViewController.swift b/macOS/ViewController.swift index 1d67c47..1199caf 100644 --- a/macOS/ViewController.swift +++ b/macOS/ViewController.swift @@ -21,6 +21,9 @@ class ViewController: NSViewController { if let view = self.skView { let scene = ClockScene(size: view.frame.size) + view.showsFPS = true + view.showsDrawCount = true + view.showsNodeCount = true view.presentScene(scene) scene.controller?.mode = .manual scene.controller?.start() From 5f36f758b4f31b465948660c18bce8b0ab993c10 Mon Sep 17 00:00:00 2001 From: Brad Root Date: Thu, 27 Jan 2022 21:40:39 -0800 Subject: [PATCH 2/7] improve inward pointing pattern animation --- Shared/Scene/Animations.swift | 23 +++++++++++++++++++++++ Shared/Scene/ClockController.swift | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Shared/Scene/Animations.swift b/Shared/Scene/Animations.swift index 41b61c6..4601ecb 100644 --- a/Shared/Scene/Animations.swift +++ b/Shared/Scene/Animations.swift @@ -345,6 +345,29 @@ let inwardPointPattern: [Int: [(CGFloat, CGFloat)]] = [ ], ] +let halfDownHalfUp: [Int: [(CGFloat, CGFloat)]] = [ + 0: [ + (-180, -180), (-180, -180), + (-180, -180), (-180, -180), + (-180, -180), (-180, -180), + ], + 1: [ + (-180, -180), (-180, -180), + (-180, -180), (-180, -180), + (-180, -180), (-180, -180), + ], + 2: [ + (0, 0), (0, 0), + (0, 0), (0, 0), + (0, 0), (0, 0), + ], + 3: [ + (0, 0), (0, 0), + (0, 0), (0, 0), + (0, 0), (0, 0), + ], +] + let horizontalLinesPattern: [Int: [(CGFloat, CGFloat)]] = [ 0: [ (-90, -90), (-270, -90), diff --git a/Shared/Scene/ClockController.swift b/Shared/Scene/ClockController.swift index 030e1f9..042ce50 100644 --- a/Shared/Scene/ClockController.swift +++ b/Shared/Scene/ClockController.swift @@ -125,8 +125,10 @@ class ClockController { Animation.display(pattern: inwardPointPattern), Animation.wait(duration: 5), Animation.spinBothHands(by: 360), - Animation.positionBothHands(minuteDegrees: 0, hourDegrees: 0), + Animation.display(pattern: halfDownHalfUp), Animation.spinBothHands(by: 360), + Animation.positionBothHands(minuteDegrees: -180, hourDegrees: 0), + Animation.spinBothHands(by: 180), Animation.currentTimePrint(), ]) case 5: From 7291ad4c913bf2981ffe1ba4992efa3a450a46d6 Mon Sep 17 00:00:00 2001 From: Brad Root Date: Fri, 28 Jan 2022 16:41:10 -0800 Subject: [PATCH 3/7] add a 'randomized position' pattern generator and animation --- Shared/Scene/Animations.swift | 27 +++++++++++++++++++++++++++ Shared/Scene/ClockController.swift | 11 ++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Shared/Scene/Animations.swift b/Shared/Scene/Animations.swift index 4601ecb..9efa460 100644 --- a/Shared/Scene/Animations.swift +++ b/Shared/Scene/Animations.swift @@ -320,6 +320,31 @@ class Animation { animation.pattern = pattern return animation } + + static func randomizedPattern() -> [Int: [(CGFloat, CGFloat)]] { + return [ + 0: [ + (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), + (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), + (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), + ], + 1: [ + (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), + (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), + (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), + ], + 2: [ + (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), + (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), + (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), + ], + 3: [ + (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), + (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), + (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), (CGFloat(Int.random(in: -359...0)), CGFloat(Int.random(in: -359...0))), + ], + ] + } } let inwardPointPattern: [Int: [(CGFloat, CGFloat)]] = [ @@ -391,6 +416,8 @@ let horizontalLinesPattern: [Int: [(CGFloat, CGFloat)]] = [ ], ] +// number patterns + let numberConfigs: [Int: [(CGFloat, CGFloat)]] = [ // Tuple format is (hour, minute) 0: [ diff --git a/Shared/Scene/ClockController.swift b/Shared/Scene/ClockController.swift index 042ce50..a6c0db9 100644 --- a/Shared/Scene/ClockController.swift +++ b/Shared/Scene/ClockController.swift @@ -98,7 +98,7 @@ class ClockController { } else if timeSinceLastAnimation >= 20 && !isAnimating { Log.debug("Displaying random animation...") - let number = Int.random(in: 1...6) + let number = Int.random(in: 1...7) switch number { case 1: // this one is pretty cool imho @@ -132,6 +132,7 @@ class ClockController { Animation.currentTimePrint(), ]) case 5: + // horizontal lines pattern queue(animations: [ Animation.display(pattern: horizontalLinesPattern), Animation.wait(duration: 10), @@ -140,6 +141,14 @@ class ClockController { Animation.positionBothHands(minuteDegrees: -180, hourDegrees: -180), Animation.currentTimePrint(), ]) + case 6: + // display randomized clock hand positions + queue(animations: [ + Animation.display(pattern: Animation.randomizedPattern()), + Animation.wait(duration: 5), + Animation.spinBothHands(by: 180), + Animation.currentTimePrint(), + ]) default: // delay spin with current time as clock queue(animations: [ From 5cb39924441b9216c70b739b77d60ffca2750969 Mon Sep 17 00:00:00 2001 From: Brad Root Date: Fri, 28 Jan 2022 17:02:48 -0800 Subject: [PATCH 4/7] at "randomized right angle pattern" function and animation --- Shared/Scene/Animations.swift | 26 ++++++++++++++++++++++++++ Shared/Scene/ClockController.swift | 10 +++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Shared/Scene/Animations.swift b/Shared/Scene/Animations.swift index 9efa460..5352ffd 100644 --- a/Shared/Scene/Animations.swift +++ b/Shared/Scene/Animations.swift @@ -345,6 +345,32 @@ class Animation { ], ] } + + static func randomizedRightAnglePattern() -> [Int: [(CGFloat, CGFloat)]] { + let options: [CGFloat] = [0, -90, -180, -270] + return [ + 0: [ + (options.randomElement()!, options.randomElement()!), (options.randomElement()!, options.randomElement()!), + (options.randomElement()!, options.randomElement()!), (options.randomElement()!, options.randomElement()!), + (options.randomElement()!, options.randomElement()!), (options.randomElement()!, options.randomElement()!), + ], + 1: [ + (options.randomElement()!, options.randomElement()!), (options.randomElement()!, options.randomElement()!), + (options.randomElement()!, options.randomElement()!), (options.randomElement()!, options.randomElement()!), + (options.randomElement()!, options.randomElement()!), (options.randomElement()!, options.randomElement()!), + ], + 2: [ + (options.randomElement()!, options.randomElement()!), (options.randomElement()!, options.randomElement()!), + (options.randomElement()!, options.randomElement()!), (options.randomElement()!, options.randomElement()!), + (options.randomElement()!, options.randomElement()!), (options.randomElement()!, options.randomElement()!), + ], + 3: [ + (options.randomElement()!, options.randomElement()!), (options.randomElement()!, options.randomElement()!), + (options.randomElement()!, options.randomElement()!), (options.randomElement()!, options.randomElement()!), + (options.randomElement()!, options.randomElement()!), (options.randomElement()!, options.randomElement()!), + ], + ] + } } let inwardPointPattern: [Int: [(CGFloat, CGFloat)]] = [ diff --git a/Shared/Scene/ClockController.swift b/Shared/Scene/ClockController.swift index a6c0db9..a3d9809 100644 --- a/Shared/Scene/ClockController.swift +++ b/Shared/Scene/ClockController.swift @@ -98,7 +98,7 @@ class ClockController { } else if timeSinceLastAnimation >= 20 && !isAnimating { Log.debug("Displaying random animation...") - let number = Int.random(in: 1...7) + let number = Int.random(in: 1...8) switch number { case 1: // this one is pretty cool imho @@ -149,6 +149,14 @@ class ClockController { Animation.spinBothHands(by: 180), Animation.currentTimePrint(), ]) + case 7: + // display randomized clock hand positions (right angles only) + queue(animations: [ + Animation.display(pattern: Animation.randomizedRightAnglePattern()), + Animation.wait(duration: 5), + Animation.spinBothHands(by: 180), + Animation.currentTimePrint(), + ]) default: // delay spin with current time as clock queue(animations: [ From d5bd1ca44bc332e31da70b077c0ac8850a29175b Mon Sep 17 00:00:00 2001 From: Brad Root Date: Fri, 28 Jan 2022 21:58:51 -0800 Subject: [PATCH 5/7] move patterns to separate file and replace rng with a pre-sorted random number array --- MultiClock.xcodeproj/project.pbxproj | 8 ++ Shared/Scene/Animations.swift | 155 ---------------------- Shared/Scene/ClockController.swift | 23 +++- Shared/Scene/Patterns.swift | 189 +++++++++++++++++++++++++++ 4 files changed, 217 insertions(+), 158 deletions(-) create mode 100644 Shared/Scene/Patterns.swift diff --git a/MultiClock.xcodeproj/project.pbxproj b/MultiClock.xcodeproj/project.pbxproj index 479665e..3408547 100644 --- a/MultiClock.xcodeproj/project.pbxproj +++ b/MultiClock.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 4413B0E127A5089100FBCCA7 /* Patterns.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4413B0E027A5089100FBCCA7 /* Patterns.swift */; }; + 4413B0E227A5089100FBCCA7 /* Patterns.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4413B0E027A5089100FBCCA7 /* Patterns.swift */; }; + 4413B0E327A5089100FBCCA7 /* Patterns.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4413B0E027A5089100FBCCA7 /* Patterns.swift */; }; 442F730627753B8F006D0991 /* Animations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 442F730527753B8F006D0991 /* Animations.swift */; }; 442F730827759C01006D0991 /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 442F730727759C00006D0991 /* Logging.swift */; }; 442F730A2775CF92006D0991 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 442F73092775CF92006D0991 /* README.md */; }; @@ -60,6 +63,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 4413B0E027A5089100FBCCA7 /* Patterns.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Patterns.swift; sourceTree = ""; }; 442F730527753B8F006D0991 /* Animations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animations.swift; sourceTree = ""; }; 442F730727759C00006D0991 /* Logging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = ""; }; 442F73092775CF92006D0991 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; @@ -181,6 +185,7 @@ 442F730527753B8F006D0991 /* Animations.swift */, 44C17D572773C947005E171A /* ClockController.swift */, 44E5F5042772BFA4007249E2 /* ClockScene.swift */, + 4413B0E027A5089100FBCCA7 /* Patterns.swift */, ); path = Scene; sourceTree = ""; @@ -384,6 +389,7 @@ 442F7322277681DF006D0991 /* ClockController.swift in Sources */, 442F7320277681DF006D0991 /* Extensions.swift in Sources */, 442F732A27768669006D0991 /* FileGrabber.swift in Sources */, + 4413B0E227A5089100FBCCA7 /* Patterns.swift in Sources */, 442F7325277681DF006D0991 /* Textures.swift in Sources */, 442F7326277681DF006D0991 /* Logging.swift in Sources */, 44884C19278A3E5F006C8FBD /* Manager.swift in Sources */, @@ -402,6 +408,7 @@ 444CD5AF2776AD0E00F51D7A /* ClusterNode.swift in Sources */, 444CD5B32776AD0E00F51D7A /* ClockNode.swift in Sources */, 444CD5B62776AD0E00F51D7A /* FileGrabber.swift in Sources */, + 4413B0E327A5089100FBCCA7 /* Patterns.swift in Sources */, 444CD5B52776AD0E00F51D7A /* Textures.swift in Sources */, 44884C1A278A3E5F006C8FBD /* Manager.swift in Sources */, 444CD59A2776A8D800F51D7A /* AppDelegate.swift in Sources */, @@ -422,6 +429,7 @@ 44E5F5072772BFA4007249E2 /* ViewController.swift in Sources */, 442F730627753B8F006D0991 /* Animations.swift in Sources */, 44C17D5B2773D45C005E171A /* Extensions.swift in Sources */, + 4413B0E127A5089100FBCCA7 /* Patterns.swift in Sources */, 44E5F5182772D315007249E2 /* ClusterNode.swift in Sources */, 44884C18278A3E5F006C8FBD /* Manager.swift in Sources */, 44C17D582773C947005E171A /* ClockController.swift in Sources */, diff --git a/Shared/Scene/Animations.swift b/Shared/Scene/Animations.swift index 5352ffd..446b5de 100644 --- a/Shared/Scene/Animations.swift +++ b/Shared/Scene/Animations.swift @@ -372,158 +372,3 @@ class Animation { ] } } - -let inwardPointPattern: [Int: [(CGFloat, CGFloat)]] = [ - 0: [ - (-105, -105), (-115, -115), - (-90, -90), (-90, -90), - (-75, -75), (-65, -65), - ], - 1: [ - (-125, -125), (-150, -150), - (-90, -90), (-90, -90), - (-55, -55), (-30, -30), - ], - 2: [ - (-210, -210), (-235, -235), - (-270, -270), (-270, -270), - (-330, -330), (-305, -305), - ], - 3: [ - (-245, -245), (-255, -255), - (-270, -270), (-270, -270), - (-295, -295), (-285, -285), - ], -] - -let halfDownHalfUp: [Int: [(CGFloat, CGFloat)]] = [ - 0: [ - (-180, -180), (-180, -180), - (-180, -180), (-180, -180), - (-180, -180), (-180, -180), - ], - 1: [ - (-180, -180), (-180, -180), - (-180, -180), (-180, -180), - (-180, -180), (-180, -180), - ], - 2: [ - (0, 0), (0, 0), - (0, 0), (0, 0), - (0, 0), (0, 0), - ], - 3: [ - (0, 0), (0, 0), - (0, 0), (0, 0), - (0, 0), (0, 0), - ], -] - -let horizontalLinesPattern: [Int: [(CGFloat, CGFloat)]] = [ - 0: [ - (-90, -90), (-270, -90), - (-90, -90), (-270, -90), - (-90, -90), (-270, -90), - ], - 1: [ - (-270, -90), (-270, -90), - (-270, -90), (-270, -90), - (-270, -90), (-270, -90), - ], - 2: [ - (-270, -90), (-270, -90), - (-270, -90), (-270, -90), - (-270, -90), (-270, -90), - ], - 3: [ - (-270, -90), (-270, -270), - (-270, -90), (-270, -270), - (-270, -90), (-270, -270), - ], -] - -// number patterns - -let numberConfigs: [Int: [(CGFloat, CGFloat)]] = [ - // Tuple format is (hour, minute) - 0: [ - (-90, -180), - (-270, -180), - (-180, 0), - (-180, 0), - (-90, 0), - (-270, 0), - ], - 1: [ - (-225, -225), - (-180, -180), - (-225, -225), - (-180, 0), - (-225, -225), - (0, 0) - ], - 2: [ - (-90, -90), - (-270, -180), - (-180, -90), - (-270, 0), - (0, -90), - (-270, -270) - ], - 3: [ - (-90, -90), - (-270, -180), - (-90, -90), - (0, -270), - (-90, -90), - (-270, 0) - ], - 4: [ - (-180, -180), - (-180, -180), - (0, -90), - (0, -180), - (-225, -225), - (0, 0) - ], - 5: [ - (-180, -90), - (-270, -270), - (0, -90), - (-270, -180), - (-90, -90), - (-270, 0) - ], - 6: [ - (-180, -90), - (-270, -270), - (0, -180), - (-270, -180), - (0, -90), - (0, -270) - ], - 7: [ - (-90, -90), - (-270, -180), - (-225, -225), - (-180, 0), - (-225, -225), - (0, 0) - ], - 8: [ - (-90, -180), - (-270, -180), - (-90, 0), - (-270, 0), - (0, -90), - (-270, 0) - ], - 9: [ - (-90, -180), - (-270, -180), - (-90, 0), - (0, -180), - (-90, -90), - (-270, 0) - ], -] diff --git a/Shared/Scene/ClockController.swift b/Shared/Scene/ClockController.swift index a3d9809..44774ac 100644 --- a/Shared/Scene/ClockController.swift +++ b/Shared/Scene/ClockController.swift @@ -37,6 +37,10 @@ class ClockController { private var timeSinceLastAnimation: Int = 30 + private var allAnimations: [Int] = [1, 2, 3, 4, 5, 6, 7, 8, 9].shuffled() + + private var availableAnimations: [Int] = [] + init(size: CGSize) { for _ in 1...4 { let cluster = ClusterNode(size: CGSize(width: size.width/4, height: (size.width/4/2)*3)) @@ -96,9 +100,13 @@ class ClockController { ]) } } else if timeSinceLastAnimation >= 20 && !isAnimating { - Log.debug("Displaying random animation...") + if availableAnimations.isEmpty { + availableAnimations = allAnimations + } - let number = Int.random(in: 1...8) + let number = availableAnimations.popLast()! + Log.debug("Displaying random animation \(number)...") + switch number { case 1: // this one is pretty cool imho @@ -157,6 +165,15 @@ class ClockController { Animation.spinBothHands(by: 180), Animation.currentTimePrint(), ]) + case 8: + // display box pattern + queue(animations: [ + Animation.display(pattern: boxPattern), + Animation.wait(duration: 5), + Animation.display(pattern: Animation.randomizedRightAnglePattern()), + Animation.spinBothHands(by: 180), + Animation.currentTimePrint(), + ]) default: // delay spin with current time as clock queue(animations: [ @@ -180,7 +197,7 @@ class ClockController { ]) let newTimer = Timer(timeInterval: updateInterval, target: self, selector: #selector(updateTime), userInfo: nil, repeats: true) - newTimer.tolerance = 0.2 + newTimer.tolerance = 5 RunLoop.main.add(newTimer, forMode: .common) timer = newTimer diff --git a/Shared/Scene/Patterns.swift b/Shared/Scene/Patterns.swift new file mode 100644 index 0000000..abfb35d --- /dev/null +++ b/Shared/Scene/Patterns.swift @@ -0,0 +1,189 @@ +// +// Patterns.swift +// MultiClock +// +// Created by Brad Root on 1/28/22. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import Foundation + +let inwardPointPattern: [Int: [(CGFloat, CGFloat)]] = [ + 0: [ + (-105, -105), (-115, -115), + (-90, -90), (-90, -90), + (-75, -75), (-65, -65), + ], + 1: [ + (-125, -125), (-150, -150), + (-90, -90), (-90, -90), + (-55, -55), (-30, -30), + ], + 2: [ + (-210, -210), (-235, -235), + (-270, -270), (-270, -270), + (-330, -330), (-305, -305), + ], + 3: [ + (-245, -245), (-255, -255), + (-270, -270), (-270, -270), + (-295, -295), (-285, -285), + ], +] + +let halfDownHalfUp: [Int: [(CGFloat, CGFloat)]] = [ + 0: [ + (-180, -180), (-180, -180), + (-180, -180), (-180, -180), + (-180, -180), (-180, -180), + ], + 1: [ + (-180, -180), (-180, -180), + (-180, -180), (-180, -180), + (-180, -180), (-180, -180), + ], + 2: [ + (0, 0), (0, 0), + (0, 0), (0, 0), + (0, 0), (0, 0), + ], + 3: [ + (0, 0), (0, 0), + (0, 0), (0, 0), + (0, 0), (0, 0), + ], +] + +let horizontalLinesPattern: [Int: [(CGFloat, CGFloat)]] = [ + 0: [ + (-90, -90), (-270, -90), + (-90, -90), (-270, -90), + (-90, -90), (-270, -90), + ], + 1: [ + (-270, -90), (-270, -90), + (-270, -90), (-270, -90), + (-270, -90), (-270, -90), + ], + 2: [ + (-270, -90), (-270, -90), + (-270, -90), (-270, -90), + (-270, -90), (-270, -90), + ], + 3: [ + (-270, -90), (-270, -270), + (-270, -90), (-270, -270), + (-270, -90), (-270, -270), + ], +] + +let boxPattern: [Int: [(CGFloat, CGFloat)]] = [ + 0: [ + (-90, -180), (-270, -90), + (0, -180), (-90, -90), + (0, -90), (-270, -90), + ], + 1: [ + (-270, -90), (-270, -90), + (-270, -90), (-270, -90), + (-270, -90), (-270, -90), + ], + 2: [ + (-270, -90), (-270, -90), + (-270, -90), (-270, -90), + (-270, -90), (-270, -90), + ], + 3: [ + (-270, -90), (-270, -180), + (-270, -270), (0, -180), + (-270, -90), (0, -270), + ], +] + +// number patterns + +let numberConfigs: [Int: [(CGFloat, CGFloat)]] = [ + // Tuple format is (hour, minute) + 0: [ + (-90, -180), + (-270, -180), + (-180, 0), + (-180, 0), + (-90, 0), + (-270, 0), + ], + 1: [ + (-225, -225), + (-180, -180), + (-225, -225), + (-180, 0), + (-225, -225), + (0, 0) + ], + 2: [ + (-90, -90), + (-270, -180), + (-180, -90), + (-270, 0), + (0, -90), + (-270, -270) + ], + 3: [ + (-90, -90), + (-270, -180), + (-90, -90), + (0, -270), + (-90, -90), + (-270, 0) + ], + 4: [ + (-180, -180), + (-180, -180), + (0, -90), + (0, -180), + (-225, -225), + (0, 0) + ], + 5: [ + (-180, -90), + (-270, -270), + (0, -90), + (-270, -180), + (-90, -90), + (-270, 0) + ], + 6: [ + (-180, -90), + (-270, -270), + (0, -180), + (-270, -180), + (0, -90), + (0, -270) + ], + 7: [ + (-90, -90), + (-270, -180), + (-225, -225), + (-180, 0), + (-225, -225), + (0, 0) + ], + 8: [ + (-90, -180), + (-270, -180), + (-90, 0), + (-270, 0), + (0, -90), + (-270, 0) + ], + 9: [ + (-90, -180), + (-270, -180), + (-90, 0), + (0, -180), + (-90, -90), + (-270, 0) + ], +] From 606fce2202cbda874b93de3e2d27405e1396863d Mon Sep 17 00:00:00 2001 From: Brad Root Date: Fri, 28 Jan 2022 22:00:57 -0800 Subject: [PATCH 6/7] commit manual mode to git --- macOS/ViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macOS/ViewController.swift b/macOS/ViewController.swift index d59a440..1199caf 100644 --- a/macOS/ViewController.swift +++ b/macOS/ViewController.swift @@ -25,7 +25,7 @@ class ViewController: NSViewController { view.showsDrawCount = true view.showsNodeCount = true view.presentScene(scene) - scene.controller?.mode = .automatic + scene.controller?.mode = .manual scene.controller?.start() } } From a040f72fab89c90d0b0573f8a1fe17603341dc86 Mon Sep 17 00:00:00 2001 From: Brad Root Date: Fri, 28 Jan 2022 22:05:34 -0800 Subject: [PATCH 7/7] remove unneeded public functions --- Shared/Scene/ClockController.swift | 48 ++++-------------------------- Shared/Scene/ClockScene.swift | 12 ++++---- 2 files changed, 12 insertions(+), 48 deletions(-) diff --git a/Shared/Scene/ClockController.swift b/Shared/Scene/ClockController.swift index 44774ac..f1a0a63 100644 --- a/Shared/Scene/ClockController.swift +++ b/Shared/Scene/ClockController.swift @@ -63,6 +63,11 @@ class ClockController { startTimer() } } + + public func queue(animations: [Animation]) { + animationQueue.append(contentsOf: animations) + startAnimationQueueIfNeeded() + } // MARK: - Timer @@ -238,11 +243,6 @@ class ClockController { scene?.run(actionGroup) } - public func queue(animations: [Animation]) { - animationQueue.append(contentsOf: animations) - startAnimationQueueIfNeeded() - } - private func runNextAnimation() { let animation = animationQueue.removeFirst() run(animation) @@ -253,41 +253,5 @@ class ClockController { runNextAnimation() } } - - // Helper functions for manually triggering animations - - public func showCurrentTime() { - queue(animations: [Animation.currentTimePrint()]) - } - - public func showTime(string: String) { - queue(animations: [Animation.printString(string: string)]) - } - - public func returnToMidnight() { - queue(animations: [Animation.positionBothHands(minuteDegrees: 0, hourDegrees: 0)]) - } - - public func moveAll(degrees: CGFloat) { - queue(animations: [Animation.positionBothHands(minuteDegrees: degrees, hourDegrees: degrees)]) - } - - public func moveAll(minuteDegrees: CGFloat, hourDegrees: CGFloat) { - queue(animations: [Animation.positionBothHands(minuteDegrees: minuteDegrees, hourDegrees: hourDegrees)]) - } - - public func setAllToCurrentTime() { - queue(animations: [Animation.currentTimeClock()]) - } - - public func rotateAll(by degrees: CGFloat) { - queue(animations: [Animation.spinBothHands(by: degrees)]) - } - - public func testQueue() { - queue(animations: [ - Animation.spinBothHands(by: 360), - Animation.currentTimePrint(), - ]) - } + } diff --git a/Shared/Scene/ClockScene.swift b/Shared/Scene/ClockScene.swift index 7119365..f333d28 100644 --- a/Shared/Scene/ClockScene.swift +++ b/Shared/Scene/ClockScene.swift @@ -70,17 +70,17 @@ class ClockScene: SKScene, ManagerDelegate { Animation.positionBothHands(minuteDegrees: 0, hourDegrees: 0), ]) case "t": - controller?.showCurrentTime() + controller?.queue(animations: [Animation.currentTimePrint()]) case "w": - controller?.returnToMidnight() + controller?.queue(animations: [Animation.positionBothHands(minuteDegrees: 0, hourDegrees: 0)]) case "x": - controller?.moveAll(degrees: -45) + controller?.queue(animations: [Animation.positionBothHands(minuteDegrees: -45, hourDegrees: -45)]) case "c": - controller?.moveAll(minuteDegrees: -45, hourDegrees: -225) + controller?.queue(animations: [Animation.positionBothHands(minuteDegrees: -45, hourDegrees: -225)]) case "r": - controller?.setAllToCurrentTime() + controller?.queue(animations: [Animation.currentTimeClock()]) case "p": - controller?.rotateAll(by: 360) + controller?.queue(animations: [Animation.spinBothHands(by: 360)]) case "o": controller?.queue(animations: [ Animation.display(pattern: horizontalLinesPattern),