diff --git a/Example/PrismExample/PrismExample/Gallery/GalleryView.swift b/Example/PrismExample/PrismExample/Gallery/GalleryView.swift index 121a84b..d812e49 100644 --- a/Example/PrismExample/PrismExample/Gallery/GalleryView.swift +++ b/Example/PrismExample/PrismExample/Gallery/GalleryView.swift @@ -13,6 +13,7 @@ enum ExampleKind: String { case basic = "Basic" case slime = "Slime" case transform = "Transform" + case logo = "Logo" case color = "Color" case gradient = "Gradient" @@ -35,6 +36,8 @@ struct GalleryView: View { SlimeGalleryView(model: model) TransformGalleryView(model: model) + + LogoGalleryView(model: model) } header: { Text("Showcase") .foregroundColor(UIColor.secondaryLabel.color) @@ -67,6 +70,8 @@ struct GalleryView: View { SlimeDetailView() case .transform: TransformDetailView() + case .logo: + LogoDetailView() case .color: ColorDetailView() case .gradient: diff --git a/Example/PrismExample/PrismExample/Showcase/Logo.swift b/Example/PrismExample/PrismExample/Showcase/Logo.swift index a8c9016..879c47a 100644 --- a/Example/PrismExample/PrismExample/Showcase/Logo.swift +++ b/Example/PrismExample/PrismExample/Showcase/Logo.swift @@ -5,6 +5,118 @@ // Created by A. Zheng (github.com/aheze) on 9/26/22. // Copyright © 2022 A. Zheng. All rights reserved. // - -import Foundation +import Prism +import SwiftUI + +struct LogoGalleryView: View { + @ObservedObject var model: ViewModel + @State var configuration = PrismConfiguration( + tilt: 1, + size: .init(width: 60, height: 60), + extrusion: 60 + ) + + var body: some View { + GalleryCardView(model: model, kind: .logo) { + PrismCanvas(tilt: configuration.tilt) { + LogoPrismView(configuration: $configuration) + } + .scaleEffect(y: 0.78) + .frame(minHeight: 240) + .offset(y: 20) + } + } +} + +struct LogoDetailView: View { + @State var configuration = PrismConfiguration( + tilt: 1, + size: .init(width: 150, height: 150), + extrusion: 150 + ) + + var body: some View { + PrismCanvas(tilt: configuration.tilt) { + LogoPrismView(configuration: $configuration) + } + .scaleEffect(y: 0.78) + .navigationTitle("Logo") + } +} + +struct LogoPrismView: View { + @Binding var configuration: PrismConfiguration + + var body: some View { + PrismView(configuration: configuration) { + LinearGradient( + colors: [ + UIColor.systemBlue.color, + UIColor.systemBlue.offset(by: 0.02).color + ], + startPoint: .bottomTrailing, + endPoint: .topLeading + ) + .opacity(0.75) + .overlay { + sticker(point: .bottomTrailing) + } + } left: { + LinearGradient( + colors: [ + UIColor.systemBlue.color, + UIColor.systemBlue.offset(by: 0.02).color + ], + startPoint: .trailing, + endPoint: .leading + ) + .opacity(0.7) + .overlay { + sticker(point: .topTrailing) + } + } right: { + LinearGradient( + colors: [ + UIColor.systemBlue.color, + UIColor.systemBlue.offset(by: 0.02).color + ], + startPoint: .leading, + endPoint: .trailing + ) + .brightness(-0.1) + .opacity(0.7) + .overlay { + sticker(point: .topLeading) + } + } + } + + func sticker(point: UnitPoint) -> some View { + GeometryReader { geometry in + Rectangle() + .foregroundStyle( + .ellipticalGradient( + stops: [ + .init(color: UIColor.systemBlue.offset(by: -0.01).color, location: -0.2), + .init(color: UIColor.systemBlue.offset(by: 0.01).color, location: 1) + ], + center: point + ) + .shadow( + .inner( + color: .black.opacity(0.1), + radius: geometry.size.width / 10, + x: 0, + y: 0 + ) + ) + ) + .frame( + width: geometry.size.width * 2 / 3, + height: geometry.size.height * 2 / 3 + ) + .frame(maxWidth: .infinity, maxHeight: .infinity) + } + } +} diff --git a/Example/PrismExample/PrismExample/Utilities.swift b/Example/PrismExample/PrismExample/Utilities.swift index d693373..e0171ec 100644 --- a/Example/PrismExample/PrismExample/Utilities.swift +++ b/Example/PrismExample/PrismExample/Utilities.swift @@ -88,4 +88,23 @@ extension UIColor { alpha: 1.0 ) } + + var hsba: (h: CGFloat, s: CGFloat, b: CGFloat, a: CGFloat) { + var h: CGFloat = 0, s: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0 + self.getHue(&h, saturation: &s, brightness: &b, alpha: &a) + return (h: h, s: s, b: b, a: a) + } + + /// Get a gradient color. + func offset(by offset: CGFloat) -> UIColor { + let (h, s, b, a) = hsba + var newHue = h - offset + + /// Wrap back to positive values. + while newHue <= 0 { + newHue += 1 + } + let normalizedHue = newHue.truncatingRemainder(dividingBy: 1) + return UIColor(hue: normalizedHue, saturation: s, brightness: b, alpha: a) + } }