/PixelUI

Create Live Graphics in SwiftUI (iOS, tvOS & macOS)

Primary LanguageSwift

PixelUI

Install

Swift Package

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

Camera Example

import SwiftUI
import PixelUI
struct ContentView: View {

    var body: some View {

        Pixels {
            PixelCamera()
        }
    }
}

Gradients Example

import SwiftUI
import PixelUI
struct GradientsView: View {
    
    var body: some View {
        
        Pixels {
                    
            PixelBlends(mode: .add) {
                
                PixelGradient(axis: .vertical, colors: [.orange, .blue])
                
                PixelNoise()
            }
            .pixelGamma(0.75)
        }
    }
}

Effects Example

import SwiftUI
import PixelUI
struct EffectsView: View {
    
    var body: some View {
        
        Pixels {
            
            PixelImage("Kite")
                .pixelDisplace(300) {
                    
                    PixelBlends(mode: .over) {
                        Color.gray
                        PixelBlends(mode: .multiply) {
                            PixelNoise()
                            PixelGradient(axis: .radial, colors: [.clear, .white])
                        }
                    }
                }
                .pixelLumaSaturation(0.0) {
                    PixelGradient(axis: .radial)
                }
        }
    }
}

Shapes Example

import SwiftUI
import PixelUI
struct ShapesView: View {
    
    var body: some View {
        
        GeometryReader { geo in
            
            let radius = geo.size.height / 2
            
            Pixels {
                
                PixelBlends(mode: .difference) {
                    
                    PixelPolygon(count: 3, radius: radius)
                        .pixelCornerRadius(radius * 0.25)
                    
                    PixelPolygon(count: 3, radius: radius * 0.55)
                        .pixelCornerRadius(radius * 0.125)
                        .pixelFlip(.y)
                    
                    PixelCircle(radius: radius * 0.15)
                    
                    PixelBlendsForEach(0..<3, mode: .difference) { index in
                        let radians = (CGFloat(index) / 3) * .pi * 2 - .pi / 2
                        return PixelCircle(radius: radius * 0.15)
                            .pixelOffset(x: cos(radians) * radius * 0.5,
                                         y: sin(radians) * radius * 0.5)
                    }
                }
            }
        }
    }
}