Skip to content

Instantly share code, notes, and snippets.

View Priva28's full-sized avatar
🪴

Christian Privitelli Priva28

🪴
View GitHub Profile
@Priva28
Priva28 / VisionOSUniformSizedWindow.swift
Created February 22, 2024 10:12
A window in visionOS with a changeable aspect ratio.
import SwiftUI
public struct UniformWindowGroup<Content: View>: Scene {
var id: String?
var maxWidth: CGFloat
var maxHeight: CGFloat
var aspectRatio: CGFloat
var content: Content
@State private var setSize: CGSize?
@Priva28
Priva28 / CRTEffect.metal
Last active September 20, 2024 17:24
SwiftUI CRT effect using metal shaders.
#include <metal_stdlib>
#include <SwiftUI/SwiftUI.h>
using namespace metal;
float2 distort(float2 uv, float strength) {
float2 dist = 0.5 - uv;
uv.x = (uv.x - dist.y * dist.y * dist.x * strength);
uv.y = (uv.y - dist.x * dist.x * dist.y * strength);
return uv;
}
import SwiftUI
struct ContentView: View {
var body: some View {
Button {
} label: {
Text("Press this button")
.foregroundColor(.white)
.padding(12)
@Priva28
Priva28 / AudioPlayThrough.swift
Last active October 15, 2024 22:51
This is a basic Swift function that allows for incoming system audio to be played to the system output. It uses the modern Swift syntax for setting up and using RemoteIO Audio Units. I hope someone can use it to avoid the pains of having to use AVAudioEngine and understand how to setup RemoteIO Audio Units in Swift just a little bit easier :)
// This is a basic Swift function that allows for incoming system audio (like the microphone or USB input) to be
// played to the system output. It uses the modern Swift syntax for setting up and using RemoteIO Audio Units.
// Of course, before running this function, you would have to setup your AVAudioSession with the playAndRecord category,
// as well as whatever other options you might like. This is just a barebones function that demonstrates the capability
// and you should implement some better error handling and respond to audio session route changes or interruptions.
// I've only created this gist because even though it seems like it would be a simple thing, there is essentially
// zero documentation on anyone trying to do this on the entire internet, and if there was any, it was basically
// ancient and using Objective-C and outdated APIs. Now with this I hope someone can use it to avoid the pains of
// having to use AVAudioEngine and understand how to setup RemoteIO Audio Units in Swift just
@Priva28
Priva28 / GradientEffect.swift
Last active December 1, 2023 04:43
Gradient effect to emulate Apple Music Lyrics/Now Playing screen.
//
// ContentView.swift
// GradientEffect
//
// Created by Christian Privitelli on 18/7/20.
//
import SwiftUI
struct ContentView: View {