This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//MARK: - Playground code | |
//: A UIKit based Playground for presenting user interface | |
import UIKit | |
import PlaygroundSupport | |
class MyViewController : UIViewController { | |
override func loadView() { | |
let view = PenroseView(frame: CGRect(x: 0, y: 0, width: 1000, height: 800)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UILabel { | |
func setText(_ text: String, prependedBySymbolNameed symbolSystemName: String, font: UIFont? = nil) { | |
if #available(iOS 13.0, *) { | |
if let font = font { self.font = font } | |
let symbolConfiguration = UIImage.SymbolConfiguration(font: self.font) | |
let symbolImage = UIImage(systemName: symbolSystemName, withConfiguration: symbolConfiguration)?.withRenderingMode(.alwaysTemplate) | |
let symbolTextAttachment = NSTextAttachment() | |
symbolTextAttachment.image = symbolImage | |
let attributedText = NSMutableAttributedString() | |
attributedText.append(NSAttributedString(attachment: symbolTextAttachment)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abandoned | |
able | |
absolute | |
adorable | |
adventurous | |
academic | |
acceptable | |
acclaimed | |
accomplished | |
accurate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns a random Emoji 🌿 | |
extension String{ | |
func randomEmoji()->String{ | |
let range = 0x1F601...0x1F64F | |
let ascii = range.startIndex + Int(arc4random_uniform(UInt32(range.count))) | |
let emoji = String(UnicodeScalar(ascii)) | |
return emoji | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// port of http://stackoverflow.com/a/17948778/3071224 | |
import UIKit | |
import Foundation | |
extension CGSize { | |
static func aspectFit(aspectRatio : CGSize, var boundingSize: CGSize) -> CGSize { | |
let mW = boundingSize.width / aspectRatio.width; | |
let mH = boundingSize.height / aspectRatio.height; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Permutations | |
// based on https://www.objc.io/blog/2014/12/08/functional-snippet-10-permutations/ | |
// but updated for Swift 2.0 (Xcode 7.0) | |
extension Array { | |
func decompose() -> (Generator.Element, [Generator.Element])? { | |
guard let x = first else { return nil } | |
return (x, Array(self[1..<count])) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// Returns a list of points on the convex hull in counter-clockwise order. | |
// Note: the last point in the returned list is the same as the first one. | |
// | |
// https://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain | |
// | |
func closedConvexHull(points_ : [CGPoint]) -> [CGPoint] { | |
// 2D cross product of OA and OB vectors, i.e. z-component of their 3D cross product. |