Skip to content

Instantly share code, notes, and snippets.

View heestand-xyz's full-sized avatar

Anton Heestand heestand-xyz

View GitHub Profile
@heestand-xyz
heestand-xyz / pixels-city.swift
Last active March 1, 2019 11:05
Pixels - City
let imagePix = ImagePIX()
imagePix.image = UIImage(named: "city")!
let resPix = ResPIX(res: .fullscreen)
resPix.fillMode = .aspectFill
resPix.inPix = imagePix
let force: LiveFloat = .touchForce
let finalPix = BlendsPIX.loop(0..<3, with: .add, loop: { i, ix in
let fraction = LiveFloat(i) / LiveFloat(3)
@heestand-xyz
heestand-xyz / pixels-circle-feed.swift
Last active March 12, 2019 12:42
Pixels - Circle Feed
let circlePix = CirclePIX(res: ._1024)
circlePix.radius = 1 / 3
let noisePix = NoisePIX(res: ._1024)
noisePix.zPosition = .live / 10
noisePix.octaves = 3
noisePix.colored = true
let dispPix = circlePix._edge()._displace(with: noisePix, distance: 0.1)
@heestand-xyz
heestand-xyz / frag_hexagon.swift
Last active May 3, 2019 07:46
Frag - Hexagon
let hexagon = MetalPIX(res: particleRes, uniforms: [
MetalUniform(name: "resx", value: LiveFloat(particleRes.width)),
MetalUniform(name: "resy", value: LiveFloat(particleRes.height))
], code:
"""
int x = int(u * in.resx);
int y = int(v * in.resy);
int i = y * int(in.resx) + x;
float f = float(i) / (in.resx * in.resy);
int hexi = int(f * 6);
let cirlce = MetalPIX(res: ._256, uniforms: [
MetalUniform(name: "resx", value: 256),
MetalUniform(name: "resy", value: 256)
], code:
"""
int x = int(u * in.resx);
int y = int(v * in.resy);
int i = y * int(in.resx) + x;
float f = float(i) / (in.resx * in.resy);
pix = float4(cos(f*pi*2)/2+0.5,sin(f*pi*2)/2+0.5,0,1);
var filterCaches: [String: [CGFloat]] = [:]
func filter(_ value: CGFloat, for seconds: CGFloat, smooth: Bool = true, bypassLow: Bool = false, bypassHigh: Bool = false, id: String) -> CGFloat {
guard filterCaches[id] != nil else {
filterCaches[id] = [value]
return value
}
filterCaches[id]!.append(value)
let frameCount = Int(seconds * CGFloat(60))
while filterCaches[id]!.count > frameCount {
filterCaches[id]!.remove(at: 0)
// QLPreviewControllerDataSource
var medaUrl: URL?
// MARK: - Quick Look
func quickLook(_ url: URL) {
medaUrl = url
let previewController = QLPreviewController()
previewController.dataSource = self
@heestand-xyz
heestand-xyz / image-resize.swift
Last active November 20, 2019 07:04
Image Resize - Aspect Fit / Fill
public enum ImagePlacement {
case fill
case fit
}
public static func resize(_ image: UIImage, to size: CGSize, placement: ImagePlacement = .fill) -> UIImage {
let frame: CGRect
switch placement {
case .fit:
@heestand-xyz
heestand-xyz / liquid.swift
Created September 27, 2019 13:26
PixelKit - Liquid
PixelKit.main.bits = ._16
let ply = PolygonPIX()
ply.radius = 0.125
let feed = ply._feed(0.99) { feed in
feed._noiseDisplace(distance: 0.01, zPosition: .live / 10, octaves: 10)
}
return feed._edge(100)._quantize(0.1)._edge(10)
import SwiftUI
struct DileView<Content: View>: View {
let kColCount: Int = 3
let scale: CGFloat
let defaultIndex: Int
let options: () -> ([Content])
let selected: (Int) -> ()
@State var index: Int = 0
@State var open: Bool = false
@heestand-xyz
heestand-xyz / cases.swift
Last active August 7, 2020 19:21
Swift Cases
import Foundation
fileprivate let badChars = CharacterSet.alphanumerics.inverted
public extension String {
var camelToTitleCased: String {
if self.count <= 1 {
return self.uppercased()
}