Skip to content

Commit

Permalink
Finish logo
Browse files Browse the repository at this point in the history
  • Loading branch information
aheze committed Sep 27, 2022
1 parent 0a47f4c commit d2cae20
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Example/PrismExample/PrismExample/Gallery/GalleryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -35,6 +36,8 @@ struct GalleryView: View {
SlimeGalleryView(model: model)

TransformGalleryView(model: model)

LogoGalleryView(model: model)
} header: {
Text("Showcase")
.foregroundColor(UIColor.secondaryLabel.color)
Expand Down Expand Up @@ -67,6 +70,8 @@ struct GalleryView: View {
SlimeDetailView()
case .transform:
TransformDetailView()
case .logo:
LogoDetailView()
case .color:
ColorDetailView()
case .gradient:
Expand Down
116 changes: 114 additions & 2 deletions Example/PrismExample/PrismExample/Showcase/Logo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
19 changes: 19 additions & 0 deletions Example/PrismExample/PrismExample/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit d2cae20

Please sign in to comment.