Skip to content

Instantly share code, notes, and snippets.

View JoshuaSullivan's full-sized avatar

Joshua Sullivan JoshuaSullivan

View GitHub Profile
@JoshuaSullivan
JoshuaSullivan / UIImage.Orientation+Correction.swift
Created December 3, 2018 17:32
An extension on `UIImage.Orientation` to convert it to the corresponding `CGImagePropertyOrientation` case.
extension UIImage.Orientation {
/// Get the equivalent `CGImagePropertyOrientation` enum case.
var cgOrientation: CGImagePropertyOrientation {
switch self {
case .up: return .up
case .down: return .down
case .left: return .left
case .right: return .right
case .upMirrored: return .upMirrored
case .downMirrored: return .downMirrored
@JoshuaSullivan
JoshuaSullivan / natural-language-playground.swift
Last active August 2, 2018 03:22
This playground demonstrates several features of the NaturalLanguage framework that's new in iOS 12.
//: # Natural Language Framework
//: by Josh Sullivan
import Swift
import NaturalLanguage
//: Create a short string to test.
let str = "I am the very model of a modern major general! 😎"
//: And a longer one. Yay, multi-line String literals!
let longStr = """
@JoshuaSullivan
JoshuaSullivan / swift4-kvo-playground.swift
Created May 11, 2018 15:15
Here is a playground demonstrating how to set up Swift 4 KVO.
//: # Setting up Swift 4 KVO
import Foundation
//: This class has a pair of properties that can be observied by KVO.
//: - Note: This class *must* inheret from `NSObject` in order to posess the KVO functionality.
class ObservableClass: NSObject {
/// An observable string property. Note that it most be annotated with both "@objc" (expose the property to the
/// Objective-C runtime) and "dynamic" (enables KVO for the property).
@objc dynamic private(set) var stringProperty: String = "Starting string!"
@JoshuaSullivan
JoshuaSullivan / mobius-ring.pde
Created March 22, 2018 02:04
Processing script for rendering a Möbius Strip.
class MobiusRing {
float majorRadius, minorRadius;
int segments;
PVector[] vertices;
MobiusRing(float majorRadius, float minorRadius, int segments) {
this.majorRadius = majorRadius;
this.minorRadius = minorRadius;
this.segments = segments;
@JoshuaSullivan
JoshuaSullivan / CollectionViewDelegateSplitter.swift
Created December 8, 2017 20:08
These two shims allow you to split the UIScrollViewDelegate calls from the collection and table view delegate calls.
//
// CollectionViewDelegateSplitter.swift
//
// Created by Joshua Sullivan on 12/7/17.
//
import UIKit
class CollectionViewDelegateSplitter: NSObject, UICollectionViewDelegate {
/// The object which will receive collection-related delegate actions.
@JoshuaSullivan
JoshuaSullivan / arkit-quickstart.markdown
Last active October 3, 2017 17:38
A quick guide for getting up and running with ARKit.

Getting Started with ARKit

First things first: Augmented Reality is an inherently 3D activity. The ease with which you pick it up will be directly proportional to your existing experience working in 3D. This is not to say someone without 3D experience can't do AR, but it will be harder for you until you become more familiar with common 3D principles. The skill set used for creating 3D games and AR experiences are essentially the same.

If your'e a complete 3D noob, I suggest checking out some of the RayWenderlich.com tutorials on getting started with 3D game development.

Step 1: Choose your IDE

The first decision to make is whether you want to use Xcode or a 3D game framework such as Unity or Unreal to create your experience. For the purposes of this guide, I'll assume you will choose Xcode, simply because I have no personal experience with the other two options. If you're already experienced with one of them or are feeling adventurous, then I'm sure you can find AR learning resources online.

X

@JoshuaSullivan
JoshuaSullivan / CapturedImageSampler.swift
Created October 1, 2017 01:38
The source code for an object that helps you sample RGB values from ARFrames.
//
// CapturedImageSampler.swift
// ARKitTest
//
// Created by Joshua Sullivan on 9/22/17.
// Copyright © 2017 Joshua Sullivan. All rights reserved.
//
import UIKit
import ARKit
@JoshuaSullivan
JoshuaSullivan / dmx.swift
Created August 31, 2017 19:25
In case you were wondering who was going to give it to you…
import Swift
struct Giver {
enum Receiver {
case ya
}
private var name: String
init(name: String) {
@JoshuaSullivan
JoshuaSullivan / pillars_fountain.pde
Last active July 14, 2017 14:27
Some forms of motion amuse the system more than others…
final int PILLAR_ORDER = 12;
final int DIAGONALS = PILLAR_ORDER * 2 - 1;
final float PILLAR_WIDTH = 20.0;
final float PILLAR_HEIGHT = 10.0;
final float PILLAR_SPACING = 2.0;
final float GRAVITY = -1.0;
final float ELASTICITY = -0.5;
final float MAX_HEIGHT = 500.0;
@JoshuaSullivan
JoshuaSullivan / pillars_complexity.pde
Last active July 14, 2017 00:43
As the system matures, it gains increasingly complex behavior…
final int PILLAR_ORDER = 8;
final int DIAGONALS = PILLAR_ORDER * 2 - 1;
final float PILLAR_WIDTH = 30.0;
final float PILLAR_HEIGHT = 15.0;
final float PILLAR_SPACING = 2.0;
final float GRAVITY = -1.0;
final float ELASTICITY = -0.6;
final float MAX_HEIGHT = 500.0;