Skip to content

Instantly share code, notes, and snippets.

View larsaugustin's full-sized avatar

Lars Augustin larsaugustin

View GitHub Profile
@larsaugustin
larsaugustin / RetroDock.swift
Created May 26, 2021 15:33
A macOS dock replacement with a modernized version of the design used before Yosemite
import SwiftUI
// MARK: - Constants
// Items in the dock: Add any application you’d like to see in here
let items =
[
"file:///Applications/Xcode.app",
"file:///Applications/Safari.app",
"file:///System/Applications/Messages.app",
@larsaugustin
larsaugustin / InnerShadow.swift
Created February 1, 2021 19:41
SwiftUI Inner Shadow
extension View {
@ViewBuilder func innerShadow<ShapeType: Shape>(_ shape: ShapeType, color: Color, radius: CGFloat = 10, spread: CGFloat = 4, x: CGFloat = 0, y: CGFloat = 0) -> some View {
self
.overlay(
shape.stroke(Color.clear, lineWidth: spread * 2)
.shadow(color: color, radius: radius, x: x, y: y)
)
.clipShape(shape)
}
}
@larsaugustin
larsaugustin / ExampleView.swift
Created August 19, 2020 16:59
Conditional view modifiers in SwiftUI
struct ExampleView: View {
var body: some View {
Text("Example")
.if(true) { $0.foregroundColor(.red) }
}
}
@larsaugustin
larsaugustin / Synth.swift
Created May 23, 2020 14:04
A simple synthesizer class in Swift
class Synthesizer {
// MARK: - Variables
var audioEngine: AVAudioEngine!
var sourceNode: AVAudioSourceNode!
var time = Float.zero
var frequencyRamp = Float.zero
var currentFrequency: Float = 20 {
didSet {
@larsaugustin
larsaugustin / reRender.swift
Created January 26, 2020 13:02
Get an array of pixels from an NSImage and use this array to render the image. Handy for performing per-pixel operations on an image
import Cocoa
// Representation of a pixel
struct Pixel {
var a: UInt8
var r: UInt8
var g: UInt8
var b: UInt8
}