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 CoreGraphics | |
extension CGImage { | |
func grayscalePixelData() -> [UInt8] { | |
let startTime = CACurrentMediaTime() | |
let size = CGSize(width: self.width, | |
height: self.height) | |
let dataSize = size.width * size.height | |
var pixelData = [UInt8](repeating: 0, |
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 Foundation | |
func getProperties(of object: AnyObject) -> [Any?] { | |
return self.getPropertyNames(of: type(of: object)).map { value(forKey: $0) } | |
} | |
func getPropertyNames(of type: AnyClass) -> [String] { | |
var count: UInt32 = 0 | |
let propertyList = class_copyPropertyList(type, &count) | |
let propertyArray = Array(UnsafeBufferPointer(start: propertyList, count: Int(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 CoreGraphics | |
import Accelerate | |
import CoreImage | |
import UIKit | |
extension CGImage { | |
public enum Error: Swift.Error { | |
case imageResizingFailed | |
case cgContextCreationFailed |
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 SceneKit | |
func createAxesNode(quiverLength: CGFloat, quiverThickness: CGFloat) -> SCNNode { | |
let quiverThickness = (quiverLength / 50.0) * quiverThickness | |
let chamferRadius = quiverThickness / 2.0 | |
let xQuiverBox = SCNBox(width: quiverLength, height: quiverThickness, length: quiverThickness, chamferRadius: chamferRadius) | |
xQuiverBox.materials = [SCNMaterial.material(withDiffuse: UIColor.red, respondsToLighting: false)] | |
let xQuiverNode = SCNNode(geometry: xQuiverBox) | |
xQuiverNode.position = SCNVector3Make(Float(quiverLength / 2.0), 0.0, 0.0) |
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 SceneKit | |
public class LineNode: SCNNode { | |
// Properties | |
var startPoint: SCNVector3! | |
var endPoint: SCNVector3! | |
var radius: CGFloat! | |
var color: UIColor! | |
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 ARKit | |
extension ARSCNView { | |
func setup() { | |
antialiasingMode = .multisampling4X | |
automaticallyUpdatesLighting = false | |
preferredFramesPerSecond = 60 | |
contentScaleFactor = 1.3 |
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 CGRect { | |
var mid: CGPoint { | |
return CGPoint(x: midX, y: midY) | |
} | |
} |
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 CGSize { | |
init(_ point: CGPoint) { | |
self.width = point.x | |
self.height = point.y | |
} | |
func friendlyString() -> String { | |
return "(\(String(format: "%.2f", width)), \(String(format: "%.2f", 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
extension CGPoint { | |
init(_ size: CGSize) { | |
self.x = size.width | |
self.y = size.height | |
} | |
init(_ vector: SCNVector3) { | |
self.x = CGFloat(vector.x) | |
self.y = CGFloat(vector.y) |
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 SCNMaterial { | |
static func material(withDiffuse diffuse: Any?, respondsToLighting: Bool = true) -> SCNMaterial { | |
let material = SCNMaterial() | |
material.diffuse.contents = diffuse | |
material.isDoubleSided = true | |
if respondsToLighting { | |
material.locksAmbientWithDiffuse = true | |
} else { | |
material.ambient.contents = UIColor.black |
NewerOlder