Skip to content

Instantly share code, notes, and snippets.

View JoshuaSullivan's full-sized avatar

Joshua Sullivan JoshuaSullivan

View GitHub Profile
@JoshuaSullivan
JoshuaSullivan / ColorCubeHelper-swift2.swift
Last active April 17, 2024 10:48
Here are the Swift 2.3 and Swift 3.0 versions of the ColorCubeHelper class.
//
// ColorCubeHelper.swift
//
// Created by Joshua Sullivan on 10/01/16.
// Copyright © 2016 Joshua Sullivan. All rights reserved.
//
import UIKit
import Accelerate
@JoshuaSullivan
JoshuaSullivan / WUndergroundAPIClient.swift
Last active June 23, 2016 15:20
This is a Swift Playground file implementing a solution to Challenge Accepted #49.
//: # Challenge Accepted #49
//: ## WUnderground API Client
//: ### Version 2.0
//:
//: Implement the networking layer for the Umbrella weather app(iOS or Android),
//: using a similar architecture to the one demonstrated in the first episode of Swift Talks.
//:
//: - note:
//: This is my updated solution to the challenge which demonstrates a more powerful and flexible
//: approach to customizing the request sent to the API through the use of closures rather than
@JoshuaSullivan
JoshuaSullivan / ColorCubeImageCreator-swift2.swift
Last active April 25, 2023 16:45
The Color Cube Image Creator creates the specially formatted images needed to create data for the CIColorCube filter.
//
// ColorCubeImageCreator.swift
// ColorCubeImageCreator
//
// Created by Joshua Sullivan on 4/25/16.
// Copyright © 2016 Joshua Sullivan. All rights reserved.
//
import UIKit
@JoshuaSullivan
JoshuaSullivan / MTKViewController.swift
Last active April 21, 2016 18:06
Trying to figure out why the View Controller using a MTKView and a Metal-backed CIContext runs at 1/3 of the speed of an GLKView + OpenGLES2-backed CIContext.
//
// ViewController.swift
// MetalCoreImage
//
// Created by Joshua Sullivan on 4/21/16.
// Copyright © 2016 The Nerdery. All rights reserved.
//
import UIKit
import MetalKit
@JoshuaSullivan
JoshuaSullivan / OptionalReturn.swift
Created March 3, 2016 16:37
Code snippets for my blog post about functions which return optional values vs functions that throw errors.
import Swift
/// This method returns half of the input value if the number is even. It returns nil if the number is odd.
func evenHalfOrNil(input: Int) -> Int? {
if (input % 2 == 0) {
return input / 2
} else {
return nil
}
}
@JoshuaSullivan
JoshuaSullivan / SparkBall.pde
Created February 25, 2016 22:56
A Processing 3 sketch animating sprites moving smoothly about the interior of an imaginary cube.
static float FOCAL_LENGTH = 200.0;
static float ORBIT_RADIUS = 180.0;
static int SPARK_COUNT = 200;
class Spark {
color clr;
float orbitRadius;
float rx, ry, rz, drx, dry, drz;
Spark(color c, float orbitRadius) {
this.clr = c;
@JoshuaSullivan
JoshuaSullivan / MakingWaves.pde
Created February 19, 2016 20:49
A Processing 3.0 sketch animating some waves!
class SingleWave {
float SEGMENTS_PER_CYCLE = 48.0;
float wavelength, r, dr;
color drawColor;
SingleWave(float wavelength, color drawColor) {
this.wavelength = wavelength;
this.drawColor = drawColor;
@JoshuaSullivan
JoshuaSullivan / TouchCaptureControl.swift
Created February 18, 2016 16:53
This is a simple control which maps touches within its bounds to a 0.0 - 1.0 range on the horizontal and vertical axes, returned as a CIVector.
class TouchCaptureControl: UIControl {
var value: CIVector = CIVector(x: 0.0, y: 0.0)
@IBInspectable var horizontalMinimumValue: CGFloat = 0.0
@IBInspectable var horizontalMaximumValue: CGFloat = 1.0
@IBInspectable var verticalMinimumValue: CGFloat = 0.0
@IBInspectable var verticalMaximumValue: CGFloat = 1.0
@IBInspectable var flipHorizontalAxis: Bool = false
@IBInspectable var flipVerticalAxis: Bool = false
@JoshuaSullivan
JoshuaSullivan / PerlinNoise.cikernel
Last active July 10, 2023 22:51
My attempt at writing a Perlin Noise function.
// Improved Noise - Copyright 2002 Ken Perlin.
// Adapted and updated for iOS by Joshua Sullivan, 2016.01.12
// Apply the function 6t^5 - 15t^4 + 10t^3
float fade(float t)
{
return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
}
// I'm keeping this around for reference.
@JoshuaSullivan
JoshuaSullivan / Confusion.cikernel
Created January 26, 2016 19:47
A confusing issue with the CIKernel's sample() method. Assigning the result of samplerTransform() to a variable and then using it in the sample() method breaks everything.
// This works.
kernel vec4 simpleFilter(sampler p)
{
vec2 dc = destCoord();
return sample(p, samplerTransform(p, dc));
}
// This does not. It produces [0, 0, 0, 255] for the first 255 pixels and then [0, 0, 0, 0] thereafter.
kernel vec4 simpleFilter(sampler p)
{