├── .gitignore ├── LICENSE.md ├── MetaSpinExample.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── owenwj.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── MetaSpinExample ├── AppDelegate.swift ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── Sources │ ├── MetaBall.swift │ ├── MetaField.swift │ └── MetaSpin.swift └── ViewController.swift ├── MetaSpinExampleTests ├── Info.plist └── MetaSpinExampleTests.swift ├── README.md └── demo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | MetaSpinExample.xcodeproj/xcuserdata 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Jin Wang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MetaSpinExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 290540BE1AE6821800D74B8D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290540BD1AE6821800D74B8D /* AppDelegate.swift */; }; 11 | 290540C01AE6821800D74B8D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290540BF1AE6821800D74B8D /* ViewController.swift */; }; 12 | 290540C31AE6821800D74B8D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 290540C11AE6821800D74B8D /* Main.storyboard */; }; 13 | 290540C51AE6821800D74B8D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 290540C41AE6821800D74B8D /* Images.xcassets */; }; 14 | 290540C81AE6821800D74B8D /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 290540C61AE6821800D74B8D /* LaunchScreen.xib */; }; 15 | 290540D41AE6821900D74B8D /* MetaSpinExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290540D31AE6821900D74B8D /* MetaSpinExampleTests.swift */; }; 16 | 299AB6581C59E702007662A1 /* MetaBall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 299AB6551C59E702007662A1 /* MetaBall.swift */; }; 17 | 299AB6591C59E702007662A1 /* MetaField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 299AB6561C59E702007662A1 /* MetaField.swift */; }; 18 | 299AB65A1C59E702007662A1 /* MetaSpin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 299AB6571C59E702007662A1 /* MetaSpin.swift */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 290540CE1AE6821900D74B8D /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 290540B01AE6821800D74B8D /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 290540B71AE6821800D74B8D; 27 | remoteInfo = MetaSpinExample; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 290540B81AE6821800D74B8D /* MetaSpinExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MetaSpinExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 290540BC1AE6821800D74B8D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | 290540BD1AE6821800D74B8D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 35 | 290540BF1AE6821800D74B8D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 36 | 290540C21AE6821800D74B8D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 37 | 290540C41AE6821800D74B8D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 38 | 290540C71AE6821800D74B8D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 39 | 290540CD1AE6821900D74B8D /* MetaSpinExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MetaSpinExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 40 | 290540D21AE6821900D74B8D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | 290540D31AE6821900D74B8D /* MetaSpinExampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetaSpinExampleTests.swift; sourceTree = ""; }; 42 | 299AB6551C59E702007662A1 /* MetaBall.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetaBall.swift; sourceTree = ""; }; 43 | 299AB6561C59E702007662A1 /* MetaField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetaField.swift; sourceTree = ""; }; 44 | 299AB6571C59E702007662A1 /* MetaSpin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetaSpin.swift; sourceTree = ""; }; 45 | /* End PBXFileReference section */ 46 | 47 | /* Begin PBXFrameworksBuildPhase section */ 48 | 290540B51AE6821800D74B8D /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | ); 53 | runOnlyForDeploymentPostprocessing = 0; 54 | }; 55 | 290540CA1AE6821900D74B8D /* Frameworks */ = { 56 | isa = PBXFrameworksBuildPhase; 57 | buildActionMask = 2147483647; 58 | files = ( 59 | ); 60 | runOnlyForDeploymentPostprocessing = 0; 61 | }; 62 | /* End PBXFrameworksBuildPhase section */ 63 | 64 | /* Begin PBXGroup section */ 65 | 290540AF1AE6821800D74B8D = { 66 | isa = PBXGroup; 67 | children = ( 68 | 290540BA1AE6821800D74B8D /* MetaSpinExample */, 69 | 290540D01AE6821900D74B8D /* MetaSpinExampleTests */, 70 | 290540B91AE6821800D74B8D /* Products */, 71 | ); 72 | sourceTree = ""; 73 | }; 74 | 290540B91AE6821800D74B8D /* Products */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 290540B81AE6821800D74B8D /* MetaSpinExample.app */, 78 | 290540CD1AE6821900D74B8D /* MetaSpinExampleTests.xctest */, 79 | ); 80 | name = Products; 81 | sourceTree = ""; 82 | }; 83 | 290540BA1AE6821800D74B8D /* MetaSpinExample */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 299AB6541C59E702007662A1 /* Sources */, 87 | 290540BD1AE6821800D74B8D /* AppDelegate.swift */, 88 | 290540BF1AE6821800D74B8D /* ViewController.swift */, 89 | 290540C11AE6821800D74B8D /* Main.storyboard */, 90 | 290540C41AE6821800D74B8D /* Images.xcassets */, 91 | 290540C61AE6821800D74B8D /* LaunchScreen.xib */, 92 | 290540BB1AE6821800D74B8D /* Supporting Files */, 93 | ); 94 | path = MetaSpinExample; 95 | sourceTree = ""; 96 | }; 97 | 290540BB1AE6821800D74B8D /* Supporting Files */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | 290540BC1AE6821800D74B8D /* Info.plist */, 101 | ); 102 | name = "Supporting Files"; 103 | sourceTree = ""; 104 | }; 105 | 290540D01AE6821900D74B8D /* MetaSpinExampleTests */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 290540D31AE6821900D74B8D /* MetaSpinExampleTests.swift */, 109 | 290540D11AE6821900D74B8D /* Supporting Files */, 110 | ); 111 | path = MetaSpinExampleTests; 112 | sourceTree = ""; 113 | }; 114 | 290540D11AE6821900D74B8D /* Supporting Files */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | 290540D21AE6821900D74B8D /* Info.plist */, 118 | ); 119 | name = "Supporting Files"; 120 | sourceTree = ""; 121 | }; 122 | 299AB6541C59E702007662A1 /* Sources */ = { 123 | isa = PBXGroup; 124 | children = ( 125 | 299AB6551C59E702007662A1 /* MetaBall.swift */, 126 | 299AB6561C59E702007662A1 /* MetaField.swift */, 127 | 299AB6571C59E702007662A1 /* MetaSpin.swift */, 128 | ); 129 | path = Sources; 130 | sourceTree = ""; 131 | }; 132 | /* End PBXGroup section */ 133 | 134 | /* Begin PBXNativeTarget section */ 135 | 290540B71AE6821800D74B8D /* MetaSpinExample */ = { 136 | isa = PBXNativeTarget; 137 | buildConfigurationList = 290540D71AE6821900D74B8D /* Build configuration list for PBXNativeTarget "MetaSpinExample" */; 138 | buildPhases = ( 139 | 290540B41AE6821800D74B8D /* Sources */, 140 | 290540B51AE6821800D74B8D /* Frameworks */, 141 | 290540B61AE6821800D74B8D /* Resources */, 142 | ); 143 | buildRules = ( 144 | ); 145 | dependencies = ( 146 | ); 147 | name = MetaSpinExample; 148 | productName = MetaSpinExample; 149 | productReference = 290540B81AE6821800D74B8D /* MetaSpinExample.app */; 150 | productType = "com.apple.product-type.application"; 151 | }; 152 | 290540CC1AE6821900D74B8D /* MetaSpinExampleTests */ = { 153 | isa = PBXNativeTarget; 154 | buildConfigurationList = 290540DA1AE6821900D74B8D /* Build configuration list for PBXNativeTarget "MetaSpinExampleTests" */; 155 | buildPhases = ( 156 | 290540C91AE6821900D74B8D /* Sources */, 157 | 290540CA1AE6821900D74B8D /* Frameworks */, 158 | 290540CB1AE6821900D74B8D /* Resources */, 159 | ); 160 | buildRules = ( 161 | ); 162 | dependencies = ( 163 | 290540CF1AE6821900D74B8D /* PBXTargetDependency */, 164 | ); 165 | name = MetaSpinExampleTests; 166 | productName = MetaSpinExampleTests; 167 | productReference = 290540CD1AE6821900D74B8D /* MetaSpinExampleTests.xctest */; 168 | productType = "com.apple.product-type.bundle.unit-test"; 169 | }; 170 | /* End PBXNativeTarget section */ 171 | 172 | /* Begin PBXProject section */ 173 | 290540B01AE6821800D74B8D /* Project object */ = { 174 | isa = PBXProject; 175 | attributes = { 176 | LastSwiftMigration = 0700; 177 | LastSwiftUpdateCheck = 0700; 178 | LastUpgradeCheck = 0800; 179 | ORGANIZATIONNAME = uthoft; 180 | TargetAttributes = { 181 | 290540B71AE6821800D74B8D = { 182 | CreatedOnToolsVersion = 6.4; 183 | DevelopmentTeam = MG8YZ6JLG6; 184 | LastSwiftMigration = 0800; 185 | }; 186 | 290540CC1AE6821900D74B8D = { 187 | CreatedOnToolsVersion = 6.4; 188 | DevelopmentTeam = MG8YZ6JLG6; 189 | LastSwiftMigration = 0800; 190 | TestTargetID = 290540B71AE6821800D74B8D; 191 | }; 192 | }; 193 | }; 194 | buildConfigurationList = 290540B31AE6821800D74B8D /* Build configuration list for PBXProject "MetaSpinExample" */; 195 | compatibilityVersion = "Xcode 3.2"; 196 | developmentRegion = English; 197 | hasScannedForEncodings = 0; 198 | knownRegions = ( 199 | en, 200 | Base, 201 | ); 202 | mainGroup = 290540AF1AE6821800D74B8D; 203 | productRefGroup = 290540B91AE6821800D74B8D /* Products */; 204 | projectDirPath = ""; 205 | projectRoot = ""; 206 | targets = ( 207 | 290540B71AE6821800D74B8D /* MetaSpinExample */, 208 | 290540CC1AE6821900D74B8D /* MetaSpinExampleTests */, 209 | ); 210 | }; 211 | /* End PBXProject section */ 212 | 213 | /* Begin PBXResourcesBuildPhase section */ 214 | 290540B61AE6821800D74B8D /* Resources */ = { 215 | isa = PBXResourcesBuildPhase; 216 | buildActionMask = 2147483647; 217 | files = ( 218 | 290540C31AE6821800D74B8D /* Main.storyboard in Resources */, 219 | 290540C81AE6821800D74B8D /* LaunchScreen.xib in Resources */, 220 | 290540C51AE6821800D74B8D /* Images.xcassets in Resources */, 221 | ); 222 | runOnlyForDeploymentPostprocessing = 0; 223 | }; 224 | 290540CB1AE6821900D74B8D /* Resources */ = { 225 | isa = PBXResourcesBuildPhase; 226 | buildActionMask = 2147483647; 227 | files = ( 228 | ); 229 | runOnlyForDeploymentPostprocessing = 0; 230 | }; 231 | /* End PBXResourcesBuildPhase section */ 232 | 233 | /* Begin PBXSourcesBuildPhase section */ 234 | 290540B41AE6821800D74B8D /* Sources */ = { 235 | isa = PBXSourcesBuildPhase; 236 | buildActionMask = 2147483647; 237 | files = ( 238 | 290540C01AE6821800D74B8D /* ViewController.swift in Sources */, 239 | 299AB65A1C59E702007662A1 /* MetaSpin.swift in Sources */, 240 | 299AB6591C59E702007662A1 /* MetaField.swift in Sources */, 241 | 299AB6581C59E702007662A1 /* MetaBall.swift in Sources */, 242 | 290540BE1AE6821800D74B8D /* AppDelegate.swift in Sources */, 243 | ); 244 | runOnlyForDeploymentPostprocessing = 0; 245 | }; 246 | 290540C91AE6821900D74B8D /* Sources */ = { 247 | isa = PBXSourcesBuildPhase; 248 | buildActionMask = 2147483647; 249 | files = ( 250 | 290540D41AE6821900D74B8D /* MetaSpinExampleTests.swift in Sources */, 251 | ); 252 | runOnlyForDeploymentPostprocessing = 0; 253 | }; 254 | /* End PBXSourcesBuildPhase section */ 255 | 256 | /* Begin PBXTargetDependency section */ 257 | 290540CF1AE6821900D74B8D /* PBXTargetDependency */ = { 258 | isa = PBXTargetDependency; 259 | target = 290540B71AE6821800D74B8D /* MetaSpinExample */; 260 | targetProxy = 290540CE1AE6821900D74B8D /* PBXContainerItemProxy */; 261 | }; 262 | /* End PBXTargetDependency section */ 263 | 264 | /* Begin PBXVariantGroup section */ 265 | 290540C11AE6821800D74B8D /* Main.storyboard */ = { 266 | isa = PBXVariantGroup; 267 | children = ( 268 | 290540C21AE6821800D74B8D /* Base */, 269 | ); 270 | name = Main.storyboard; 271 | sourceTree = ""; 272 | }; 273 | 290540C61AE6821800D74B8D /* LaunchScreen.xib */ = { 274 | isa = PBXVariantGroup; 275 | children = ( 276 | 290540C71AE6821800D74B8D /* Base */, 277 | ); 278 | name = LaunchScreen.xib; 279 | sourceTree = ""; 280 | }; 281 | /* End PBXVariantGroup section */ 282 | 283 | /* Begin XCBuildConfiguration section */ 284 | 290540D51AE6821900D74B8D /* Debug */ = { 285 | isa = XCBuildConfiguration; 286 | buildSettings = { 287 | ALWAYS_SEARCH_USER_PATHS = NO; 288 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 289 | CLANG_CXX_LIBRARY = "libc++"; 290 | CLANG_ENABLE_MODULES = YES; 291 | CLANG_ENABLE_OBJC_ARC = YES; 292 | CLANG_WARN_BOOL_CONVERSION = YES; 293 | CLANG_WARN_CONSTANT_CONVERSION = YES; 294 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 295 | CLANG_WARN_EMPTY_BODY = YES; 296 | CLANG_WARN_ENUM_CONVERSION = YES; 297 | CLANG_WARN_INFINITE_RECURSION = YES; 298 | CLANG_WARN_INT_CONVERSION = YES; 299 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 300 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 301 | CLANG_WARN_UNREACHABLE_CODE = YES; 302 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 303 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 304 | COPY_PHASE_STRIP = NO; 305 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 306 | ENABLE_STRICT_OBJC_MSGSEND = YES; 307 | ENABLE_TESTABILITY = YES; 308 | GCC_C_LANGUAGE_STANDARD = gnu99; 309 | GCC_DYNAMIC_NO_PIC = NO; 310 | GCC_NO_COMMON_BLOCKS = YES; 311 | GCC_OPTIMIZATION_LEVEL = 0; 312 | GCC_PREPROCESSOR_DEFINITIONS = ( 313 | "DEBUG=1", 314 | "$(inherited)", 315 | ); 316 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 317 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 318 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 319 | GCC_WARN_UNDECLARED_SELECTOR = YES; 320 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 321 | GCC_WARN_UNUSED_FUNCTION = YES; 322 | GCC_WARN_UNUSED_VARIABLE = YES; 323 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 324 | MTL_ENABLE_DEBUG_INFO = YES; 325 | ONLY_ACTIVE_ARCH = YES; 326 | SDKROOT = iphoneos; 327 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 328 | }; 329 | name = Debug; 330 | }; 331 | 290540D61AE6821900D74B8D /* Release */ = { 332 | isa = XCBuildConfiguration; 333 | buildSettings = { 334 | ALWAYS_SEARCH_USER_PATHS = NO; 335 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 336 | CLANG_CXX_LIBRARY = "libc++"; 337 | CLANG_ENABLE_MODULES = YES; 338 | CLANG_ENABLE_OBJC_ARC = YES; 339 | CLANG_WARN_BOOL_CONVERSION = YES; 340 | CLANG_WARN_CONSTANT_CONVERSION = YES; 341 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 342 | CLANG_WARN_EMPTY_BODY = YES; 343 | CLANG_WARN_ENUM_CONVERSION = YES; 344 | CLANG_WARN_INFINITE_RECURSION = YES; 345 | CLANG_WARN_INT_CONVERSION = YES; 346 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 347 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 348 | CLANG_WARN_UNREACHABLE_CODE = YES; 349 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 350 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 351 | COPY_PHASE_STRIP = NO; 352 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 353 | ENABLE_NS_ASSERTIONS = NO; 354 | ENABLE_STRICT_OBJC_MSGSEND = YES; 355 | GCC_C_LANGUAGE_STANDARD = gnu99; 356 | GCC_NO_COMMON_BLOCKS = YES; 357 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 358 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 359 | GCC_WARN_UNDECLARED_SELECTOR = YES; 360 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 361 | GCC_WARN_UNUSED_FUNCTION = YES; 362 | GCC_WARN_UNUSED_VARIABLE = YES; 363 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 364 | MTL_ENABLE_DEBUG_INFO = NO; 365 | SDKROOT = iphoneos; 366 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 367 | VALIDATE_PRODUCT = YES; 368 | }; 369 | name = Release; 370 | }; 371 | 290540D81AE6821900D74B8D /* Debug */ = { 372 | isa = XCBuildConfiguration; 373 | buildSettings = { 374 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 375 | DEVELOPMENT_TEAM = MG8YZ6JLG6; 376 | INFOPLIST_FILE = MetaSpinExample/Info.plist; 377 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 378 | PRODUCT_BUNDLE_IDENTIFIER = "com.uthoft.$(PRODUCT_NAME:rfc1034identifier)"; 379 | PRODUCT_NAME = "$(TARGET_NAME)"; 380 | SWIFT_VERSION = 3.0; 381 | }; 382 | name = Debug; 383 | }; 384 | 290540D91AE6821900D74B8D /* Release */ = { 385 | isa = XCBuildConfiguration; 386 | buildSettings = { 387 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 388 | DEVELOPMENT_TEAM = MG8YZ6JLG6; 389 | INFOPLIST_FILE = MetaSpinExample/Info.plist; 390 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 391 | PRODUCT_BUNDLE_IDENTIFIER = "com.uthoft.$(PRODUCT_NAME:rfc1034identifier)"; 392 | PRODUCT_NAME = "$(TARGET_NAME)"; 393 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 394 | SWIFT_VERSION = 3.0; 395 | }; 396 | name = Release; 397 | }; 398 | 290540DB1AE6821900D74B8D /* Debug */ = { 399 | isa = XCBuildConfiguration; 400 | buildSettings = { 401 | BUNDLE_LOADER = "$(TEST_HOST)"; 402 | DEVELOPMENT_TEAM = MG8YZ6JLG6; 403 | GCC_PREPROCESSOR_DEFINITIONS = ( 404 | "DEBUG=1", 405 | "$(inherited)", 406 | ); 407 | INFOPLIST_FILE = MetaSpinExampleTests/Info.plist; 408 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 409 | PRODUCT_BUNDLE_IDENTIFIER = "com.uthoft.$(PRODUCT_NAME:rfc1034identifier)"; 410 | PRODUCT_NAME = "$(TARGET_NAME)"; 411 | SWIFT_VERSION = 3.0; 412 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MetaSpinExample.app/MetaSpinExample"; 413 | }; 414 | name = Debug; 415 | }; 416 | 290540DC1AE6821900D74B8D /* Release */ = { 417 | isa = XCBuildConfiguration; 418 | buildSettings = { 419 | BUNDLE_LOADER = "$(TEST_HOST)"; 420 | DEVELOPMENT_TEAM = MG8YZ6JLG6; 421 | INFOPLIST_FILE = MetaSpinExampleTests/Info.plist; 422 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 423 | PRODUCT_BUNDLE_IDENTIFIER = "com.uthoft.$(PRODUCT_NAME:rfc1034identifier)"; 424 | PRODUCT_NAME = "$(TARGET_NAME)"; 425 | SWIFT_VERSION = 3.0; 426 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MetaSpinExample.app/MetaSpinExample"; 427 | }; 428 | name = Release; 429 | }; 430 | /* End XCBuildConfiguration section */ 431 | 432 | /* Begin XCConfigurationList section */ 433 | 290540B31AE6821800D74B8D /* Build configuration list for PBXProject "MetaSpinExample" */ = { 434 | isa = XCConfigurationList; 435 | buildConfigurations = ( 436 | 290540D51AE6821900D74B8D /* Debug */, 437 | 290540D61AE6821900D74B8D /* Release */, 438 | ); 439 | defaultConfigurationIsVisible = 0; 440 | defaultConfigurationName = Release; 441 | }; 442 | 290540D71AE6821900D74B8D /* Build configuration list for PBXNativeTarget "MetaSpinExample" */ = { 443 | isa = XCConfigurationList; 444 | buildConfigurations = ( 445 | 290540D81AE6821900D74B8D /* Debug */, 446 | 290540D91AE6821900D74B8D /* Release */, 447 | ); 448 | defaultConfigurationIsVisible = 0; 449 | defaultConfigurationName = Release; 450 | }; 451 | 290540DA1AE6821900D74B8D /* Build configuration list for PBXNativeTarget "MetaSpinExampleTests" */ = { 452 | isa = XCConfigurationList; 453 | buildConfigurations = ( 454 | 290540DB1AE6821900D74B8D /* Debug */, 455 | 290540DC1AE6821900D74B8D /* Release */, 456 | ); 457 | defaultConfigurationIsVisible = 0; 458 | defaultConfigurationName = Release; 459 | }; 460 | /* End XCConfigurationList section */ 461 | }; 462 | rootObject = 290540B01AE6821800D74B8D /* Project object */; 463 | } 464 | -------------------------------------------------------------------------------- /MetaSpinExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MetaSpinExample.xcodeproj/xcuserdata/owenwj.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /MetaSpinExample.xcodeproj/xcuserdata/owenwj.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | MetaSpinExample.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 290540B71AE6821800D74B8D 16 | 17 | primary 18 | 19 | 20 | 290540CC1AE6821900D74B8D 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /MetaSpinExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // MetaSpinExample 4 | // 5 | // Created by Jin Wang on 21/04/2015. 6 | // Copyright (c) 2015 uthoft. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /MetaSpinExample/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /MetaSpinExample/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /MetaSpinExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /MetaSpinExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /MetaSpinExample/Sources/MetaBall.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MetaBall.swift 3 | // MetaSpinExample 4 | // 5 | // Created by Jin Wang on 21/04/2015. 6 | // Copyright (c) 2015 uthoft. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import GLKit 11 | 12 | let ForceConstant: CGFloat = 6.67384 13 | let DistanceConstant: CGFloat = 2.0 14 | let MaximumForce: CGFloat = 10000 15 | 16 | class MetaBall: NSObject { 17 | dynamic var center: GLKVector2 18 | var radius: CGFloat { 19 | didSet { 20 | self.mess = radius // ForceConstant * CGFloat(M_PI) * radius * radius 21 | } 22 | } 23 | fileprivate(set) var mess: CGFloat 24 | 25 | var borderPosition = GLKVector2Make(0, 0) 26 | var trackingPosition = GLKVector2Make(0, 0) 27 | var tracking = false 28 | 29 | convenience init(center: CGPoint, radius: CGFloat) { 30 | let centerVector = GLKVector2Make(Float(center.x), Float(center.y)) 31 | self.init(centerVector: centerVector, radius: radius) 32 | } 33 | 34 | init(centerVector: GLKVector2, radius: CGFloat) { 35 | self.center = centerVector 36 | self.radius = radius 37 | self.mess = radius // ForceConstant * CGFloat(M_PI) * radius * radius 38 | } 39 | 40 | func forceAt(_ position: GLKVector2) -> CGFloat { 41 | let dis = distance(center, toPoint: position) 42 | let div = dis * dis 43 | return div == 0 ? MaximumForce : mess / div 44 | } 45 | } 46 | 47 | func distance(_ fromPoint: GLKVector2, toPoint: GLKVector2) -> CGFloat { 48 | return CGFloat(GLKVector2Distance(fromPoint, toPoint)) 49 | } 50 | -------------------------------------------------------------------------------- /MetaSpinExample/Sources/MetaField.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MetaField.swift 3 | // MetaSpinExample 4 | // 5 | // Created by Jin Wang on 21/04/2015. 6 | // Copyright (c) 2015 uthoft. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import GLKit 11 | 12 | private let rungKutaStep: Float = 1.0 13 | 14 | class MetaField: UIView { 15 | 16 | let fieldThreshold: CGFloat = 0.04 17 | 18 | var ballFillColor: UIColor = UIColor.black { 19 | didSet { 20 | pathLayer.fillColor = ballFillColor.cgColor 21 | } 22 | } 23 | 24 | fileprivate var unitThreshold: CGFloat = 0 25 | 26 | var currentPath: CGPath? { 27 | didSet { 28 | pathLayer.path = currentPath 29 | } 30 | } 31 | 32 | fileprivate var pathLayer = CAShapeLayer() 33 | 34 | fileprivate var minSizeBall: CGFloat = 1000 { 35 | didSet { 36 | unitThreshold = fieldThreshold / minSizeBall 37 | } 38 | } 39 | 40 | fileprivate(set) var metaBalls: [MetaBall] = [] 41 | 42 | override init(frame: CGRect) { 43 | let rect = CGRect(x: frame.minX, y: frame.minY, width: CGFloat(Int(frame.width)), height: CGFloat(Int(frame.height))) 44 | 45 | super.init(frame: rect) 46 | 47 | pathLayer.fillColor = ballFillColor.cgColor 48 | pathLayer.frame = bounds 49 | layer.addSublayer(pathLayer) 50 | } 51 | 52 | required init?(coder aDecoder: NSCoder) { 53 | super.init(coder: aDecoder) 54 | } 55 | 56 | func addMetaBallAt(_ position: CGPoint, radius: CGFloat) { 57 | let newBall = MetaBall(center: position, radius: radius) 58 | addMetaBall(newBall) 59 | } 60 | 61 | func addMetaBall(_ metaBall: MetaBall) { 62 | metaBalls.append(metaBall) 63 | updateMinSize() 64 | setNeedsDisplay() 65 | } 66 | 67 | fileprivate func updateMinSize() { 68 | minSizeBall = 100000 69 | for metaBall in metaBalls { 70 | if metaBall.mess < minSizeBall { 71 | minSizeBall = metaBall.mess 72 | } 73 | } 74 | } 75 | 76 | func pathForCurrentConfiguration() -> CGPath? { 77 | 78 | let path = CGMutablePath() 79 | 80 | for metaBall in metaBalls { 81 | metaBall.trackingPosition = trackTheBorder(GLKVector2Add(metaBall.center, GLKVector2Make(0, 1))) 82 | metaBall.borderPosition = metaBall.trackingPosition 83 | 84 | metaBall.tracking = true 85 | } 86 | 87 | for metaBall in metaBalls { 88 | 89 | path.move(to: CGPoint(x: CGFloat(metaBall.borderPosition.x), y: CGFloat(metaBall.borderPosition.y))) 90 | 91 | for i in 0..<1000 { 92 | 93 | if !metaBall.tracking { 94 | break 95 | } 96 | 97 | // Store the old tracking position 98 | // Walk along the tangent 99 | metaBall.trackingPosition = rungeKutta2(metaBall.trackingPosition, h: rungKutaStep, targetFunction: { 100 | let tenant = self.tangentAt($0) 101 | return tenant 102 | }) 103 | 104 | // Correction step towards the border 105 | (metaBall.trackingPosition, _) = stepOnceTowardsBorder(metaBall.trackingPosition) 106 | 107 | path.addLine(to: CGPoint(x: CGFloat(metaBall.trackingPosition.x), y: CGFloat(metaBall.trackingPosition.y))) 108 | 109 | // Check if we've gone a full circle or hit some other edge tracker 110 | for otherBall in metaBalls { 111 | if (otherBall !== metaBall || i > 3) && GLKVector2Distance(otherBall.borderPosition, metaBall.trackingPosition) < rungKutaStep { 112 | // CGPathCloseSubpath(metaBall.borderPath) 113 | if otherBall !== metaBall { 114 | path.addLine(to: CGPoint(x: CGFloat(otherBall.borderPosition.x), y: CGFloat(otherBall.borderPosition.y))) 115 | } else { 116 | path.closeSubpath() 117 | } 118 | 119 | metaBall.tracking = false 120 | } 121 | } 122 | } 123 | } 124 | 125 | return path 126 | } 127 | 128 | private func trackTheBorder(_ position: GLKVector2) -> GLKVector2 { 129 | var position = position 130 | // Track the border of the metaball and return new coordinates 131 | var currentForce: CGFloat = 1000000 132 | 133 | while currentForce > fieldThreshold { 134 | (position, currentForce) = stepOnceTowardsBorder(position) 135 | 136 | if !bounds.contains(CGPoint(x: CGFloat(position.x), y: CGFloat(position.y))) { 137 | continue 138 | } 139 | } 140 | 141 | return position 142 | } 143 | 144 | fileprivate func stepOnceTowardsBorder(_ position: GLKVector2) -> (GLKVector2, CGFloat) { 145 | // Step once towards the border of the metaball field, return the new coordinates and force at old coordinates. 146 | let force = forceAt(position) 147 | let np = normalAt(position) 148 | 149 | let stepSize = pow(minSizeBall / fieldThreshold, 1 / DistanceConstant) - 150 | pow(minSizeBall / force, 1 / DistanceConstant) + 0.01 151 | return (GLKVector2Add(position, GLKVector2MultiplyScalar(np, Float(stepSize))), force) 152 | } 153 | 154 | fileprivate func tangentAt(_ position: GLKVector2) -> GLKVector2 { 155 | // Normalized (length = 1) tangent at position 156 | let np = normalAt(position) 157 | 158 | return GLKVector2Make(-np.y, np.x) 159 | } 160 | 161 | fileprivate func normalAt(_ position: GLKVector2) -> GLKVector2 { 162 | // Normalized (length = 1) normal at position 163 | 164 | var totalNormal = GLKVector2Make(0, 0) 165 | 166 | // Loop through the meta balls 167 | for metaBall in metaBalls { 168 | let div = pow(GLKVector2Distance(metaBall.center, position), Float(2 + DistanceConstant)) 169 | let addition = GLKVector2MultiplyScalar(GLKVector2Subtract(metaBall.center, position), 170 | Float(-DistanceConstant * metaBall.mess) / div) 171 | totalNormal = GLKVector2Add(totalNormal, addition) 172 | } 173 | 174 | return GLKVector2Normalize(totalNormal) 175 | } 176 | 177 | fileprivate func forceAt(_ position: GLKVector2) -> CGFloat { 178 | var totalForce: CGFloat = 0 179 | 180 | // Loop through the meta balls and calculate the total force 181 | for metaBall in metaBalls { 182 | totalForce += metaBall.forceAt(position) 183 | } 184 | 185 | return totalForce 186 | } 187 | 188 | fileprivate func rungeKutta2(_ position: GLKVector2, h: Float, targetFunction: (GLKVector2) -> GLKVector2) -> GLKVector2 { 189 | let oneTime = GLKVector2MultiplyScalar(targetFunction(position), h / 2) 190 | let nextInput = GLKVector2Add(position, oneTime) 191 | let twoTime = GLKVector2MultiplyScalar(targetFunction(nextInput), h) 192 | 193 | return GLKVector2Add(position, twoTime) 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /MetaSpinExample/Sources/MetaSpin.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MetaSpin.swift 3 | // MetaSpinExample 4 | // 5 | // Created by Jin Wang on 21/04/2015. 6 | // Copyright (c) 2015 uthoft. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import GLKit 11 | 12 | class MetaSpin: UIView { 13 | 14 | var centralBallRadius: CGFloat = 50 { 15 | didSet { 16 | centralBall.radius = centralBallRadius 17 | cruiseRadius = (centralBallRadius + sideBallRadius) / 2 * 1.3 18 | } 19 | } 20 | var sideBallRadius: CGFloat = 10 { 21 | didSet { 22 | self.sideBall.radius = sideBallRadius 23 | cruiseRadius = (centralBallRadius + sideBallRadius) / 2 * 1.3 24 | } 25 | } 26 | var cruiseRadius: CGFloat = 50 27 | var ballFillColor: UIColor = UIColor.white { 28 | didSet { 29 | self.metaField.ballFillColor = ballFillColor 30 | } 31 | } 32 | 33 | // The following two variables will toggle the speed and the efficiency of the ball. 34 | var speed: CGFloat = 0.02 35 | 36 | fileprivate var centralBall: MetaBall! 37 | fileprivate var sideBall: MetaBall! 38 | fileprivate var metaField: MetaField! 39 | 40 | override init(frame: CGRect) { 41 | super.init(frame: frame) 42 | 43 | // Set backgrounds 44 | backgroundColor = UIColor.clear 45 | 46 | metaField = MetaField(frame: frame) 47 | metaField.backgroundColor = UIColor.clear 48 | 49 | addCentralBall() 50 | addSideBall() 51 | 52 | addSubview(metaField) 53 | } 54 | 55 | required init?(coder aDecoder: NSCoder) { 56 | super.init(coder: aDecoder) 57 | } 58 | 59 | fileprivate func addCentralBall() { 60 | centralBall = MetaBall(center: center, radius: centralBallRadius) 61 | 62 | metaField.addMetaBall(centralBall) 63 | } 64 | 65 | fileprivate func addSideBall() { 66 | sideBall = MetaBall(center: CGPoint(x: center.x, y: center.y), radius: sideBallRadius) 67 | 68 | metaField.addMetaBall(sideBall) 69 | } 70 | 71 | func animateSideBall() { 72 | // let animationCenter = CGPoint(x: CGFloat(centralBall.center.x), y: CGFloat(centralBall.center.y) - centralBall.radius) 73 | // 74 | // let animationPath = UIBezierPath(arcCenter: animationCenter, radius: centralBall.radius, startAngle: CGFloat(3 * M_PI_2), endAngle: CGFloat(7 * M_PI_2), clockwise: true) 75 | // 76 | // let pathAnimation = CAKeyframeAnimation(keyPath: "position") 77 | // pathAnimation.path = animationPath.CGPath 78 | // pathAnimation.calculationMode = kCAAnimationPaced 79 | // pathAnimation.fillMode = kCAFillModeForwards 80 | // pathAnimation.removedOnCompletion = false 81 | // pathAnimation.repeatCount = HUGE 82 | // pathAnimation.duration = 1.0 83 | // pathAnimation.delegate = self 84 | // 85 | 86 | let displayLink = CADisplayLink(target: self, selector: #selector(MetaSpin.moveSideBall)) 87 | 88 | displayLink.add(to: RunLoop.main, forMode: RunLoopMode.defaultRunLoopMode) 89 | } 90 | 91 | var currentAngle = CGFloat(0) 92 | var maxAngle = CGFloat(2.0 * M_PI) 93 | var flip = false 94 | 95 | fileprivate var pathPool: [Float: CGPath] = [:] 96 | 97 | func moveSideBall() { 98 | nextAngle() 99 | 100 | let adjustedAngle = toEaseIn(toEaseIn(currentAngle)) 101 | 102 | sideBall.center = newCenter(adjustedAngle, relatedToCenter: centralBall.center) 103 | 104 | let centerIndex = sideBall.center.x * sideBall.center.y 105 | 106 | // We'll store the path and reuse it. 107 | if pathPool[centerIndex] == nil { 108 | pathPool[centerIndex] = metaField.pathForCurrentConfiguration() 109 | } 110 | 111 | metaField.currentPath = pathPool[centerIndex] 112 | 113 | metaField.setNeedsDisplay() 114 | } 115 | 116 | func newCenter(_ angle: CGFloat, relatedToCenter center: GLKVector2) -> GLKVector2 { 117 | let x = center.x + Float(cruiseRadius) * Float(flip ? -sin(angle) : sin(angle)) 118 | let y = center.y + Float(flip ? cruiseRadius : -cruiseRadius) + Float(cruiseRadius) * Float(flip ? -cos(angle) : cos(angle)) 119 | 120 | return GLKVector2Make(x, y) 121 | } 122 | 123 | fileprivate func nextAngle() { 124 | if currentAngle >= maxAngle { 125 | currentAngle = 0 126 | flip = !flip 127 | } else { 128 | currentAngle += CGFloat(maxAngle * speed) 129 | } 130 | 131 | } 132 | 133 | fileprivate func toEaseIn(_ angle: CGFloat) -> CGFloat { 134 | let ratio = angle / CGFloat(2 * M_PI) 135 | var processed_ratio: CGFloat = ratio 136 | if ratio < 0.5 { 137 | processed_ratio = (1 - pow(1 - ratio, 3.0)) * 8 / 14 138 | } else { 139 | processed_ratio = 1 - (1 - pow(ratio, 3.0)) * 8 / 14 140 | } 141 | 142 | return processed_ratio * CGFloat(2 * M_PI) 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /MetaSpinExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // MetaSpinExample 4 | // 5 | // Created by Jin Wang on 21/04/2015. 6 | // Copyright (c) 2015 uthoft. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | 17 | let metaSpin = MetaSpin(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) 18 | metaSpin.center = view.center 19 | metaSpin.ballFillColor = UIColor(red: 189/255, green: 195/255, blue: 199/255, alpha: 1.0) 20 | metaSpin.centralBallRadius = 50.0 21 | metaSpin.sideBallRadius = 15.0 22 | metaSpin.speed = 0.02 23 | 24 | view.backgroundColor = UIColor(red: 52/255, green: 73/255, blue: 94/255, alpha: 1.0) 25 | 26 | view.addSubview(metaSpin) 27 | 28 | metaSpin.animateSideBall() 29 | } 30 | 31 | override func didReceiveMemoryWarning() { 32 | super.didReceiveMemoryWarning() 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /MetaSpinExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /MetaSpinExampleTests/MetaSpinExampleTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MetaSpinExampleTests.swift 3 | // MetaSpinExampleTests 4 | // 5 | // Created by Jin Wang on 21/04/2015. 6 | // Copyright (c) 2015 uthoft. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class MetaSpinExampleTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MetaballLoader 2 | A metaball loader written in Swift. 3 | 4 | # Look like this 5 | 6 | ![Demo](https://raw.githubusercontent.com/KelvinJin/MetaballLoader/master/demo.gif) 7 | 8 | # License 9 | MIT 10 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KelvinJin/MetaballLoader/ab1aac255717aca4e14c9c93806fc1de0bdda7a3/demo.gif --------------------------------------------------------------------------------