Skip to content

heestand-xyz/MetalUI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MetalUI

Install

.package(url: "https://github.com/heestand-xyz/MetalUI", from: "0.1.0")

Gradient Blur

| | |

import SwiftUI
import MetalUI

struct ContentView: View {
    
    @State var radius: CGFloat = 0.0
    @State var curve: CGFloat = 1
    
    var body: some View {
        VStack {
            Slider(value: $radius, in: 0...100)
            Slider(value: $curve, in: 0...2)
            HStack(spacing: 0) {
                Color.red
                Color.yellow
                Color.green
                Color.cyan
                Color.blue
            }
            .padding()
            .gradientBlur(
                axis: .vertical,
                radii: [0.0, radius],
                curve: curve
            )
        }
    }
}

#Preview {
    ContentView()
}

GradientBlurStop can also be used for more fine grained control over the stops.

Green Screen

| | |

import SwiftUI
import MetalUI

struct ContentView: View {
    var body: some View {
        ZStack {
            Color.blue
                .ignoresSafeArea()
            Image("Superman")
                .resizable()
                .aspectRatio(contentMode: .fit)
                .chromaKey(color: Color(red: 0.0,
                                        green: 1.0,
                                        blue: 0.0))
        }
    }
}

#Preview {
    ContentView()
}

Kaleidoscope

MetalUI.Kaleidoscope.mov
import SwiftUI
import MetalUI

struct ContentView: View {
    
    @State var value: CGFloat = 0.0
    
    var body: some View {
        VStack {
            Color.red
            Color.green
            Color.blue
        }
        .frame(width: 200, height: 200)
        .kaleidoscope(count: 12, angle: .degrees(180))
    }
}

#Preview {
    ContentView()
}

Circle Blur

import SwiftUI
import MetalUI

struct ContentView: View {
    
    @State var value: CGFloat = 0.0
    
    var body: some View {
        VStack {
            Text("Hello World")
                .padding()
                .border(Color.black)
                .circleBlur(value * 10)
            Slider(value: $value)
        }
        .padding()
        .frame(width: 250)
    }
}

#Preview {
    ContentView()
}

Feedback

import SwiftUI
import MetalUI

struct ContentView: View {
    
    var body: some View {
        Text("Hello, World!")
            .foregroundStyle(.white)
            .frame(maxWidth: .infinity,
                   maxHeight: .infinity)
            .feedback { source, loop in
                ZStack {
                    source
                        .opacity(0.1)
                    loop
                        .scaleEffect(1.01)
                        .opacity(0.99)
                }
            }
    }
}

#Preview {
    ContentView()
}

Edge

import SwiftUI
import MetalUI

struct ContentView: View {
    
    var content: some View {
        
    }
    
    var body: some View {
        HStack {
            Image(systemName: "globe")
            Text("Hello, World!")
        }
        .font(.system(size: 50, weight: .bold))
        .padding()
        .edge()
    }
}

#Preview {
    ContentView()
}

Pixelate

import SwiftUI
import MetalUI

struct ContentView: View {
    
    var body: some View {
        VStack {
            Text("Hello, World!")
            Text("Hello, World!")
                .pixelate()
            Text("Hello, World!")
                .quickPixelate()
        }
        .font(.largeTitle)
    }
}

#Preview {
    ContentView()
}

Noise

import SwiftUI
import MetalUI

struct ContentView: View {
    
    var body: some View {
        Noise()
    }
}

#Preview {
    ContentView()
}